Expand an existing Disk in Linux 7 Virtual Machine VM

In this post I am going to share how to extend an existing disk and increase its size. This whole process is online and no downtime involved.

Steps:

1) Identify the disk which needs to be extended.


root@funebs122:~# df

/dev/mapper/vg01_funebs122-lvol0                          157205508 151190476   6015032  97% /u01
lsblk

root@funebs122:/var/log# fdisk -l /dev/sdd

Disk /dev/sdd: 161.1 GB, 161061273600 bytes, 314572800 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

 

2) Identify the SCSI ID using below command for the disk. I have highlighted the ID.



root@funebs122:/var/log# udevadm info --query=all --name=/dev/sdd

P: /devices/pci0000:00/0000:00:15.0/0000:03:00.0/host0/target0:0:2/0:0:3:2/block/sdd

N: sdd

S: disk/by-id/lvm-pv-uuid-gasyg52-bIv2-t1Yr-gs64-ntvY-6yz8-jhas67

S: disk/by-path/pci-0000:03:00.0-scsi-0:0:3:2

E: DEVLINKS=/dev/disk/by-id/lvm-pv-uuid-gasyg52-bIv2-t1Yr-gs64-ntvY-6yz8-jhas67 /dev/disk/by-path/pci-0000:03:00.0-scsi-0:0:3:2

E: DEVNAME=/dev/sdd

E: DEVPATH=/devices/pci0000:00/0000:00:15.0/0000:03:00.0/host0/target0:0:2/0:0:3:2/block/sdd


 3) Verify the SCSI devices


root@funebs122:/var/log# ls /sys/class/scsi_device/

0:0:0:0  0:0:1:0  0:0:3:2  3:0:0:0

 4) Extend the disk from the VM disk and resize. This can be done from your system Admin if you don't have access.


 

5) Rescan the disk after the increase at VM level.


root@funebs122:/var/log# echo 1 > /sys/class/scsi_device/0\:0\:2\:0/device/rescan

 6) Check the new size of the disk


root@funebs122:/var/log# fdisk -l /dev/sdd


Disk /dev/sdd: 214.7 GB, 214748364800 bytes, 419430400 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

 

7) As I am using an LVM we need to increase. the PV size.


root@funebs122:/var/log# pvresize  /dev/sdd

  Physical volume "/dev/sdd" changed

  1 physical volume(s) resized / 0 physical volume(s) not resized

 

root@funebs122:/var/log# pvdisplay /dev/sdd

  --- Physical volume ---

  PV Name               /dev/sdd

  VG Name               vg01_funebs122

  PV Size               200.00 GiB / not usable 3.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE              51199

  Free PE               12800

  Allocated PE          38399

  PV UUID               PZzCCd-bIv2-t1Yr-0Ch7-ntvY-6yz8-7dSYoB

 

8) Now Validate the VG free allocated space. It should show the amount of free space what we have increased in disk.


root@funebs122:/var/log# vgdisplay  vg01_funebs122

  --- Volume group ---

  VG Name               vg01_funebs122

  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               200.00 GiB

  PE Size               4.00 MiB

  Total PE              51199

  Alloc PE / Size       38399 / 150.00 GiB

  Free  PE / Size       12800 / 50.00 GiB

  VG UUID               SBbrwc-Ym4P-1I6d-NYrr-ygow-hRTU-MkMPLV

 

9) Check the file system type of the Mount


root@funebs122:/var/log# grep u01 /etc/fstab

/dev/vg01_funebs122/lvol0 /u01                     xfs     defaults        1 2

 

10) Extend the LVM by 50 GB

 

root@funebs122:/var/log# lvextend -L +50g /dev/vg01_funebs122/lvol0

  Size of logical volume vg01_funebs122/lvol0 changed from 150.00 GiB (38399 extents) to 200.00 GiB (51199 extents).

  Logical volume vg01_funebs122/lvol0 successfully resized.

 

11) Expand the filesystem 

 

root@funebs122:/var/log# xfs_growfs  /dev/vg01_funebs122/lvol0

meta-data=/dev/mapper/vg01_funebs122-lvol0 isize=256    agcount=4, agsize=9830144 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0        finobt=0 spinodes=0

data     =                       bsize=4096   blocks=39320576, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal               bsize=4096   blocks=19199, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

data blocks changed from 39320576 to 52427776

 

12) Validate the Mount point size

 

root@funebs122:/var/log# df -h /u01

Filesystem                     Size  Used Avail Use% Mounted on

/dev/mapper/vg01_funebs122-lvol0  200G  145G   56G  73% /u01




If you like please follow and comment