Setting up a virtualized Fedora Core 4 system with QEmu
With all the talk these days around Xen, one could be forgiven for thinking it is the only open source virtualization technology out there. This is certainly not the case, however, User Mode Linux has been providing the ability to run the Linux kernel in userspace for years, and more recently QEmu has matured to the point where it can reliably run pretty much any i?86 / x86_64 / PPC operating system. Each of these systems uses a different approach for virtualization; Xen uses hypervisor to mutliplex hardware access amongst multiple guest OS’; User Mode Linux consists of the a number of kernel patches to enable one to run the Linux kernel as a regular user space process; QEmu provides a userspace CPU emulator, with an optional kernel accelerator. The latter is particularly intersting in the realm of testing because it allows one to mix architectures, ie emulate a PPC guest on a x86 host, or vica-verca.
Setting up a Fedora Core 4 guest
So how does one go about setting up a guest OS running in QEmu ? For this post, I’ll outline the steps for setting up a minimal Fedora Core 4 instance on x86.
Creating a local install tree
While one could install directly from the Fedora download site, it is preferrable to setup a local YUM repository containing a Fedora Core install tree. The first step is to download the master ISO images to /mnt/isos/fc4/i386
:
# mkdir -p /mnt/isos/fc4/i386 # cd /mnt/isos/fc4/i386 # wget http://download.fedora.redhat.com/pub/fedora/linux/core/4/i386/iso/FC4-i386-disc1.iso # wget http://download.fedora.redhat.com/pub/fedora/linux/core/4/i386/iso/FC4-i386-disc2.iso # wget http://download.fedora.redhat.com/pub/fedora/linux/core/4/i386/iso/FC4-i386-disc3.iso # wget http://download.fedora.redhat.com/pub/fedora/linux/core/4/i386/iso/FC4-i386-disc4.iso
Now its time to unpack all the files to a convenient directory, forming the master installation image. For this guide, setup the install tree to be /mnt/distros/fc4/i386
.
# mkdir -p /mnt/distros/fc4/i386 # mkdir /mnt/loopback # cd /mnt/distros/fc4/i386 # for i in 1 2 3 4 do mount /mnt/isos/fc4/i386/FC4-i386-disc${i}.iso /mnt/loopback -o loop cp -af /mnt/loopback/* . umount /mnt/loopback done
If one is tight for disk space, the ISO images can be discarded now, although its a wise idea to at least burn them to a CD for future reference. The final step is to make the install tree available via Apache. This can be achieved by dropping a single file into /etc/httpd/conf.d
containing:
Alias /distros/ /mnt/distros/ <Location /distros> Allow from all Options +Indexes </Location>
Installing QEmu packages
Thomas Chung provides RPM builds of QEmu and the kernel accelerator module for Fedora Core 4 systems, so download the RPMs which match the kernel currently running in your host system, and install them now
# cd /root # wget -r -l 1 http://fedoranews.org/tchung/qemu/fc4/0.7.2/2.6.13_1.1532_FC4/ # cd fedoranews.org/tchung/qemu/0.7.2/2.6.13_1.1532_FC4 # rpm -ivh *.i386.rpm
Preparing a Kickstart file
If one plans to install multiple guest OS images, its worthwhile creating kickstart file containing the desired anconda options. The system-config-kickstart
program provides a simple GUI for doing this. At the minimum change the following options:
- Basic configuration: clear the ‘reboot after installation’ checkbox
- Basic configuration: select your timezone, keyboardk, and default language
- Basic configuration: choose a suitable root password
- Installation method: select ‘HTTP’ and enter ‘10.0.2.2’ for the ‘HTTP server’, and ‘/distros/fc4/i386’ as the ‘HTTP directory’
- Partition information: create a single ext3 partition on /, and make it fill to maximum size.
- Network configuration: add a single ethernet device, and use DHCP
- Firewall configuration: disable firewall, and disable SELinux
- Package configuration: select whichever package groups are desired.
Save the finished kickstart file to /mnt/distros/fc4/i386/qemu-ks.cfg
Creating and installing a guest
It is now time to create a QEmu guest OS. First of all prepare a disk image to use as the root filesystem, making sure its large enough to hold the package selection choose in the kickstart. As a rule of thumb, 1 GB is enough for a minimal install, 2 GB if X is added, and 6 GB for everything.
# mkdir /mnt/guests # cd /mnt/guests # qemu-img qemu-fc4-i386.img 2G
Now launch a virtual machine with this root filesystem, and booting the anaconda CD installer. The VM must have at least 256 MB of memory, otherwise anaconda will crash during installation.
# qemu -user-net -hda qemu-fc4-i386.img -boot d -cdrom /mnt/distros/fc4/i386/images/boot.iso -m 256
When the initial anaconda boot prompt is displayed, request a kickstart install by specifying
linux ks=http://10.0.2.2/distros/fc4/i386/qemu-ks.cfg
If all goes to plan, in about 10-15 minutes time anaconda will have completed installation of the guest OS. When it is done, shutdown the virtual machine – simply close its window once anaconda has shutdown.
Using the guest OS
Now, to use the virtual machine one can simply launch it with
# qemu -user-net -m 256m qemu-fc4-i386.img
With the userspace networking support, when inside the guest, the host machine can be accessed using the IP address 10.0.2.2
. For convenience it may be easier to run the guest OS headless, and access it over a SSH connection. To do this, launch it with the following options
# qemu -user-net -m 256m -nographic -redir tcp:8000::22
The once booted, the guest can be accessed via SSH on port 8000
# ssh -p 8000 localhost