Monday, April 20, 2009

Changing your home directory to a new Drive on Ubuntu

I recently was trying to install Windows with my Ubuntu on my machine. I ended up moving my /home partition to another extended one :).

Windows Vista can't be installed on an extended partition (or at least that is what it told me), so i had to make a new primary partition for it. Since I'm using 3 primary partitions for my linux (boot, root and home) plus the extended partition area. The total primary partition (and maximum you can have) is 4 primary partitions. I had to relocate one of my Linux partitions to an extended one. Either i move my boot partition, or the home partition. home was my choice so i did the following.

First you have to make a new extended partition for your home. I choose to try the reiserfs as i read it has some performance advantage over ext3. let's call it /dev/sda5.

Next, you should mount it and copy all your /home data to your new partition.

sudo mkdir /media/home_new
sudo mount -t ext3 /dev/sda6 /media/home_new

replace "sda6" with your correct drive file

Next copy your files:
Since your "/home" directory will have soft links, hard links and nested directories, normal copy "cp" will not do the job. We can use a command similar to the one in the Debian archiving directory

find . -depth -print0 | cpio --null --sparse -pvd /media/home_new

After copying the data you have to edit "/etc/fstab" to make sure your "/home" is pointing to your new partition. You may find some "UUID"s instead of "/dev/..." just replace your UUID with your new drive path "/dev/sda6" or whatever it is.
/dev/sda6  /home reiserfs relatime  0 2

I just replaced the drive file and the file system as i changed both of them. It is best to keep the rest on their default settings.

Now Restart your machine and everything should work fine.You can even create a new primary partition for your windows installation now.