Skip navigation
2009

A question that comes up from time to time in the forums is about how to use the vmrun application with the runProgramInGuest command to install a Windows Installer (MSI) package in a virtual machine running Windows. In other words, someone needs to run something similar to the following command:

||vmrun -T ws -gu USERNAME -gp PASSWORD runProgramInGuest "C:\VMs\VM1\VM1.vmx" "C:\Windows\system32\msiexec.exe /i C:\app.msi"||

The runProgramInGuest command will be issued without error, but a look at the virtual machine's console will reveal a Windows Installer options screen displaying all of the switches that are available to the msiexec.exe application. Any approach or combination of single-quotes, double-quotes, slashes, backslashes, spaces or special characters thrown at vmrun and runProgramInGuest results in the same options screen or (even worse) the "Error: A file was not found" message.

 

After some quick research into this issue, I discovered a discussion on VMTN, where VMware employee mattrich states that "vmrun quotes each argument it passes to the guest." This is good to know. It is actually this behavior that creates the problem for the Windows Installer.

 

To verify that the behavior mattrich describes is correct, use the free Process Monitor utility from Sysinternals. On the virtual machine, launch Process Monitor and press Ctrl+L to bring up the filter menu. Working from the left, choose "Operation" from the first drop-down menu. Choose "is" from the second drop-down menu. Choose "Process Create" from the third drop-down menu and "Include" from the fourth drop-down menu. Now click the "Add" button. The new filter will now be listed in the bottom of the filter window. Click OK to continue. 

 

Now use the vmrun application with the runProgramInGuest command to send the Windows Installer commands to the virtual machine again. 

 

||vmrun -T ws -gu USERNAME -gp PASSWORD runProgramInGuest "C:\VMs\VM1\VM1.vmx" "C:\Windows\system32\msiexec.exe /i C:\app.msi"||

Viewing the detail column in Process Monitor, it becomes very apparent that each argument sent to the Windows host via runProgramInGuest is encapsulated in quotes, just like mattrich said. Using Start->Run in Windows, re-typing this same command (exactly as it appears in Process Monitor) will create the same output of a Windows Installer options screen. So there is definitely a problem; but how about a workaround?

 

There is actually an easy workaround that can be used to solve this problem. On the host, create a batch file by issuing the following command:

 

echo C:\Windows\system32\msiexec.exe /i C:\app.msi > C:\sourcebatch.bat

Now run the following command on the same host where the batch file is located:

 

vmrun -T ws -gu USERNAME -gp PASSWORD copyFileFromHostToGuest "C:\VMs\VM1\VM1.vmx" "C:\sourcebatch.bat" "C:\destbatch.bat"

This will copy the batch file C:\sourcebatch.bat from the host to the guest as C:\destbatch.bat.  All that is left is to run the batch file on the virtual machine with:

 

vmrun -T ws -gu USERNAME -gp PASSWORD runProgramInGuest "C:\VMs\VM1\VM1.vmx" cmd.exe "/c C:\destbatch.bat"

After the install completes, one final command should be run (in the interest of cleaning up):

 

vmrun -T ws -gu USERNAME -gp PASSWORD deleteFileInGuest "C:\VMs\VM1\VM1.vmx" "C:\destbatch.bat"

This workaround certainly isn't as elegant as just running a single command would be, but it will get the task done.  This approach is also interesting in that it solves a possible limitation of an existing product, by using additional functionality contained in the same product. I refer to a "possible limitation," because I am optimistic that someone will figure out the secret combination of characters to make vmrun runProgramInGuest work with msiexec.exe!

P2V conversions are always interesting. I don't think that I have ever seen any two go exactly the same way, and each one always has something unique about it.  The most recent Windows 2003 Server P2V I ran went relatively smooth, with one exception. On every Windows startup, I would receive the following error: 

 

Event Type:     Error

Event Source:     Service Control Manager

Event Category:     None

Event ID:     7000

Description:

The Parallel port driver service failed to start due to the following error:

The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.

 

 

