#!/bin/bash # This scrip makes some evil assumptions: # # o That the disk was partitioned as 120 Gigs # o That the real disk size will be reported as numGB (in Gigs) # (i.e. this wont work if parted decides to display it in terabytes # or megabytes on some disks) # OUTPATTERN="Disk /dev/hdb: " DISKOUT=`parted /dev/hdb print | grep "$OUTPATTERN"` DISKSIZE=${DISKOUT#$OUTPATTERN} echo "this disk size is $DISKSIZE" echo "that would be ${DISKSIZE%GB} Gigs I think" DISKGIGS=${DISKSIZE%GB} if [ $DISKGIGS -gt 120 ]; then # Found a disk that is physically bigger than 120GB # Resize the extended partition to span till the end of the disk parted /dev/hdb resize 4 3208MB $DISKSIZE # Create /dev/hdb7 with the remaining disk space parted /dev/hdb mkpart logical 120GB $DISKSIZE # XXX massgaol dissapears here for a few secs.... sleep 2 vgscan # Give the system some time to create the fs nodes needed # to proceed sleep 5 # Create a physical volume for pvcreate -y -ff /dev/hdb7 # Adding more ... sleep 2 # Scan volume groups... needed to make 'massgaol' recognized # in the next step. vgscan # Add new physical volume to the volume group vgextend massgaol /dev/hdb7 # Get the current size of the virtual group now... # (get the 12'th field, separated by ':'). VGSIZE=`vgdisplay -c massgaol | cut -d : -f12` # Activate the group -- this creates /dev/massgaol/massgaolLV vgchange -ay # Extend the logical volume to span the entire volume group lvextend /dev/massgaol/massgaolLV -L${VGSIZE}KB # Resize sometimes wants an fsck first. e2fsck -f /dev/massgaol/massgaolLV # Resize the overlying filesystem resize2fs /dev/massgaol/massgaolLV # deactivate the group for now vgchange -an fi