Friday, January 7, 2011

VMware Disk Mount (vmware-mount) - Intro and Windows Usage


(Part 1) -See here for VDDK Overview and How to Download VMware Disk Mount


 Disk Mount lets you mount an offline virtual disk to a Windows or Linux host without having to connect to it through its virtual machine.  It even allows you to mount partitions inside of a virtual disk file.  After the virtual disk is mounted, it appears as another drive letter in Windows or mount point in Linux and can be read from or written to.  The drive could be mounted to expand the partition, scanned for a virus, or defragmented with the vmware-vdiskmanager tool (more on that later).  The idea here is that getting the drive mounted is typically the first step in what you would like to accomplish.

There are some restrictions and limitations with the Disk Mount tool, some obvious, some not so obvious. 

·      VM has to be offline, not powered on or suspended in order for the virtual disk to be mounted.
·      The virtual disk to be mounted cannot be read only, encrypted or compressed.
·      A Windows host can only mount FAT and NTFS partitions and Linux hosts can only mount Linux partitions.
·      Windows Dynamic Disks are not supported.
·      A Linux host can only mount the latest snapshot, a Windows host can mount any of the previous snapshots.
·      If the VM contains a snapshot, you can only mount the parent vmdk in non-persistent, read only mode.
·      Do not modify or revert any of the snapshots of a mounted virtual disk.

Disk Mount works on pretty much any of the current Windows platforms, XP/Vista/7 and 2003/2008 and will run on any of the supported Linux distros VMware Workstation supports.  Both the Windows and Linux version will support a 32 or 64 bit OS.

VMware Disk Mount – Windows

First we’ll take a look at the Windows version with ESXi, vCenter and Workstation.  The installation for ESXi and vCenter can be installed on any Windows based machine.  If you want to use this for VMware Workstation, you’ll need to install it on the host OS.  Wherever you install it, the installation is the same and very easy.  The only real option you have is where you want the tool installed. 

After you install VDDK, to run vmware-mount, open a command prompt and browse to the directory where the VDDK was installed (default is c:\program files\vmware\vmware virtual disk development kit\ for 32-bit and c:\program files (x86) \vmware\vmware virtual disk development kit\ for 64-bit) and then change to the .\bin directory.
A “dir *.exe” directory listing shows the vmware-mount.exe tool we’ll be using.

Example of connecting to an ESXi host

The first option we’ll look at is mounting a virtual disk through an ESXi host.  Here’s an example of what the syntax looks like:

vmware-mount [drive letter:] “[datastore name] path to the vmdk i:/”ha-datacenter/vm/VM Name” /h:ESXi-Hostname  /u:username /s:password

It is a lot to take in, so lets take a look at the CLI options used.

drive letter:
Drive letter on the host to map the virtual disk. 
“[datastore name] path to vmdk”
Name of the datastore and folder path where the virtual disk file lives
/i:”ha-datacenter/VM/VM Name”
Inventory path on the ESXi host to access the managed disk. 
/h:ESXi-Hostname
Name or IP Address of the ESXi host to connect to
/u:username /s:password
Credentials to connect to the ESXi host

The drive letter is self-explanatory.  It is the drive letter you would like the virtual disk mapped to on the host you are running the command from.  Keep in mind, the drive letter needs to start at D:.  A:-C: will not work and must be an drive letter not already in use.

The next option is the datastore and path to the vmdk.  The datastore name does require and starts with a quote and bracket.  The easiest way to find this path is to open up the properties of the virtual machine and select the Hard Disk you are trying to mount.  You can then copy and paste it to the command prompt.

In the screen shot above, this portion of the command would be:

“[datastore1] ThinApp/ThinApp-000001.vmdk”

The next part of the command is the Inventory path to the virtual machine on the ESXi host.  The syntax for connecting to an ESXi host is a lot easier than the syntax for vCenter. It will always start with /i:”ha-datacenter/vm/…”.  Again, note the quotes.  The only item you have to concern yourself with is the actual VM name; the rest will always stay the same when connecting to an ESXi host.  Since the VM we want to connect to is “ThinApp”, this part of the command would look like:

