« iPhone into iSpy | Main | Scam, scam, scam »


It's one of the common Linux mistakes: forgetting to place the /home directory in a separate partition. It's not a critical failture, but it does give you a bit more safety and security. If the latest upgrade turns to custard or you accidentally trash something vital, you can simply reinstall the operating system knowing that all your user data, settings, etc. will remain untouched.

There's also a school of thought that says it means you can use the same user account when installing multiple distributions, but I'm a little hesitant here. Certainly you can use the same /home partition, but I'd suggest setting up different user accounts as there are sometimes subtle differences in program settings that don't translate well between different distros.


Making room

The first step is finding somewhere to put it, and that usually means adding a partition to the current drive. (That doesn't have to be the case of course. You could add it to a second drive, but you're still likely to want to partition the disk, so carry on.)

Obviously you can't repartition a drive you're currently working in so you'll need an appropriate bootable tool. For this I reccommend the System Rescue CD from www.sysresccd.org. I'll admit it's a little bit of overkill as it has tons more tools than just partitioning, but SysRescue is so useful I reckon it should be in everyone's toolbox.



Once you're into the GUI, start GParted from the menu and you'll get a screen like this.

OK, how much space do you give your new /home? That depends on you and the size of your hard disk, but as an indication, 70% of the 15GB I allocated to the / (root) partition on my main machine has been used (and I have lot installed!), so all the rest is /home. If it turns out you want more or less for any particular partition, changing things is just a SysRescue boot away.


Here I've resized the first partition and added a new /home.


Movin' it

Now we need to move the /home folder to it's new location. For this we'll use the command line so switch to SysRescue's Terminal.

Before we can do anything, we need to create mount points for the two partitions:  
mkdir /mnt/part1 /mnt/part2

and mount them  
mount /dev/sda1 /mnt/part1
mount /dev/sda2 /mnt/part2

Note that the /dev (short for "device") settings comes from GParted. Yours may be different!

If you now travel to the first mounted partition ...
 
cd /mnt/part1

... and list its contents ...  
ls

... you should get a display like the following:
bin   cdrom  etc   homee       lib         media  opt   root  selinux  sys 
boot  dev    home  initrd.img  lost+found  mnt    proc  sbin  srv      tmp

It's now simply a matter of copying the contents of the /home
folder from one partition to the other:  
cp -av home /mnt/part2

Note that we're only copying the contents. The next step will mount and use that copy but if anything goes wrong, simply back out the next step and you'll be back where you were with a bootable disk.



Telling it where to go

There's one final step. We need to tell the root partition where the new /home partition now resides. We do this by editing root's file system table /etc/fstab. SysRescue has a built-in GUI editor called Geany so let's use that:  
geany /mnt/part1/etc/fstab

Add a line like the following:  
/dev/sda2 /home ext4 defaults 0 2

What does that all mean?
/dev/sda2 is the device name
/home
is the mount point
ext4
is the partition type
defaults are mount options
0 is the dump frequency (disabled)
2 indicates the partition should be checked for errors at boot time after / (root) has been checked.

Save the file and we're done. Shut down SysRescue, reboot.

As a final check, run
df -h

to see where your filesystems are mounted 
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              15G  9.7G  4.1G  71% /
/dev/sda2              97G 22.1G 75.6G  22% /home


Now enjoy your new /home!


Previous Hidden Linux



Follow Geoff Palmer on Twitter

Comments

Absolutely, Ross!

I am running out of room for personal files on my home partition. I have a user partition which I don't have permission to write to. Can I shrink this using the SysRescue CD, then expand home?

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Subscribe
Newsletter & SubscriptionsPC World is New Zealand’s top selling computing and technology magazine.

It provides up-to-the-minute editorial, insight and buying advice for personal computing, cell phones, game consoles, digital entertainment and broadband.
SIGN UP
PCWorldUpdate
PC World's weekly round-up of tech news, gear and game reviews, software selections, and handy How Tos.