Resize an LVM Partition on VMware

Accommodate growth of a VM by expanding an LVM partition

At some point, a “physical volume” may have to be enlarged to accommodate growth on a VM. This is how you grow the filesystem of an existing VMDK without adding an additional disk to your VM.

Enlarging a VMDK

  • login to VMware
  • Find the VM with the disk that needs to be made larger
  • Right click and select “Edit Settings”
  • Find the specific Hard Disk and update the capacity to the desired size
  • Click “Ok”

Expanding the VM Volume Size

In most cases, the “Physical Volume” information will not be updated automatically. To force a recheck of the SCSI bus and drive settings run the following commands.

Figure out the configured SCSI ID

[root@server ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
    Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
    Type: CD-ROM ANSI SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
    Vendor: VMware Model: Virtual disk Rev: 1.0
    Type: Direct-Access ANSI SCSI revision: 02

Using output from the above sample the command would be

echo '1' > /sys/class/scsi_disk/2\:0\:0\:0/device/rescan

Use fdisk to Edit the Drive Geometry

The below is an example and may be different on the actual host you are enlarging a partition on. Do not proceed unless you know what you are doing.

fdisk /dev/sda

Hit p to print configuration

WARNING: DOS-compatible mode is deprecated. It is strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
 
Command (m for help): p
 
Disk /dev/sda: 375.8 GB, 375809638400 bytes
255 heads, 63 sectors/track, 45689 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00048792
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64       32635   261627613+  8e  Linux LVM

Hit d and then enter the partition number. In the above example there are only two partitions so 2 is the appropriate number

Command (m for help): d
Partition number (1-4): 2

Make sure not to change the starting cylinder to anything other than its original value. Doing so may result in data loss.

Hit n to create a new partition

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (64-45689, default 64):
Using default value 64
Last cylinder, +cylinders or +size{K,M,G} (64-45689, default 45689):
Using default value 45689

Hit t to change the partition type to LVM (8e)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Hit p to verify the new partition table is correct and hit w to write changes

Command (m for help): p
 
Disk /dev/sda: 375.8 GB, 375809638400 bytes
255 heads, 63 sectors/track, 45689 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00048792
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64       45689   366483868+  8e  Linux LVM
 
Command (m for help): w
The partition table has been altered!

If making changes to the disk where the root / partition is mounted, the system will have to be restarted

shutdown -r now

Resize the Physical Volume

Resize physical volume

pvresize /dev/sda2
pvscan

Extend the logical volume you wanted to grow

lvextend -L +100G /dev/vg_local/lv_var

Depending on the partition type xfs or ext4, pick the instructions that are most appropriate. You can check by using df -Tf or lsblk -f

a:) Resize ext4 Partition

resize2fs /dev/vg_local/lv_var

b:) Resize xfs Partition

yum install xfsprogs.x86_64
xfs_growfs /dev/vg_local/lv_var

Check Volume Size

lvdisplay

You must be logged in to post a comment.

Proudly powered by WordPress   Premium Style Theme by www.gopiplus.com