After entering the "set devmgr_show_nonpresent_devices=1" command, I could see a device listed as "Direct Parallel" under the "Network Adapters" in Device Manager. This device could be disabled, but to uninstall it was not possible.  At least not initially.....

 

After a few quick Google searches for "Direct Parallel", I ran across a post at the WinDrivers forums that appeared to have a fix for a similar issue. The suggestion there lead me to try a registry search for "Direct Parallel" under the HKLM\SYSTEM\CurrentControlSet\Control\Class key. Once the correct key was found, it was a simple matter of locating the REG_DWORD named "Characteristics" and changing the binary Hexadecimal value from 29 to 09.  Apparently this change clears the "not user removable" value from the "Direct Parallel" device. Returning to Device Manager, I was now able to remove the "Direct Parallel" device from under "Network Adapters" without issue.

 

A subsequent reboot for another issue revealed that even though the "Direct Parallel" device was now gone, there was still a problem.  The Event ID 7000 message was still present. The final fix was to disable the ParPort service, which required one additional registry edit. Under the HKLM\SYSTEM\CurrentControlSet\Services\Parport key, there is a REG_DWORD named "Start" and changing this value from 1 to 4 disabled the service. Now the virtual machine boots right up and starts Windows 2003 with no errors.

 

I have quite a few P2Vs in my immediate future, so there will probably be more things to share very soon!

I have read several blogs and articles about the possibility of file level restores for files contained within vmdks (and snapshots of vmdks) housed on NFS volumes. Most of these reads discussed, at a high level, how to make it work, and some even included commands. What I couldn't find was a decent guide to setting the whole environment up and making it work. So I built my own, and documented the steps. 

 

   

Note: If you already have a working Ubuntu virtual machine that is networked and has the VMware Tools installed, or if you simply don't need the step-by-step instructions for creating one, skip straight to Step 04 below for the configuration settings.

 

STEP 01: CREATE THE VM

01. Using the VMware Infrastructure Client, start the New Virtual Machine Wizard.

 

02. Choose Custom Configuration.

 

03. Choose the required inventory location and datastore for the new virtual machine.

 

04. Choose Linux and for the version, choose Ubuntu Linux (32-bit).

 

05. Choose 1 virtual processor, 512 MB Memory, and 1 NIC on the appropriate network.

 

06. Choose the LSI Logic SCSI Adapter.

 

07. Create a new virtual disk, sized at 5 GB, in the appropriate location for your environment.

 

08. Click Next to accept the default values for the Advanced Options.

 

09. Click Finish.

 

 

STEP 02: INSTALL THE OS

01. Right-click the newly created virtual machine and choose Edit Settings.

 

02. Verify the virtual machine settings.

 

03. Click CD/DVD Drive 1 and choose the Ubuntu 8.04.2 installation iso or media.

    Note: Remember to select the Connect at power on option in the device status area.

 

04. Click the OK button, and wait for the virtual machine to finish with the reconfiguration.

 

05. Right-click on the virtual machine and choose Open Console.

 

06. Press the green triangle button (or use the VM menu) to power on the virtual machine.

 

07. If all goes well, the Ubuntu live cd will boot.  Choose a language, and then choose the Install Ubuntu option.

    Note: It is always a good idea to choose the Check CD for defects before beginning.

 

08. At the Welcome screen, click the Forward button to continue.

 

09. Choose the correct time zone and click the Forward button.

 

10. Choose the correct keyboard layout and click the Forward button.

 

11. Take the default of Guided - use entire disk for the detected VMware Virtual disk and click the Forward button.

 

12. Fill out the name, username, password and computer name and click the Forward button.

 

13. At the Ready to Install screen, click the Install button. 

 

14. Wait for the Installation complete screen, and then click the Restart now button. 

 

15. Now press Ctrl+Alt to escape the console window, and go to the VM menu and choose Edit Settings. Select the CD/DVD Drive 1, and then un-check Connected and Connect at power on in the Device Status area.  Click the OK button.

 

16. Press ENTER as instructed on the Ubuntu setup screen.

 

 

STEP 03: CONFIGURE THE OS - Part I

01. Login to Ubuntu, using the username and password selected during the install.

 

