Ubuntu – How to use move space from /home lvm to root lvm


I have a root lvm with 10 GB, most of which is used, and a /home lvm with 877 GB. I want to resize the /home lvm to free up space, and then allocate that to root. I'm not clear on whether I can dynamically resize the partitions while mounted, but as far as I can tell, that's not possible. Also, as far as I can tell, I can't unmount /home or root unless I'm using a rescue disk.

Normally if I wanted to resize a disk partition that I couldn't otherwise unmount, I would use a gparted live disk. But as far as I know, gparted only works on "real" partitions, and can't operate on lvm partitions. So what's the best way to get access to the unmounted partitions and resize them?



Best Answer

LVM makes this rather easy and straightforward. lvreduce will have to unmount the filesystem you want to shrink, but the filesystm to be expanded can do so while being mounted.

Steps: 1 backup - 2 reduce home lv - 3 check - 4 grow root lv - 5 check - 6 backup config

Only steps 2 and 4 are needed - the rest is just good practice. I also recommend logging the entire process by running script.

Note: The Volume group in the example output is called tetrad (same as the hostname), you will want to insert the name of your volume group into the commands. The example output was gathered from archived logs as might be deduced from the differring version numbers of the resize2fs command.

  1. Backup (at least your current configuration). Copy your backup somewhere outside the volume group being modified.

    root@tetrad:~/Documentation/LVM# vgcfgbackup -f tetrad-vgcfg-2014-10-09-before-2
  2. Reduce home lv

    root@tetrad# lvresize --resizefs -L -35G /dev/mapper/tetrad-export

    resize2fs 1.42 (29-Nov-2011)
    Resizing the filesystem on /dev/mapper/tetrad-export to 23955456 (4k) blocks.
    The filesystem on /dev/mapper/tetrad-export is now 23955456 blocks long.
    Reducing logical volume export to 91.38 GiB
    Logical volume export successfully resized
  3. Check (optional), backup current state as in step 1. You will notice that step 4 does a backup to /etc/lvm/backup/<vgname>, but since that's on the filesystem being modified, you want your copy somewhere else.

    root@tetrad# pvs
    PV         VG     Fmt  Attr PSize   PFree 
    /dev/sda3  tetrad lvm2 a-   201.14g 37.76g
  4. Grow root lv

    root@tetrad:~/Documentation/LVM# lvextend -L +2G /dev/mapper/tetrad-root -r -v
        Finding volume group tetrad
        Executing: fsadm --verbose check /dev/tetrad/root
    fsadm: "ext4" filesystem found on "/dev/mapper/tetrad-root"
    fsadm: Skipping filesystem check for device "/dev/mapper/tetrad-root" as the   filesystem is mounted on /
        fsadm failed: 3
        Archiving volume group "tetrad" metadata (seqno 27).
      Extending logical volume root to 26,00 GiB
        Found volume group "tetrad"
        Found volume group "tetrad"
        Loading tetrad-root table (252:0)
        Suspending tetrad-root (252:0) with device flush
        Found volume group "tetrad"
        Resuming tetrad-root (252:0)
        Creating volume group backup "/etc/lvm/backup/tetrad" (seqno 28).
      Logical volume root successfully resized
        Executing: fsadm --verbose resize /dev/tetrad/root 27262976K
    fsadm: "ext4" filesystem found on "/dev/mapper/tetrad-root"
    fsadm: Device "/dev/mapper/tetrad-root" size is 27917287424 bytes
    fsadm: Parsing tune2fs -l "/dev/mapper/tetrad-root"
    fsadm: Resizing filesystem on device "/dev/mapper/tetrad-root" to 27917287424 bytes (6291456 -> 6815744 blocks of 4096 bytes)
    fsadm: Executing resize2fs /dev/mapper/tetrad-root 6815744
    resize2fs 1.42.9 (4-Feb-2014)
    Filesystem at /dev/mapper/tetrad-root is mounted on /; on-line resizing required
    old_desc_blocks = 2, new_desc_blocks = 2
    The filesystem on /dev/mapper/tetrad-root is now 6815744 blocks long.

You're done. Now let's just admire the results and keep a backup of the current state.

  1. Check with pvs, lvs
  2. Backup configuration and store copy on a separate filesystem for safekeeping.
Related Question