Moving /home to its own partition

Ubuntu - Disk Usage AnalyzerAfter upgrading Ubuntu to 8.04 I decided it would be a good idea to finally move /home folder to a separate partition. It makes it much easier to make backups and reinstall operating system if all data/configurations are safely stored on their own partition.

Without installing additional hard drive (which would be impractical for laptop user anyway) the only source for extra space was Vista partition. Vista comes preinstalled with most modern laptops, but there’s no need for it to exist taking up to 40Gb of hard drive space, when Ubuntu is the primary OS.

WARNING: Before executing any of the belowmentioned steps, it is highly recommended to make a full backup of your data.

1. Check how much space you will need

It is good to check how much space you will need for your /home partition. Use “Scan Home” in Disk Usage Analyzer (Applications->Accessories->Disk Usage Analyzer) to check how much space do you use now. This tool will give you excellent perspective on how you use your disk space – and where you can possibly save a few gigabytes. Add some gigabytes on top of the current usage figure for future use and now you now what should be the size of your new /home.

2. Create new partition/filesystem

In Ubuntu there's an excellent tool for manipulating partitions - GParted (System->Administration->Partition Editor).

If the estimated size of your home partition is smaller than the size of Vista partition (or any other partition you’re prepared to re-allocate), then the task is really simple – you just convert Vista’s ntfs partition into ext3. In my case all my data in /home folder didn’t fit into 40Gb, so I had to resize the root / partition. This is not possible while the system is running, so I had to burn Ubuntu Live CD, boot from the CD with “try Ubuntu without affecting you current system” option, and run GParted from there.

Note, that resizing and moving partitions is a time-consuming process – it may take hours, depending on the size of your partitions, so reserve enough time for this operation.

3. Mount the new filesystem

$sudo mkdir /mnt/newhome
$sudo mount -t ext3 /dev/??? /mnt/newhome

4. Copy all files to new home

$cd /home
$sudo cp -ax * /mnt/newhome

That is a copy with “preserve links, preserve mode, ownership, timestamps, copy directories recursively, stay on this file system” parameters.

5. Change homes

Unmount new home partition from temporary mount point

$sudo umount /mnt/newhome

Move old home to a temporary folder oldhome (note that this works only when you are moving /home to own partition from root partition, if you had /home on its own partition already and just moving it to the new place, you’ll need to unmount old /home partition instead of moving it to a temporary folder oldhome)

$sudo mv /home /oldhome

Create a mount point for new home partition

$sudo mkdir /home

Mount new home partition to /home

$sudo mount /dev/??? /home

6. Compare the results

You don’t really have to do that, but if you want to be extra sure that everything is ok and are prepared to wait a bit longer, then type:

$sudo diff -rq /home /oldhome

7. Make changes permanent

Add a line to the “/etc/fstab” file that looks like the following:

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

8. Remove old home

Now that everything is ok, you can remove the old home folder (same note as in step 5 – if you had old home on its own partition already – then use GParted to reallocate old partition for new needs)

$sudo rm -r /oldhome

Voila! Now your /home is on its very own partition.

Share

7 thoughts on “Moving /home to its own partition”

  1. Thank you for this simple yet comprehensive (and most importantly – ACCURATE) guide.
    It worked perfectly.

  2. Very nice. Easy to use.
    I did, however, have the problem of not being able to log in. Said something about trying to log in as root, then said I had no permissions.
    I had to adjust the /etc/fstab file (Step 7) to this:

    /dev/??? /home ext3 defaults,errors=remount-ro 0 1

    Once I did this, everything was great!
    Thanks for the help!

  3. Ivan,

    Thanks for your careful step by step guide! Now I’ve got my home on a new ext4 partition. I increased the Google search result order for your side. I tried this guide here that Google listed first but it got me into big trouble: http://www.ubuntu4life.com/node/30

    After a near nervous breakdown I have access to my new home folder again!

    Nils

  4. Thank you for the guide. Unfortunately I can not copy my old Home folder to the new Partition. It’s weird, I created a 15gb Partition (ext4) for home, then I mounted it and started to copy the files. If I look for properties of the old home folder it says 20000 Items, totalling 4.9gb. But the copying process takes very long. There is much more data than 4.9gb copied. Even the 15gb Partition is too small. Everything else seems to work. Why is more then 4.9 Data being copied?

  5. I even used in on an Ubuntu installed image on a VM Virtual Box and it works great. Way to go.

Leave a Reply

Your email address will not be published. Required fields are marked *