02. Choose the VM menu and select Install/Upgrade VMware Tools.  Click OK at the Information Screen.

    Note: If a window doesn't automatically open, double-click the VMware Tools icon on the desktop. 

 

03. In the File Browser window, right-click the VMwareTools-X.X.X-123456.tar.gz file and choose Extract To...

At the top left, under Places, scroll down and select the directory that has the same username that you are currently logged in with - it should be the third option down.  Leave all other options at the defaults, and press the Extract button.

 

04. On the Ubuntu desktop, on the top toolbar, use the Places menu and select Home Folder.  When the File Browser window opens, verify that there is a vmware-tools-distrib directory.

 

05. Close all windows that are currently open in the Ubuntu virtual machine.

 

06. On the Ubuntu desktop, on the top toolbar, use the Applications -> Accessories menu and choose Terminal.

Enter the following commands in the terminal window:

 

  cd vmware-tools-distrib

  sudo ./vmware-install.pl

 

When prompted, enter your password and press Enter.

When prompted for which directory to install the binary files, press Enter.

When prompted for which directory contains the init directories, press Enter.

When prompted for which directory contains the init scripts, press Enter.

When prompted for which directory to install the daemon files, press Enter.

When prompted for which directory to install the library files, press Enter.

When informed about path creation, including parent directories, press Enter.

When prompted for which directory to install the documentation, press Enter.

When informed about path creation, including parent directories, press Enter.

 

The install should now be complete, but configuration still needs to happen.

 

When prompted about invoking the vmware-config-tools command, press Enter.

When prompted about pre-built vmmemctl modules and a C compiler, press Enter.

When prompted about the location of the C header files, press Enter.

Choose the appropriate display size by entering the corresponding number (probably 2 for 800x600) and pressing Enter

At this point, the screen will probably go black and flicker about, but the terminal window will re-appear eventually.

 

VMware Tools setup is now complete.  Enter the following command:

 

  exit

 

07. On the Ubuntu desktop, on the top toolbar, use the System menu and select Administration - Network.

On the Connections tab, select the Wired Connection and then click the Properties button.

Un-check the Enable Roaming Mode option for eth0 properties.

Under Configuration Settings - Configuration, choose the required settings for static or DHCP addressing and then click the OK button.

Select the General tab and verify the correct host name, and enter a domain name (if required).

Select the DNS tab and enter DNS servers and/or search domains (as/if required).

Click the Close button.

 

08. On the Ubuntu desktop, on the top toolbar, use the System menu and select Preferences - Network Proxy and configure as/if

required.  If proxy server access is not required, omit this step.

 

09. Test network connectivity (web, ping, etc), before continuing to the next step.

 

 

STEP 04: CONFIGURE THE OS - Part II

01. On the Ubuntu desktop, on the top toolbar, use the Applications -> Accessories menu and choose Terminal.

Enter the following commands:

 

  sudo apt-get update

  sudo apt-get install portmap nfs-common

 

When prompted if you want to continue, type y for yes and press Enter.

 

02. In the same terminal window, enter the following command:

 

  gksudo gedit /etc/hosts.deny

 

Add the following line to the end of the file:

 

  portmap : ALL

 

Press the Save button and close gedit

 

Now, enter the following command:

 

  gksudo gedit /etc/hosts.allow

 

Add the following line to the end of the file:

 

  portmap : 91.189.94.8

 

Note: Replace 91.189.94.8 with the IP address of the correct NFS server.  DNS names will not work.

Press the Save button and close gedit.

 

03. In the same terminal window, enter the following commands:

 

  sudo mkdir /mnt/datastore01

  sudo mount 91.189.94.8:/vol/vol1 /mnt/datastore1

 

Note: Replace the ip address and export path (91.189.94.8:/vol/vol1) in the above example as required.

 

04. On the Ubuntu desktop, on the top toolbar, use the Places menu and select Computer.  Now open Filesystem in the right pane.

