Create a separate home partition in Ubuntu

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Note: I no longer maintain this tutorial. It works fine for me and a lot of other users, but some people have complained that it doesn't work for them, and I don't frankly know enough about this process to help people troubleshoot following these steps.

If this works for you, great. Otherwise, you can try the community site:
https://help.ubuntu.com/community/Partitioning/Home/Moving

For help with this, please post on the Ubuntu Forums.

Introduction
Disclaimers
Requirements
Making the new partition
Using the new partition
What if it doesn't work?

Introduction

This guide is for creating a separate /home partition if you already installed Ubuntu without a /home partition (i.e., /home is just a folder inside your / partition).

Having a separate /home partition makes it easier for you to reinstall Ubuntu while preserving your personal files and settings. This is a matter of convenience but is not foolproof. You should still regularly back up your data.

Important Disclaimers

  • Even though I created the form of this tutorial, the steps outlined in it are taken directly from a text-only (command-line-driven) guide for this process. If you believe there is something wrong with the steps, leave a comment on that guide. I did not create these steps. I just was able to follow them successfully myself and wanted to present them in a more new-user-friendly form.
  • I and others have been successful in creating a separate /home partition using this tutorial, but there are many who have had difficulty being successful with the process. If you are not confident in what you're doing or in repairing or recovering from this process should anything go wrong, then do not attempt the instructions outlined here. I cannot help you troubleshoot problems that result from following this tutorial.
  • In this tutorial, I used extremely small partition sizes just for the purposes of creating more up-to-date screenshots. If you have less than 30 GB of hard drive space, I would not recommend creating a separate /home partition.
  • Creating a separate /home partition involves resizing at least one existing partition. In almost all cases, the resizing of partitions does not result in data loss, but there still exists a (however small) risk of data loss, so you should back up your important data before attempting to resize your partitions.

Requirements

You must use a live CD for this process, for two reasons:
  1. In order to resize your existing / partition, it needs to be unmounted. The only way to unmount it is for it not to be in use, which means you can't boot to your regular Ubuntu installation while resizing it... which means you need a live CD. By default, the Ubuntu live CD does not automatically mount internal partitions and drives, but if you happen to notice the drive appear on the desktop, right-click it to unmount it before starting this process.
  2. If you screw up your installation by accident, you can use the live CD to restore your old settings and, in the worst situation, at least recover your important files

I'm using the example of a Ubuntu Desktop CD and GParted, but you can very well use QTParted on Knoppix or DiskDrake on PCLinuxOS.

Making the new partition

Boot up the Ubuntu Desktop CD and choose to try Ubuntu without installing it.


Once the desktop has loaded, go to System > Administration > Partition Editor to launch GParted.


In GParted, find the partition you want to resize in order to make room for your upcoming /home partition. In this case, I'm resizing /dev/sda1, but your partition may be different. Be sure to keep track of the names of your partitions—these names are very important (/dev/hda1, /dev/hdb1, /dev/sda2, etc.).

To make room for your new (soon-to-be-/home) partition, right-click an existing partition and select Resize/Move


With your mouse, grab the right side of the partition and drag it to the size you want. Then click Resize/Move


You should now see some new space called unallocated. Select it with your mouse and then go to Partition and select New.


Under Filesystem, select Ext3. Then click Add.


Once you have the partitions set up the way you want, click Apply in the main menu and then click Apply in the resulting confirmation dialogue to apply the changes.


Wait for the changes to finish being applied, click Close, and then quit GParted.

Now, in my example, my original partition that I shrunk was /dev/sda1, and it created a new partition called /dev/sda3, and my /home folder at this point still lives on /dev/sda1. It's very important that you substitute in your own appropriate partition names for the ones I'm using.

Using the new partition


Go to Applications > Accessories > Terminal to launch the terminal.

Now, back in the terminal, I'm going to mount /dev/sda1 and /dev/sda3 by pasting in these commands (please remember to change the partition device names to the ones appropriate for your setup):

sudo mkdir /old
sudo mount -t ext3 /dev/sda1 /old
sudo mkdir /new
sudo mount -t ext3 /dev/sda3 /new

Now we're going to back up the /home directory on the old partition and move it to the new partition:

cd /old/home
find . -depth -print0 | cpio --null --sparse -pvd /new/
sudo mv /old/home /old/home_backup
sudo mkdir /old/home

Yes, one of those lines looks really complicated—so please copy and paste the commands into the terminal instead of retyping them.

Note: I have tested the second command myself, and it works, but some have pointed out it might make sense to preface the commands with sudo in case one of the other users has subdirectories manually marked as unreadable to the user making the move. Since I have not tested this out and all directories and readable to all by default, I'm offering this as only an alternative in case the command as given does not work:
sudo find . -depth -print0 | sudo cpio --null --sparse -pvd /new/

Next, we're going to specify to use the new home partition as /home:

sudo cp /old/etc/fstab /old/etc/fstab_backup
gksudo gedit /old/etc/fstab

You'll then see the /etc/fstab file opened in the Gedit text editor. Add in this line at the end of the file:

/dev/sda3 /home ext3 nodev,nosuid 0 2

Save the file and exit Gedit.

After you reboot, you should be now using your new /home partition.

If you find that you are running out of room on your old partition and you're pretty confident everything is working as it should be, then go ahead and delete the backup of home:

sudo rm -rf /home_backup

It's very important you paste in the above command. Retyping it could be extremely dangerous if you mess up, and you could end up deleting your entire installation.

What if it doesn't work?

If you reboot and are unable to log in because of some errors having to do with the $HOME/.dmrc file and/or .ICEauthority file, this may help.

Boot into recovery mode (if you don't know how to do this, go to this section of another tutorial).


Once in recovery mode, type (unfortunately, you won't be able to copy and paste, so please be careful what you type)

chown -R username:username /home/username
chmod 644 /home/username/.dmrc
chmod 644 /home/username/.ICEauthority
exit

where username is your actual username. Obviously, you'd repeat the first three commands for all users experiencing the problem before you typed exit.


Once you've exited recovery mode, resume the normal boot and log in.

If, for some reason, no matter what you try, the separate /home doesn't work, that's why we have a live CD, so we can fix things.

Boot up the live CD, go to a terminal, and paste in (being sure to change the partition device name, of course):

sudo mkdir /recovery
sudo mount -t ext3 /dev/sda1 /recovery
sudo cp -R /recovery/home_backup /recovery/home
sudo cp /recovery/etc/fstab_backup /recovery/etc/fstab

Then, reboot.

If you have suggestions or corrections for these tutorials, please post in this Ubuntu Forums thread or leave a comment on my blog.

I will not give help to people posting in the above places. If you require technical support, start a support thread on the Ubuntu Forums. That is the appropriate place to ask for help.