VMware offers three virtual disk types for virtual machine (VM) file storage. But how do you know which type is best suited for VMs? The answer isn't always obvious, because each disk type offers different benefits: One, for example, offers better performance during initial disk writes, a second is more secure and a third is optimal when disk space is a key factor.
This tip defines virtual disks, explains the three main types of virtual disks and makes recommendations on when to use each type.
The three virtual disk types A virtual disk has a .vmdk extension and consists of two files: a small text disk descriptor file that contains configuration parameters of a disk and a larger data file that contains the raw data of a virtual disk.
There are three main virtual disk file types that you can use with ESX : thick, thin and raw.
A raw disk is referred to as raw device mapping (RDM) and enables a virtual machine (VM) to have direct access to a logical unit number (LUN) on a storage area network (SAN). This means that a VM's disk data file does not reside on a Virtual Machine File System (VMFS) volume. Instead, a small disk descriptor file is created for the virtual disk in a VM's working directory on the VMFS volume.
RDM can be configured in two different modes: virtual compatibility mode or physical compatibility mode. Virtual compatibility mode virtualizes the mapped device and is generally transparent to a guest operating system. This mode also provides some VMFS volume advantages, such as the ability to create snapshots. Physical compatibility mode provides minimal SCSI virtualization of a mapped device, and the VMkernel passes almost all SCSI commands directly to the device, which enables closer VM and LUN integration.
- Thick disks. All space is allocated at creation time and may contain stale data on the
physical media. These disks are less secure, because their disk blocks (which make up a disk) have
not been cleared of previous data.
- Zeroed thick disks. At creation time, all space is allocated and a disk is wiped clean
of previous data. As the space is used, data is zeroed out on demand, but only for the first write
to a disk block. When creating VMFS volume virtual disks using the VMware Infrastructure Client (VI
Client), this is the default disk type. Zeroed thick disks are also known as lazy zeroed thick
disks. These types of disks also have slightly worse input/output (I/O) performance on the first
disk block write, as the disk must be zeroed, or cleaned, before the first disk write. Subsequent
writes to the disk block perform similarly to eager zeroed thick disks.
- Eager zeroed thick disks. At creation time, all space is allocated and wiped clean of previous data on physical media. In addition, when the disk is created, all data is zeroed out, which, compared with creating other disk types, takes more time. These disks are the most secure and, because the block has already been cleared of previous data, offer slightly better performance on the first write of data to a disk block.
As disk write blocks are created, thin disks start small and grow to a preset maximum size. If you create a VM with a thin 10 GB disk, it will initially be 1 MB in size and, over time, grow to a maximum size of 10 GB. As they grow, thin disks pose a slight performance penalty, because space is allocated on demand. Also, the first write to a disk block is zeroed on demand, which creates an additional performance penalty. Once the disk has grown and its block has been zeroed, however, thin disks perform similarly to other disk types.
Thin disks are useful for conserving disk space on a VMFS volume but can cause problems if you fail to monitor their growth. Thin disks are often the default choice on Network File System (NFS) data stores. But their appropriateness is determined by the allocation policy of the NFS server and not the VMware ESX server. With thin disks, it's important to note that you see only a disk's actual size when using the VI Client data store browser. If you use a different method, such as the command line Ls command, the command returns the maximum size of the disk and not its current size.
Additionally, there is a special format called 2GBsparse. 2GBsparse divides a disk into multiple disks with a maximum size of 2 GB per disk. A VM with a 20 GB disk in this format, for example, would have its disk divided into 10 2 GB disks. VMware Workstation and VMware Server can use this format, but unless you first import into a thick or thin disk format, you can't power on a VM in this format on an ESX host. This format is sometimes used to break down larger VMware ESX disks into smaller pieces that can be copied to other ESX hosts or to physical media so that they can be delivered elsewhere.
Determining disk type
So which disk should you use for VMs? If you are concerned about disk space on VMFS volumes, using thin disks is a smart idea. If you are concerned about security and want slightly better performance on initial disk writes, use eager zeroed thick disks. If you want easier administration, use the default disk type (lazy zeroed thick disks). Note that once an initial write to a new disk block has been completed, disk performance is equal across all disk types. If you run an application inside a VM that is SAN-aware and needs direct access to a SAN LUN or if you use a clustering solution like Microsoft Clustering Server that requires two VMs to access the same disk file, use RDM.
Creating a new virtual machine with an alternative disk type
If you want to use a disk file type other than the default, you must use the vmkfstools service console utility application.
The fastest way to create a VM with an alternative disk type is to do so without creating a
disk, but this is an option only if you use VMware ESX 3.5. (Make sure to select Custom instead of
Typical for the VM configuration when you are creating the hard disk.) If you run VMware ESX 3.0,
you can create a VM with any hard disk and change it afterward.
Click to enlarge.
- Log in to the service console and change to the directory of a VM. Use the vmkfstools command
to create the hard disk. In the following example, we create a thin disk for the VM "magenta" using
the command vmkfstools –c <disk size> -d thin <disk file name>:
vmkfstools –c 10G –d thin magenta.vmdk
- Edit the VM and add a virtual hard disk. Opt to use an existing disk and browse to the newly created virtual disk in the VM's directory. You can now power on your VM and install an OS. If you check your VM disk size later, note that it grows as additional data is written to the disk.
Changing disk types in an existing virtual machine
If you want to change the format of existing disks, you must use the vmkfstools command. Make sure your VMs are powered off and do not have snapshots running. Here is a list of commands and an explanation of what they accomplish:
- vmkfstools –j <disk file name> - This command inflates a thin disk to its
maximum size and erases previous data, which will change the thin disk to an eager zeroed thick
disk. Existing data remains intact, because only new disk blocks are zeroed out or reformatted.
- vmkfstools –w <disk file name> - This command completely cleans a virtual disk
file; all existing data is deleted. This parameter should be used only for newly created virtual
disks that have no data.
- vmkfstools –i <source disk file name> <destination disk file name> -d thin – This command converts an existing thick disk to a thin disk. Once the conversion completes, you have to remove the existing disk, add a new disk and browse to the destination disk file. Once you ensure that the VM boots without error, you can delete the source disk file with the data store browser. Note that your thin disk size will vary and may not match the amount of disk space the VM uses. If data has been written in the OS and subsequently deleted, the ESX host still sees the space as used and not as free space.
For more information on using the vmkfstools command, type vmkfstools without adding any other commands in the VMware service console, or see Appendix B of VMware's server configuration guide. For more technical information on VMware's VMDK file format check out this VMware's VMDK page.
ABOUT THE AUTHOR: Eric Siebert is a 25-year IT veteran who specializes in Windows and VMware system administration. He is a guru-status moderator on the VMware community VMTN forums and maintains VMware-land.com, a VI3 information site. He is also the author of an upcoming book titled VI3 Implementation and Administration due out in June 2009 from Pearson Publishing and is a regular on VMware's weekly VMTN Roundtable podcast.
This was first published in February 2009