Personal tools
You are here: Home Team Members Jason Farrell A new /home A new /home

A new /home

by zcat last modified Apr 23, 2008 11:56 AM
— filed under:

How to separate "/home" from "/" on an existing Fedora LVM default install. This allows future fresh reinstalls (VS upgrades) to be performed without having to first backup /home, and it also allows future LVM flexibility in that the system does not need to be taken offline again because the root filesystem is now optimally resized.

Applicable to Fedora Versions

  • All


  1. A default LVM layout installation: /boot + / LV + SWAP LV
  2. Enough free space on the / LV to fit a new /home LV

Doing the Work

The following steps detail: how to shrink the "/" Logical Volume (LV) to make room for a new and separate "/home" LV in the free Volume Group (VG) space; how to format it, tune2fs it, mount both, and migrate the old home to the new; optionally, how to rename the other generically named "LogVolXX" LVs; and finally, how to reinstall Fedora using this new layout such that /home is preserved.

All the examples below were done using a virtual disk drive that was only 8GB in size; a normal HD will obviously be much larger, so the sizes of / and /home will vary. In general, for a desktop system, "/" should be between 5G and 15G, and "/home" should fill the rest of the available space.

  1. First thing's first: You need to make sure you have enough free space available on the existing root LogVol00 for it to be shrunk small enough, to free enough VolGroup space, to then contain a new /home logical volume.
    [root@f7vm1 ~]# df -h /
    Filesystem Size Used Avail Use% Mounted on
    6.7G 3.5G 2.8G 56% /
    [root@f7vm1 ~]# du -sh /home
    237M /home

    Here we can see that we have 2.8G available, so we can shrink it that much, and we see that we're only using 237M in /home, so it will fit with a lot of room to spare.

    If it were the case that there wasn't enough free space, then an in-place migration of /home is not possible; it would be necessary to backup /home to external storage beforing continuing, and to restore from this backup storage (below) rather than copying from LogVol00.

  2. Reboot into Rescue mode using your Fedora installation DVD (or rescue CD). On the last step of the rescue setup before getting a shell, choose to "Skip" the automatic mounting of your partitions under /mnt/sysimage. This saves us the trouble of unmounting them manually.
  3. Make LVM available
    sh-3.2# lvm vgchange -a y
  4. scan the available LVM PVs, VGs, and LVs to see what's what.
    sh-3.2# lvm pvs; lvm vgs; lvm lvs
    PV VG Fmt Attr PSize PFree
    /dev/sda2 VolGroup00 lvm2 a- 7.88G 32.00M
    VG #PV #LV #SN Attr VSize VFree
    VolGroup00 1 2 0 wz--n- 7.88G 32.00M
    LV VG Attr LSize Origin Snap% Move Log Copy%
    LogVol00 VolGroup00 -wi-a- 6.84G
    LogVol01 VolGroup00 -wi-a- 1.00G
  5. Resize the "/" filesystem on LogVol00, fsck'ing it first if necessary. Note that the example LogVol00 below is being shrunk from 6.84G to 5G, but for normal-sized drives you should be shrinking from a much larger size, down to between 10G and 15G.
    sh-3.2# resize2fs /dev/VolGroup00/LogVol00 5G
    resize2fs 1.40.2 (12-Jul-2007)
    Please run 'e2fsck -f /dev/VolGroup00/LogVol00' first.

    sh-3.2# fsck -fC /dev/VolGroup00/LogVol00
    fsck 1.40.2 (12-Jul-2007)
    WARNING: couldn't open /etc/fstab: No such file of directory
    e2fsck 1.40.2 (12-Jul-2007)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    /dev/VolGroup00/LogVol00: 135909/179520 files (2.2% non-contiguous), 972176/1794048 blocks
    sh-3.2# resize2fs -p /dev/VolGroup00/LogVol00 5G
    resize2fs 1.40.2 (12-Jul-2007) Resizing the filesystem on /dev/VolGroup00/LogVol00 to 1310720 (4k) blocks. Begin pass 2 (max = 53541) Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 3 (max = 54) Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 4 (max = 2798) Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The filesystem on /dev/VolGroup00/LogVol00 is now 1310720 blocks long.

  6. Now resize the "/" LogVol00 container itself to match its new filesystem size. This new size should be the same size as above (or slightly larger for a safety margin).
    sh-3.2# lvm lvresize --size 5G /dev/VolGroup00/LogVol00
    WARNING: Reducing active logical volume to 5.00 GB
    THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce LogVol00? [y/n]: y
    Reducing logical volume LogVol00 to 5.00 GB
    Logical volume LogVol00 successfully resized
  7. See how much space is now free in the volume group
    sh-3.2# lvm vgs
    VG #PV #LV #SN Attr VSize VFree
    VolGroup00 1 2 0 wz--n- 7.88G 1.88G
  8. Create a new logical volume named "lvhome" that will later be mounted at /home. Make its size less than or equal to how much space is now free. In this case, we have 1.88G free, so we'll make our new home 1.6G, leaving a little space leftover (for snapshots).
    sh-3.2# lvm lvcreate --size 1.6G --name lvhome VolGroup00
    Rounding up size to full physical extent 1.62GB
    Logical volume "lvhome" created
    sh-3.2# lvm lvs
    LV VG Attr LSize Origin Snap% Move Log Copy%
    LogVol00 VolGroup00 -wi-a- 5.00G
    LogVol01 VolGroup00 -wi-a- 1.00G
    lvhome VolGroup00 -wi-a- 1.62G
  9. Format the new lvhome volume
    sh-3.2# mkfs.ext3 /dev/VolGroup00/lvhome
    mke2fs 1.40.2 (12-Jul-2007)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    212992 inodes, 425984 blocks
    21299 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=436207616
    13 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912

    Writing inode tables: done
    Creating journal (8192 blocks): done
    Writing superblocks and filesystem accounting information: done

    This filesystem will be automatically checked every 31 mounts or
  10. Set a few filesystem options.
    sh-3.2# tune2fs -m1 -c0 -i0 -o user_xattr,acl /dev/VolGroup00/lvhome
    tune2fs 1.40.2 (12-Jul-2007)
    Setting maximal mount count to -1
    Setting interval between checks to 0 seconds
    Setting reserved blocks percentage to 1% (4259)

    All of the above options, except for -m1, are set on new filesystems during install, but we need to set them ourselves for manually created filesystems.

    What these options do:

    • -m1 -- if you run out of disk space, 1% will be set aside so that the root user can still write to it. The default is 5% reserved, which is too much "wasted" space for a home partition where it isn't critical for root to be able to keep writing to logs and so forth. Use "-m0" to reclaim even more space. e.g. on a 500GB drive each reserved percentage point is 5GB that you can't use.
    • -c0 -i0 -- disables doing automatic long fsck's after a default of every 31 mounts or 180 days. ext3's journal means regular bootup fsck'ing isn't as necessary as it used to be
    • -o user_xattr,acl -- filesystem will be mounted with "Access Control List" and "Extended Attributes" support that some apps (such as beagle) rely upon.
  11. Mount the "/" LogVol00, and the newly created lvhome, and then copy the old /home on LogVol00 to the new lvhome.
    sh-3.2# mkdir /mnt/lvroot
    sh-3.2# mkdir /mnt/lvhome
    sh-3.2# mount /dev/VolGroup00/LogVol00 /mnt/lvroot
    sh-3.2# mount /dev/VolGroup00/lvhome /mnt/lvhome
    sh-3.2# cp -av /mnt/lvroot/home/. /mnt/lvhome/
    Note: the period at the end of "/home/lvroot/home/." is intentional.
  12. Rename the old /home real directory and make a new /home mountpoint directory in its place:
    sh-3.2# mv /mnt/lvroot/home /mnt/lvroot/home.old
    sh-3.2# mkdir /mnt/lvroot/home
  13. Use the vi editor to update /etc/fstab in order to automatically mount the new lvhome logical volume ontop of the new /home mountpoint. Instead of using vi, you can more simply append the needed line using echo:
    sh-3.2# echo '/dev/VolGroup00/lvhome   /home   ext3   defaults  0 0' >> /mnt/lvroot/etc/fstab
    (Note: it's never too late to learn how to use "vi". run "vimtutor" for a lesson.)
  14. OPTIONAL STEP: Rename the generic default names for the other two logical volumes, LogVol00 and LogVol01, to something that makes more sense.
    sh-3.2# lvm lvrename VolGroup00 LogVol00 lvroot
    Renamed "LogVol00" to "lvroot" in volume group "VolGroup00"
    sh-3.2# lvm lvrename VolGroup00 LogVol01 lvswap
    Renamed "LogVol01" to "lvswap" in volume group "VolGroup00"

    CRITICAL: Remember to update fstab with the new names, AND to update grub.conf with the new "root=" device name on the kernel lines. Note that /boot usually needs to be mounted first. e.g.:

    sh-3.2# vi /mnt/lvroot/etc/fstab
    sh-3.2# mount -L /boot /mnt/lvroot/boot
    sh-3.2# vi /mnt/lvroot/boot/grub/grub.conf
  15. All done! type "exit" to reboot normally.
    sh-3.2# exit
  16. Assuming all went well (check /home), delete the old /home.old directory to free up its space on the root lv.
    [root@f7vm1 ~]# df -h
    Filesystem Size Used Avail Use% Mounted on
    4.9G 3.5G 1.2G 76% /
    /dev/sda1 99M 19M 76M 20% /boot
    tmpfs 252M 0 252M 0% /dev/shm
    1.6G 271M 1.4G 17% /home
    [root@f7vm1 ~]# swapon -s
    Filename Type Size Used Priority
    /dev/mapper/VolGroup00-lvswap partition 1048568 0 -1
    [root@f7vm1 ~]# rm -rf /home.old/
    [root@f7vm1 ~]# df -h /
    Filesystem Size Used Avail Use% Mounted on
    4.9G 3.3G 1.4G 71% /
  17. That's it. Enjoy your new /home until you're ready to clean install the next version of Fedora (see below if that time is now)...

Reinstallation Notes

Now that your /home is separated from your root '/' filesystem, you can reinstall Fedora from scratch without having to first backup /home and restore it later (though backups are still recommended).

  1. In the installer, you must must must remember to change "Remove Linux partitions on selected drives and create default layout" to "Create custom layout", then click next. If you forget to do this, your reinstall WILL wipeout your new /home. Now click Next and you should see something similar to this:


  2. You now need to tell the installer to reformat ONLY your /boot partition and your "/" lvroot LV (or LogVol00 if you didn't rename it above), and what their "Mount Points" are ("/boot" and "/" respectively).


  3. Do the same for the new lvhome LV, mounting it on "/home", but making sure to leave it set to "Leave unchanged" so it doesn't get formatted. You should end up with something like the following before continuing with the install as normal:



Common problems and fixes

  1. It may be necessary to fix the SELinux security context on /home

    # ls -ldZ /home*
    drwxr-xr-x root root system_u:object_r:root_t:s0 /home
    drwxr-xr-x root root system_u:object_r:home_root_t:s0 /home.old
    # chcon system_u:object_r:home_root_t:s0 /home
    # ls -ldZ /home*
    drwxr-xr-x root root system_u:object_r:home_root_t:s0 /home
    drwxr-xr-x root root system_u:object_r:home_root_t:s0 /home.old
  2. One thing to be aware of when keeping your /home directory alive across many installs is that sometimes old configuration files in your $HOME dir may conflict with newer versions of the apps that use them. In these rare cases it is necessary to remove the offending ~/.fubar/configfiles.



Added Reading

Document Actions
Log in

Forgot your password?
New user?