Virtual Box virtual machine file slimming processing
Today, I suddenly found that there was an error in the virtual Box virtual machine booting! According to the error message, the disk is full. Zixuan saw that the D: disk where the virtual machine file is located was all occupied.
After searching for information, we concluded that since the virtual machine file actually takes up space after deleting things in the virtual system, the virtual machine file will only become larger and not smaller.
According to some information found online, the solution is as follows: (My physical machine is Windows, and the virtual machine is centos)
1. Empty the write space of D: disk (make sure the virtual machine can start)
2. Fill in 0 and delete the idle place of the virtual machine system.
The processing process is as follows:
Start the virtual machine and execute the following command in the console:
<span style="white-space:pre"> </span>sudo dd if=/dev/zero of=/EMPTY bs=1M <span style="white-space:pre"> </span>sudo rm -f /EMPTY
3. Compress the virtual machine files.
The processing process is as follows:
Open cmd and switch to VirtualBox installation directory
The command is as follows:
C:\Program Files\Oracle\VirtualBox\
3.1 If the virtual machine file is in the format of vdi, directly perform 3.2 operations.
This step is aimed at vmdk format, converting vmdk format into vdi format
The command is as follows:
VBoxManage clonehd "vmdk file (including path)" "vdi file (including path and is vdi suffix)" --format vdi
3.2 Compress the vdi file, the command is as follows:
VBoxManage modifyhd vdi file (including path) --compact
For virtual machine files in vmdk format, if you continue to use vmdk format after compression, you will convert the format again
The command is as follows:
VBoxManage clonehd "vdi file (including path)" "vmdk file (including path and is vmdk suffix)" --format vmdk
At this point, the virtual machine file size has become the size used in the actual virtual machine system. After compression, the file was reduced by about half. In addition, when converting vmdk to vdi, it will also reduce the size of virtual machine files.
Virtual Box disk resizing operation
Environmental description
- Host windows
- Virtual Machine ubuntu
The 80G hard drive has been allocated, and now it has taken up 80G. In fact, many files have been deleted.
Ideas
1. Fill in the remaining space of the hard disk with 0 data, and then create a file with all 0 under ubuntu, and then delete it.
2. Use to compress the hard disk
operate
1. Mount the hard disk to be compressed to ~/data
sudo mount /dev/sdb ~/data/
2. Fill in 0 files
~$ sudo dd if=/dev/zero of=~/data/EMPTY bs=1M dd: error writing '/home/chenct/data/EMPTY': No space left on device 11417+0 records in 11416+0 records out 11970859008 bytes (12 GB, 11 GiB) copied, 138.392 s, 86.5 MB/s
From this point of view, 11G of space can be saved
3. Delete all 0 empty files
rm ~/data/EMPTY
4. Virtual machine shutdown
5. Use it to compress in Windows environment
C:\Program Files\Oracle\VirtualBox> .\ modifyhd "F:\vm\ubuntu\ubuntu-20\ubuntu-20_data.vdi" --compact 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
OK, look at the results, successfully lose weight 10 G
Enlarge hard drive
If you want to increase the hard disk size, you can adjust it in VirtualBox Manager --> Management --> Virtual Media Management, which is relatively simple
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.