Creating a separate home partition

From LXF Wiki

Creating a separate home partition


Use GParted or QTparted to move your /home directory.

(taken from LXF 100 answers)

It is possible, but care is needed. As always, backup first! The danger is of the process being interrupted by a power failure or other software crashing the computer.

Working with in-use filesystems should be avoided too, so boot from the live CD distro like Knoppix for this task.

There are three stages: resize your root partition, create a new home partition in the space made and move your data over. The process is a lot easier if you have plenty of free space; if your drive is nearly full, move some files to DVDs or an external disk. While it is possible to resize a partition from the command line with acombination of cfdisk (or fdisk) and appropriate resizing tools for your filesystem, it is easier with GParted or QTparted (on Ubuntu and Knoppix CDs respectively). The Knoppix live DVD has both. We use GParted here, but they work similarly.

Partitions cannot be resized when mounted, so if a mount point shows alongside the partition in GParted, right-click the partition and select unmount. When resizing a partition, it is normally only possible to move the end point, so start by dragging the end of the root partition to the left until it is the size you want. It is considered good practice to not fill a partition beyond 80 per cent, filling that last 20 per cent can lead to fragmentation, but remember that you are going to remove the contents of /home after resizing, so you can probably pull that slider as far over as you want. Now create a partition in the vacated space and press Apply to start the process. This is the risky part, it is best to leave the computer undisturbed while it completes this. Once you have created the new partition, it is safest to reboot, to the live disc again, to make sure the kernel knows about the new partition layout.

Now you need to move the files from the old home directory to the new partition.

This must be done as the root user, so open a terminal and type su to become root - or sudo -i if using an Ubuntu disc.

If the root partition is on /dev/hda1 and the new partition on /dev/hda2, the commands to make the copy are

mkdir -p /mnt/{root,home}
mount /dev/hda1 /mnt/root
mount /dev/hda2 /mnt/home
mv /mnt/root/home/* /mnt/home/

or you can replace the last command with

rsync -a /mnt/root/home/ /mnt/home/
rm -fr /mnt/root/home/*

which is a little slower but preserves all timestamps and can be interrupted and resumed is necessary.

This assumes you have a relatively small amount of data in the home directory, otherwise you will not be able to shrink the root partition as much as you need and will have a lot of wasted space after moving the file.

And finally.....


Now, you have to tell Linux to mount your new home when you boot. In Ubuntu you would be expected to use UUID for your partition so typing

sudo blkid

will give you that and then add the entry to /etc/fstab: Code:

# /dev/sda5
UUID=e9f1c53f-a126-498a-9ed3-49092b681e32 /home            ext3    defaults        0       2

You'll have a different UUID, the code is on a single line like the rest of /etc/fstab and the comment "# /dev/sda5" is just a reminder that is "human" readable


For other Distributions add a line to the “/etc/fstab” file that looks like the following:

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

(Here, change the partition label “hda5″ to the label of the new partition, and you may have to change “ext3″ to whatever filesystem you chose for your new “home”)


 1 Resize root Use the slider to reduce the size of your root partition, creating space for your new home.
1 Resize root Use the slider to reduce the size of your root partition, creating space for your new home.
 2  A new home Create a new partition in the space you have freed up and choose a filesystem. Unless you've strong preferences, use the same as for root.
2 A new home Create a new partition in the space you have freed up and choose a filesystem. Unless you've strong preferences, use the same as for root.
 3 Ready to proceed Note the list of queued actions listed at the bottom of the window. Nothing is changed until you press Apply.
3 Ready to proceed Note the list of queued actions listed at the bottom of the window. Nothing is changed until you press Apply.


 4  Give it time Resizing a large filesystem can take a long time. Resist the temptation to disturb the computer while it is working on this.
4 Give it time Resizing a large filesystem can take a long time. Resist the temptation to disturb the computer while it is working on this.
 5   Move home If there is only a single directory in /home, you could move it with a file manager, but I prefer to do this in a shell. either way, you need to be root.
5 Move home If there is only a single directory in /home, you could move it with a file manager, but I prefer to do this in a shell. either way, you need to be root.
 6 QTParted QTParted works much the same as GParted, they both use the same backend, but with a KDE-style GUI.
6 QTParted QTParted works much the same as GParted, they both use the same backend, but with a KDE-style GUI.