How do I create a separate partition for my /home directory?

11,437

Solution 1

An LVM volume group is an abstraction of a hard drive, or multiple hard drives, or multiple RAIDs, or... It's really a separate question, so I don't think it's pertinent to get more detailed than that here.

The point is, both LVM groups and hard drives can contain partitions. Which way you go is a matter orthogonal to your main question.

The easiest way to make /home a separate partition is to do it during OS installation, with a complete hard drive repartition and format pass. You can change your mind and make /home separate later, but it's more work.

The way you create a separate /home partition differs depending on the particular OS installer, but these days, you typically have to tell it you want to do an "advanced" hard drive setup, overriding its simple defaults. You can then choose to reserve some amount of hard drive space for /home and leave the rest of the disk (or LVM group, or RAID, or...) to the rest of the system.

To make /home a separate partition after you've installed the OS, you either have to repartition or add another volume. Just as a simple example, you could insert a USB stick and put /home on it like this:

(assume the USB stick is /dev/sdc, mounted on /media/usb)
# umount /media/usb
# mke2fs -j -L /home /dev/sdc1
# mount /dev/sdc1 /media/usb
# cd /home
# find . -print | cpio -mpud /media/usb
# umount /media/usb
# mount /dev/sdc1 /home

What we've done so far is reformat the USB stick with a fresh ext3 filesystem, then copied the entire contents of /home over to it while preserving all permissions, timestamps, etc. Then we've laid the new /home copy over the top of the old for testing. Once you're satisfied that it works, you could unmount /dev/sdc1, nuke the old /home and remount the new one.

Beware, this is dangerous. I am presenting it as an example, not a recommendation.

Also dangerous is repartitioning the drive after it's already been formatted. You'd have to do that if you wanted to move /home to a new partition without adding another volume to the machine. The gparted tool can do this, but it's not without risks. Having opened up space for a new partition and created it with gparted, you could do something much like I show above to move the contents of the old /home directory to the new partition.

You should also beware that making /home separate has its own problems. One is, it forces you to set aside a slice of your disk for /home and then live with it. It's easy to get too clever with partitioning; you could end up with like 10 partitions, 8 of which are full and 2 which have less than 10% usage, and no easy way of reassigning space from the empty ones to the full ones. LVM and gparted each provide some solutions to this, but the important point to keep in mind is, be very sure you need the extra partitions. The more moving parts, the more things there are to break.

Solution 2

Simple answer. First put LVM to the side.

To make a separate /home make a partition on your hard drive, using either fdisk or gparted a gui wrapper for fdisk. The linux method of accessing partitions is straightforward. /dev/hda, /dev/hdb ... /dev/hd[a letter] are ide drives. /dev/sda,/dev/sdb, ... /dev/sd[a letter] are scsi/sata/usb drives. The last letter describes the order they appear. 1st sata /dev/sda 2nd sata /dev/sdb ...

When you use fdisk or gparted to partition the drives, individual partitions are accessed by numbers ... /dev/sda1, /dev/sda2 ... . Format your partition

So now edit /etc/fstab and enter something like /dev/sd?? /home 0 0 rw.

I'm sorry I can't be more specific, my primary hd just died :( and I have no examples. ( On the plus side I was replacing it next week anyway, on the minus side couldn't it have held out another week? ) But between man and google you should get it done.

Also you shouldn't change the boundaries of any partitions with data on them by using fdisk. If you are familiar with Partition Magic, gparted is a similar tool and can be used to resize and move partitions safely. There is also a liveCD called Parted magic which will allow you to resize partitions.

It has been standard UNIX practice to keep as many partitions as you feasibly could. Typically /,/home,/tmp,/root, /var are seperately partitions. On Linux I add /boot ( since in the old days /boot had to be in the ext family).

There are several reasons for this: it made backups easier ( just backup all of sopme of the partitions ), if a partition became corrupted it kept the damage local, it kept the fragmentations of partitions to a low. With more modern filesystems, I am not sure how relevant these reasons are anymore.

let me as an example assume that some program keeps some of it's temporary data in /tmp and it has a bug which causes it to just fill /tmp. This will cause programs to act flakey, but probably not crash the system and give you a cance to repair the damage. If your whole system were on one partition, it could cause a lot more problems. Maybe even force you to try and repair the damage from a liveCD.

As for LVM. LVM basically creates a partition and then allows you to make some subpartitions from it. If you need more space then if there is more free space you can use it to grow your subpartitions. If you run out of space you can add a second partition to the volume to make more available. My one experience indicated it caused more problems then it's worth and chewed up more CPU then I liked, but YMMV. Also if you have a problem and have to use a liveCD, you have to be careful to pick one which can access your LVM partitions.

Share:
11,437

Related videos on Youtube

jonderry
Author by

jonderry

Updated on September 17, 2022

Comments

  • jonderry
    jonderry over 1 year

    I was reading http://docs.fedoraproject.org/en-US/Fedora/14/html/Installation_Guide/s1-diskpartitioning-x86.html, but it's not clear to me what this means. What's an LVM Volume Group versus a Hard Drive? I want to make sure that my home directory is on it's own partition so that I can more easily reinstall and upgrade the os.

    EDIT: If /home is on its own logical volume, will I be able to easily reinstall the os, or is a logical volume a different type of entity from a partition?

  • simon
    simon about 13 years
    +1 for a good summary. Just want to add that, while I agree that having lots of partitions is more hassle that it's worth, having /home on a separate partition is really solid advice, imo, almost a no-brainer. For a single user workstation (laptop or desktop), I will have 1 or more OS partitions, and throw all the remaining space into /home.
  • jonderry
    jonderry about 13 years
    Thanks for the detailed summary. One question though is that I just finished setting up my reinstall, and I set /home to be on it's own logical volume. Is this the same as putting it on it's own partition? When reinstalling or updating the OS, how do I keep the old home partition with the old data? (I just reinstalled, and did not see an option to use an existing partition as the home partition. I just copied the files over, which was a pain)
  • Warren Young
    Warren Young about 13 years
    @jonderry: The only thing you need to watch out for is that you continue to use OSes that understand the particular logical volume management (lowercase "lvm", if you will) scheme you used during installation. There are actually a bunch of these schemes out in the wild, two of which are Linux's LVM1 and LVM2. They're not all compatible.