Archive

Archive for the ‘Virtualization’ Category

VMWare vs VirtualBox vs Parallels for DevOps

What is the best virtualization engine for Mac OS X? The answer depends on who you are. As always these days, I started by checking what Google has to say. After some reading I decided on VMWare. Solid with a long track record, the best support for uncommon guest platforms and the best performance. However, after a short time I realized it was not for me.

Most comparisons focus on users with limited IT experience who want to run Windows as seamlessly as possible. They want Windows programs to work as if they were Mac programs. VMWare and Parallels both beat VirtualBox with ease on that score, but I really don’t care.

What I’m looking for as a DevOps (not part of my job description, but in practice that’s what I’ve been doing for as long as I can remember) is good support for running multiple servers with other operating systems (mostly Linux) with full control over the finer details. There VirtualBox shines.

A simple example is port forwarding for NAT. With VirtualBox I can open a new tunnel into a machine with a few clicks without restarting. With VMWare on Mac that is not possible at all through the user interface. It seems to be supported by editing a hidden configuration file, but then it seems to be global rather than limited to a specific machine? Not sure, didn’t go that route. Options for hard disks are also much richer in VirtualBox.

In short I found that the free VirtualBox engine beats the commercial alternatives for my use cases. What do you think?

Advertisements
Categories: Virtualization

Shrink VirtualBox VDI files with TRIM

Historically I have always tried to keep virtual disks small by defragmenting, clearing unused space and compacting. It works, but it is tedious and takes time. Now there is a much better option, as VirtualBox has TRIM support!

Stop the image if it is running, then open the configuration file with a text editor. Locate the virtual disk and add discard and nonrotational:


<AttachedDevice discard="true" nonrotational="true" type="HardDisk" ... >

The nonrotational setting can be edited in the user interface (Solid-state drive), but my version of VirtualBox still doesn’t expose the discard option.

I’m often using Linux Mint as a guest. Start it and verify that TRIM is available for the disk:


sudo hdparm -I /dev/sda | grep TRIM

Provided that TRIM is in fact supported, add discard support to LVM if it is used. Edit /etc/lvm/lvm.conf and make sure that issue_discards is set:


devices {
    ...
    issue_discards = 1
}

Also edit /etc/fstab and add discard to the file systems, for example:


UUID=somevalue / ext4 discard,errors=remount-ro 0 1

Reboot and delete something big. You should see the vdi file shrink in real time. Is that cool or not? You can also discard unused data manually:


sudo fstrim /

With a file system that has been used for a while that can reduce the size of the vdi file a lot.

Categories: Virtualization

VMWare networking disabled with McAfee

Our company recently switched from Norton to McAfee. I don’t know if it is the product itself or the corporate security policy it enforces, but since then the host-only and NAT networks in VMWare no longer work for me. I have tried everything without luck. The networks are listed as connected in Windows, but are not listed by ipconfig and the adapters are disabled and cannot be enabled in VMWare. Attempts to repair them fail with the message that TCP/IP is disabled for them, although it is not according to the registry and configuration screens. Very frustrating.

The bridged network still works, but it shuts down when there is no network cable attached. Not exactly optimal for a laptop.

Finally I have found a workaround if not a solution. VMWare recognizes Microsoft’s loopback adapter as a physical adapter that can be bridged. Simply install it, give it a fixed IP address and configure VMWare to use it. On the road the bridged loopback adapter is as good as the host-only networking option and when a real network (wired or wireless)  is available the loopback adapter can simply be disabled and the bridge reconfigured to the physical device. Some extra work to be sure, but it gets the job done.

Categories: Virtualization

Minimal VMWare images

In my line of work I typically have ten or more VMWare images with me on my laptop, each loaded with a different application server or database combination. That means disk space is at a premium. Unfortunately the images available for download are often wasteful, so I often have to tune them myself. This is a short summary of how to do it. I once had to spend a whole week (!) waiting for a download of a 70G image to complete, only to trim it to a small fraction of the original size when done. Some time spent pruning before publishing can be a wise investment.

I’m using VMWare Server 1.0.8, but most of the steps are generic.

If you create the image from scratch, be sure not to preallocate disk space and to split the disks into 2G files. That will make your life easier. The goal here is to make a lean developer image, not a performance-critical production image.

The first step for a finished image is to remove unused files and programs. This should be obvious, but it is often missed. For example, the installation files for server software may be quite large and are often left behind. Temporary files in browser caches and the OS temp directory can also add up, not to mention old log files. Once I even found a full Office installation. Uninstall and delete!

Next it is time to deal with the swap files. If they are located on the main disk(s) they should be cleared before the image is compressed. Ideally I like to put them on a separate disk that can be excluded from the archive – the swap files will not be available, but can be recreated when the image is restored. To clear the swap file on shutdown in Windows, start regedit and set HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\ClearPageFileAtShutDown to 1. With Linux I usually remove the swap partition and recreate it when I need it instead.

What next? Defragment the remaining files. This can be done in two ways. First, defragment inside the operating system. When that has been done, shutdown and defragment with VMWare:

  vmware-vdiskmanager.exe -d [virtual disk].vmdk

When the disks have been defragmented they should be wiped clean. If the unused space is zeroed out it will compress better. For Windows I normally use sdelete:

  sdelete -c c:

For Linux, this should work:

  cat /dev/zero >largefile; remove largefile

In both cases, repeat for all partitions. Finally, shutdown the system again and shrink the disks:

  vmware-vdiskmanager.exe -k [virtual disk].vmdk

Create a rar-file with maximum compression, delete the directory and you are done. Feel free to compare the result before and after tuning. There should be a significant gain in disk space. Any other suggestions? Please let me know.

Categories: Virtualization