How to Dynamically Resize Root LVM Partition in Fedora Without Reboot or LiveCD


1 views

When working with Fedora servers in production environments, resizing the root LVM partition often requires system downtime. However, we can achieve this dynamically through careful LVM manipulation. Here's how I successfully expanded a 20GB root partition to 50GB without rebooting.

First, confirm your disk space allocation:

# fdisk -l /dev/sda
Disk /dev/sda: 53.7 GB, 53687091200 bytes
...
/dev/sda2         1026048    83886079    41430016   8e  Linux LVM

Unlike regular partitions, LVM partitions require special handling. Use parted for this operation:

# parted /dev/sda
(parted) print
(parted) rm 2
(parted) mkpart primary 1026048s 100%
(parted) set 2 lvm on
(parted) quit

After modifying the partition table, inform the kernel without rebooting:

# partprobe /dev/sda
# echo 1 > /sys/block/sda/device/rescan

With the partition resized, we can now extend the LVM components:

# pvresize /dev/sda2
# pvs
  PV         VG       Fmt  Attr PSize  PFree
  /dev/sda2  VolGroup lvm2 a--  49.99g 13.89g

Now we'll allocate the new space to the root volume:

# lvextend -l +100%FREE /dev/mapper/VolGroup-lv_root
# lvs
  LV      VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_root VolGroup -wi-ao---- 49.99g

Finally, expand the filesystem to use the new space. For ext4:

# resize2fs /dev/mapper/VolGroup-lv_root
# df -h /
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root  49G   18G   29G  39% /

Always verify each step:

# pvdisplay
# vgdisplay
# lvdisplay
# lsblk
# df -h

For XFS filesystems, use xfs_growfs instead:

# xfs_growfs /

If you encounter "device busy" errors, try:

# dmsetup remove_all
# vgchange -an VolGroup
# vgchange -ay VolGroup

For systems with swap volumes, temporarily disable swap:

# swapoff -a
# lvextend commands...
# swapon -a

When your VM storage grows but your root LVM partition doesn't automatically follow, you're left with unused space that's visible in fdisk -l but inaccessible to your system. The traditional LiveCD approach isn't viable for production servers where uptime is critical.

First verify your current setup:

# Check disk space
lsblk
sudo fdisk -l /dev/sda

# Verify LVM structure
sudo pvdisplay
sudo vgdisplay
sudo lvdisplay

The most delicate part - resizing the LVM-containing partition. While parted resize fails for LVM, we can safely:

# Delete existing partition (data remains intact in LVM)
sudo parted /dev/sda
(parted) rm 2
(parted) mkpart primary 1026048s 100%

# Set partition type
(parted) set 2 lvm on
(parted) quit

Note: The start sector (1026048s) must match exactly your original partition's start.

Now inform LVM about the new space:

# Rescan the partition table
sudo partprobe /dev/sda

# Extend physical volume
sudo pvresize /dev/sda2

# Verify free space
sudo pvdisplay

Allocate the new space to your root volume:

# Extend LV (using all free space)
sudo lvextend -l +100%FREE /dev/mapper/VolGroup-lv_root

# For precise allocation (e.g., +30G):
# sudo lvextend -L+30G /dev/mapper/VolGroup-lv_root

Finally grow the filesystem online:

# For ext4:
sudo resize2fs /dev/mapper/VolGroup-lv_root

# For xfs:
sudo xfs_growfs /

Confirm the changes took effect:

df -h
lsblk
sudo lvdisplay

Before performing these operations:

  • Take a VM snapshot if possible
  • Have console access in case of network interruption
  • Run during low-traffic periods
  • Consider testing on a non-critical system first

Common issues and fixes:

# If pvresize fails:
sudo pvresize --setphysicalvolumesize 50G /dev/sda2

# If filesystem resize fails:
sudo e2fsck -f /dev/mapper/VolGroup-lv_root
sudo resize2fs /dev/mapper/VolGroup-lv_root