Contents
Shrinking and Defragmenting Virtual Disks
Shrinking and Defragmenting Virtual Disks
Shrinking a virtual disk reclaims unused space in the virtual disk. If there is empty space in the disk, this process reduces the amount of space the virtual disk occupies on the host drive.
Note: ESX Server 3 does not support shrinking virtual disks.
Shrinking a disk is a two-step process: a preparation step and the actual shrink step. In the first step, VMware Tools reclaims all unused portions of disk partitions (such as deleted files) and prepares them for shrinking. This allows for the maximum shrink possible. This step takes place in the guest operating system.
The shrink process itself is the second step, and it takes place outside the virtual machine. The VMware application reduces the size of the disk based on the disk space reclaimed during the preparation step.
Shrinking requires:
Free disk space on the host equal to the size of the virtual disk being shrunk.
VMware Tools to have sufficient access rights to write a file in the partition's directory. If it cannot do so, change the directory access rights or unselect that partition.
In some configurations, it is not possible to shrink virtual disks. If your virtual machine uses such a configuration, the Shrink tab displays information explaining why you cannot shrink your virtual disks. For example, you cannot shrink a virtual disk if:
You preallocated disk space when you created the disk, which is the default option for virtual machines running under GSX Server and VMware Server.
The virtual machine has a snapshot. To remove an existing snapshot in Workstation 5 or higher, go to VM > Snapshot > Snapshot Manager, select a snapshot in the snapshot tree, and click Remove. To remove an existing snapshot in all other VMware products, choose Snapshot > Remove Snapshot.
The virtual machine contains physical (raw) disks.
The virtual disk is not an independent disk in persistent mode. You can change the mode of a virtual disk before the virtual machine is powered on. For more information about independent disks, see your VMware product documentation.
The virtual disk file is stored on a CD-ROM or DVD-ROM.
Shrinking a Virtual Disk
Shrinking a Virtual Disk
When a virtual machine is powered on, you shrink its virtual disks from the VMware Tools control panel.
To shrink virtual disks, you should run VMware Tools as the root user (su -). This way, you ensure the whole virtual disk is shrunk. Otherwise, if you shrink the virtual disk as a non-root user, you cannot prepare to shrink the parts of the virtual disk that require root-level permissions.
1. To launch the control panel, become root (su -), then run vmware-toolbox.
2. Click the Shrink tab.
3. Select the virtual disks and partitions you want to shrink, then click Shrink.
Note: If you deselect some of the partitions, the whole disk is still shrunk. However, those partitions are not prepared for shrinking, and the shrink process does not reduce the size of the virtual disk as much as it could otherwise.
4. A progress bar appears for each partition. You can abort the operation at any time by clicking Cancel.
5. When VMware Tools finishes preparing the selected disk partitions, you are prompted to begin shrinking the disks.
If you click Yes, the virtual machine freezes and VMware Tools shrinks your virtual disk(s). After that, the virtual machine continues to run normally.
If you click No, you can delay shrinking the virtual disks. You may shrink the disks at a later time by using the Shrink tab.
Shrinking disks may take considerable time.
Defragmenting a Virtual Disk
Defragmenting a Virtual Disk
You can defragment a virtual disk, which rearranges files, programs and unused space on the virtual disk so that programs run faster and files open more quickly. Defragmenting does not reclaim unused space on a virtual disk; to reclaim unused space, shrink the disk.
If you preallocated all the space for your virtual disk at the time you created it, you cannot defragment it.
For best disk performance, you can take the following three actions, in the order listed:
1. Run a disk defragmentation utility inside the virtual machine.
2. Power off the virtual machine, then defragment its virtual disks from the virtual machine settings editor (VM > Snapshot > Remove Snapshot). Select the virtual disk you want to defragment, then click Defragment.
Note: This capability works only with virtual disks, not with raw or plain disks (plain disks are a feature of older VMware products).
3. Run a disk defragmentation utility on the host computer.
Defragmenting disks may take considerable time.
Note: The defragmentation process requires free working space on the host computer's disk. If your virtual disk is contained in a single file, for example, you need free space equal to the size of the virtual disk file. Other virtual disk configurations require less free space.