Expand LVM in CentOS 6 Running on vCenter
Posted 82 days ago by Alex in Hardware, Software, Technology
This is an update to the post I created back in June of 2011 on how to expand an LVM in CentOS 5.6 running on vCenter. CentOS 6 has made some changes to the way the LVMs are setup so I thought I would update this document accordingly.
- Using your vSphere client, increase the size of the disk attached to the VM.
- Boot into the CentOS 6 installation disk and select ‘Rescue Mode’ from the list of options.
- When prompted to search for LVM partitions on the disk, select ‘Skip’.
- Type the following commands at the prompt. The following assume you have a standard CentOS LVM configuration.
fdisk /dev/sda p # Print partition table n # New partition p # Primary partition 3 # ID = 3 # When prompted, add 1 to the end block value for the sda2 partition and use it as the start of the sda3 partition. # Use the default for the size which should be the rest of the free space on the disk. t # Change partition type 3 # Change partition 3 8e # Type = Linux LVM p # Print partition table w # Write partition table # Create a new LVM physical volume from the new partition lvm pvcreate /dev/sda3 lvm pvdisplay # Mount the volume group lvm vgscan lvm vgchange -ay # You will see the name of the volume group that is activated. Usually something like 'vg_hostname'. # Extend the volume group with the new physical volume. Be sure to substitute the name of your volume group in the command below. lvm vgextend /dev/vg_hostname /dev/sda3 # Extend the logical volume to include 100% of the free space on the volume group. lvm lvextend /dev/vg_hostname/lv_root /dev/sda3 # Mount the volume group lvm vgscan lvm vgchange -ay # Run a filesystem check on the newly expanded disk e2fsck -f /dev/vg_hostname/lv_root # Resize the filesystem to use the entire disk resize2fs /dev/vg_hostname/lv_root
- After rebooting, you can confirm the final size of your disk using:
df -h
As always, have a backup of your data.
