1. 背景
工作电脑切换到 Mac 之后对 .NET 开发一直念念不忘,于是又在 VirtualBox 里安装了 Windows + .NET + Office + Power Designer 环境。一不小心 100GB 的虚拟机就用了 80%,原本不大的 SSD 更加捉襟见肘。
继 VS Code for Mac 后,Visual Studio for Mac 也逐渐稳定了,于是动了重装 VirtualBox Windows 的念头。
可是,一想到安装 Windows 就有逢年过节回老家的感觉,那就走走 Geek 路线?
是否可以把 VirtualBox 软件卸载后,收缩 VMDK 文件呢?
感谢万能的 Google,真的有人这么干过!
2. 收缩成绩单
2.1. 文件收缩前 77.95 GB
Before Shrink2.2. 文件收缩后 28.84 GB
After Shrink2.3. 每个文件的收缩前后对比
No | Filename | Size Before Shrink | Size After Shrink |
---|---|---|---|
1 | Win8EN-s001.vmdk | 2,094,792,704 | 1,961,623,552 |
2 | Win8EN-s002.vmdk | 2,146,762,752 | 2,069,364,736 |
3 | Win8EN-s003.vmdk | 2,141,257,728 | 2,087,714,816 |
4 | Win8EN-s004.vmdk | 2,146,500,608 | 2,088,566,784 |
5 | Win8EN-s005.vmdk | 2,145,845,248 | 2,123,890,688 |
6 | Win8EN-s006.vmdk | 2,146,762,752 | 2,115,764,224 |
7 | Win8EN-s007.vmdk | 2,146,762,752 | 2,098,528,256 |
8 | Win8EN-s008.vmdk | 2,146,762,752 | 2,113,339,392 |
9 | Win8EN-s009.vmdk | 2,145,058,816 | 2,117,074,944 |
10 | Win8EN-s010.vmdk | 2,146,762,752 | 2,085,945,344 |
11 | Win8EN-s011.vmdk | 2,146,762,752 | 2,106,916,864 |
12 | Win8EN-s012.vmdk | 2,146,762,752 | 2,034,302,976 |
13 | Win8EN-s013.vmdk | 2,146,762,752 | 2,142,437,376 |
14 | Win8EN-s014.vmdk | 2,146,172,928 | 715,653,120 |
15 | Win8EN-s015.vmdk | 2,146,697,216 | 93,650,944 |
16 | Win8EN-s016.vmdk | 2,146,762,752 | 24,444,928 |
17 | Win8EN-s017.vmdk | 2,146,762,752 | 137,232,384 |
18 | Win8EN-s018.vmdk | 2,119,368,704 | 7,995,392 |
19 | Win8EN-s019.vmdk | 2,129,788,928 | 155,058,176 |
20 | Win8EN-s020.vmdk | 2,146,762,752 | 51,773,440 |
21 | Win8EN-s021.vmdk | 2,146,762,752 | 45,285,376 |
22 | Win8EN-s022.vmdk | 2,146,762,752 | 42,532,864 |
23 | Win8EN-s023.vmdk | 2,144,927,744 | 1,966,080 |
24 | Win8EN-s024.vmdk | 2,146,762,752 | 720,896 |
25 | Win8EN-s025.vmdk | 2,146,762,752 | 21,364,736 |
26 | Win8EN-s026.vmdk | 2,146,762,752 | 50,921,472 |
27 | Win8EN-s027.vmdk | 2,146,762,752 | 150,274,048 |
28 | Win8EN-s028.vmdk | 2,146,762,752 | 1,703,936 |
29 | Win8EN-s029.vmdk | 2,146,762,752 | 9,961,472 |
30 | Win8EN-s030.vmdk | 2,146,762,752 | 1,376,256 |
31 | Win8EN-s031.vmdk | 2,146,762,752 | 1,114,112 |
32 | Win8EN-s032.vmdk | 2,146,762,752 | 917,504 |
33 | Win8EN-s033.vmdk | 2,146,762,752 | 15,597,568 |
34 | Win8EN-s034.vmdk | 2,146,762,752 | 10,944,512 |
35 | Win8EN-s035.vmdk | 2,146,762,752 | 27,721,728 |
36 | Win8EN-s036.vmdk | 1,608,450,048 | 38,404,096 |
37 | Win8EN-s037.vmdk | 327,680 | 327,680 |
38 | Win8EN-s038.vmdk | 327,680 | 327,680 |
39 | Win8EN-s039.vmdk | 536,346,624 | 47,316,992 |
40 | Win8EN-s040.vmdk | 327,680 | 327,680 |
41 | Win8EN-s041.vmdk | 327,680 | 327,680 |
42 | Win8EN-s042.vmdk | 327,680 | 327,680 |
43 | Win8EN-s043.vmdk | 327,680 | 327,680 |
44 | Win8EN-s044.vmdk | 767,426,560 | 38,404,096 |
45 | Win8EN-s045.vmdk | 327,680 | 327,680 |
46 | Win8EN-s046.vmdk | 327,680 | 327,680 |
47 | Win8EN-s047.vmdk | 327,680 | 327,680 |
48 | Win8EN-s048.vmdk | 327,680 | 327,680 |
49 | Win8EN-s049.vmdk | 327,680 | 327,680 |
50 | Win8EN-s050.vmdk | 327,680 | 327,680 |
51 | Win8EN-s051.vmdk | 131,072 | 131,072 |
52 | Win8EN.vmdk | 2,495 | 2,495 |
3. 操作步骤
3.1. 卸载 Windows 中无用的软件
我主要卸载了 Visual Studio 2013、Visual Studio 2015 Preview,Power Designer 偶尔还要用下。
3.2. 使用 WICleanup 删除无用的安装包
WICleanupWICleanup 用于删除 C:\Windows\Installer
中无用的 MSP 和 MSI 文件,卸载了许多软件之后发现剩余的磁盘空间变化不大,此时就是 WICleanup 出手的最好时机,帮我清除了近 20GB 的空间。
3.3. 使用 Defraggler 整理磁盘(可选)
用 Windows 时超爱这款免费软件,今天忽然想看看用了两年多的虚拟机磁盘有多少碎片,就临时增加了这个步骤。
3.4. 使用 CCleaner 的 Drive Wipe 功能
Securely erase free space on a drive
CCleaner-Wipe.pngCCleaner 除了 Wipe 之外还提供了清理文件和注册表等功能。
3.5. Shutdown Windows
先关机,再收缩文件。
3.6. 安装 VMWare Fusion for Mac
就是为了 vmware-vdiskmanager
命令 :P
3.7. 收缩文件
cd /Applications/VMware\ Fusion.app/Contents/Library
./vmware-vdiskmanager -k /myVirtualBox/Win8EN/Win8EN.vmdk
4. 参考资料
- 3 Ways to Safely Delete Unused MSI and MSP Files from Windows Installer Folder
- Shrink a vmdk Virtualbox disk image
- Running the VMware Virtual Disk Manager Utility
- Fusion for Mac
5. 小礼品
很多年前 Windows 要求单文件小于 2GB,于是就养成了建立虚拟机拆分文件的习惯,至今也没改过来……
赠送一条命令给感兴趣的读者吧(既然您都读到这儿了)
# 建立 100GB 的 VMDK 文件,拆分成每个文件 2G
vboxmanage createhd --filename Win8EN.vmdk --size 102400 --format vmdk --variant Split2G
网友评论