Resizing Linux Logical Volumes With LVM

Expanding an Existing Disk

If you are using a virtualization platform such as VMWare/Hyper-V/Xen/KVM/Citrix Xen/etc you will need to shutdown the VM and extend the virtual drive. Once you have finished doing this power the machine back on and do the following:

pvdisplay

This will display the physical volume group and what is currently in it. If you are working with a system that has a single disk you will likely be working off of /dev/sda of /dev/xvda in Citrix Xenserver. We will need to create a new partition on this disk to extend the logical volume in question

fdisk /dev/sda
p
n
p
3
accept default begin block
accept default end block
t
3
8e
p
w
q

The sequence of steps above opens fdisk for /dev/sda. The p denotes the printing of the current partition table, which can be useful to see how many partition numbers there are, usually this will be /dev/sda1 for the boot partition and /dev/sda2 for the filesystem partition. Assuming this is the case pressing n will create a new partition, select p for primary, then select the next available digit (in this case 3 so we can create /dev/sda3). Then accept the default starting block and the default ending block. Once this is complete we need to set the type by pressing t then select the partition number (3) then choose 8e as the identifier for Linux LVM. Once this is done press p to confirm everything looks correct then w to write changes and q to quit.

Once you press w you have committed the changes if you make a mistake press q and try again, this will prevent any erroneous writes from occurring.

At this point we can proceed to extend the volume

partprobe

running partprobe will resync the partition table to the OS so that it can see the new partition, a reboot will do the same thing and may be required if the next step fails, however if possible to avoid a reboot it would be advisable.

pvcreate /dev/sda3

This creates /dev/sda3 as a new physical volume in the physical volume group. Next we will need to see what the volume group name is and then extend the volume group.

vgdisplay

Using the output of the above command we can then extend that volume group. For this example I’ll call it vg_example, yours will be different

vgextend vg_example /dev/sda3

Next we will need to identify the name of your logical volume you wish to extend by running the following command

lvdisplay

Once you have acquired this name we can proceed to the next example. Please note I’ve used lv-root as the name, yours may differ, and I have also used 50Gb as the amount to extend by, please use the correct amount for your use case

lvextend -L +50G /dev/mapper/vg_example/lv-root

Now we have arrived at the final step which is to resize the filesystem

resize2fs /dev/mapper/vg_example/lv-root

If you are using CentOS 7 or another OS that defaults to an XFS filesystem you will need to use xfs_growfs instead of resize2fs

Adding an Additional Disk

If you are working with a physical machine or a VM that you are adding another disk to the process is similar to the above but moderately easier. Assuming the new device we are adding is /dev/sdb, if you are doing this without restarting the machine run partprobe before attempting the below command. If this doesn’t work a reboot may be required.

pvcreate /dev/sdb

This creates /dev/sdb as a new physical volume in the physical volume group. Next we will need to see what the volume group name is and then extend the volume group.

vgdisplay

Using the output of the above command we can then extend that volume group. For this example I’ll call it vg_example, yours will be different

vgextend vg_example /dev/sdb

Next we will need to identify the name of your logical volume you wish to extend by running the following command

lvdisplay

Once you have acquired this name we can proceed to the next example. Please note I’ve used lv-root as the name, yours may differ, and I have also used 50Gb as the amount to extend by, please use the correct amount for your use case

lvextend -L +50G /dev/mapper/vg_example/lv-root

Now we have arrived at the final step which is to resize the filesystem

resize2fs /dev/mapper/vg_example/lv-root

If you are using CentOS 7 or another OS that defaults to an XFS filesystem you will need to use xfs_growfs instead of resize2fs

 

Unable to Manage VMs in Hyper-V

Recently I came across a situation where a set of VMs running on cluster shared storage were all in an un-manageable state. They were not listing as being present on the host and exhibited the error shown in symptoms:

Symptoms

Virtual Machines show in a running or paused state but have the following error when attempting to access console, settings, or take any other management actions:

Screen Shot 2015-12-26 at 12.45.36 PM

Additionally try listing the VMs in Powershell

Get-VM

If the VM does not show in the list it is definitely in this state.

Problem

Check to see if any other VMs exhibit this issue and if they are on cluster shared storage. If you are using it make an exclusion for the Cluster Volume or disable AV as this is usually the culprit.

Remediation

Install Sysinternals process explorer here: https://technet.microsoft.com/en-us/sysinternals/processexplorer.aspx

Next we will locate the GUID of the VM in question

Screen Shot 2015-12-26 at 12.10.36 AM

Once you have located the GUID open process explorer as administrator and locate right click the VWP.exe processes and check the commandline entry under the “image” tab. This will display the GUID of the VMs. Select the VWP.exe that matches your trouble VM and kill the process.

DO NOT kill any other processes or you will potentially bring down other VMs

Screen Shot 2015-12-26 at 12.10.23 AM

Once you have done this you will need to restart the Hyper-V management stack by restarting the VMMS process. I have found some of these will not work properly with the restart-service cmdlet, so you will need to stop and then start the service. This does not effect the running VMs, it only effects your ability to manage them while this service is stopped.

Get-Service vmms
Stop-Service vmms
Start-Service vmms
Get-Service vmms

Now you should be up and running!