How to Create a Separate Home Partition in Ubuntu LinuxBy Veronica Henry
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.
- 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.
- 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
- 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.
- Right click the partition you choose and click, Resize/Move
- 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.
- 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.
- Click Apply twice.
- Click Close, then Quit.
- 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:
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
- 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?
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.
About the Author
Veronica Henry is a writer, web developer and tech guru. Her 20 year IT career came to an end when her inner writer and entrepreneur inexplicably besieged her to give it all up. She is a self-proclaimed girl-geek and linux convert, who has held MCSE, GSEC and PMP certifications. In her dreams, she is a international best-selling sci-fi and fantasy author, but in the meantime, she now spends her days writing, managing her websites and wrecking havoc on her Ubuntu laptop.
Author's Website: http://www.veronicawrites.com
- Guide to Installing and Setting up Linux — The Easy Way
- Out With The Slow, In With The Linux
- Simplify, Organize and Protect Your Digital Life with a Home Server
- How to Connect Your Xbox 360 to Your Home Server
- How to Create a Backup Image in Windows Vista and Windows XP
- How to Setup a Small Home Network — Part 1
- Virtualization Interoperability with Windows Server and Red Hat Linux
- How to Setup a Small Home Network — Part 2
- How to Create a New Virtual Machine with Hyper-V
- Learn How to Create Relationships and Master Them in Access 2007