Extend Linux VM’s Drive (Proxmox, VMware and Others)

In this example we are going to add a new disk 5GB and extend root (/) partition partition.

Edit VM and add new 5GB Drive. New drive /dev/vdc has been added.

fdisk -l

Disk /dev/vdc: 5368 MB, 5368709120 bytes, 10485760 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

Use fdisk utility to partition new disk

fdisk /dev/vdc
 n --> New Partition
 p --> Primary 
 Enter --> Default Partition Number
 Enter --> Default First Sector
 Enter --> Default Last Sector
 w --> Save Partition Table

Create a physical volume using newly created partition

[root@10431 ~]# pvcreate /dev/vdc1
 Physical volume "/dev/vdc1" successfully created.

First check the volume groups name

[root@10431 ~]# vgs
 VG #PV #LV #SN Attr VSize VFree
 cl 2 2 0 wz--n- 68.99g 1020.00m

He here cl is Volume Group’s Name

Extend Volume Group

[root@10431 ~]# vgextend cl /dev/vdc1
 Volume group "cl" successfully extended

Get Logical Volume Name

[root@10431 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 66G 11G 56G 17%
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.4M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 1014M 231M 784M 23% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0

/dev/mapper/cl-root

Extend the logical volume

[root@10431 ~]# lvextend -l +100%FREE /dev/mapper/cl-root
 Size of logical volume cl/root changed from <66.00 GiB (16895 extents) to <71.99 GiB (18429 extents).
 Logical volume cl/root successfully resized.

Finally Resized
In Centos 7 default filesystem is xfs.
xfs file system supports only extend not reduce. So if you want to resize the filesystem use xfs_growfs rather than resize2fs.

[root@10431 ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root isize=512 agcount=16, agsize=1113856 blks
 = sectsz=512 attr=2, projid32bit=1
 = crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=17300480, imaxpct=25
 = sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
 = sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 17300480 to 18871296

Note: For ext4 filesystem use

resize2fs /dev/mapper/cl-root

Check new size

[root@10431 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 72G 11G 62G 15%
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.4M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 1014M 231M 784M 23% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0

New size changed from 56G to 62G