User Tools

Site Tools


extend_vmware_lvm_disk

This is the process I've used to extend a LVM VMware disk. I try to setup each mount point as it's own disk so it is easier to expand on demand.

For example, you want to expand /bk from 500MB to 750MB.

Find out which volume group the mount point is on:

[[email protected] ~]# df -h /bk
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_bkup-lv_bk
                      457M  2.3M  431M   1% /bk

The volume group is vg_bkup and the logical volume is lv_bk

Determine the disk:

[[email protected] ~]# pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sdb   vg_root lvm2 a--   33.97g    0
  /dev/sdc   vg_temp lvm2 a--    6.97g    0
  /dev/sdd   vg_prog lvm2 a--    9.97g    0
  /dev/sde   vg_data lvm2 a--    4.00g    0
  /dev/sdf   vg_bkup lvm2 a--  480.00m    0

vg_bkup is on /dev/sdf

Determine the SCSI ID:

[[email protected] ~]# ll /dev/disk/by-path/
total 0
lrwxrwxrwx 1 root root  9 Jul  9 15:46 pci-0000:00:07.1-scsi-1:0:0:0 -> ../../sr0
lrwxrwxrwx 1 root root  9 Jul  9 15:46 pci-0000:03:00.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 Jul  9 15:46 pci-0000:03:00.0-scsi-0:0:0:0-part1 -> ../../sda1
lrwxrwxrwx 1 root root  9 Jul  9 15:46 pci-0000:03:00.0-scsi-0:0:1:0 -> ../../sdb
lrwxrwxrwx 1 root root  9 Jul  9 15:46 pci-0000:03:00.0-scsi-0:0:2:0 -> ../../sdc
lrwxrwxrwx 1 root root  9 Jul  9 15:46 pci-0000:03:00.0-scsi-0:0:3:0 -> ../../sdd
lrwxrwxrwx 1 root root  9 Jul  9 15:46 pci-0000:03:00.0-scsi-0:0:4:0 -> ../../sde
lrwxrwxrwx 1 root root  9 Jul  9 15:46 pci-0000:03:00.0-scsi-0:0:5:0 -> ../../sdf

You can look back from sdf and see that the the ID is 0:0:5:0. The important part is the two middle numbers - 0:5

Open vSphere Console and edit the settings for the machine. By checking the Hard disks and looking under the Virtual Device Node, you should find the disk that matches those SCSI numbers - in this case, it is hard disk 6. Update the drive size to add the required space and click OK.

Get Linux to rescan the drive (note the device in the middle):

echo '1' > /sys/block/sdf/device/rescan

Then expand the physical volume:

[[email protected] ~]# pvresize /dev/sdf
  Physical volume "/dev/sdf" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

Then look at the volume:

[[email protected] ~]# vgdisplay vg_bkup
  --- Volume group ---
  VG Name               vg_bkup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               736.00 MiB
  PE Size               32.00 MiB
  Total PE              23
  Alloc PE / Size       15 / 480.00 MiB
  Free  PE / Size       8 / 256.00 MiB
  VG UUID               Z2l4Rd-kBJr-JaZd-uP5H-Rcg9-XfFM-CxW0Pm

You can see by the free PE / size that the volume now has potentially free space.

Add the space the the logical volume. I spec this use the physical extents number as it is the most accurate:

[[email protected] ~]# lvextend -l +8 /dev/vg_bkup/lv_bk
  Size of logical volume vg_bkup/lv_bk changed from 480.00 MiB (15 extents) to 736.00 MiB (23 extents).
  Logical volume lv_bk successfully resized

And then extend the filesystem

[[email protected] ~]# resize2fs /dev/vg_bkup/lv_bk
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_bkup/lv_bk is mounted on /bk; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/vg_bkup/lv_bk to 753664 (1k) blocks.
The filesystem on /dev/vg_bkup/lv_bk is now 753664 blocks long.

And check the results:

[[email protected] ~]# df -h /bk
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_bkup-lv_bk
                      705M  2.6M  666M   1% /bk
extend_vmware_lvm_disk.txt · Last modified: 2016/02/12 13:42 by The SuperUser