Ubuntu doesn’t use a separate /home partition by default, although many Linux users prefer one. Using a separate home partition allows you to reinstall Ubuntu without losing your personal files and settings.
While a separate home partition is normally chosen during installation, you can also migrate to a separate home partition after installing Ubuntu – this takes a bit of work, though.
While Installing Ubuntu
Creating a separate home partition while installing Ubuntu is easy. Choose the “Something Else” installation option to use a custom partition layout and create multiple partitions. Set the mount point for one of your partitions as / – which will contain the root file system – and the mount point of another partition as /home. When you install Ubuntu in the future, you can set your old home partition as /home again – but make sure to uncheck the Format checkbox or your files will be deleted.
After Installing Ubuntu
If you don’t create a separate home partition while installing Ubuntu, you don’t have to reinstall Ubuntu from scratch. To migrate to a separate home partition after installation, you’ll have to create a new partition (which may require resizing your existing partitions), copy the files from your existing home directory to that partition, and tell Ubuntu to mount the new partition at /home.
Step 1: Create a New Partition
If you have some free space, this step is easy. If you don’t, you’ll have to resize your system partition and create a new partition in the free space. Follow our guide to resizing Ubuntu partitions to complete this step. If you have free space or don’t need to resize a system partition, you can just install GParted and create the partition without restarting from a live CD – you’ll want to create an ext4 partition.
Step 2: Copy Home Files to New Partition
Ubuntu makes it easy to mount the new partition – just click it under Devices in the file manager. After you do, click the Go menu and select Location to view its mount point.
Launch a terminal and run the following command to create a copy of your current /home directory on the new partition, where /mount/location is the location of your mounted partition:
sudo cp -Rp /home/* /mount/location
You’ll see an error about a .gvfs directory – this is normal; you can ignore it.
You should check the new home directory to verify it contains your files. However, we won’t be deleting the old home directory just yet.
Step 3: Locate the New Partition’s UUID
The long, random-looking string above is actually the partition’s UUID, and we’ll need it to add the partition to our fstab file, which tells Linux where to mount partitions when it boots. You can also locate the partition’s UUID by running the following command in a terminal:
Step 4: Modify the fstab File
Before modifying our fstab file, we should create a backup copy that we can restore, just in case:
sudo cp /etc/fstab /etc/fstab.backup
Next, run the following command to open the fstab file in gedit. You can also use another text editor, if you prefer.
gksu gedit /etc/fstab
Add the following text to the fstab file on a new line, replacing the _____ portion with the full UUID of your new home partition from the sudo blkid command above:
UUID=_____ /home ext4 nodev,nosuid 0 2
Save the file after adding the line.
Step 5: Move Home Directory & Restart
From a terminal, run the following command to leave your home directory, move your current home directory to a placeholder location, and create a new, empty home directory which your new partition will be mounted at:
cd / && sudo mv /home /home_old && sudo mkdir /home
Reboot your computer after running this command. You can restart with the following command:
sudo shutdown -r now
After restarting your computer, you should be able to log in normally. Ubuntu is now using the separate home partition. After making sure that everything went okay and you still have all your files in your /home directory – just in case – you can you can remove your /home_old directory to free up space:
sudo rm -rf /home_old
Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.
- Published 06/17/12