vbox虚拟机扩容(CentOS 7.2)

时间:2023-03-09 18:31:15
vbox虚拟机扩容(CentOS 7.2)
Preface
My virtual machine was simply created by vagrant in default mode without anything about the extra disk volume configuration.The default size is about 10.5G.In order to use the web browse to configure the MySQL Enterprise Monitor,I have to install the gnome desktop environment first,but I found out it was out of free space like below:
 ... //Omitted.
Error Summary
-------------
Disk Requirements:
At least 1988MB more space needed on the / filesystem. [root@zlm2 :: ~]
#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root .3G .1G .2G % / //Only 1.2G free space left.
devtmpfs 911M 911M % /dev
tmpfs 921M 921M % /dev/shm
tmpfs 921M 8.3M 912M % /run
tmpfs 921M 921M % /sys/fs/cgroup
/dev/sda1 497M 164M 334M % /boot
none 80G 27G 53G % /vagrant
tmpfs 185M 185M % /run/user/
Therefore,I need to enlarge the disk for that.It's a little bit different from that adding a disk then mount it as a directory outside the "/" position.It's the way to increase the space of "/"(the root directroy).
Procedure
  • Halt the virtual machine first,and then add a vdi disk from the original disk(vmdk) in windows cmd cli.
 C:\Users\Administrator>cd F:\Program Files\Oracle\VirtualBox

 C:\Users\Administrator>F:

 F:\Program Files\Oracle\VirtualBox>VBoxManage clonehd "G:\VirtualBox VMs\zlm2\centos-vm-disk1.vmdk" "G:\VirtualBox VMs\zlm2\centos-vm-disk1.vdi" --format vdi
%...%...%...%...%...%...%...%...%...%...%
Clone medium created in format 'vdi'. UUID: 63be4ac1-48a1-4b52-848f-71933c6c4adc F:\Program Files\Oracle\VirtualBox>VBoxManage modifyhd "G:\VirtualBox VMs\zlm2\centos-vm-disk1.vdi" --resize (default "M")
%...%...%...%...%...%...%...%...%...%...% F:\Program Files\Oracle\VirtualBox>exit
  • Restart the virtual machine and then add a new partition.
 [root@zlm2 :: ~]
#fdisk -l Disk /dev/sda: 31.5 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x0000ca5e Device Boot Start End Blocks Id System
/dev/sda1 * Linux
/dev/sda2 8e Linux LVM Disk /dev/mapper/centos-root: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/centos-swap: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes [root@zlm2 :: ~]
#fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.). Changes will remain in memory only, until you decide to write them.
Be careful before using the write command. Command (m for help): p Disk /dev/sda: 31.5 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x0000ca5e Device Boot Start End Blocks Id System
/dev/sda1 * Linux
/dev/sda2 8e Linux LVM Command (m for help): n
Partition type:
p primary ( primary, extended, free)
e extended
Select (default p): p
Partition number (,, default ):
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ):
Using default value
Partition of type Linux and of size 19.5 GiB is set Command (m for help): t
Partition number (-, default ):
Hex code (type L to list all codes): L Empty NEC DOS Minix / old Lin bf Solaris
FAT12 Hidden NTFS Win Linux swap / So c1 DRDOS/sec (FAT-
XENIX root Plan Linux c4 DRDOS/sec (FAT-
XENIX usr 3c PartitionMagic OS/ hidden C: c6 DRDOS/sec (FAT-
FAT16 <32M Venix Linux extended c7 Syrinx
Extended PPC PReP Boot NTFS volume set da Non-FS data
FAT16 SFS NTFS volume set db CP/M / CTOS / .
HPFS/NTFS/exFAT 4d QNX4.x Linux plaintext de Dell Utility
AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
AIX bootable 4f QNX4.x 3rd part Amoeba e1 DOS access
a OS/ Boot Manag OnTrack DM Amoeba BBT e3 DOS R/O
b W95 FAT32 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
OPUS EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
Hidden FAT12 Golden Bow a8 Darwin UFS f1 SpeedStor
Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
Hidden FAT16 < SpeedStor ab Darwin boot f2 DOS secondary
Hidden FAT16 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
Hidden HPFS/NTF Novell Netware b7 BSDI fs fc VMware VMKCORE
AST SmartSleep Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 Old Minix
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 : 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() or kpartx()
Syncing disks. [root@zlm2 :: ~]
#partprobe [root@zlm2 :: ~]
#fdisk -l Disk /dev/sda: 31.5 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x0000ca5e Device Boot Start End Blocks Id System
/dev/sda1 * Linux
/dev/sda2 8e Linux LVM
/dev/sda3 8e Linux LVM Disk /dev/mapper/centos-root: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/centos-swap: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
  • Create a new PV,add to the original VG and then extend the VG.
 [root@zlm2 :: ~]
#pvdisplay | grep "VG Name"
VG Name centos [root@zlm2 :: ~]
#pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created [root@zlm2 :: ~]
#pvdisplay | grep "VG Name"
VG Name centos
VG Name [root@zlm2 :: ~]
#vgextend centos /dev/sda3
Volume group "centos" successfully extended
  • Check the information logical partition.
 [root@zlm2 :: ~]
#cat /etc/fstab #
# /etc/fstab
# Created by anaconda on Wed Jan ::
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(), findfs(), mount() and/or blkid() for more info
#
/dev/mapper/centos-root / xfs defaults
UUID=461cd9c0-513e-48db-bb08-d07a8f6ef260 /boot xfs defaults
/dev/mapper/centos-swap swap swap defaults
  • Extend the new PV into the original logical partition and expand it.
 [root@zlm2 :: ~]
#lvextend /dev/mapper/centos-root /dev/sda3
Size of logical volume centos/root changed from 8.26 GiB ( extents) to 27.79 GiB ( extents).
Logical volume root successfully resized. [root@zlm2 :: ~]
#resize2fs /dev/mapper/centos-root //Resizes only for ext2/ext3/ext4 filesystem.
resize2fs 1.42. (-Dec-)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock. [root@zlm2 :: ~]
#xfs_growfs /dev/mapper/centos-root //Expands an existing XFS filesystem.
meta-data=/dev/mapper/centos-root isize= agcount=, agsize= blks
= sectsz= attr=, projid32bit=
= crc= finobt=
data = bsize= blocks=, imaxpct=
= sunit= swidth= blks
naming =version bsize= ascii-ci= ftype=
log =internal bsize= blocks=, version=
= sectsz= sunit= blks, lazy-count=
realtime =none extsz= blocks=, rtextents=
data blocks changed from to
  • Check the diskspace again with "df -h" again.
 [root@zlm2 :: ~]
#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 28G .5G 21G % /
devtmpfs 911M 911M % /dev
tmpfs 921M 921M % /dev/shm
tmpfs 921M 8.4M 912M % /run
tmpfs 921M 921M % /sys/fs/cgroup
/dev/sda1 497M 164M 334M % /boot
none 80G 29G 51G % /vagrant
tmpfs 185M 185M % /run/user/
Okay,now I've got the enough disk space to install the gnome desktop environment.That's awesome!