We are all living in a technological wasteland.


Windows 3.11 with qemu-kvm – Part 1: Xubuntu


For my little Windows 3.11 PaaS system I fell on a dead track with VirtualBox. So I’ve been researching another way to virtualize Windows 3.11 and I found qemu. Below is my little take at emulating Windows 3.11.

Installing qemu-kvm

Installing is pretty easy, just grab all needed packages. I am using the package ‘virt-manager’ as a GUI frontend.

sudo apt-get install qemu qemu-kvm libvirt-bin bridge-utils virt-manager

Next up is to add your current user to the correct groups. This ensures that your virtual machines can be run with your current user.

sudo adduser `id -un` libvirtd
sudo adduser `id -un` kvm

Now to check if everything is ok run virsh. This should return an empty list of virtual machines.

virsh -c qemu:///system list

If you get following error, then you need to change the permissions of your ‘libvirt-sock’ file.

error: failed to connect to the hypervisor
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied
sudo chown legacy:libvirtd /var/run/libvirt/libvirt-sock

Next up is create a virtual machine. For this part I will be using Windows 3.11. However you could use any operating system.

Before we can start creating the virtual machine, I like to create my virtual disks myself. In my template I am using a C:\ drive of 100MB for the system and a data disk of 200MB.

qemu-img create -f qcow2 ~/qemu/template/boot.img 100M
qemu-img create -f qcow2 ~/qemu/template/data.img 200M

Next up, go to your menu and select the ‘Virtual Machine Manager’. This piece of software is a GUI frontend.

In this frontend GUI press the upper left icon to start the wizard to create a new virtual machine.

Give the virtual machine a name, in my case: TEMPLATE. And select ‘Local install media’.

Both types I’ll leave as ‘Generic’. Also select the install image. My windows 3.11 source is an ISO file.

Select the amount of memory and CPU. In the virtual machine manager there is a little bug that won’t allow you to assign less than 50MB. But this shouldn’t be a problem, we’ll fix this later. As for CPU, use one.

Press the ‘Select managed…’ option here and navigate to the disks you’ve made with the ‘qemu-img’ command. The type will be wrong (raw) but we will fix this later too.

Last step of the wizard. Here by default the hypervisor will be ‘kvm’. My recent findings have found this to cause some stability issues with Windows 3.11. Select qemu instead. As architecture select i686. This is your default 32-bit architecture.

So that’s it. Create the image and let’s continue. Once your virtual machine is created select the blue ‘i’ button to edit the machine a little bit further.

Press the ‘Memory’ tab and assign 32MB. 32 should be enough for Windows 3.11.

Next go to ‘Boot options’ and activate floppy and hard drive. The floppy should go first before we boot from hard drive.

Once this is done, fix your disk one. Select ‘qcow2’ as type and make sure the disk bus is ‘IDE’.

After this assign the second hard drive. Press the ‘Add hardware button’ below and select ‘Storage’. From this menu assign the existing image as disk two.

Last step is the floppy drive. Add a new storage drive and select floppy from the dropdown list and press Finish.

That’s it now your virtual machine is configured to run.

Installing Windows 3.11 / MS-DOS

Next step would be to install the operating system. From the settings page you can connect and disconnect floppies to install your operating system. Press the ‘Disconnect’ button to disconnect the floppy image and press ‘Connect’ to reconnect an image.

Here we go, one fresh MS-DOS 6.22 install.

I won’t explain the other details of installing Windows 3.11, as this post will only cover qemu-kvm. However a little hint: you will need the tools listed on http://www.scampers.org/steve/vmware/

Managing with virtsh

Managing a running virtual machine is very easy. The tool to use for this is called ‘virsh’.

To suspend a machine use ‘virsh suspend’ followed by your virtual machine name. (In my case ‘TEMPLATE’). A suspend will keep your machine in RAM. However it won’t be using any other system resources (except disk space).

virsh suspend TEMPLATE

To resume a suspended state, use ‘resume’.

virsh resume TEMPLATE

To fully dump your running virtual machine use save. This will create an image file of your running config and will unload any RAM assigned to this machine.

virsh save TEMPLATE ~/qemu/template/suspend

First time you will need to change the rights of your suspend image as by default it will be owned by ‘root’. If you try to resume a suspended machine owned by root you will get a permission denied error.

sudo chown `id -un` ~/qemu/template/suspend

To resume a saved virtual machine you can use the ‘restore’ command followed by your image file.

virsh restore ~/qemu/template/suspend

To view the stats of your virtual machine you can use following command:

virsh -c qemu:///system list

It will show the state of your machines. A machine which has been saved to disk won’t show up in this table though.

 Id    Name                           State
 23    TEMPLATE                       running

More information about managing your virtual machine with virsh can be found at: http://www.centos.org/docs/5/html/5.2/Virtualization/chap-Virtualization-Managing_guests_with_virsh.html

Changing media with virsh

To view all your media assigned to an image you can use the ‘domblklist’ command.

virsh domblklist TEMPLATE

This will output a table showing you the assigned disks.

Target     Source
hda        /home/legacy/qemu/template/boot.img
hdb        /home/legacy/qemu/template/data.img
hdc        /home/legacy/qemu/resources/windows.iso
fda        /dev/sdb

Example: to change the floppy with the command line use ‘change-media’. First disconnect the floppy drive.

virsh change-media TEMPLATE fda --eject

Verify that it has been disconnected.

virsh domblklist TEMPLATE
Target     Source
hda        /home/legacy/qemu/template/boot.img
hdb        /home/legacy/qemu/template/data.img
hdc        /home/legacy/qemu/resources/windows.iso
fda        -

Now insert a new floppy image.

virsh change-media TEMPLATE fda ~/qemu/resources/tools.img --insert

There we go, the floppy is now usable in the virtual machine.

virsh domblklist TEMPLATE
Target     Source
hda        /home/legacy/qemu/template/boot.img
hdb        /home/legacy/qemu/template/data.img
hdc        /home/legacy/qemu/resources/windows.iso
fda        /home/legacy/qemu/resources/tools.img

This example used a floppy image, however it is also possible to swap out disk drives and CD-ROM drives too.

That’s about it for the Xubuntu part. Next topic will probably cover this in an AWS – Amazon EC2 instance.

Leave a Reply

You must be logged in to post a comment.