
我使用免費的VMware Player建立了Windows Server 2008系統的映像,並將最大硬碟大小設為100GB。然後我將這些圖像檔案(當時為 30GB)交給了一家伺服器託管公司。幾週後,我向他們要了一份。圖像的大小應該不會發生太大變化,但我得到的檔案是完整的 100GB 大小。
我根本不是VMware專家,所以我有兩個問題:
- 他們如何/為什麼擴展整個動態磁碟?
- 有什麼辦法可以以某種方式將該圖像縮小到實際包含資料的大小嗎?
我嘗試了VMware轉換器,它似乎無法讀取我的映像(vmdk)檔案;它只是輸出一個一般錯誤。
答案1
我的猜測是,當他們從您的映像建立虛擬機器時,他們預先分配了映像的完整大小(這可以具有更好的效能)。當他們導出它們時,您會得到完整的圖像。
我懷疑你可以用VMware播放器縮小映像。 VMware Workstation 隨附了 vmware-vdiskmanager,它顯然可以從固定大小的磁碟轉換為可增長的磁碟,從而減少映像的大小。我從未嘗試過這個,所以我不能說它的效果如何。
手冊在這裡:http://www.vmware.com/support/developer/vddk/vddk12_diskmanager.pdf
答案2
我不知道 VMWare Player,但 VMWare Workstation 附帶 vmware-vdiskmanager.exe 命令列實用程式。找到 C:\Program Files\VMware\VMware Workstation 資料夾。
以下是命令列選項:
VMware Virtual Disk Manager - build 385536.
Usage: vmware-vdiskmanager.exe OPTIONS <disk-name> | <mount-point>
Offline disk manipulation utility
Operations, only one may be specified at a time:
-c : create disk. Additional creation options must
be specified. Only local virtual disks can be
created.
-d : defragment the specified virtual disk. Only
local virtual disks may be defragmented.
-k : shrink the specified virtual disk. Only local
virtual disks may be shrunk.
-n <source-disk> : rename the specified virtual disk; need to
specify destination disk-name. Only local virtual
disks may be renamed.
-p : prepare the mounted virtual disk specified by
the mount point for shrinking.
-r <source-disk> : convert the specified disk; need to specify
destination disk-type. For local destination disks
the disk type must be specified.
-x <new-capacity> : expand the disk to the specified capacity. Only
local virtual disks may be expanded.
-R : check a sparse virtual disk for consistency and attempt
to repair any errors.
-D : make disk deletable. This should only be used on disks
that have been copied from another product.
Other Options:
-q : do not log messages
Additional options for create and convert:
-a <adapter> : (for use with -c only) adapter type
(ide, buslogic, lsilogic). Pass lsilogic for other adapter types.
-s <size> : capacity of the virtual disk
-t <disk-type> : disk type id
Options for remote disks:
-h <hostname> : hostname of remote server
-u <username> : username for remote server
-f <filename> : file containing password
-P <port> : optional TCP port number (default: 902)
-S : specifies that the source disk is remote, by default
the remote options are assumed to refer to the
destination.
Disk types:
0 : single growable virtual disk
1 : growable virtual disk split in 2GB files
2 : preallocated virtual disk
3 : preallocated virtual disk split in 2GB files
4 : preallocated ESX-type virtual disk
5 : compressed disk optimized for streaming
6 : thin provisioned virtual disk - ESX 3.x and above
The capacity can be specified in sectors, KB, MB or GB.
The acceptable ranges:
ide adapter : [1MB, 2040.0GB]
scsi adapter: [1MB, 2040.0GB]
ex 1: vmware-vdiskmanager.exe -c -s 850MB -a ide -t 0 myIdeDisk.vmdk
ex 2: vmware-vdiskmanager.exe -d myDisk.vmdk
ex 3: vmware-vdiskmanager.exe -r sourceDisk.vmdk -t 0 destinationDisk.vmdk
ex 4: vmware-vdiskmanager.exe -x 36GB myDisk.vmdk
ex 5: vmware-vdiskmanager.exe -n sourceName.vmdk destinationName.vmdk
ex 6: vmware-vdiskmanager.exe -r sourceDisk.vmdk -t 4 -h esx-name.mycompany.com \
-u username -f passwordfile "[storage1]/path/to/targetDisk.vmdk"
ex 7: vmware-vdiskmanager.exe -k myDisk.vmdk
ex 8: vmware-vdiskmanager.exe -p <mount-point>
(A virtual disk first needs to be mounted at <mount-point>)
您可以獲得免費的 VMWare Workstation 試用版。
答案3
縮小虛擬磁碟通常分為兩個階段:
- 擦拭。 這會將來賓檔案系統中未使用的區塊清零。 這必須在來賓內執行。
- 壓實。 這將從擦除階段刪除 .vmdk 檔案的歸零區塊。 這必須由主機執行(儘管它可以由客人觸發)。
vmware-vdiskmanager
在主機上執行可以執行壓縮階段,但不能執行擦除階段。擦拭的方法有以下幾種:
跑步
vmware-toolbox-cmd disk shrink LOCATION
。運行vmware-toolbox-cmd help disk
以獲取更多資訊。 (在 Windows 用戶端上vmware-toolbox-cmd
命名VMwareToolboxCmd
。)這將在擦除完成時觸發壓縮階段。該
vmshrink
計劃來自VM Back第三方工具包。對於無法使用 VMware Tools 的來賓來說,這可能是個不錯的選擇。當擦拭完成時,這也會觸發壓縮階段。您可能可以
dd
在來賓中使用(或等效的東西),但這留給讀者作為練習。
也有一些情況不需要擦拭階段。例如,如果用戶端在從檔案系統中刪除檔案時碰巧已經將檔案內容歸零,或者客戶機是 Windows,在這種情況下,VMware Workstation 自己知道如何檢查 NTFS 用戶端分割區以確定哪些區塊未使用。