Amateur Topologist

Everything but topology.

Keep / and /home on a Separate Partition

The title pretty much says it all; if you’re running Linux, I highly, highly recommend that you put /home on a separate partition of your hard drive than the root partition /. Why do this? The biggest reason is that in case you mess up your operating system and need to reinstall it, then you only need to overwrite the / partition, leaving your data in /home fully intact. Since most applications store settings in some su<b>b</b>directory of your home directory, you’ll even get to keep your settings. How do you do this? Simple: when you’re installing the operating system, specify an additional partition to be used as /home. You also might want to set up a swap partition with size about equal to your RAM, but you don’t strictly have to. As for sizing the root partition, I’d go with about 20GB or so; most applications don’t take up a lot of space. If you’re on a SSD and 20 GB is a lot of capacity, you can probably get away with 10; I wouldn’t go any lower than that, though.

Now, the natural question is: how do you set up /home on a separate partition if you already have it on the same partition as /? It’s possible, but dangerous; if you mess this up, you can leave your system in a state that would require a good deal of knowledge to recover.  You should be fine as long as you follow these instructions, but I can’t guarantee anything, obviously. I also highly recommend you have an external hard drive of sufficient size to contain your current /home directory (which you can find out via du -sh /home ).

  1. Create a gparted CD or USB drive. You can’t modify a partition that you’re currently using, and you can’t unmount the root partition while you’re using that operating system. The natural solution: create a LiveCD or USB drive. First, you’ll need to download GParted from here. You can use brasero to burn the CD (pick ‘Burn image’) or usb-creator (both of which are likely in your repositories if you don’t have them already) to create a bootable USB drive from the .iso.
  2. Reboot and open up GParted. You should boot into the GParted CD/USB. If not, you did it wrong.
  3. Open up a terminal and GParted. Self-explanatory.
  4. Mount your current partition. Figure out which device is your Linux partition; look at the GParted window and take note of the entries in the ‘Partition’ column; your Linux partition will likely have filetype ext3, or ext4. For simplicity’s sake, I’m going to assume that it’s /dev/hda1, although you’ll likely have a different one. In the terminal, type the following:
    mkdir /tmp/linuxpart
    mount /dev/hda1 /tmp/linuxpart
  5. Mount your external hard drive. For the sake of this tutorial, I’m assuming it’s already formatted to something like ext3 and it only has one partition. If you only have one internal drive, then you’re going to be using /dev/sdb1, if you have two, then /dev/sdc1, etc.
    mkdir /tmp/exthd
    mount /dev/sdb1 /tmp/exthd
    mkdir /tmp/exthd/newhome

    Obviously, if the exthome directory exists already on your external, use a different filename.

  6. Copy. You can’t just use a plain ‘cp -R’ for this; you’d lose a lot of information. Instead, do
    cp -avu /tmp/linuxpart/home/* /tmp/exthd/newhome

    This will preserve various stuff, such as symbolic links. It’ll also take a while, so find something else to do.

  7. Delete. This is the moment of truth; so far, everything that you’ve done is harmless to your drive. Once you do this step, you’re essentially committed.
    rm -rf /tmp/linuxpart/home/*
  8. Unmount. Unmount the internal hard drive with
    umount /tmp/linuxpart
    This will let you resize it. Don't unmount the external hard drive, though.
  9. Shrink your old partition. Once that's done, you can right-click on the  partitions in GParted to manipulate them; it's fairly self-explanatory. Right-click the main home partition, select Resize/Move, set it to however large you think you'll need (I recommend 10-20 GB).
  10. Resize/move your new partition. Right-click your new partition, pick Resize/Move, and stretch it out to fill all of the available space.
  11. Execute. So far, you've only told GParted what you want it to do; once you click 'Apply', it'll do all the formatting and resizing and such. Give it a while, especially if you have a big hard drive. Once it's done, make note of the partition device; I'll assume it's /dev/hda2.
  12. Mount the new partition and copy files back.

    mkdir /tmp/homepart
    mount /dev/hda2 /tmp/homepart
    cp -avu /tmp/exthd/newhome/* /tmp/homepart
  13. Edit your filesystem table. This is important; without this, your OS won't know where to find /home . In the terminal, run
    mount /dev/hda1 /tmp/linuxpart
    nano -w /tmp/linuxpart/etc/fstab

    You should see a file pop up; you can ignore the lines that are already there and add one at the bottom that looks like this:

    /dev/hda2 /home  ext3 relatime 0 2

    Obviously, make sure to replace /dev/hda2 with whatever device your home partition is on; if you chose a filesystem other than ext3 for /home, then change that as well.

  14. Reboot You're done now; reboot, take the GParted CD out, and boot back into your freshly-partitioned Linux installation

Hopefully, this has all gone well and you now have /home on a separate partition. If it hasn't, well... that's why you make backups. You did make backups, right?

« Previous post

One ResponseLeave one →

  1. how do you set up /home on a separate partition if you already have it on the same partition as /? It’s possible, but dangerous; if you mess this up, you can leave your system in a state that would require a good deal of knowledge to recover.

    Linux

    Reply

Leave a Reply