Windows7之家(www.908098.com):给Win7下的Windows Virtual PC虚拟机瘦身
使用Virtual PC 2007 或 Windows Virtual PC 时VHD(Virtual Hard Disk)是虚拟机必不可少的部分也是虚拟机的母体,提及.vhd 文件共分为:动态扩展(Dynamically Expanding)、固定大小(Fixed Size)、差分(Differencing)、链接至物理硬盘(Linked to a Hard Disk)四种类型。在Windows 7 中我们可以直接通过磁盘管理工具创建动态扩展或固定大小两种类型的VHD 文件,在Windows Virtual PC 和Virtual Server 中可以支持动态扩展、固定大小型和差分三种类型。
在虚拟机使用一段时间后,如果VHD 是动态扩展型,随着虚拟机安装的软件越来越多VHD 的“体重”必然会逐日增加,本篇将为大家介绍如何为VHD “瘦身”,说是瘦身其实就是要对VHD 文件进行压缩(Compact)。注意,压缩操作只对动态扩展型VHD 其作用。如果你的VHD 是固定(Fixed)型,则需要先将其转换为动态型。如何确定我的VHD是什么类型?如何转换为动态型?请参考1部分内容,如果你的VHD 文件已经是动态型可直接参考2部分及以后内容。
1. VHD 格式转换
打开Windows Virtual PC 找到相应的虚拟机文件点击设置(Settings),在窗口左侧的Setting 栏中找到带有.vhd 文件的Hard Disk 1,便可获得当前虚机VHD 文件类型:

点击修改(Modify)按钮,便可对.vhd 进行格式转换,这个转换过程时间可能较长,取决于VHD 文件大小:

2. VHD 预压缩
在对VHD 进行真正压缩前,必须进行预压缩操作将虚拟磁盘上一些未使用的空间清除,否则后续的压缩操作也不会有任何效果。这时我们需要使用Windows Virtual PC 自带的Precompact 工具进行预压缩,这个工具便在Windows Virtual PC 安装目录下C:Program FilesWindows Virtual PCIntegration ComponentsPrecompact.iso。同样我们还是进入虚机的设置界面,选择“DVD Drive”,将Precompact.iso 放入其中,启动虚拟机:

进入虚拟后,打开光驱,执行precompact.exe 开始预压缩操作:

预压缩进行中,耐心等待… …

经过漫长等待后,预压缩完成:

3. VHD 压缩
在预压缩结束后,我们就要开始真正的压缩操作了,在设置窗口找到Hard Disk 1,点击Modify:

选择“压缩虚拟磁盘”(Compact virtual hard disk):


继续漫长的压缩等待… …

压缩完成后,看看VHD “减”了多少,因为我这个虚拟没装什么东东,所以效果可能不很明显:

相关参考资料
1. Compacting dynamically expanding virtual hard disks
http://technet.microsoft.com/en-us/library/cc708394(WS.10).aspx
2. Modify a virtual hard disk
http://technet.microsoft.com/en-us/library/ee449414(WS.10).aspx
3. Virtual Hard Disk Image Format Specification
http://technet.microsoft.com/en-us/virtualserver/bb676673.aspx
Windows7之家(www.908098.com),凝聚你我他 |