Virtualization is quite the hot topic these days. More companies and individuals in rapidly advancing numbers are deploying virtualized machines and services. In fact I no longer run a physical windows box. All of my systems are running on Linux and I have virtualized my Windows XP machine (keeping it only out of a pure evil necessity of corporate reasons). I’ll also go on record that my Windows box runs faster as a vm than when it was a physical entity. It is easy to say that VMware is neat, but let’s scrape away the magic here for a moment.
What is a virtualized machine? Boil it down, trim off the icing and pull out your T-square from drafting class and you’ll simply find that the operating system has been converted into one large fat pack of data. That’s right, the vmdk (virtual machine disk) is nothing more than a large file. Now, if you remember back to my tip on the command lsof I made the comment that the Linux kernel basically looks at everything as a file. What does that mean for us? A great deal actually. It means that with the power of Linux you can manipulate your virtual machines without having them running.
Example time. Let’s say you have a virtual Windows machine. You are getting ready to go play in traffic and head home. You’ve powered down the vm when suddenly your boss calls and says “quick, I need the reconfigure configurations of the configures document”. You could restart and wait for the virtual box to boot up and start all of its services, or you can simply mount the vmdk in a loop inside your Linux box and pull the file off.
VMware includes some tools for you when you install the software. One of these tools is a perl script called vmware-mount.pl. You use it just the same as your normal mount command. The command structure is…
#vmware-mount.pl /home/user/vmware/windows.vmdk 1 -o ro /mnt/point
For example mounting my Windows XP vmdk would be:
#vmware-mount.pl /home/kryptikos/vmware/windowsxp.vmdk 1 -o ro /mnt/vm_mnt
The “1″ represents the partition number and “-o” passes the option to mount the file as read-only. You will be prompted by some comments about lack of guarantees and asking to proceed. The script will create a network block device driver for you as you can see below:
root@kryptikos:/mnt# vmware-mount.pl /home/kryptikos/vmware/windowsxp.vmdk 1 -o ro /mnt/vm_mount/ -------------------------------------------- VMware for Linux - Virtual Hard Disk Mounter Version: 1.0 build-56528 Copyright 1998 VMware, Inc. All rights reserved. -- VMware Confidential -------------------------------------------- It has been reported that this program does not work correctly with 2.4+ Linux kernels in some cases, and you are currently running such a kernel. Do you really want to continue? [N] Y No Network Block Device detected. There is no Network Block Device defined on this machine. This script is about to create the /dev/nb0 Network Block Device. Continue? [Y] Creating the /dev/nb0 Network Block Device No Network Block Device driver detected. Trying to load the Network Block Device driver kernel module... Success. Client: The partition is now mapped on the /dev/nb0 Network Block Device. Using another terminal, you can now browse your Virtual Hard Disk partition in /mnt/vm_mount/. Hit Control-C in this terminal when done.
The kernel does the rest of the heavy lifting and completes the mount. You are now able to access and look into your Windows machine just as if it was running real-time. You can open Nautilus, Konqueror etc to look through the virtual disk, or do it via another shell. Just remember that you will have to exit the mount by using “ctrl-c” from the terminal shell you executed the command in.
That’s it. Fairly clean and simple. Being able to access your virtual machine files at anytime regardless if the machine is running or not is a great tool for any user or engineer. I can’t claim this particular quote as mine, but I loved it…”This is Linux country. On a quiet night you can hear Windows reboot”.