Skip to content

Instantly share code, notes, and snippets.

@mhlavac
Created June 18, 2013 05:10
Show Gist options
  • Save mhlavac/5802789 to your computer and use it in GitHub Desktop.
Save mhlavac/5802789 to your computer and use it in GitHub Desktop.
LVM add new physical volume to existing logical volume and extend that logical volume as much as possible.
#!/bin/sh
if [ `id -u` -ne '0' ]; then
echo "This script must be run as root" >&2
exit 1
fi
drive=$1
volume_group=$2
volume_group_location=$3
pvcreate $drive
vgextend $volume_group $drive
pvdisplay_output=`pvdisplay $drive --units b | grep "PV Size"`
pv_size=`echo $pvdisplay_output | awk '{print $3}'
pv_not_usable=`echo $pvdisplay_output | awk '{print $8}'
extend=`expr $pv_size - $pv_not_usable`
lvextend -L +$extend $volume_group_location
resize2fs $volume_group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment