How to Create a Separate Home Partition in Ubuntu Linux

One of the joys of being a Linux user is the flexibility. Virtually every aspect of your system is customizable. Testing and tweaking desktop managers, compiling a new kernel, fearlessly contributing through trial and error, to the open source movement. Yet, all this flexibility is not without its perils.

It’s happened to us all at some point. We’ve tinkered ourselves into a technical abyss rife with grub errors, system freezes, or black screens of death-our systems fried. When all attempts at recovery fail, we sigh, break out our LiveCD and reinstall. While devastating, the pain can become compounded if you have not properly backed up the data residing in your /home directory.


Advantages of a Separate Home Partition

The general consensus among Linux enthusiasts is that the /home directory should be placed on its own partition. There have even been proposals that this be made a part of the default installation process.

The separation accomplishes two things: facilitates cleaner, simpler Linux upgrades and provides a safe haven for your data in the event of a problem with your primary Linux partition. As a side benefit, if you run multiple Linux flavors (i.e. Fedora, openSUSE, Mint, etc.), you’ll be able to use the same /home partition for each of these.

Ubuntu Linux operates on a 6 month release cycle. Clicking the upgrade button in the synaptic package manager will upgrade your distribution – albeit, with varied results. Some upgrades work flawlessly, while others are plagued with problems. Consequently, many agree that a clean install is the preferred option.

A clean install does exactly what the name implies, wiping the hard drive during the installation process. One can easily back up their data and then restore it, but this step can be eliminated if /home is on a separate partition.

Creating a Separate Home Partition in Ubuntu

Convinced? Wondering how to make the change on your existing Ubuntu installation? Great! Without further ado, we’ll walk through the simple steps to repartition your drive, moving your /home directory to its own partition.

It is important to note, that while these steps (or the many variations on them) have been successfully performed many times over, the potential for data loss exists.

It is imperative that you backup your data before you begin. You can use an external drive, online storage systems like Ubuntu One or Dropbox or whatever solution you choose. But I can’t stress the importance of this step enough.

  1. Assuming you’ve backed up your data, you’ll need to boot from your LiveCD. Why? Basically, because you can’t alter a partition if it’s mounted. So, after booting, select your language, and then select: try Ubuntu without installing.
  2. There are several partition managers available, but for this tutorial, we’re going to be using the Gparted partition manager. From the application menu, click on:

    System > Administration > Gparted

    How to Create a Separate Home Partition in Ubuntu Linux

  3. When Gparted loads, you’ll see a graphical depiction of all the partitions on your hard drive. You’ll need to decide which partition you want to resize to create space for /home.

    How to Create a Separate Home Partition in Ubuntu Linux

  4. Right click the partition you choose and click, Resize/Move

    How to Create a Separate Home Partition in Ubuntu Linux

  5. As most important data is stored at the beginning, or the left side of the partition, I suggest you resize from the right side. In terms of size, needs vary depending on the user, but allocate as much room as you can for /home.

    Use your mouse and drag left, to resize the partition and then click, Resize/Move.

    How to Create a Separate Home Partition in Ubuntu Linux

  6. You should now have a space called unallocated. This will be the home of your new partition. Select this space with your mouse and click on Partition > New from the menu.

    Now select the filesystem you want, ideally, this should match your existing file system , ext3 or ext4.

    *make note of your partition names, we’ll need these later.

    How to Create a Separate Home Partition in Ubuntu Linux

  7. Click Apply twice.
  8. Click Close, then Quit.
  9. Now we’ll need to tell Ubuntu how to use the new partition. Open up a terminal and type the following commands:

    To mount the new partition, (for this example, assuming partitions sda1 and sda2 and file system ext3, yours may be different):

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

    Now backup the old /home and move 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

    Tell Ubuntu to use the new partition as /home:

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

    This will open fstab in Gedit, now type the following:

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

  10. Save the Gedit file, exit and reboot. Viola, you should now be using your new separate /home partition!


When Things Go Wrong …

Inevitably, things go wrong. What should you do, you ask?

The Ubuntu forums and IRC channel are an excellent resource. However if you’d like to skip the troubleshooting and start over, type these commands to restore things to their previous configuration:

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

Creating a separate /home partition may seem like more trouble than it is worth, but in the end, can save you countless hours of exasperated troubleshooting on Ubuntu’s next update.

This isn’t an exercise you should undertake lightly. However, knowing your data is safe and sound is a powerful incentive. Still, as hardware failure looms ever possible, it is best to develop and stick to a consistent backup schedule.



This site uses Akismet to reduce spam. Learn how your comment data is processed.