Open the mnt directory.  datastore01 should be visible here.  Open datastore01 to browse the nfs volume.  To view the snapshot directory, use the View menu in File Browser to select Show Hidden Files, or press Ctrl+H.  Once hidden files are visible, a .snapshot directory should be available.  Browsing this directory is one way to find the path to the desired snapshot.

 

05. In the same terminal window, enter the following commands:

 

  sudo mkdir /mnt/vmdk

  sudo mount /mnt/datastore01/.snapshot/hourly.1/test/test-flat.vmdk /mnt/vmdk -o ro,loop=/dev/loop0,offset=32768 -t ntfs

 

Note: Change the above path to reflect the actual path of the desired vmdk in the desired snapshot.  Also note the offset value of 32768,

which may need to be changed. See the FULL DISCLOSURE, WARNINGS AND OTHER section below for more information on the offset.

 

06. On the Ubuntu desktop, on the top toolbar, use the Places menu and select Computer.  Now open Filesystem in the right pane.

Open the mnt directory.  The vmdk directory should be visible here.  Open to view/browse the contents of the virtual disk.  This is one method to locate files contained in the snapshot. 

 

07. To restore files to a Windows server, on the Ubuntu desktop, on the top toolbar, use the Places menu and select Connect to Server. Use the following settings:

 

Service type: Windows share

Server: dns name of the Windows server

Share: share name on Windows server - c$, USERS$, DATA$, etc

User name: Active Directory or local server account with permission to the share

Domain name: Active Directory domain name or blank if local account will be used

 

Click Connect and then enter the correct password, for the account provided previously.  Also, choose the "Remember password until you logout" option.  Ignore any errors, and then look on the desktop for the Ubuntu equivalent of a mapped drive to the Windows share.

 

08. From here its simple copy and paste operations from the /mnt/vmdk directory to the desired location on the Windows share to accomplish the file-level restores.

 

 

FULL DISCLOSURE, WARNINGS AND OTHER:

This document details how to create a working Ubuntu virtual machine that can recover files from NFS snapshots.  If the OS is built to the level detailed in this document, the Ubuntu install will not be patched, secured or otherwise hardened in any way. For these reasons, this exact implementation is not considered ready for production environments. I can make no guarantees about the use of this setup.  Use it "as-is" and at your own risk! You've been warned...

 

The techniques described here will not work for non-NTFS vmdk files.  This essentially means, Windows virtual machines only. Other options are possible, but not covered in this document.  Check VMware on NFS: Backup Tricks for additional information.

 

On the NFS server, the NFS datastore should be exported Read-Only to the Ubuntu virtual machine. 

 

The NFS datastore should also be mounted Read-Only on the Ubuntu virtual machine. 

 

Any VMDK files contained in snapshots should be mounted Read-Only on the Ubuntu virtual machine. 

 

When mounting VMDK files that have NTFS partitions on them, you must specify the offset as part of the mount command.  If you do not happen to know the partition offset of the virtual machine's disk you are working with, there is an easy way to find it.  On the virtual machine in question, run msinfo32.  Navigate to Components -> Storage -> Disks and then find the Partition Starting offset value.  Use this value in the mount command offset option. 

 

There is a helpful script for mounting and unmounting iso images, that is available at:

http://www.debianadmin.com/mount-and-unmount-iso-images-without-burning-them.html

that can be easily modified to mount the vmdk files from the snapshots, but will most likely need to be modified (or expanded into multiple versions) to deal with offset differences.  Maybe that will be a future blog entry...

 

The NFS datastore can be added to fstab on the Ubuntu virtual machine, so that it is always available at boot.

To achieve this, add the following line to /etc/fstab on the Ubuntu virtual machine:

91.189.94.8:/vol/vol1 /mnt/datastore1 nfs ro,hard,intr 0 0

 

 

REFERENCES AND FURTHER READING:

VMware on NFS: Backup Tricks

http://storagefoo.blogspot.com/2007/09/vmware-on-nfs-backup-tricks.html

 

Guest Operating System Installation Guide

http://www.vmware.com/pdf/GuestOS_guide.pdf

 

ISO Mounting Scripts

http://www.debianadmin.com/mount-and-unmount-iso-images-without-burning-them.html