Consider using directly Qemu instead of VMware Player, because Qemu is free software. See Installation/QemuEmulator.
Introduction
VMware is a great virtualization tool. There is no doubt about that. It is faster than many other emulators and provides many nice features. But let’s say you really just want to test out some stuff, don’t need all of VMware’s features, and don’t want to shell out a few hundred bucks for something you only half need.
You can use VMware’s VMware Player. That's great, but you can’t create new virtual machine images with that, only use existing ones. For testing installations and such, being able to create new images is important. We can still use VMware Player we just need to create the virtual machine disk image some other way. This is where qemu comes in handy. In this tutorial we will discuss how to use qemu to create a blank VMware image for us and then use VMware Player for everything else. The main benefit being that VMware Player is a much faster emulator than qemu. Let's get started by downloading and installing VMware Player.
Installing VMware Player
Update: VMware Player is now available in the multiverse repository as package vmware-player
Installing VMware Player involves downloading the VMware Player tarball from http://www.vmware.com/ then compiling and installing it. This is a fairly simple task that only requires running a few simple commands. First let's download VMware Player.
Downloading VMware Player
To download VMware Player we need only to go to VMware's website and get it. Here is a direct link to VMware's VMware Player download page:
Download the "for Linux (.tar)" version and save it to your desktop. Before we build and install VMware Player we need to install some additional tools which we will do now.
Installing Build Prerequisites
To build and install VMware Player we need to have the correct build tools installed. The tools we need are the build-essential tools, gcc-3.4 and the Linux kernel headers for your running kernel. Let's install them individually so that we know exactly why we need each one.
Installing the build-essential Tools
The build essential tools is a collection of basic tools needed to compile software on Ubuntu. The tools installed by the build-essential package include make, gcc, patch, perl and more. You can install the build essential tools with the following command:
sudo apt-get install build-essential
Now that we have the essential tools installed let's install the gcc-3.4 compiler that we need for the compilation of VMware Player.
Installing the gcc-3.4 Compiler
Ubuntu uses gcc-4.0 by default but the kernel is still compiled with gcc-3.4 for various legitimate reasons1. Because of this we need to manually install the gcc-3.4 compiler. We need to use gcc-3.4 because the VMware Player installer needs to compile and install kernel modules and these modules must be built with the same compiler the kernel was built with. To install gcc-3.4 use the following command:
sudo apt-get install g++-3.4
We use g++-3.4 as the package to install because it will bring in all the dependencies that we need to build and install VMware Player.
Now that we have all the compilation tools that we need installed we only need to install one package. The Linux kernel headers for our running kernel.
Installing the Linux Kernel Headers
In order for VMware Player to be able to build its kernel modules it needs the development header files for your running kernel. You can install the kernel headers for your kernel with the following command:
sudo apt-get install linux-headers-$(uname -r)
Great, we now have all of our prerequisites installed. The next step is to make sure that VMware Player uses these tools by setting the correct environment variables.
Setting Your Environment Variables
To ensure that the VMware Player installer uses the correct tools, the ones we just installed, we must set one environment variable. This environment variable is called "CC" and tells the VMWare Player installer which compiler to use2. Run the following command to set the compiler to gcc-3.4, the one we need. Don't worry, this is not a permanent change, this setting will only last as long as your shell window is open.
export CC=/usr/bin/gcc-3.4
Alright, now we are ready to build and install VMware Player so let's get to it.
Building & Installing VMware Player
Building and installing VMware Player is fairly straight forward. There is a script that comes with VMware Player that will walk you through the installation. To get started "cd" to your desktop where we saved our VMware-player-*.tar.gz (where * is the VMware Player version number) tarball, decompress it and "cd" into the directory it creates using the commands below:
cd ~/Desktop/ tar zxvf VMware-player-*.tar.gz cd vmware-player-distrib/
Once you are in the vmware-player-distrib directory we need only to run the installer script which will then ask us a few questions about where to install VMware Player and what options we want enabled. Start the installation process by running the script with this command:
sudo ./vmware-install.pl
We will not discuss every question asked since these may change from release to release but here are a few pointers for the more important questions.
- This installation process will ask you where to store the VMware Player binaries. The defaults are fine so you can just hit enter and accept all of the default directory paths.
- The installer will also ask you, among other things, what networking features you would like enable and if it should probe for unused network addresses. It is safe to enable all of the networking features if you so choose. It is also safe, and recommended, that you allow it to probe for a network address on its own. It will find one it can use on its own.
I'll go get some popcorn while you install VMware Player.
Oh, you're back already
Great, VMware Player is now installed and ready for use. Now let's install qemu so we can create a disk image that we can use with VMware Player.
On Ubuntu 6.04 (Dapper Drake), the kernel is compiled with gcc-4.0, therefore this step is not needed as gcc-4.0 has been already installed and will be used by default. To determine which gcc version was used to compile your running kernel, look at the output of the dmesg | grep gcc command. (1)
As explained above, this is not needed on Ubuntu 6.04 (Dapper Drake). (2)
Installing qemu
Now it is time to install qemu which we will use to create our virtual machine disk images. The following instructions describe how to install the required version of qemu on both Breezy (Ubuntu 5.10) and on Dapper (Ubuntu 6.04).
On Ubuntu 5.10 (Breezy Badger)
Ubuntu 5.10 currently uses an older version of qemu which is not capable of creating a vmdk image so we need to install a newer version of qemu. The link below is a link to the version of qemu that we need for 5.10 so go ahead and download the qemu_0.8.0-1ubuntu0_i386.deb package saving it to your desktop.
Install this new version of qemu by going to your desktop and using dpkg to install it using the following commands:
cd ~/Desktop/ sudo dpkg -i qemu_0.8.0-1ubuntu0_i386.deb
If you are using Dapper the installation is even easier.
On Ubuntu 6.04 (Dapper Drake)
Ubuntu 6.04 already contains a usable version of qemu that is capable of creating vmdk images. It is in the universe repository and can be installed with a simple:
sudo apt-get install qemu
That's it! Let's go create some images.
Where To Store Your Images
Before we actually create our images we should define a place for them to live. Traditionally VMware stores the images in ~/vmware/(virtual machine name). In this tutorial we will do the same to keep things simple and organized.
Go ahead and create the directory structure to store your images and then "cd" into the directory where our current image will live. The following commands can do this for you although of course you are free to call these directories what ever you are comfortable with.
cd ~ mkdir vmware cd vmware/ mkdir dapper cd dapper/
Create a vmdk Image
Creating a vmdk image is an easy one line command where we use the command "qemu-img" to create a disk image. All we have to do is tell "qemu-img" the file name we want and the size of the disk image we would like.
With this command we are going to create a vmdk image called "qemu-dapper.vmdk" with a virtual size of 20G. (Note that the image will initially occupy only a few megabytes, and will grow in size to store the operating system that you install in VMware.) I like to use 20G because it leaves plenty of room to work inside the virtual machine. You can use any size you are comfortable with. If you are installing Ubuntu Server, for example, it only requires around 200M for a default install so you could create a 1G image and have plenty of space to play.
Let's create our 20G image with this command:
qemu-img create -f vmdk qemu-dapper.vmdk 20G
There is one more thing we need to do before we can use our new vmdk image and that is to create a .vmx configuration file for it.
Create the VMware Image vmx Configuration File
Every VMware virtual machine has a configuration file that defines what features to enable or disable and where various files are located. This file is a series of simple option names with values associated with them (key value pairs). Below is a sample configuration file that you can use for your virtual machines. Copy the contents of the code block below and save it to a file named "vmware-dapper.vmx" in the directory "~/vmware/dapper/" (or whatever you called your directory). After you save it there are a few modifications that need to be made.
config.version = "8" virtualHW.version = "3" memsize = "356" ide0:0.present = "TRUE" ide0:0.fileName = "vmware-dapper.vmdk" ide1:0.present = "TRUE" ide1:0.fileName = "/home/mgalvin/Desktop/dapper-install-i386.iso" ide1:0.deviceType = "cdrom-image" floppy0.fileName = "/dev/fd0" ethernet0.present = "TRUE" ethernet0.connectionType = "nat" usb.present = "TRUE" sound.present = "TRUE" sound.virtualDev = "es1371" displayName = "Ubuntu - The Dapper Drake" guestOS = "ubuntu" nvram = "ubuntu.nvram" scsi0:0.redo = "" ethernet0.addressType = "generated" uuid.location = "56 4d 3a f5 0c 53 c4 50-1a 4d ba 8e 83 6b d0 36" uuid.bios = "56 4d 3a f5 0c 53 c4 50-1a 4d ba 8e 83 6b d0 36" ide1:0.autodetect = "TRUE" ethernet0.generatedAddress = "00:0c:29:6b:d0:36" ethernet0.generatedAddressOffset = "0" checkpoint.vmState = "" tools.remindInstall = "TRUE" ide0:0.redo = ""
You may have noticed that my desktop directory is hard coded in this config file... you need to change that and a few other options. Without getting into the details of each option, you really only need to set the memory size that you want to use in MB's
memsize = "356"
set the name of the vmdk image file which is the vmdk image we created earlier
NOTE: This should work as is unless you used a different name than described in the instructions.
ide0:0.fileName = "vmware-dapper.vmdk"
and the name of the ISO that you want to use to perform the installation
ide1:0.fileName = "/home/mgalvin/Desktop/dapper-install-i386.iso"
In the alternative...
If you have an unused distribution disk of some other OS, you can use the location of your CD drive--such as "dev/hdc"--and install from a CD instead of an ISO. A config file with this option might read, in part:
ide0:0.present="TRUE" ide0:0.fileName="/dev/hdc" ide0:0.deviceType="atapi-cdrom" ide1:0.present="TRUE" ide1:0.fileName="whatever.vmdk"
Other changes in the configuration file that may be useful, especially if you want to boot from the CD, are:
ide:0:0.startConnected="TRUE" floppy0.start.Connected="TRUE" (or "FALSE")
In addition, you may have more luck with ethernet if instead of "nat" you use
ethernet0.connectionType="bridged"
Set those options to the appropriate values and save the file. Once you are all done with that we can use our new blank vmdk image with VMware Player.
Using Our New vmdk Image in VMWare Player
Now we can use the blank vmdk image we created with VMware Player. When we installed VMware Player it added a menu entry at "Applications" -> "System Tools" -> "VMware Player". Go ahead and start up VMware Player. It will now prompt you for the location of the .vmx configuration file of the virtual machine you would like to start. Browse to ~/vmware/dapper/ and select "vmware-dapper.vmx" and click "Open".
VMware Player will now boot using the dapper-install-i386.iso image and you can now install Dapper. Dapper will get installed onto the blank image we created earlier. Once the installation is complete VMware Player will boot using our newly installed Dapper system from now on.
When you first start the virtual machine VMware Player may ask you to create a new UUID. It is safe to just click "Create".
Have fun using your virtual machines!
Here is a screen shot of VMware Player while getting ready to install Dapper Flight 3 onto the vmdk image we created.
Managing Your Custom Images
VMware Workstation would normally be used to manage the images and everything you could possible want to do with them. Since we are not inside the nice VMware Workstation environment we have to do these things on our own manually or via scripts. Here are a few tips for managing your virtual machines.
Manual Cloning
VMware Workstation provides the ability to "clone" virtual machines. This is a really neat feature allowing you to keep a clone of the original virtual machine while testing on a separate copy. If something goes wrong you can delete the clone and start over again with the original without having to reinstall the operating system from scratch. We can still make "clones" but we have to do it manually.
A clone is really just a copy of an existing virtual machine with a few things changed like the directory it lives in and its name.
To create a clone of our dapper image simply copy the directory "dapper" to another directory like so:
cp -R dapper dapper_clone
Then if you wish you can change the various settings like the virtual machine name in the "daper_clone/vmware-dapper.vmx" virtual machine configuration file. Note that the clone does not require changes, changing settings is strictly optional.
Conclusion
In this tutorial we discussed how to install VMware Player, create our own blank vmdk images, and manage those images. As you can imagine being able to rapidly create new images and install operating systems on a whim can have enormous benefits. You can now test new operating system releases without having to touch your stable working environment. This, or any, virtual machine environment is also great for taking screen shots of new software features without having to actually install the new, possibly unstable, software on your workstation.
Have fun using your new virtual machines!
Additional Tips & Resources
Here are some additional resources that may be useful.
Pre-Rolled Blank VMware vmdk Image
If you don't have the ability to create the blank vmdk image on your own or if something went wrong with the above examples here is a working blank image you can use to get started.
Using Your VMware vmdk Image in Windows
If you want to be able to use the VMware Player from Windows you can:
Download and install the VMware Player for Windows from the download page, http://www.vmware.com/download/player/
- Copy the vmware-dapper.vmdk and vmware-dapper.vmx files that you made using the instructions above to your Windows computer.
- Edit the vmware-dapper.vmx to reflect the change in paths for the .iso file, i.e. the line that starts with "ide1:0.fileName = "
- If you want to use your floppy drive also change /dev/fd0 to A: on the line that starts with "floppy0.fileName ="
- Now start the VMware Player and select your vmware-dapper.vmx file.
- Enjoy running Ubuntu from within Windows.