How to expand the disk size of a virtual machine

How to expand the disk size of a virtual machine

After Vmvare sets the disk size of the virtual machine, it is found that the disk space is not enough. How to expand the disk size at this time?

First, make sure the virtual machine is turned off, right-click Settings, select Hard Disk, and Expand to increase the size of the disk.

However, since the partition and disk mounting settings are not made, we cannot use the increased disk space after starting the virtual machine. What should we do at this time? There are two ways

First log in to the system with the root account

1. Mount the newly added disk space to a directory

1. fdisk -l will display 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 disk size and the size used

This means the newly created partition will be sda3.

2. Partition the remaining space

fdisk /dev/sda/

Prompt to enter m

Enter command n to add a new partition

Enter the command p to create a primary partition

Enter and select the default size so that no space is wasted.

Enter w to save 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格式化

3. Mount to directory

Create a disk3 directory in the root directory

[mount /dev/sda3 /disk3/] Mount the partition to /disk3/

Modify the /etc/fstab file in vim, add the line [/dev/sda3 /disk3 ext2 defaults 0 0], and save it to achieve automatic mount at boot.

Enter df -h to view

At this point, the newly added disk space capacity can be reflected on disk3, and the partition will be automatically mounted when the computer is restarted, and the work of adding disk space is completed.

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

2. Directly expand the new disk space to the "/" root directory

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

1. fdisk -l will display 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 disk size and the size used

This means the newly created partition will be sda3.

2. Partition the remaining space

fdisk /dev/sda/

Prompt to enter m

Enter command n to add a new partition

Enter the command p to create a primary partition

Enter and select the default size so that no space is wasted.

Enter w to save the changes.

3. Our newly created partition /dev/sda3 is not LVM. So, next 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 the partition number Hex code (type L to list codes): 8e //Specify the id number to be changed, 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 will find an extra partition.

#mkfs -t ext3 /dev/sda3 //Create an "ext3" file system on the hard disk partition "/dev/sda3".

Now we can use the newly added partition:

5. Expand new partition

#lvs
#pvcreate /dev/sda3 //The pvcreate command is used to initialize the physical hard disk partition as a physical volume for use by LVM. To create a physical volume, you must first partition the hard disk and set the hard disk partition type to "8e" before you can use the pvcreat command to initialize the partition as a physical volume.
Physical volume "/dev/sda3" successfully created
#vgextend VolGroup00 /dev/sda3 (where is the name of the lvm group that needs to be expanded, which can be viewed through df -h, for example, mine is: /dev/mapper/VolGroup00-LogVol00) //The vgextend command is used to dynamically extend the volume group. It increases the capacity of the volume group by adding physical volumes to the volume group.
#vgdisplay //Used to display 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, which means we can have a maximum of 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 file system errors. You can also use "fsck -t ext2 -V /dev/sda3/ to check the ext2 file system. 
(Do fsck, check the file system)
#resize2fs /dev/VolGroup00/LogVol00 //The resize2fs command is used to increase or decrease the size of the unloaded "ext2/ext3" file system.
#df -h // Check your system disk space. The "/" directory has become 40GB

OK, that's it.

Summarize

The above is what I introduced to you about Vmvare expanding the virtual machine disk size. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to add a new disk in CentOS 7 without rebooting the system
  • Detailed explanation of how to add a new hard disk in a VMware virtual machine
  • Add a hard disk to centos using VMware
  • How to add a disk in Vmware: Expand the disk
  • vmware adds a new hard disk command script that takes effect without restarting

<<:  A graphic tutorial on how to install MySQL in Windows

>>:  Summary of some common uses of refs in React

Recommend

Element-ui directly clicks on the cell in the table to edit

Table of contents Achieve results Implementation ...

Detailed explanation of how to use several timers in CocosCreator

1. setTimeOut Print abc after 3 seconds. Execute ...

MySQL grouping queries and aggregate functions

Overview I believe we often encounter such scenar...

WeChat applet implements user login module server construction

I chose node.js to build the server. Friends who ...

Details after setting the iframe's src to about:blank

After setting the iframe's src to 'about:b...

Example code for using HTML ul and li tags to display images

Copy the following code to the code area of ​​Drea...

About the configuration problem of MyBatis connecting to MySql8.0 version

When learning mybatis, I encountered an error, th...

A simple method to implement Linux timed log deletion

Introduction Linux is a system that can automatic...

Summary of Linux command methods to view used commands

There are many commands used in the system, so ho...

...

Detailed explanation of the role of static variables in MySQL

Detailed explanation of the role of static variab...

mysql5.7.20 installation and configuration method graphic tutorial (mac)

MySQL 5.7.20 installation and configuration metho...

Examples of clearfix and clear

This article mainly explains how to use clearfix a...

Detailed example of IOS database upgrade data migration

Detailed example of IOS database upgrade data mig...

Analysis of the cause of docker error Exited (1) 4 minutes ago

Docker error 1. Check the cause docker logs nexus...