How to Resize LVM Partitions: Transfer 150GB Space from /home to /root in Linux


2 views

Looking at the system configuration, we have a typical LVM setup with:

[root@testsyst ~]# vgdisplay
  VG Name               vg_testsyst
  VG Size               299.50 GiB
  Free  PE / Size       0 / 0

The key volumes we're working with:

  • /dev/mapper/vg_testsyst-lv_root: 50GB (46% used)
  • /dev/mapper/vg_testsyst-lv_home: 245.50GB (only 188MB used)

Here's how to safely move 150GB from /home to /:

# First, unmount /home if possible (if users aren't actively using it)
umount /home

# If umount fails because it's busy:
fuser -vm /home  # Identify processes using /home
# Kill or stop these processes before proceeding

# Resize the filesystem (ext4 in this case) - leave some buffer space
e2fsck -f /dev/mapper/vg_testsyst-lv_home
resize2fs /dev/mapper/vg_testsyst-lv_home 90G

# Now resize the logical volume
lvresize -L 90G /dev/mapper/vg_testsyst-lv_home

# Verify the changes
lvdisplay /dev/mapper/vg_testsyst-lv_home

# Add the freed space to root volume
lvextend -L +150G /dev/mapper/vg_testsyst-lv_root
resize2fs /dev/mapper/vg_testsyst-lv_root

# Remount /home
mount /home

If you can't unmount /home, some modern systems support online resize:

# Shrink filesystem first (critical!)
resize2fs /dev/mapper/vg_testsyst-lv_home 90G

# Then shrink LV (must match or be slightly smaller than FS)
lvresize --resizefs -L 90G /dev/mapper/vg_testsyst-lv_home

After the operation, verify with:

df -h
lsblk
vgdisplay

Common issues to watch for:

  • Never resize LV before filesystem
  • Always maintain backups
  • Consider adding 1-2GB buffer beyond what you calculate

For frequent operations, here's a safety-check script:

#!/bin/bash
SOURCE_LV="/dev/mapper/vg_testsyst-lv_home"
TARGET_LV="/dev/mapper/vg_testsyst-lv_root"
SHRINK_SIZE="90G"
GROW_SIZE="150G"

# Safety checks
if ! lvdisplay $SOURCE_LV >/dev/null 2>&1; then
    echo "ERROR: Source LV not found"; exit 1
fi

# Main operations
echo "Starting resize operation..."
umount /home || { echo "Failed to umount /home"; exit 1; }
e2fsck -f $SOURCE_LV
resize2fs $SOURCE_LV $SHRINK_SIZE
lvresize -L $SHRINK_SIZE $SOURCE_LV
lvextend -L +$GROW_SIZE $TARGET_LV
resize2fs $TARGET_LV
mount /home

echo "Operation completed successfully"

Before performing any resizing operations, let's examine the current LVM setup based on the provided outputs:

# Current disk usage
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/vg_testsyst-lv_root   50G   22G   26G  46% /
/dev/mapper/vg_testsyst-lv_home  242G  188M  230G   1% /home

# Volume Group information
VG Name               vg_testsyst
VG Size               299.50 GiB
Allocated PE          76671/76671
Free PE               0

Here's how to safely transfer 150GB from /home to /:

1. Unmount the Home Partition

umount /home
# Verify unmount was successful
mount | grep home

2. Check Filesystem Integrity

e2fsck -f /dev/vg_testsyst/lv_home

3. Resize the Home Logical Volume

# Reduce lv_home by 150GB (from 245.5GB to 95.5GB)
lvreduce -L -150G /dev/vg_testsyst/lv_home

# Resize the filesystem to match (ext4 example)
resize2fs /dev/vg_testsyst/lv_home

4. Extend the Root Logical Volume

# First check available space in VG
vgs

# Extend lv_root by 150GB
lvextend -L +150G /dev/vg_testsyst/lv_root

# Resize the filesystem (ext4 example)
resize2fs /dev/vg_testsyst/lv_root

5. Remount the Home Partition

mount /home
df -h  # Verify new sizes

Filesystem in Use Error

If you encounter "target is busy" errors when trying to unmount /home:

# Find processes using /home
fuser -vm /home

# Kill processes or use lazy unmount
umount -l /home

Insufficient Space in VG

If vgdisplay shows no free space, check if you can reclaim space:

# Check for snapshots
lvdisplay

# Remove unnecessary snapshots
lvremove /dev/vg_testsyst/snapshot_name

For more flexible space management in the future:

# Convert to thin pool (example)
lvconvert --type thin-pool vg_testsyst/lv_home

# Create thin volumes
lvcreate -V 100G -T vg_testsyst/lv_home -n lv_thin_vol

For repeated operations, consider this bash script template:

#!/bin/bash
VG_NAME="vg_testsyst"
LV_HOME="/dev/${VG_NAME}/lv_home"
LV_ROOT="/dev/${VG_NAME}/lv_root"
SIZE_TO_MOVE="150G"

echo "Starting LVM resize operation..."
umount /home || { echo "Failed to unmount /home"; exit 1; }
e2fsck -f $LV_HOME
lvreduce -L -$SIZE_TO_MOVE $LV_HOME
resize2fs $LV_HOME
lvextend -L +$SIZE_TO_MOVE $LV_ROOT
resize2fs $LV_ROOT
mount /home
echo "Operation completed successfully. New sizes:"
df -h | grep -E "Filesystem|${VG_NAME}"

Remember to backup critical data before performing these operations and test in a non-production environment first.