Using VM VirtualBox creates a CentOS virtual machine, divides 3GB of disk space, uses dynamically allocated storage, and the file system is LVM. After a while, they found that there was not enough disk capacity. After reading some information, I finally added disk capacity to VirtualBox's virtual machine and let the CentOS LVM use it.
Here's a new virtual machine with a disk size of 3GB, then adjust it to 5GB and record the operation steps.
First look at the partition table for the virtual disk in the virtual machine:
# fdisk-l/DEV/SDA
disk/dev/sda:3221 MB, 3221225472 bytes
255 heads, Sectors/track, 391 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x00052338
Device Boot Start End Blocks Id System
/DEV/SDA1 * 1 512000 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 392 2632704 8e Linux LVM
Partition 2 does not end on cylinder boundary.
As you can see, the total disk size is 3221MB.
1. VirtualBox Disk Management ¶
The following command line uses VirtualBox to adjust the disk allocation of the virtual machine from 3GB to 5GB.
The method for adjusting the size of the virtual machine disk is clearly shown in the VirtualBox documentation.
Vboxmanage MODIFYHD <uuid>|<filename>
[--type normal|writethrough|immutable|shareable|
Readonly|multiattach]
[--autoreset On|off]
[--compact]
[--resize <megabytes>|--resizebyte <bytes>]
The MODIFYHD instruction is used to resize the disk. An object can be a UUID of a virtual machine, or you can specify the disk file name (full path) of the virtual machine to be resized directly. Note that if you install VirtualBox without adding its path to the system path, you need to specify the path when you run the command line, for example,
C:>d:appsoraclevirtualboxvboxmanage.exe modifyhd "D:centos2.vid"--resize 5120
0%.. 10%.. 20%.. 30%.. 40%.. 50%.. 60%.. 70%.. 80%.. 90%.. 100%
The instructions above CENTOS2.VDI the virtual machine disk in the D-packing directory to (parameter –resize) 5120, in megabytes.
If you want to see the corresponding UUID, you can use the directive:
C:>d:appsoraclevirtualboxvboxmanage.exe List HDDs
uuid:7a0b7b7a-298d-4fcf-b9d0-09ae2737441d
Parent Uuid:base
Format:vdi
Location:d:centos2.vdi
state:created
Type:normal
Usage:centosi (UUID:34A666FA-24C9-4510-9CCA-50E2A04C8E98)
When the virtual disk size is resized, the virtual machine must be turned off!
The above instructions were tested under 64bit Windows 7 + VirtualBox 4.2.16.
2. CentOS's LVM Management ¶
Restart the virtual machine. Take a look at the disk situation again:
# fdisk-l/DEV/SDA
disk/dev/sda:5368 MB, 5368709120 bytes
255 heads, Sectors/track, 652 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x00052338
Device Boot Start End Blocks Id System
/DEV/SDA1 * 1 512000 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 392 2632704 8e Linux LVM
Partition 2 does not end on cylinder boundary.
The disk size is now 5368MB. Disk occupancy is:
# df-h
FileSystem Size Used Avail use% mounted on
/dev/mapper/volgroup-lv_root
1.7G 1.5G 83M 95%/
Tmpfs 250M 0 250M 0%/dev/shm
/DEV/SDA1 485M 117M 343M 26%/boot
Try using the DD command to create a block file size of 1GB:
# dd If=/dev/zero of=1.0g.img bs=1m count=1000
Dd:writing ' 1.0g.img ': No spaces left on device
1+0 Records in
0+0 Records out
8192 bytes (8.2 kB) copied, 0.00300509, 2.7 mb/s
The tip says there is not enough disk space (No spaces left on device). Although we gave the virtual machine enough space, the system in the virtual machine (here is CentOS) did not use this part of the space. As you can see, the disk space in the virtual machine is only 1.7G, the original allocation of 3G is not run out. This also shows that the system in the virtual machine does not automatically modify its own disk, even when the virtual machine is created using dynamic allocation of disk size. If you use it properly, you may experience a warning of insufficient disk space in the virtual machine, even if the virtual disk is large enough.
The file system of the virtual machine operating system is adjusted below to make all space available.
A. Create a free disk as a SDA3
Restart the virtual machine, log in CentOS, and use Fdisk to create the free space of the virtual disk as a new partition. Note To use the partition number 8e, which represents the Linux LVM, as the ID.
# FDISK/DEV/SDA
n {New Partition}
p {Primary Partition}
3 {partition Number}
t {change partition ID}
3 {partition Number}
8e {Linux LVM partition}
W
After the above command is executed, you can use the
Fdisk-l/DEV/SDA
To see if Sda3 was successfully created and marked as LVM, and if not, a reboot is required. Unfortunately, I saved the result.
Reboot
B. Adjusting the LVM size
First look at the current Volume Group:
# Vgdisplay
---Volume Group---
VG Name Volgroup
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 2.51 GiB
PE Size 4.00 MiB
Total PE 642
Alloc pe/size 642/2.51 GiB
Free Pe/size 0/0
VG UUID M42pdq-k830-cfly-ckr2-1aqf-isyx-3x2ady
The name is Volgroup, resizable (resizable), and the current size is 2.51GB. The active LVM volume has,
# Lvscan
ACTIVE '/dev/volgroup/lv_root ' [1.67 GiB] Inherit
ACTIVE '/dev/volgroup/lv_swap ' [856.00 MiB] Inherit
The new disk space that is allocated is first created as a new physical volume.
Pvcreate/dev/sda3
Then use the new physical volume to extend the LVM Volgroup,
# Vgextend Volgroup/dev/sda3
No Physical Volume label Read From/dev/sda3
Writing physical volume data to disk "/dev/sda3"
Physical volume "/dev/sda3" successfully created
Volume Group "Volgroup" successfully extended
Then expand the LVM logical Volume Volgroup-lv_root,
# Lvextend/dev/volgroup/lv_root/dev/sda3
Extending logical Volume Lv_root to 3.66 GiB
Logical Volume Lv_root successfully resized
Finally, adjust the size of the logical volume file system,
Resize2fs/dev/volgroup/lv_root
RESIZE2FS 1.41.12 (17-may-2010)
FileSystem at/dev/volgroup/lv_root is mounted on/; On-line resizing required
Old desc_blocks = 1, new_desc_blocks = 1
Performing a on-line resize of/dev/volgroup/lv_root to 959488 (4k) blocks.
The filesystem on/dev/volgroup/lv_root is now 959488 blocks long.
Complete. Look at the effect:
# Lvscan
ACTIVE '/dev/volgroup/lv_root ' [3.66 GiB] Inherit
ACTIVE '/dev/volgroup/lv_swap ' [856.00 MiB] Inherit
In addition, several useful LVM directives (LVM2):
Lvmdiskscan
Vgdisplay
Pvdisplay
Lvdispay
Vgcreate
Pvcreate
Lvscan
Pvscan
Vgscan
I'm using the CentOS system here. If Windows is simpler, the partition size can be resized to occupy all available disk space through Disk Management for Windows