Table of Content

highlight steps to expand disk for vmware vm

  • delete snapshot
  • expand to 100GB
  • create partition for new expanded disk
  • add expended disk to root logical group

expand disk in vmware

the expand disk is default feature in vmware, you need to delete snapshot before expand.

The Expand button is under vmware GUI Hardware/Hard Disk/Disk utilities, it is straightforward in few seconds, will see virtual disk to 100G; however in fact it added new disk 80G following up the current disk 20G when expanding to 100G from 20G, the next step is to do partition on new added disk. We will see more details inside guest vm.

precheck the disk details

current root disk is 20GB,

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 17G 1.5M 100% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 12M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 144M 871M 15% /boot
tmpfs 781M 0 781M 0% /run/user/0

device name is sda, in my case, sda1 is swap 2GB, sda2 is root FS 20G,

[root@localhost ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x000bc4a0

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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

Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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

partition for new disk

[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (41943040-209715199, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-209715199, default 209715199):
Using default value 209715199
Partition 3 of type Linux and of size 80 GiB is set

Command (m for help): t
Partition number (1-3, default 3):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

new partition sda3 80G is ready but you still cannot see it due to root disk controlled by LVM, need more work to add new disk to logical disk.

LVM config for new disk sda3

[root@localhost ~]# partprobe -s
/dev/sda: msdos partitions 1 2 3

[root@localhost ~]# pvscan
PV /dev/sda2 VG centos lvm2 [19.00 GiB / 0 free]
Total: 1 [19.00 GiB] / in use: 1 [19.00 GiB] / in no VG: 0 [0 ]

[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 19.00 GiB
PE Size 4.00 MiB
Total PE 4863
Alloc PE / Size 4863 / 19.00 GiB
Free PE / Size 0 / 0
VG UUID eeJ4bt-Cj3s-3MPE-540I-UvPu-h7KV-mK0b1F

[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.

[root@localhost ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended

[root@localhost ~]# pvscan
PV /dev/sda2 VG centos lvm2 [19.00 GiB / 0 free]
PV /dev/sda3 VG centos lvm2 [80.00 GiB / 80.00 GiB free]
Total: 2 [98.99 GiB] / in use: 2 [98.99 GiB] / in no VG: 0 [0 ]

[root@localhost ~]# ls /dev/centos
root swap

[root@localhost ~]# lvextend /dev/centos/root /dev/sda3
Size of logical volume centos/root changed from 17.00 GiB (4351 extents) to 96.99 GiB (24830 extents).
Logical volume centos/root successfully resized.

[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, 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 4455424 to 25425920

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 97G 17G 80G 18% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 12M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 144M 871M 15% /boot
tmpfs 781M 0 781M 0% /run/user/0

Finally root FS expanded to 100G now.