Ubuntu Home Directory Relocation Recipe
A very easy method to move the Ubuntu Home directory to another partition or hard drive.
Now, why might you want to do this? Many reasons I am sure, but the main reason for me was to ensure that my data location was independent of the OS. If my data is not on the same partition as the OS, upgrading and recovering the OS is much easier!
The Recipe - for use at your own risk!
- Get another partition or hard drive prepared and formatted as EXT4. Whatever way suits you… GParted, more hardware, up to you. If you created another partition on your main hdd, this is how to re-order hdd partitions.
- Get the destination UUID: At a command prompt, run “sudo blkid”. Note the UUID for the partition or hard drive you have prepared.
- Prepare to temporarily mount the destination: At a command prompt, run “sudo nano /etc/fstab”
Add these lines to the end of /etc/fstab - separate each part with <tab>:
# /home directory relocated to /dev/xxxx
UUID=xxx-xxxxx-xxxxx /mnt/home ext4 nodev,nosuid 0 2
Then, save (ctrl + o) and exit (ctrl + x) the file. - Create the temporary mount point: At a command prompt, run “sudo mkdir /mnt/home”
- Now mount it: At a command prompt, run “sudo mount -a”
- Copy data: At a command prompt, run “sudo rsync -aXS /home/. /media/home/.”
- Put the source somewhere safe: At a command prompt, run these commands:
cd /
sudo mv /home /home_backup
sudo mkdir /home - Prepare to mount the destination: At a command prompt, run “sudo nano /etc/fstab”
Amend the line,
UUID=xxx-xxxxx-xxxxx /mnt/home ext4 nodev,nosuid 0 2
to be,
UUID=xxx-xxxxx-xxxxx /home ext4 nodev,nosuid 0 2
Then, save (ctrl + o) and exit (ctrl + x) the file. - Now mount it: At a command prompt, run “sudo mount -a”
- Reboot your machine and confirm everything works.
- Some clean-up: At a command prompt, run these commands:
sudo rm -rf /mnt/home
sudo rm -rf /home_backup
