Giving the HOME directory it’s own partition

by

The more you use linux, the more you begin to realise that your HOME directory should be on a different partition from your ROOT directory. This way, your config files remain unaffected by system crashes, OS reinstalls etc. Now _if_ you started out without a separate partition for your home directory, here’s how you can rectify the problem.

Basically, we have to do three tasks.
1) Choose a partition for your HOME directory
2) Copy ALL files from your current home to this new partition
3) Make an entry in fstab to mount this partition as /home on bootup.

We’ll be using a tool called GParted to make our life easy.

sudo apt-get install gparted

Yes, it’s a GUI tool and yes, I also know how to do the same things in a more complicated way using pure CLI. However, this is a beginner guide. So I’ll leave that part as an exercise for the interested reader.

Right! So lets get started:

1) Choose a partition for your HOME directory

a) Run GParted. You will have to use sudo, as you need root privileges to use gparted. gparted messes with your partitions, so don’t fool around unless you know what you are doing.

b) Select the partition. It obviously has to have enough free space to hold all the files in your current home. You may or may not format it, though I recommend you format it with ext4 as the filesystem.

c) Note the UUID of the partition. You can do this by selecting the partition, clicking on the Partition tab in the main menu, and clicking on Information. Also note the device name of the partition (something like /dev/sda3)

2) Copy ALL files from your current home to this new partition

For this part of the tutorial, CLI is still the best way to go.

We have to make sure we’ve copied everything from the /home directory. find and cpio commands will do this for us. After that we rename the home to home_backup (just to have a safety net if stuff goes wrong). Lets not forget to remake a home dir. This is how it’s done:

mkdir /media/tempdir
sudo mount /dev/sda3 /media/tempdir
cd /home
find . -depth -print0 | cpio --null --sparse -pvd /media/tempdir
mv /home /home_backup
mkdir /home

Remember to replace /dev/sda3 with the device name you noted down earlier.

3) Make an entry in fstab to mount this partition as /home on bootup.

Open the file /etc/fstab in your favorite editor. You’ll need sudo privilegdes to edit it, so remember to open it accordingly. Add an entry to it as follows:

UUID=UUID_you_noted_earlier /home ext4 relatime,errors=remount-ro 0 1

Remember to change ext4 with the filesystem of _your_ partition.

That’s it. Reboot and we are done. If you don’t want to immediately reboot you can manually mount your partition. sudo mount /dev/sda3 /home

Advertisements

3 Responses to “Giving the HOME directory it’s own partition”

  1. priyesh gandhi Says:

    well said. Faced the same problems but did not know about GParted. will definitely try it. Thanks!

  2. sevesteen Says:

    This did not work for me in eeebuntu–as soon as I ran the mv command, I lost access to nautilus and sudo, and mv /home_backup /home failed to work. I booted from a USB live distro in order to restore my home directory.

    • vedang Says:

      I don’t know why you lost access to nautilus and sudo, I’ll look into this and see if I find anything. But once you boot into a live distro, you can continue with the rest of the steps, i.e make a new home directory (mkdir /path_to_orig_install_location/home) and edit the fstab. On restart, it’ll find the new home and start working with that.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: