Difference between revisions of "Command Line Management of VMware Virtual Disks"
(→Defragmenting a Virtual Disk) |
m (Text replacement - "<google>BUY_VMWARE_SERVER_2_BOTTOM</google>" to "<htmlet>vmware</htmlet>") |
||
(One intermediate revision by the same user not shown) | |||
Line 8: | Line 8: | ||
− | < | + | <htmlet>vmware</htmlet> |
Line 171: | Line 171: | ||
− | < | + | <htmlet>vmware</htmlet> |
Latest revision as of 18:48, 29 May 2016
Previous | Table of Contents | Next |
Managing VMware Server 2.0 Virtual Disks | VMware Server 2.0 Security - Access, Roles and Permissions |
Purchase and download the full PDF and ePub editions of this VMware eBook for only $8.99 |
The previous chapter covered the management of VMware virtual disks using the VI Web Access interface and VMware Tools. VMware also provides the option to perform a wide range of virtual disk management tasks from the command line using the Virtual Disk Manager tool (vmware-vdiskmanager).
This chapter of VMware Server 2.0 Essentials will cover the use of vmware-vdiskmanager to create, defragment, shrink, rename, convert and extend VMware based virtual disks.
The VMware Virtual Disk Manager Command Line Tool
The VMware Virtual Disk Manager command line tool is installed by default along with VMware products such as VMware Server. The executable file is named vmware-vdiskmanager and is installing in Program Files\VMware\VMware Server on Windows hosts, and /usr/bin on Linux. The tool accepts a wide range of command line arguments, a summary of which may be obtained by running the tool with no command-line arguments:
vmware-vdiskmanager
Converting Virtual Disks
VMware Server supports both growable and pre-allocated virtual disks. In addition, the disks can be specified to be contained in a single file, or split into multiple 2GB files (usually only used on hosts with restrictive file size limits).
The virtual disk type is initially defined at the point that the disk is created. Whilst this is generally not a problem, VMware Server does not support the shrinking of pre-allocated virtual disks. Before a pre-allocated disk can be reduced in size, therefore, it is necessary to first convert it to a growable disk. This can be performed using the Virtual Disk Manager tool (vmware-vdiskmanager).
The type to which a virtual disk is to be converted is specified using the -t flag, together with the target disk type. This is represented by a number as outlined in the following table:
Type Identifier |
Description |
---|---|
0 |
Growable (single .vmdk file) |
1 | Growable (multiple 2GB files) |
2 | Pre-allocated (single file) |
3 |
Pre-allocated (multiple 2GB files) |
4 | Pre-allocated ESX |
5 | Compressed for streaming |
The vmware-vdiskmanager command requires a number of arguments to perform a virtual disk type conversion. The syntax for a type conversion is as follows:
vmware-vdiskmanager -r <oldfilename>.vmdk -t <type> <newfilename>.vmdk
where <oldfilename>.vmdk is the name of the virtual disk image file to be converted, <type> is the number from the above table indicating the target virtual disk type, and <newfilename>.vmdk is the name of the new, converted file.
For example, to convert a virtual disk image file called win2008-1_2.vmdk to a growable disk called new.vmdk the following command would need to be executed:
vmware-vdiskmanager -r win2008-1_2.vmdk -t 0 new.vmdk Creating disk 'new.vmdk' Convert: 100% done. Virtual disk conversion successful.
Once the conversion is completed, the virtual machine will need to be configured to use the converted disk, or the new disk renamed to have the name of the original disk.
Renaming a Virtual Disk
An existing virtual disk may be renamed using the -n command line flag as follows:
vmware-vdiskmanager -n <oldfilename>.vmdk <newfilename>.vmdk
where <oldfilename>.vmdk is the name of the virtual disk image file to be renamed, and <newfilename>.vmdk is the new name of the file.
Creating a Virtual Disk
The creation of a virtual disk using the vmware-vdiskmanager tool requires the specification of a number of different configuration options:
- The type of the virtual disk. This is specified using the -t flag combined with the numerical type identifier, as outlined in the above table.
- The size of the new disk specified in GB with the -s flag.
- The disk adapter type, using the -a flag and one of ide, buslogic or lsilogic.
- The name of the virtual disk image (.vmdk) file to contain the new virtual disk.
For example, to create a new 100GB, growable, SCSI BusLogic virtual disk in a file named NewDisk.vmdk, the following command would need to be executed:
vmware-vdiskmanager -c -t 0 -s 100GB -a buslogic NewDisk.vmdk
Shrinking a Virtual Disk
Shrinking a virtual disk involves the reduction in size of a virtual disk image file by discarding unallocated space in the virtual disk. The process reduces the amount of space the virtual disk uses on the host, but does not change the size of the disk as far as the guest operating systems which use the disk are concerned. When more disk space is needed by a guest, VMware will automatically increase the size of the virtual disk file accordingly, until the maximum specified size of the virtual disk is reached.
The amount by which a virtual disk file can be reduced depends entirely on the amount of unallocated space available and cannot be specified by the user. Only growable virtual disks may be shrunk. Before a pre-allocated disk can be shrunk it must first be converted using the steps outlined previously in this chapter. A further restriction is that there must be no snapshots of the virtual disk. If snapshots exist, they should be removed prior to performing the shrink operation.
Assuming the virtual disk to be shrunk is a "growable" disk and is on a Windows host, the first step is to prepare the virtual disk for shrinking. To do this, the disk must be mounted with a drive letter on the Windows host. This can be achieved using the VMware DiskMount Tool which is available for download from www.vmware.com/download/ws/#utilities. Once installed, a virtual disk may be mounted using a command similar to the following:
vmware-mount G: "D:\VirtualMachines\Win2008\Win2008.vmdk"
Once the virtual disk is mounted using a suitable drive letter (G: in the above example), the disk must be prepared for shrinking:
vmware-vdiskmanager -p G:
Once the disk is prepared, the vmware-vdiskmanager tool requires only the -k flag followed by the name of the virtual disk image file to perform a shrink operation. For example, to shrink a virtual disk named win2008.vmdk:
vmware-vdiskmanager -k win2008.vmdk
To unmount the virtual disk from the host system, use the vmware-mount command combined with the drive letter and the /d option:
vmware-mount G: /d
Expanding a Virtual Disk
The size of a virtual disk may be expanded using the -x flag together with the new size of the disk. For example, the following command extends the size of the virtual disk containing in the file win2008.vmdk to 100GB:
vmware-vdiskmanager -x 100GB win2008.vmdk
An important point to note is that although the virtual disk has been extended by VMware, the new space will typically be treated as being unallocated by the guest operating system. In order to use the extra space, either an existing partition on the virtual disk will need to be extended, or a new partition created from within the guest operating system.
Defragmenting a Virtual Disk
A VMware virtual disk may be defragmented only if created as, or subsequently converted to a growable disk. The defragmenting of pre-allocated virtual disks is not supported. In addition, any virtual machines making use of the virtual disk must be powered off prior to beginning the defragmentation process.
Defragmentation is initiated using the -d flag of the vmware-vdiskmanager tool combined with the name of the virtual disk image file. For example:
vmware-vdiskmanager -d win2008.vmdk
Purchase and download the full PDF and ePub editions of this VMware eBook for only $8.99 |