The examples given are with and without an existing swap volume and will use an Ubuntu Live CD ISO as the surrogate.
Shutdown the target machine.
In VMware Player, select the target and go to 'Edit virtual machine settings'.
Select the 'Hard Disk' and then go to 'Utilities -> Expand...'.
Enter the new size, ie 32GB and click on 'Expand'.
Select the 'CD/DVD', ensure 'Connect at power on' is checked, select 'Use ISO image file:' and browse for an approriate Live CD ISO file to boot from. Click OK.
In VMware Player, select the target and start it. Ensure you are booting into the Live CD.
If the boot is incorrect, append the line 'bios.forceSetupOnce = "TRUE"' to your target 'vmx' file, make the necessary bios changes and then boot into the Live CD.
Make sure you select 'Try Ubuntu' and NOT install.
root@ubuntu:~# lsblk
Now that we have identified sda as our target we can go to work on it. Proceed with caution as you can easily destroy all your data!
fdisk /dev/sda # open sda in 'fdisk'
Use the 'p' command to print the current partition table, note the start sector addresses of both sda2 and sda5.
Use the 'd' command to delete partitions 5 and then 2.
Use the 'n' command to create a new extended partition 2. Use the default sector start address which may be less than the original sda2.
Use the 'n' command to create a new logical partition 5. Make sure the sector start address is exactly the same as the original sda5. Do not remove the LUKS signature if asked.
Use the 'w' command to write the changes and exit from 'fdisk'.
The system may automatically mount sda1/sda5 during operations. If so unmount them.
Simple Single Volume
In this example we will expand the entire disk from 32GB to 64GB.
cryptsetup luksOpen /dev/sda5 target # use the LUKS password to decrypt sda5
vgscan --mknodes && vgchange -ay # Identify and activate the LVM.
cryptsetup resize target # Resize the crypt
pvresize /dev/mapper/target # Resize the volume group
pvchange -x y /dev/mapper/target # unlock the (LVM) physical volume.
lvresize -r -L+32G /dev/xubuntu-vg/root # increase our root volume by in this case 32GB, resizing (-r) the underlying filesystem
vgdisplay # find out how much space is now available in our volume group
pvchange -x n /dev/mapper/target # re-lock the physical volume
shutdown -h now # we are done with the Live CD so.
Include A Swap File
In this example we will expand the entire disk from 32GB to 64GB moving an existing swap file of 4GB to the end of the drive.
cryptsetup luksOpen /dev/sda5 target # use the LUKS password to decrypt sda5
# the system may automatically mount sda and the logical volumes
# inside target_encrypted_volume. If so unmount them.
vgscan --mknodes && vgchange -ay # Identify and activate the LVM.
cryptsetup resize target # Resize the crypt
pvresize /dev/mapper/target # Resize the volume group
lvdisplay # Use 'lvdisplay' to identify the target volumes for managing
lvremove /dev/xubuntu-vg/swap # remove our swap volume, it is in the way.
pvchange -x y /dev/mapper/target # unlock the (LVM) physical volume.
lvresize -r -L+32G /dev/xubuntu-vg/root # increase our root volume by in this case 32GB, resizing (-r) the underlying filesystem
vgdisplay # find out how much space is now available in our volume group
lvcreate --extents 1024 -n /dev/xubuntu-vg/swap xubuntu-vg # Create a new volume (516 comes from finding the available 'logical extents' in the group using 'vgdisplay'). Remove Swap signature
pvchange -x n /dev/mapper/target # re-lock the physical volume (may be redundant)
mkswap /dev/xubuntu-vg/swap # make the new 4GB volume a swap volume. Copy the UUID to the clipboard.
lvdisplay # Use 'lvdisplay' to check our new volumes look good.
lsblk # final sanity check
shutdown -h now # we are done with the Live CD
Edit the target machine to disconnect the CDROM at startup.
Start the target machine and check all changes work as intended.
References Used
https://linux.die.net/man/8/lvcreate
http://www.systemadminihater.com/linux/split-a-lvm2-volume-group-into-two-or-more/
http://www.thegeekstuff.com/2010/08/how-to-create-lvm
https://linux.die.net/man/8/lvresize
http://tldp.org/HOWTO/LVM-HOWTO/removelv.html
https://help.ubuntu.com/community/ResizeEncryptedPartitions
http://askubuntu.com/questions/63594/mount-encrypted-volumes-from-command-line ]]>