/i:”ha-datacenter/vm/ThinApp”

Finally, the last three options kind of go hand in hand.  The ESXi host you are connecting to and then the username and password to authenticate.

When we put this all together and using the ThinApp VM as an example, here is what we come up with:

vmware-mount G: "[datastore1] ThinApp/ThinApp-000001.vmdk" /i:"ha-datacenter/vm/ThinApp" /h:192.168.1.5 /u:root /s:password

Note that when you execute the command, unless there is an error, nothing is returned.

Example of Connecting Through a vCenter Server

Now let’s move on and connect through a vCenter Server.  Generally, it’s about the same, but we just need to pay a bit more attention to the inventory and host/authentication piece.

The first piece of the command will be the same:

vmware-mount G: “[datastore1] ThinApp/ThinApp-000001.vmdk”

To get the inventory piece correct, the easiest way is to open a vCenter Client and look at the Home/Inventory/VMs and Templates tab.















The syntax of the command is:

/i:”datacenter name/VM/folder path to vm/vm name

Staying with the ThinApp example, we just need to follow the path down to the VM, datacenter, folders and all.  This portion of the command would be:

/i:”DC/VM/Windows XP Desktops/ThinApp”

Notice the “/VM/” placed right after the Datacenter name.  This is required and will always be there.  Once again, notice the quotes around the path.

The host/authentication piece is pretty simple.  We just need the vCenter FQDN or IP address of the vCenter Server and a vCenter Server username and password.  Remember, this will more than likely be a Windows AD user or local Windows account on the vCenter Server.   So the final command would look like:

vmware-mount G: “[datastore1] ThinApp/ThinApp-000001.vmdk” /i:”DC/VM/Windows XP Desktops/ThinApp” /h:vcenter.vmwdave.local /u:administrator /s:password

 Example of Mounting a VMware Workstation VMDK

This is probably the easiest of all three scenarios, but it also gives us the chance to bring up the topic of multiple partitions in a single vmdk file.  To mount a VMware Workstation virtual disk installed on a Windows machine, you just need to specify a drive letter and the path to the vmdk file:

vmware-mount G: “c:\users\drollins\documents\virtual machines\thinapp\thinapp-000001.vmdk”

You could also copy a VMware Fusion vmdk file to a Windows machine with the VDDK installed and mount it there, if needed. 

If you do have multiple partitions in a single vmdk file, maybe a dual boot Windows/Linux VM or a simple C and D drive in a Windows VM, you’ll need to specify which partition you’d like to mount with the /v:N (replacing the ‘N’ with the partition number). 


How do you find out what the partition number is?  There is a /p option that will display the partition information, but it only works when the tool is run on the same machine as the vmdk.  So unless you copy the vmdk file from a datastore to the local machine, you will need to find the partition scheme some other way.  I’ve done some limited testing with the ‘/p’ option and it will work over a mapped network drive.


Listing and Unmounting Drives

The last two items we’ll talk about are listing the mounted virtual drives and unmounting or deleting the virtual drive mappings.  This applies to all three situations, ESXi, vCenter and local virtual disk mounting.  It is critical the virtual drives be unmounted when you are finished with them.  Your virtual machine will not power on when the drive is mounted and there is the potential for data loss if someone inadvertently deletes or reverts a snapshot wile the drive is mounted.

In order to see which virtual disks you have mapped, just issue the vmware-mount command with the ‘/L’ option.  This will show you which drive letter on your local host is mapped to what virtual disk and its path.


To unmount a drive, just issue the vmware-mount with the drive letter you would like to unmount and the ‘/d’ option.


Conclusion
That was a look at vmware-mount for the Windows platform.  I hope it was useful for you, but feedback as always appreciated. 

Next we’ll take a look at using vmware-mount on the Linux platform and troubleshooting the vmware-mount tool.  Stay tuned!!!

1 comment:

  1. Very good written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing – can’r wait to read more posts.
    vmware training

    ReplyDelete