Extend disk space on Linux on Virtual Machine
Now that you have extended the disk space from VMWare ESXi. Lets check into the OS level and extend it from the OS level.
here is an example using Linux Virtual Machine (VM)
list all the disks available on the target Linux VM so we can identify which one’s extended
lsblk
once you’ve identified the target disk, you can have system rescan the disk
*sda can be changed to your target disk name
echo 1 > /sys/class/block/sda/device/rescan
use below command to make sure the device size is changed successfully
dmesg
Run command parted and resize partition to use new free space
*note that sda can be changed to your target disk name
# parted /dev/sda
GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted)
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 365GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 258GB 257GB primary lvm
Use command resizepart inside parted to resize existing partition
(parted) resizepart
Partition number? 2
End? [258GB]? 365GB
Use command print inside parted to list current partition table (note that p is short for print)
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 365GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 365GB 364GB primary lvm
Use command quit inside parted to exit to bash CLI
(parted) quit
Information: You may need to update /etc/fstab.
force the kernel to re-read partition table from sda
# partprobe /dev/sda
It is optional but you can force to re-read all the partitions in the system (usefull if you particularly created a new disk/partition)
# pvscan
# partx -v -a /dev/sda
We can now see the change and increase the size of LVM PV (the disk you just resize)
# pvresize /dev/sda2
You will now see free space in VG, that you can use as you wish.
Here’s other helpful tips if you want to create new logical volume after extending disk space
# pvresize /dev/sda#
# pvscan
# lvcreate -n “nameOfVolume” -L “sizeInG” “volumeGroupName”
# lvscan
# mkfs.xfs “nameOfVolume”
# mount -t xfs “nameOfVolume” “pathToMount”
# vi /etc/fstab