Moving home to it’s own partion (Ubuntu)

We are going to move all accounts including their personal data on a distinct partition. This recommended in case of system failure to not loose any data.
I have no idea, why the Ubuntu installation wizard does not do this by default — it should!

This post is based on an article in German – I will mainly translate it, strip some plush and add some stuff to make life easier and to reduce the risk of data loss. But be aware: to perform any of those following things, you will need super user rights and you should feel somewhat comfy with using the command line. And of course, it might be possible in circumstances unforeseen, that you lose all your personal data — but there are a lot of backup steps included below.

Here we go: (console input or statements are written in italics)

  1. Preparation
    1. Create a backup: rsync -avx –progress /home <your backup destination>
    2. If you do not have a free partition yet, I recommend GParted to create one (use sudo apt-get install gparted). I recommend ext3 for compatibility issues — but if you use Linux only, you can go for ext4 (please change ext3 to ext4 in step 1.6 in case) — make sure your new partition is big enough for your home folder! Try to remember the size (get size: du -sh /home) of /home, you can use it later on to verify your new home location.
    3. Get partion name sudo fdisk -l /dev/sda — e.g. /dev/sda7 — I will refer to this name as (name)
    4. Copy your current file system configuration: sudo cp /etc/fstab /etc/
    5. Get partion UUID of new partition: sudo blkid — you will find a line about (name) stating a UUID (quite a long hex string), I will refer to it as (uuid) — copy it.
    6. Edit /etc/, add a new line at the end as follows (the layout should follow previous lines – simply copy one and adjust it):
      UUID=(UUID)  /home                ext3         defaults                    0  2
  2. Copy
    1. Sign off / Log out
    2. Switch to console mode by pressing Ctrl+Alt+F1
    3. Create a mount point for the new partition: sudo mkdir /mnt/tmp
    4. Add partion: sudo mount (name) /mnt/tmp
    5. Copy home from the old location to the new partition: sudo rsync -avx –progress /home/ /mnt/tmp
    • Test
        1. Mount copy of home as new home: sudo mount (name) /home
        2. Check size of home folder — should be the same as in step 1.: du -sh /home
        3. Check mounting worked: sudo mount| grep /home should print out something like
          (name) on /home
        • Switch
            1. yet another home backup: sudo mv /home /home.bak
            2. create new home mount point: sudo mkdir /home
            3. create a backup of fstab: sudo mv /etc/fstab /etc/fstab.bak
            4. put updated version in place: sudo mv /etc/ /etc/fstab
            5. reboot and you should be done: sudo reboot

            Ok, that’s that. If everything works fine, you can delete the backup home sudo rm -rf /home.bak and the fstab backup sudo rm /etc/fstab.bak. Hope you found it useful and I did not put in a mistake or typo. Gimme feedback! 🙂

            Leave a Reply

            Your email address will not be published. Required fields are marked *