Skip to content

Instantly share code, notes, and snippets.

@huksley
Last active December 17, 2015 06:48
Show Gist options
  • Save huksley/5567559 to your computer and use it in GitHub Desktop.
Save huksley/5567559 to your computer and use it in GitHub Desktop.
Extend LVM with new logical sdaX disk. Online, hot, without restart.
#!/bin/sh
LV=`lvs | grep -v swap | sed -re "s/^[ ]+//;s/[ ]+/ /g" | cut -d" " -f1 | tail -n+2`
VG=`lvs | grep -v swap | sed -re "s/^[ ]+//;s/[ ]+/ /g" | cut -d" " -f2 | tail -n+2`
if [ "$1" = "" ]; then
echo specify /dev/sda?
exit
fi
echo Extending /dev/mapper/$VG-$LV using $1 as source space
pvcreate $1
vgextend $VG $1
lvextend -l +100%FREE /dev/mapper/$VG-$LV
resize2fs /dev/mapper/$VG-$LV
df -h /dev/mapper/$VG-$LV
@huksley
Copy link
Author

huksley commented May 14, 2013

If you are using VMWare and adding space to existing disk, issue as root

echo 1 > /sys/block/sda/device/rescan

to rescan disk for changes (dmesg must say sda: detected capacity change from X to Y)
after that,

make partition using cfdisk to make this disk as logical, 8e type (for LVM)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment