Moving the /home folder to its own partition « Blogternals

Just a heads up, we talk about and mention Ubuntu in the article but this will really work for any distro. Some of these instructions may vary just a bit for Logical Volumes but you should easily be able to figure out the slight differences.

Having the “/home” directory tree mounted on it’s own partition has several advantages amongst them is being able to reinstall the OS (or even a different distro of Linux) without losing all your data.

Different reason have left some of us not installing a separate partition for “/home” when we first installed Ubuntu. Now for what ever reason we need to move “/home” to its own partition.

First, we need to create a partition of sufficient size for your “/home” directory. You do what ever you need to do here before we continue just make sure you have an empty partition somewhere to work with that is big enough and that you know what file format it uses I suggest ext3 or ext4.

Next, mount the new partition:

    mkdir /mnt/myhome
sudo mount -t ext3 /dev/sda5 /mnt/myhome

(You have to change the “sda5″ above to reflect the correct partition label for your situation.)

Now, we copy the files over:
Since the “/home” directory probably has some hardlinks, softlinks, and maybe files and nested directories, a regular copy (cp) will not, I repeat, will not do the job. Therefore, comes a useful trick.

    cd /home/
find . -depth -print0 | cpio --null --sparse -pvd /mnt/newhome/

Check everything at this point, you may have to do some tweaks now or later, or now and later you get the picture but this should have got 99% there.

Next, unmount the new partition.

    sudo umount /mnt/newhome

Make way for the new “home”.

    sudo mv /home /old_home

Since we moved our /home to /old_home, we need to recreate a new /home by doing the following.

    sudo mkdir /home
sudo mount /dev/hda5 /home

(Again, you have to change “sda5″ to whatever the new partition’s label is.)

Meticulously verify that everything works correctly, better to find your mistake now than to land that new job and find you can’t work on the project till you fix your box.

Now, we have to tell Ubuntu to use our new home partition when you boot. Add this line to the “/etc/fstab”

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

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

Once all this is done, and everything works fine, you can delete the “/old_home” directory by using:

    sudo rm -r /old_home

Enjoy and Have a Good’n!


Moving the /home folder to its own partition « Blogternals

Comments

Popular posts from this blog

Ubuntu 14.04 LTS: the cloud platform of choice, due on 17th April 2014

New Pop!_OS Update Makes (Some) Computers Faster

Ubuntu’s New Installer is Shaping Up Nicely