VirtualBox扩展及压缩虚拟磁盘

1、首先定位各虚拟磁盘的UUID

C:\ProgramerTools\Oracle\VirtualBox>VBoxManage.exe list hdds
UUID:           b806ffa9-ea8e-4059-9dd8-2d246e850ab6
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\WinXP\WinXP.vdi
Storage format: VDI
Capacity:       10240 MBytes

UUID:           945de0c8-f928-44ad-ae39-9a12a71568ef
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\Debian8\Debian8.vdi
Storage format: VDI
Capacity:       20480 MBytes

UUID:           e49d8a88-d68b-43b8-954e-2be419933e08
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\Docker\Debian8Docker\Debian8Docker
.vdi
Storage format: VDI
Capacity:       20480 MBytes

UUID:           eab29989-ce9c-4491-8dd0-2190ed3029d6
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\FreeBSD10\FreeBSD10.vdi
Storage format: VDI
Capacity:       20480 MBytes

UUID:           74bcd43e-a315-437e-9b4f-895051ff8433
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       D:\VirtualMashines\VirtualBox\FreeBSD10\FreeBSD10A01.vdi
Storage format: VDI
Capacity:       20480 MBytes

2、扩展WinXP虚拟磁盘
2.1我的xp虚拟机一共只有10G,我需要扩展到20G(要关虚拟机)

C:\ProgramerTools\Oracle\VirtualBox>VBoxManage modifyhd b806ffa9-ea8e-4059-9dd8-
2d246e850ab6 --resize 20480
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

2.2扩展后,开启虚拟机,自己到磁盘管理器中分配空间即可。

3、扩展Debian虚拟磁盘
3.1我的Debian8Docker虚拟机一共只有20G,我需要扩展到30G(要关虚拟机)

C:\ProgramerTools\Oracle\VirtualBox>VBoxManage modifyhd e49d8a88-d68b-43b8-954e-
2be419933e08 --resize 30720
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

3.2扩展后,开启虚拟机,使用gparted等工具分配空间即可。
需要提前unmount分区,如果是调整扩展分区,需要umount该扩展分区下的所有挂载点。

4、压缩WinXP虚拟磁盘
4.1需要到微软官网下载sdelete工具,然后在虚拟机中运行:

sdelete -z

4.2关闭虚拟机,运行:

VBoxManage modifyhd b806ffa9-ea8e-4059-9dd8-2d246e850ab6 --compact

5、压缩Debian虚拟磁盘:
5.1A在虚拟机中运行zerofree命令,需要将分区挂载为只读模式

apt-get install zerofree
cd /
umount /home
zerofree /dev/sda6

5.1B在虚拟机中运行dd命令,需要将分区挂载为读写模式

dd if=/dev/zero of=/bigemptyfile
rm bigemptyfile 

5.2关闭虚拟机,运行:

VBoxManage modifyhd 945de0c8-f928-44ad-ae39-9a12a71568ef --compact

6、压缩FreeBSD虚拟磁盘:
6.1A在虚拟机中运行dd命令,需要将分区挂载为读写模式

dd if=/dev/zero of=bigemptyfile bs=1m
rm bigemptyfile

6.1B在虚拟机中运行dd命令,需要将分区挂载为读写模式(适用于影片空闲空间较小)

cat /dev/zero > bigemptyfile;sync;sleep 1;sync;
rm -f bigemptyfile

6.2关闭虚拟机,运行:

VBoxManage modifyhd eab29989-ce9c-4491-8dd0-2190ed3029d6 --compact
VBoxManage modifyhd 74bcd43e-a315-437e-9b4f-895051ff8433 --compact

Leave a Reply

Your email address will not be published. Required fields are marked *

*