How to use VMware Player to create your own images

4116

The easiest way to get a virtual image is to have someone with VMware Workstation create one for you, or to download a pre-made image from VMware. If you don’t know anyone with a copy of Workstation, or the OS you want isn’t available as a VMware appliance, you’re out of luck. For example, if you want to test a development release of Ubuntu or Debian, it’s unlikely that you’ll find a VMware image available.

If you plan to make extensive use of VMware — i.e., if you need to run more than a single OS, if it’s for your work, or if you’re doing more than just tinkering for fun — go ahead and buy a copy of VMware Workstation. It’s much easier to use VMware Workstation to create virtual machines than to do it manually. Also, Workstation has a number of features you won’t find in VMware Player, such as the ability to take snapshots of the guest OS, take movies of the virtual machine, and use virtual SMP.

But VMware Player will get the job done if you just want to run a virtual host under Linux or Windows. You can also modify your virtual machines for VMware Workstation using the tips here for VMware Player, but you should be able to do most if not all of this through the VMware Workstation GUI. I’ll walk through the process of creating a guest OS on Linux; this should also work under Windows, but you may need to change things such as pathnames.

Getting started

The easy way to do this is to grab a VMware appliance from the VMware site, and then make a few modifications. I’ll use the Gentoo appliance for this example.

Download the appliance and unzip it into the ~/vmware directory. Under the Gentoo directory, you’ll find a file called Gentoo.vmx; if you’ve chosen another virtual image, look for its .vmx file. This is the configuration file used by VMware to hold information about the virtual environment. It specifies the location of the disk image, the amount of RAM, and so on.

Look for the lines ide1:0.fileName and ide1:0.deviceType. If you want to install a new guest OS from a CD-ROM or DVD, the defaults are fine. If you’d like to use an ISO image instead of a CD-ROM, however, you’ll need to tweak this a bit. To use an ISO image, change the fileName and deviceType lines to this:

 

ide1:0.fileName = "/path/to/cd.iso"ide1:0.deviceType = "cdrom-image"

 

Once that’s done, fire up VMware Player. However, instead of letting it boot into the virtual machine, press Esc when you see the screen in Figure 1. VMware will give you the option of booting from the hard disk or booting from other devices. Select the CD-ROM drive from the boot menu instead of the hard drive. You should be able to move through your installation normally after that.

By the way — and this is one of my favorite features of VMware Workstation — you can download an ISO for a Linux distro and try it out in VMware without even having to take the time to burn it to CD. This feature has helped me avoid wasting a lot of CD-Rs.

Creating your own virtual image from scratch

Modifying an existing guest OS is pretty easy, but it has its drawbacks. For one thing, you can’t specify the size of the virtual disk — you’re stuck with whatever size the virtual image had when it was created. The VMware site doesn’t actually specify what the size of the virtual images is, so you might have to download several to find one the size that you like.

Also, most if not all of the virtual images I’ve seen use virtual SCSI hard drives rather than IDE. Some operating systems don’t like SCSI and won’t detect the disk. So, if you want to use an IDE disk, or just want to specify the size of the disk, you’ll have to create a guest disk image without using VMware’s tools.

To do this, you’ll need to have Qemu installed. Specifically, you’ll need the qemu-img program that creates disk images for Qemu. This handy application writes disk images in several formats, including VMware’s. To create a disk image, run qemu-img create -f vmdk imagename.vmdk nG, where n is the size of the disk image you want to create. Note that the size of the disk image is the size it can eventually grow to — not the size it will be when it’s first created. So, if you create a 20G image, it will only occupy about 3MB on disk without any data.

Once you’ve created the image, you’ll need to modify the configuration file to tell VMware Player about it. First, comment out all the lines that begin with scsi0, because the Qemu disk will be seen by VMware Player as an IDE disk. Then add two new entries to the configuration:

 

ide0:0.present = "TRUE"ide0:0.fileName = "filename.vmdk"

 

Note that you don’t need to include the full path if the file is in the same directory as the configuration file.

If you use qemu-img to create your hard disk, you don’t really even need to download a virtual guest at all — you’ll just need a sample configuration and a virtual disk. You can use the following as a template to get started:

 

#!/usr/bin/vmwareconfig.version = "8"
virtualHW.version = "4"memsize = "256"
ide0:0.present = "TRUE"
ide0:0.fileName = "newvm.vmdk"
ide1:0.present = "TRUE"
ide1:0.fileName = "/path/to/iso"
ide1:0.deviceType = "cdrom-image"
floppy0.fileName = "/dev/fd0"
ethernet0.present = "TRUE"
usb.present = "TRUE"
sound.present = "TRUE"
sound.virtualDev = "es1371"
displayuName = "Test Machine"
guestOS = "otherlinux"
scsi0:0.redo = ""
ethernet0.addressType = "generated"
displayName = "DisplayName"
checkpoint.vmState = "test.vmss"
ide0:0.redo = ""

 

I’m not sure how much difference it makes, but you may also want to tell VMware Player what type of guest OS you’ll be installing. Look for the line guestOS and change it to whatever OS you’re going to install. I found a full list of supported OSes on a site called Forever For Now. The site also hosts some SCSI and IDE guest images, which is a quick way to get started if you don’t want to install Qemu.

One of the things that I’ve added to the configuration that you might not find in many of the guests you can download is the information to add a soundcard via the sound.virtualDev and sound.present directives. I don’t usually need a soundcard for testing server operating systems like CentOS, but it comes in handy if you want to use a desktop OS in VMware Player.

Virtual floppy

Another thing you might want to do is to change floppy.fileName. I haven’t had a diskette drive on my main systems for quite a few years, and it gets annoying to have VMware complain about the missing floppy each time you restart the virtual machine. To silence it, add this to the configuration:

floppy0.startConnected = “FALSE”

If for some reason you don’t have a floppy drive on the computer but want to use a floppy inside the virtual machine, you could try this instead:

 

floppy0.startConnected = "TRUE"floppy0.fileName = "/path/to/floppy.img"

 

This might be useful if you wanted to use a diskette image rather than an ISO image to boot your system — if you were installing OpenBSD, for example.

Multiple network interfaces

If you want to use multiple network interfaces, rather than adding virtual interfaces inside the OS, you can add a second (and possibly third, fourth, etc. — I’ve only tried working with two) Ethernet interface by adding this line:

Ethernet1.present = “TRUE”

You might notice that the .vmx file includes a couple of other lines related to the first Ethernet device:

 

ethernet0.addressType = "generated"
ethernet0.generatedAddress = "00:0c:29:03:31:3d"
ethernet0.generatedAddressOffset = "0"

 

You don’t have to worry about those — simply start up VMware player and it will add those lines the first time it sees the Ethernet1 device.

That’s really all there is to it. You can tinker a little bit with the configuration to add more hard disks if you need to, but this should be enough to get going with just about any OS you’d want to run.

Again, if you’re going to be using VMware extensively, I strongly recommend buying VMware Workstation rather than using this method to create new virtual machines. But, if you just need to run a virtual guest for a one-off project, this is a good way to get a guest OS up and running with VMware Player.