Relocate the /home Directory to a New Partition ยป Page 2

First, you’ll have to connect a new hard drive, or make a new partition on an existing drive to make room for your new /home. I’ll assume you’ve done this and everything’s working. If you haven’t and are stuck, feel free to comment with questions.

Second, you may need to create a directory in which to temporarily mount your new partition and then mount it (it is possible that your partition will be detected and mounted already for you, so check your /media directory before proceeding). This is accomplished with two simple commands:

sudo mkdir /media/new_home

Then, you’ll have to mount your new partition in your new directory:

sudo mount /dev/sdxn /media/new_home

Where x and n refer to your hard drive number and your partition number within that drive, respectively (ie. the second partition on the first hard disk will be referred to as sda2).

Now that you have your new partition ready to be filled with the contents of your /home directory, navigate to /home…

cd /home

…and copy everything over (a simple copy & paste from within a file browser will not do):

sudo find . -depth -print0 |sudo cpio --null --sparse --preserve-modification-time -pvd /media/new_home

Now everything needed for /home is in /media/new_home. Your new partition is now ready to fill its role.

A good idea now would be to move your current /home to another folder to make room for the new /home directory that will serve as a mount point for your new partition:

sudo mv /home /home-old

Now make the aforementioned new /home:

sudo mkdir /home

Having done that, you can test that everything works:

sudo umount /media/new_home
sudo mount /dev/sdxn /home

I suggest at this point to make sure that all users have ownership of their files:

sudo chown -hR username:username /new_home/username

Of course you will substitute all the usernames on your system for username above. Execute the command once for each user.

If all is well (and it should be), edit your fstab so that the system will use your new partition for /home every time it boots up.

sudo nano /etc/fstab

You’ll have to add the line:

/dev/sdxn /home ext3 defaults 0 0

Comment out any other reference to /home that may exist in fstab by placing a “#” at the beginning of the line. Close and save the file. If everything goes smoothly, you should be able to come back and delete this line after the next reboot. You should also be able to delete the old /home directory:

sudo rm -r /home-old

That’s it!

The Result:

An 80 GB drive is now mounted in the /home directory on my Ubuntu 8.04 (Hardy Heron) machine. My documents, pictures and desktop folders are synchronized between it and my main PC, and I didn’t have to reinstall anything to make it work.

I’ve also repeated the process similarly on my main PC running Ubuntu 8.10 (Intrepid Ibex) to prepare the system as I plan to reinstall openSUSE 11, test out Fedora 10 (I haven’t used Fedora since it was still called Red Hat), all while sharing a single /home partition between the three (another advantage to a separate /home partition: sharing it between Linux distributions, or even saving documents and settings if you need to reinstall the version you’ve got).

Bookmark and Share