Back to Article Listing

OpenBSD in a virtual machine on WinXP

Table of Contents


Need to run a unix instance at an 'all windows' workplace

I was on a client site, sitting at a WinXP desktop talking to the department manager. We needed a PostgreSQL database instance for some development work and he said to just install it on the box in front of me. I said "ok", and he walked away. I got it installed but my 'windows' is rusty. I had a tough time in the DOS shell; spaces in path names, no tab completion, no grep, no diff, bad editors, etc. I could go on, but you get my point. I decided I needed a more comfortable and sane environment. This would make me more productive, which is good for the client. It would also make me happier, which is good for both of us!


OpenBSD in a virtual machine

I tried out cygwin but found it lacking. I wanted a whole environment; a virtual machine. There are many options down this path. But since my host was going to be WinXP, VMware was my first choice. Besides, I already have a licensed copy of VMware Workstation 5.5.1 build-19175 (yes, I paid for it). I run it at home on Gentoo Linux so I can have a windows instance for testing. I googled around and found that OpenBSD (and other *BSDs) will run in a virtual machine. I also found that VMware has a free, downloadable Player. I could create the vm at home and 'play' it at the client site. The Player is compatible with the version of Workstation I have. This solution will solve my need, add value to the project, and not cost the client any money.

I was aware that VMware has downloadable machines for their player: Virtual Machine Center

VMTN's collection of pre-built virtual machines and virtual appliances from industry-leading ISV partners, open source partners and the VMware community simplifies software packaging, distribution, and deployment. Instead of spending time installing and configuring applications, developers and QA teams and other technologists can now focus their efforts on their work.

I checked out the OpenBSD vm at the Virtual Machine Center but it allocated a pretty small hard drive. I would need more overhead for database storage. Besides, I trust myself to create a custom, secure OS the way I want it.

Working with VMware really is easy. Choose New Virtual Machine, Typical configuration. For Guest Operating System I chose "Other" and picked FreeBSD from the drop down box. After I gave it a name, I was prompted for networking. I chose Bridged (over NAT, host only, or none) for a specific reason. This vm will appear on the client network as a real machine. It will get an IP via their dhcp server. This way they can (with the proper config) get to the database using familiar tools or even putty their way in to a shell.

I figured a 5G instance was sufficient for the db development we were doing but not so large as to gobble up the hard drive. I set it to grow as needed rather than allocate now. That is pretty much it. You prescribe a chunk of hard drive, and choose from a limited range of devices. After clicking finish, you are welcome to make some devices changes. I reduced the memory allocation from 256m to 128m, got rid of the floppy, USB, mouse, and sound card.

So, I have a virtual machine, now to install the OS. Using VMware Workstation, I started the blank vm so it would try to initialize the nic. It writes the mac address to the vmx file.. and get this.. tries to pxe boot. Nice touch, VMware! After I stopped the vm, I edited my local dhcp server to answer that mac with instructions in my boot.conf to boot the OpenBSD ram disk I had downloaded. I restarted the vm and watched it boot.

Installing OpenBSD is outside of the scope of this paper, so I will not go into it. I installed a few personal favorite packages and, of course, PostgreSQL. After a few tweaks I was ready to go!

I gracefully shutdown the OS and stopped the vm. I then took a look at the vm on the file system. Conveniently, all the necessary files are in one directory. While I could have made a tarball, the total sum of files was small enough to fit on a standard CD. So, I burned one and took it onsite the next morning. I created a new directory on the WinXP box and copied over the files from the CD into that directory. I then downloaded the free VMware Player, and started it up. The first thing the Player does is ask where my vm is. I pointed to the new directory (actually the vmx file) and BANG! I had a PostgreSQL instance running in the latest snapshot of OpenBSD!

An OpenBSD instance, created on Gentoo Linux, to be run on WinXP.

I was amazed how easy it was to bring a sane, productive environment into a windows shop. If all goes well, I will suggest that my client donate to the OpenBSD project, as I do.


Customizing vm's used with VMware Player

Interesting side note on vm's. Even if you do not own the Workstation, you can get around the allocation size that the original author sets up, provided they have not used all the IDE devices already. When launching a virtual machine, the Player (and Workstation) reads a config file, the vmx file.

Here's a directory listing. You can see my main hard drive (OpenBSD.vmdk) and its slices (OpenBSD-s00[123].vmdk)

$ ls -al vmware/OpenBSD/
total 690M
drwxr-xr-x  2 user users  400 Feb 17 10:16 ./
drwxr-xr-x  5 user users  136 Feb 18 15:15 ../
-rw-------  1 user users 613M Feb 15 23:20 OpenBSD-s001.vmdk
-rw-------  1 user users  42M Feb 15 23:20 OpenBSD-s002.vmdk
-rw-------  1 user users  35M Feb 15 23:20 OpenBSD-s003.vmdk
-rw-------  1 user users 8.5K Feb 15 23:20 OpenBSD.nvram
-rw-------  1 user users  424 Feb 15 23:16 OpenBSD.vmdk
-rw-------  1 user users    0 Feb 15 20:31 OpenBSD.vmsd
-rwxr-xr-x  1 user users 1.1K Feb 15 23:20 OpenBSD.vmx*
-r--r--r--  1 user users   11 Feb 17 10:16 OpenBSD.vmx.WRITELOCK
-rw-r--r--  1 user users  46K Feb 15 23:14 vmware-0.log
-rw-r--r--  1 user users  23K Feb 15 23:20 vmware.log

Here's the vmx file

$ cat vmware/OpenBSD/OpenBSD.vmx

config.version = "8"
virtualHW.version = "4"
scsi0.present = "TRUE"
scsi0.virtualDev = "lsilogic"
memsize = "128"
MemAllowAutoScaleDown = "FALSE"

ide0:0.present = "TRUE"
ide0:0.fileName = "OpenBSD.vmdk"
ide0:0.writeThrough = "TRUE"

ide0:1.present = "TRUE"
ide0:1.autodetect = "TRUE"
ide0:1.deviceType = "atapi-cdrom"

ide0:1.startConnected = "TRUE"
ide0:1.fileName = ""

floppy0.startConnected = "FALSE"
floppy0.fileName = "/dev/fd0"

ethernet0.present = "TRUE"
usb.present = "FALSE"
sound.present = "FALSE"
sound.virtualDev = "es1371"
displayName = "OpenBSD"
guestOS = "freebsd"
nvram = "OpenBSD.nvram"

floppy0.present = "FALSE" = "TRUE"

ide0:0.redo = ""
ethernet0.addressType = "generated"
uuid.location = "{deleted}"
uuid.bios = "{deleted}"
tools.remindInstall = "TRUE"
ethernet0.generatedAddress = "{deleted}"
ethernet0.generatedAddressOffset = "0"

To add another hard drive to the above vm, just create a new vmdk (in this case, OpenBSD-0.vmdk) and edit the vmx file. QEMU can create a virtual hard drive for VMware. As you know, IDE can have 4 devices total (0:0, 0:1, 1:0, and 1:1) In the above config we have.. first hard drive (0:0) and a cdrom (0:1). So we need to add another hard drive (1:0) and configure it as writeThrough. That means do not allocate up front, just grow as needed.

ide1:0.present = "TRUE"
ide1:0.fileName = "OpenBSD-0.vmdk"
ide1:0.writeThrough = "TRUE"

Then launch the vm and have the OS format, mount, whatever.

"Thank you" to VMware for a pretty cool product.
"Thank you" to all the OpenBSD developers for letting us use and benefit from your hard work!

Copyright © 20060218 genoverly
(db datestamp: 20070821)

Copyright © 2003-2015 genoverly