Skip to content

Instantly share code, notes, and snippets.

@vpetersson
Created September 12, 2013 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpetersson/6531944 to your computer and use it in GitHub Desktop.
Save vpetersson/6531944 to your computer and use it in GitHub Desktop.
#!/bin/bash
NEWDEV='/dev/vdb'
# Partition the new disk as LVM
echo -e "n\np\n1\n\n\nt\n8e\nw" | sudo fdisk $NEWDEV
# Initiate the disk
sudo pvcreate $NEWDEV\1
# Get the VG Name
VGNAME=$(sudo vgdisplay | grep 'VG Name' | awk {'print $3'})
# Extend the volume
sudo vgextend $VGNAME $NEWDEV\1
# Get the free size in VG
FREESIZE=$(sudo vgdisplay | grep 'Free PE / Size' | awk {'print $7'})
# Get root partition
LVROOT=$(sudo lvdisplay | grep 'LV Name' | grep 'root' | awk {'print $3'})
# Expand the volume
sudo lvextend -L $FREESIZE\G $LVROOT
# Expand the file system
sudo sudo resize2fs $LVROOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment