Wednesday, February 2, 2011

VMware Disk Mount (vmware-mount) – Installation and Linux Usage


(Part-2) - 
See here for VDDK Overview and How to Download VMware Disk Mount
See here for  VMware Disk Mount (vmware-mount) - Intro and Windows Usage



In the last post, we looked at installing and using the VDDK in Windows.  It was a fairly easy process and being somewhat savoy in Linux, I thought it would be the same.  For the most part it was, but I did struggle a bit with some syntax and the Linux environment itself needed to be prepped a bit more. 

Prerequisites
Supported/Tested Linux Operating Systems
The first thing to look at is the Virtual Disk API Programing Guide to verify what distribution and versions are supported with the VDDK Toolkit.  Both 32 and 64-bit editions are supported.  While not every flavor of Linux is represented, for the most part the newer editions should work.  I’ve tried it with Fedora Core 8, SUSE Enterprise Linux for Desktops 11 SP1 and Ubuntu 10 and all worked fine for me, just don’t expect to get support if you are not running a tested/supported version.

FUSE
The FUSE package may be required to run the VDDK tools in Linux.  FUSE (or Filesystem in USErspace) allows a non-root user to create and access their own file systems.  Fuse is a loadble module that acts as a bridge between the user space and the actual kernel mount interface.  The module was implemented in kernel version 2.6.14 and higher, meaning if you have this version or higher of the kernel, you already have FUSE as part of the OS.

To check if you have FUSE installed, try this command on kernel versions lover than 2.6.14:

 
If your kernel version is prior to v2.6.14, you will need to load the FUSE package, if it’s not already there.  I won’t go into the details on the installation process of FUSE, but you can obtain and install the package from many different sources.

From SourceForge:

Or if your version of Linux supports APT:
sudo apt-get install fuse-utils

Installing the VDDK Toolset
After you have downloaded the tarball from VMware’s site, you will need to unpack it.  This can also be done from the GUI, but the actual installation process will have to be run at the command line.


Once the command is run, as long as there are no errors, you’ll be dropped back to the command prompt.  If you do a directory listing (ls), you will see the extracted folder, vmware-vix-disklib-distrib. 

Change to that directory (cd vmware-vix-disklib-distrib).  You can also use the <TAB> key once you start typing the first few letters of the directory name.

Once you are in the directory, do another listing and find the vmware-install.pl file.  To make sure we can execute the installer, we’ll do a long listing (ll).  On some systems, if the alias isn’t setup correctly, you may need to use the ls –l command.


We can see with the ‘x’ in all positions, this script is executable, so let’s run it.  Make sure to use the ‘./’ in front of the name, otherwise the command won’t execute.  You may or may not have to use sudo, depending on who you are logged in as.  You aren’t logged in as root, are you???

Enter the password (if needed) and then press ‘Enter’ to display the License Agreement.

Press the Spacebar a few times (after you carefully read through the document) and then type ‘yes’ and then ‘Enter’, if you accept the terms…

You will be asked where you want to install the API Toolset, unless you feel otherwise, take the default of the ‘/usr’ directory by either typing out ‘/usr’ or just pressing the ‘Enter’ key.

If all goes well, you should see the following.  Note the uninstallation script, if you need it in the future.

LD_LIBRARY_PATH
This was where I struggled.  It was one of those cases of I knew this was the file I needed to edit and include a path to the shared object file for VDDK, but it was the syntax that had me confused. As always, the Internet was a huge help in giving me multiple ways of producing the same results.

In pretty much all cases, you’ll need to add the installed libraries to the search path.  Otherwise, you will get a message saying VixDiskLib: Failed to load libvixDiskLibVim.so.  After sorting through the various ways and options I had, I found the way easiest for me and in no time, I had vmware-diskmount working.  

 First, edit the ld.so.conf file located in the /etc directory using vi or any other text editor and add the following to the bottom:

/usr/lib/vmware-vix-disklib/lib32         (for 64-bit versions, just change the 32 to a 64).

Below is an example of what the /etc/ld.so.conf file looks like under SLED 11 (32-bit).


In order for the change to take effect, you’ll need to run the ldconfig command as root or sudo.


Example of connecting to an ESXi host

Now that we have the VDDK Toolset installed, let’s try running it against an ESXi host.  Conceptually, the command is about the same as the Windows version:

vmware-mount /path to vmdk {partition #} /mount point

Just like in Windows, the default partition number is 1, so if you don’t specify it, the command will assume the first partition of the vmdk file.

If you took the default installation path of ‘/usr’, the vmware-mount command will be in the /usr/bin directory and in the systems search path for commands, so you won’t need to change to the directory where the command is.  If you didn’t take the default path for installation, you’ll need to change to that directory or modify the search path.

One difference between the Windows and Linux versions is how you specify the password to connect to the ESX/ESXi host or vCenter Server.  The password is placed in a text file and the path to it is given when the command is executed.  This way it can be included in scripts without the password being seen as the command is executed.  Here’s a simple way to create a text file with the password in it.  First we create the file with the ‘touch’ command.  Then we set the permissions on the file, your level may vary, since I’m in a test environment, 777 will wok just fine.  Finally, we ‘echo’ the password to the file.  We can check to make sure it was written using the cat command.


One last thing needs to be done before we can mount vmdk files.  Since Linux uses mount points instead of drive letters as in Windows, we need a mount point to place the vmdk in.  It’s a good practice to use the ‘/mnt’ directory so we’ll create a directory under that called vmdk.  


Now that the prep work is done, we can run the actual command.  One quick note worth mentioning again, more than likely, you will have to be logged in as root or use the sudo command for vmware-diskmount to work. 

Just like the Windows version of the command, you will need to know the inventory and datastore path to the virtual machine.  When connecting to an ESX/ESXi server, this is easy because it is always the same.  For the datastore path, the quickest way to find this information is to use the vSphere Client and open the properties of the virtual machine, select the Hard disk and you'll find the datastore path listed under 'Disk File'.


The overall syntax of the command is:

vmware-mount –v ha-datacenter/vm/{virtual machine inventory path} –h {hostname} –u {username} –F {path to password file} “[{datastore name] vm name/vmdk file to mount}” {mount point}

Just like the Windows version of the  command, it is a lot to digest (refer back to the Windows explanation for more details).  To mount the VMware Capacity IQ VM’s Hard disk 1, we would type the following:

vmware-mount –v ha-datacenter/vm/VMware\ Capacity\ IQ –h 192.168.1.111 –u root –F /root/vddk.pwd “[ds3] VMware Capacity IQ/VMware Capacity IQ.vmdk” /mnt/vmdk

Two things to note in the above command.  The first is if your VM’s inventory path has a space in it, you can either add a ‘\’ before the space or just use quotes.  For example, “ha-datacenter/vm/VMware Capacity IQ” would work the same in the above command.  The second point is to always remember your quotes around the datastore path as they are not optional.  It seems I'm always forgetting the end quotes.  You'll know this when you're dropped at a '>' prompt waiting for input.  Ctrl+C will be your friend, too.

Here is the executed command and the directory listing of the mounted vmdk:



Example of connecting through a vCenter Server
Now let’s take a look at connecting through a vCenter Server.  Not a whole lot different than the ESX/ESXi version of the command, but we do need to be concerned with the inventory path of the virtual machine.  If we look at the VMware Capacity IQ virtual machine again, the inventory path is DC/VMware Capacity IQ.


So the command would look like this:

vmware-mount –v “DC/vm/VMware Capacity IQ” – h vcenter –u administrator –F /root/vddk.pwd “[ds3] VMware Capacity IQ/VMware Capacity IQ.vmdk” /mnt/vmdk



Common mistakes made (by me) here are not changing the user name from root to administrator and forgetting to update the password file if it is different than the ESX/ESXi password.

To add a bit more complexity, let’s try mounting a VM that isn’t right off the root structure of the Datacenter.


We will mount the win7x64-2 virtual machine in the DC/Windows 7 Desktops/Win7x64 inventory path.  Remember to include the ‘/vm/’ right after the Datacenter name and it’s probably easier to use quotes around the whole thing.

The command would look like this:

vmware-mount -v "DC/vm/Windows 7 Desktops/Win7x64/win7x64-2" -h vcenter -u administrator -F /root/vddk.pwd "[ds3] win7x64-2/win7x64-21-internal.vmdk" /mnt/vmdk


Oops, don’t forget you can only mount a VM’s vmdk file if it is powered down.  Also, you will not be able to power the machine back on until the vmdk file is unmounted and released back to vCenter or ESX/ESXi.


That’s better and I have mail.  Yea!

Example of Mounting a VMware Workstation VMDK
Finally, let’s take a look at mounting a drive on a Linux host running VMware Workstation.  First, if you have VMware Workstation on a Linux host, you already have vmware-mount installed.  However, it is a limited version and only allows you to mount vmdk files locally, not through ESXi/ESX or a vCenter Server.

To run the vmware-mount tool on a local vmdk file, just tell it where the vmdk file is and where you want to mount it.

vmware-mount /home/drollins/vmware/Ubuntu/Ubuntu.vmdk /mnt/vmdk


Let see what happens when we try to upgrade to the full version of the VDDK toolkit.  It is pretty much the same installation process, only you are asked if you would like to over-write /usr/bin/vmware-mount and /usr/bin/vmware-diskmanager.  Take the default of yes and it will install properly.


You will still need to add the ‘/usr/lib/vmware-vix-disklib/lib32 (or64) to your ld.so.conf file and run ldconfig as root (or sudo) to complete the installation.



Listing and Unmounting Drives
The last thing we’ll take a look at is listing the mounted vmdk files and unmounting them.

To list a drive, just run the vmware-mount command with the ‘L’ option

vmware-mount -L

Lastly, I can’t stress how important it is to unmount the drive when you are done working with it.  Use the “d” option and the mount point to cleanly unmounts a vmdk file. 

vmware-mount –d  /mnt/vmdk

Conclusion
That’s a look at the Linux version of the VMware Disk Mount Tool, vmware-mount.  One thing I did learn that contradicts my original post is the ability to mount a Windows volume in Linux.  I was able to do this even though the User Guide said it was not possible.  It may be a case of support rather than technically feasible.  It makes me wonder what a Linux vmdk mounted on a Windows host would look like.  I should really give that a try.

I hoped you enjoyed this post and please post any comments or questions you have.  It was fun to write and had me searching for some Linux skills I’d tucked away.

I may skip the troubleshooting post and move right on to the vmware-vdiskmanager on the Windows and Linux platforms.  I think the troubleshooting piece may be a work in progress and will probably end up being a combination of diskmount and diskmanager.


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!!!

Introduction to VMware's Virtual Disk Development Kit (VDDK)


One of the conditions of moving to vSphere for a customer of mine was the ability to quickly modify a set of files in a virtual disk after cloning it, but before deploying it as a virtual machine.  Fortunately for him (and myself) VMware has a tool that will do just that and more.  Although not widely known, VMware released the Virtual Disk Development Kit (VDDK) as a set of Open APIs a couple of years ago for modifying and manipulating virtual disk files (or vmdk’s).  The main purpose of the VDDK was for partners and customers to write their own applications to integrate with VMware storage using the included set of C function calls and executables.

Most of these partners used the VDDK to develop slick backup applications that made the VI Admins life’s a lot easier and there was no longer a need for a backup proxy server in most cases (think VCB).  The VDDK, along with the vSphere SDK make up the vStorage APIs for Data Protection enabling these backup solutions to function.  The VDDK is both a Windows and Linux based set of APIs that can interact with pretty much any of VMware’s hypervisors and their associated disk files.

I’m not a programmer and don’t intend to focus on the APIs.  In the posts that follow, I’ll walk you though the two executables included with the VDDK, vmware-mount and vmware-vdiskmanager and how they can best be used.  Since both tools are CLI based, there are third party tools that take advantage of the VDDK for all you fans of the GUI and we’ll take a look at those as well.

Documentation and Download

First and foremost, how do you get the VDDK and where is the documentation?  All of the documentation is here along with the download link.  Since you will need a VMware Store account to access the download, I cannot provide a direct link to it, just click on the Download link at the top.  There are separate PDF files for the Disk Mount User’s Guide, the Virtual Disk Manager User’s Guide, as well as Designing Backup Solutions for vSphere and the Virtual Disk Programmers Guide.