LVM offers extending logical partitions over multiple hard drives or creating mirrored storage. Whilst seemingly easy and user-friendly, caution has to be taken as boot repair is sometime not possible and issues can occur while trying to extend partitions or execute various LVM-specific operations. Below is example of reasonable LVM operation (extending logical volume using new physical device). Note that all LVM operations carry significant risk of total data loss due to human/software error.
Helpful commands
- Displaying layout and names of disk devices (device names in first column)
sudo lsblk -fp
- Displaying mounted partitions (including LVM logical volume names, when used)
df -hT
- Listing LVM volume groups
sudo vgs
- Listing LVM logical volumes
sudo lvs
- Extending logical volume LV_NAME (see: listing LVM logical volumes), a
member of volume group VG_NAME (see: listing LVM volume groups) by 10 GiB
sudo lvextend -L +10G VG_NAME/LV_NAME
or by 10% of free (unassigned) spacesudo lvextend -l +10%FREE VG_NAME/LV_NAME
- Growing ext4 filesystem of FILESYSTEM_PATH (see: displaying mounted
partitions) to fill out all unused space on logical volume
sudo resize2fs FILESYSTEM_PATH
for XFSsudo xfs_growfs FILESYSTEM_PATH
Expanding LVM partition by adding disk device
This is typical, least-risky method of adding space to a partition that is located on Logical Volume. It's still risky operation which might result in outage/data loss without any operator error, especially under heavy IO load and it "pollutes" list of devices attached to VM (in case of virtualized environment).
- Open new tmux session, to ensure operation will continue even if connection is lost
tmux
If you've lost connection to machine performing changes, attach to an existing tmux sessiontmux a
Alternatively, if you prefer to use screen, open new screen sessionscreen
To detach screen session from other and attach to itscreen -d -r
- Extend volume group VG_NAME (see: listing LVM volume groups) by device with device
path DEVICE_PATH (see: displaying layout and names of disk devices)
sudo vgextend VG_NAME DEVICE_PATH
- Follow instructions on how to extend logical volumes
- Follow instructions on how to resize filesystem
Expanding Logical Volume that uses LVM-based pseudo-RAID1
LVM redundancy capabilities cost performance and are fragile (as LVM is).
❗ This guide offer less details on how to determine correct arguments. Always learn in safe test environment, never do anything on production without backups that were recently verified to be sufficient and accessible.
- Open LVM config file - make sure scan_lvs is set to 1
sudo nano /etc/lvm/lvm.conf
- Create PVs on both new devices
sudo pvcreate NEW_FIRST_DEVICE_PATH
sudo pvcreate NEW_SECOND_DEVICE_PATH
- Create new VG NEW_VG_NAME with members PVs NEW_FIRST_DEVICE_PATH and NEW_SECOND_DEVICE_PATH
sudo vgcreate NEW_VG_NAME NEW_FIRST_DEVICE_PATH NEW_SECOND_DEVICE_PATH
- Create new LV NEW_LV_NAME in new VG NEW_VG_NAME
sudo lvcreate --mirrors 1 --type raid1 -l 100%FREE --nosync -n NEW_LV_NAME NEW_VG_NAME
- Create new PV (it will accessible as NEW_VG_NAME!) in LV NEW_LV_NAME (we do this to extend LV that is
already in LVM RAID1)
sudo pvcreate /dev/NEW_LV_NAME
- Use NEW_VG_NAME from here as LV_NAME there
Expanding LVM partition by resizing disk device
It's more risky and complex method of adding space to partition that is located on Logical Volume which does not add additional disk devices to gain more space without rebooting.
- Issue iSCSI rescan command;
-
characters are wildcards to scan for any change of channel, SCSI target ID and LUNecho "- - -" > /sys/class/scsi_host/host0/scan echo "- - -" > /sys/class/scsi_host/host1/scan echo "- - -" > /sys/class/scsi_host/host2/scan
- Refresh size of iSCSI devices
echo 1 > /sys/block/DISK_DEVICE_PATH/device/rescan
- Check for capacity change in kernel logs
sudo dmesg | grep 'detected capacity change'
- Check current partition table of DEVICE_PATH (see: displaying layout and names of disk
devices) to determine number of partition (PARTITION_NUMER) you wish to extend. Typically, on boot
disk, first partition will be backward-compatibility related, second will be boot partition and third
will be root partition
fdisk -l DEVICE_PATH | grep ^/dev
- Resize target partition on DEVICE_PATH
parted DEVICE_PATH print F resizepart PARTITION_NUMER 100% quit
- Resize PV to use all of available space
sudo pvresize PV_NAME
- Follow instructions on how to extend LV
- Follow instructions on how to resize filesystem
Last update: 2024-08-10