VMware expand virtual machine disk size

Time:2020-3-30

After VMware sets the disk size of the virtual machine, it finds that the disk space is insufficient. How to expand the disk size at this time?

First of all, when the virtual machine is shut down, right-click the settings, select the hard disk, and expand, so that the size of the disk can be increased.

VMware expand virtual machine disk size

But without setting partition and disk mount, we cannot use the increased disk space after starting the virtual machine. What should we do at this time? There are two ways

Log in to the system with root account first

1、 Mount the new disk space to a directory

1. Fdisk – L displays the following information:

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 2611 20458496 8e Linux LVM

Disk /dev/mapper/vg_zxw-lv_root: 18.8 GB, 18832424960 bytes
255 heads, 63 sectors/track, 2289 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

We can see the total size of the disk and the size used

Note that the newly created partition will be sda3

2. Partition the remaining space

fdisk /dev/sda/

Prompt for M

Enter the command n to add a new partition

Enter the command p to create the primary partition

Enter the carriage return and select the default size so as not to waste space

Enter w to keep the changes

Enter reboot to restart Linux. Reboot is required. Otherwise, / dev / sda3 cannot be formatted

At this time, you can see the new partition in the / dev / directory, such as / dev / sda3

Mkfs.ext2/dev/sda3 format

3. Mount to directory

Create a Disk3 directory at the root

[mount / dev / sda3 / Disk3 /] mount the partition to / Disk3 /

Modify the / etc / fstab file in VIM, add a line of [/ dev / sda3 / Disk3 ext2 defaults 0 0], and save it to realize automatic mount after power on.

Enter DF – h to view

At this point, the newly increased disk space capacity can be reflected on Disk3, and the partition will be automatically mounted after rebooting, and the work of adding disk space is completed.

If the current disk has no capacity, you can use the method of adding disk. In the main interface of VMware, select the [VMware] drop-down menu, select [settings], and use the [add] method to add a disk. The following operations are similar and will not be repeated.

2、 Directly expand the new disk space to the “/” root directory

This may be more practical. We can directly expand the new disk space to the root directory, which is more convenient.

1. Fdisk – L displays the following information:

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 2611 20458496 8e Linux LVM

Disk /dev/mapper/vg_zxw-lv_root: 18.8 GB, 18832424960 bytes
255 heads, 63 sectors/track, 2289 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

We can see the total size of the disk and the size used

Note that the newly created partition will be sda3

2. Partition the remaining space

fdisk /dev/sda/

Prompt for M

Enter the command n to add a new partition

Enter the command p to create the primary partition

Enter the carriage return and select the default size so as not to waste space

Enter w to keep the changes

3. Our new partition / dev / sda3 is not LVM’s. So, we use fdisk to change it to LVM.

fdisk /dev/sda
Command (m for help): m
Command (m for help): T // change partition system ID

Partition number (1-4): 3 // specify partition number
Hex code (type L to list codes): 8e // specifies the ID number to be changed, and 8e represents LVM.
Command (m for help): w

After restarting the system, log in to the system. (be sure to restart the system, otherwise the new partition cannot be expanded)

4. Format the newly added partition:

#fdisk -l

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 3916 10483750 8e Linux LVM
You'll find an extra partition.
#Mkfs - t ext3 / dev / sda3 // create the "ext3" file system on the hard disk partition "/ dev / sda3".

Now we can use the new partition:

5. Expand new partition

#lvs
#The pvcreate / dev / sda3 // pvcreate instruction is used to initialize a physical hard disk partition to a physical volume for use by LVM. To create a physical volume, you must first partition the hard disk and set the type of hard disk partition to "8e" before you can use the pvcreate command to initialize the partition as a physical volume.
Physical volume "/dev/sda3" successfully created
#Vgextend volgroup00 / dev / sda3 (where is the LVM group name that needs to be expanded at present, which can be viewed through DF - H, for example, / dev / mapper / volgroup00 logvol00) // the vgextend instruction is used for dynamic extended volume groups. It increases the capacity of volume groups by adding physical volumes to volume groups.
#Vgdisplay // displays the metadata information of the LNM volume group.

--- Volume group ---
VG Name vg_zxw
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.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 4994 / 10.01GB
VG UUID sqBgTs-iA8x-tCXZ-KYxK-SyWS-TfXQ-uBsLaR
(mainly check free PE / size 4994 / 10.01gb, indicating that we can have up to 10.01gb of expansion space. I usually choose less than 10.01gb)
# lvextend -L+9.8G /dev/VolGroup00/LogVol00 /dev/sda3

Logical volume LogVol00 successfully resized
#E2fsck - A / dev / volgroup00 / logvol00 // use the e2fsck command to check the file system for errors. You can also check the EXT2 file system with "fsck - t ext2 - V / dev / sda3 /. 
(do fsck and check the file system)
#The resize2fs / dev / volgroup00 / logvol00 // resize2fs instruction is used to increase or shrink the size of an unloaded "ext2 / ext3" file system.
#DF - H // check that the "/" directory of your system disk space has become 40Gb
OK, that's it

More blogs about real-time computing, Flink, Kafka and other related technologies, welcome to pay attention to real-time streaming computing

VMware expand virtual machine disk size