Qemu with kqemu accelorator, tun networking, and qemu-launcher for Ubuntu.
Version 1.0 – Please leave comments.
1 Introduction
A lot of information in this guide was borrowed from other helpful threads in the ubuntu forums, I will give credit where I can, but if I have lost the name of the original post then sorry, you can send me an email if it is you and I will update.
2 About this documentation
Throughout this document commands that you have to type are shown in red and text that must be typed into a text file is shown in green.
All text files have been edited with “vi” if you don't feel confident with vi, you can substiture it with “gedit” or “nano -w”
3 Downloading the packages
If you already have qemu installed we need to remove it.
sudo apt-get remove qemu
Make a source directory in your home folder.
cd
mkdir src
Go to http://fabrice.bellard.free.fr/qemu/download.html
Download qemu source (At the time of writing I used qemu-0.7.2.tar.gz)
Download kqemu binary (At the time of writing I used kqemu-0.7.2.tar.gz)
Save these downloaded files into your newly created src directory.
Install your kernel headers.
sudo apt-get install linux-headers-$(uname -r)
Install building packages
sudo apt-get install libsdl1.2-dev
sudo apt-get install zlib1g-dev
sudo apt-get install checkinstall
sudo apt-get build-dep qemu
There are more packages to get, but we should get these later.
4 Extract and Build Qemu
Extract qemu and kqemu
Make sure you substitute the x for your version number.
cd $HOME/src
tar zxvf qemu-0.7.x.tar.gz
cd qemu-0.7.x
tar zxvf ../kqemu-0.7.x.tar.gz
sudo ln -s /usr/src/linux-headers-$(uname -r) /usr/src/linux-headers
cd qemu-0.7.x
Edit the configure file
vi configure
change this line:
kernel_path=""
To this
kernel_path="/usr/src/linux-headers"
After you save and quit, run:
./configure
You should see something similar to the following:
harrisj@brightstar:~/src/qemu-0.7.2$ ./configure
Install prefix /usr/local
BIOS directory /usr/local/share/qemu
binary directory /usr/local/bin
Manual directory /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path /home/harrisj/src/qemu-0.7.2
C compiler gcc
Host C compiler gcc
make make
host CPU i386
host big endian no
target list i386-user arm-user armeb-user sparc-user ppc-user i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu mips-softmmu
gprof enabled no
static build no
SDL support yes
SDL static link yes
mingw32 support no
Adlib support no
FMOD support no
kqemu support yes
KQEMU Linux module configuration:
kernel sources /usr/src/linux-headers
kbuild type 2.6
harrisj@brightstar:~/src/qemu-0.7.2$
If everything has gone as planned, you should have yes next to kqemu.
Now type
make
5 Creating a Debian/Ubuntu package
When you install a package from source there is usually no way to uninstall that package. This can cause problems down the track when you want to upgrade a program, there is no way to uninstall the old package safely.
This is where “checkinstall” steps in. Checkinstall creates a .deb package for you, which is easy to remove later.
Create the deb package.
sudo checkinstall -D
At this point checkinstall will ask you some questions.
1st question: Answer = default y
2nd question: Answer = Any description you like about qemu
You can safely leave the next menu alone and just press enter
Next, checkinstall will build the .deb package and install it. For me and other checkinstall reports that it fails and asks if you want to view the output.
Do not worry about this. Qemu did install successfully.
6 Make the modules start on boot
sudo vi /etc/modules
Add to the bottom:
kqemu
tun
Load them manually for now:
sudo modprobe kqemu
sudo modprobe tun
7 Creating the network bridge
This section is the hardest section but it brings great rewards. If you want the virtual machine to be accessible by any other computer on the network this section is necessary.
Other wise you can use “user mode” networking and skip to “Section 10 – Qemu-launcher”
Install bridge utilities and user mode utilities
sudo apt-get install bridge
sudo apt-get install uml-utilities
A network bridge is a virtual network interface that contains one or more real/virtual interfaces. Basically what this does is:
Create a bridge device
Add our eth0 (or other LAN device) to the bridge.
Modify security permissions to allow qemu to add a Virtual interface to the bridge.
This will allow your virtual ip address of your virtual pc to have a real ip address on your internal LAN. Get it?
*Note – During this section you will lose network connectivity.
**Note – Please substitute eth0 for the name of your LAN interface.
Create the bridge interface
sudo brctl addbr br0
Give the LAN interface a neutral IP
sudo ifconfig eth0 0.0.0.0
Add the LAN interface to the bridge
sudo brctl addif br0 eth0
Next we have to modify the file /etc/network/interfaces to allow your bridge to obtain an ip address automatically. For static IP, check further below.
sudo vi /etc/network/interfaces
For Dynamic IP
Change these lines from this:
mapping hotplug
script grep
map eth0
To this:
#mapping hotplug
# script grep
# map eth0
From This:
# The primary network interface
iface eth0 inet dhcp
To this:
# The primary network interface
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 1
bridge_hello 1
bridge_stp off
For Static IP
*Note – Substitute all IP addresses in bold for LAN address specific to your setup.
Change these lines from this:
mapping hotplug
script grep
map eth0
To this:
#mapping hotplug
# script grep
# map eth0
From This:
iface eth0 inet static
address 192.168.1.2
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
To This:
auto br0
iface br0 inet static
address 192.168.1.2
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
bridge_ports eth0
bridge_fd 1
bridge_hello 1
bridge_stp off
Now its time to restart the Network and restore network connectivty.
sudo /etc/init.d/hotplug restart
sudo /etc/init.d/network restart
To check if everything went well type ifconfig and check to see if the device br0 listed has an IP address.
Eg
br0 Link encap:Ethernet HWaddr 00:0C:6E:74:41:62
inet addr:192.168.0.77 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:6eff:fe74:4162/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3826802 errors:0 dropped:0 overruns:0 frame:0
TX packets:3899124 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2844083685 (2.6 GiB) TX bytes:3126628692 (2.9 GiB)
Wow you just created a network bridge in linux Good Job!
8 Setting up the Virtual interface and permissions.
Now you have created a bridge and added your LAN interface, you can create the virtual interface for Qemu to use.
Create the tun interface – Be sure to substitute “harrisj” for your username.
sudo tunctl -u 'harrisj' -t tun0
sudo chgrp admin /dev/net/tun
sudo chmod g+w /dev/net/tun
sudo vi /etc/qemu-ifup
Change the file to the following:
#!/bin/sh
echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
echo "Adding $1 to br0..."
sudo /usr/sbin/brctl addif br0 $1
sleep 2
sudo chmod ug0+x /etc/qemu-if
9 Setting up sudoers.
Later on you will probably want to install qemu-launcher to launch your Virtual Machines from a nice graphical interface. In the previous section we created/edited a script called /etc/qemu-ifup. This script contains “sudo” commands. Sudo commands do not like being run within a script when you don't run qemu from a terminal. To fix this, we have to make sudo not require a password when issued certain commands.
sudo visudo
*Note - visudo will warn you when you make a syntax mistake in sudoers file.
From this:
# Cmnd alias specification
To This:
# Cmnd alias specification
Cmnd_Alias QEMU=/sbin/ifconfig,/usr/sbin/brctl
And From this:
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
To This:
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
%admin ALL=NOPASSWD:QEMU
Save by pressing “Control x”, y
If visudo exits cleanly then all is well.
Restart sudo
sudo init.d/sudo restart
To test your sudo modifications do the following:
sudo -K
sudo ifconfig
If you were not requested to type a password on the second command, then you have success.
10 Qemu Launcher – You are almost there.
I discovered that if you launch a qemu vm from a terminal and then close that terminal my qemu vm disappeard. Not happy Jan.
There is a great little gtk2 application out there called qemu-launcher. It has some incompatibility issues with the latest version of qemu, but I worked out a hack around it.
Install qemu-launcher
Note - Erik Meitner Wrote this little gem.
sudo vi /etc/apt/sources.list
Add
deb http://emeitner.f2o.org/debian/ ./
sudo apt-get update
sudo apt-get install qemu-launcher
Note – At the time of writing qemu-launcher was at version 1.3.2. If you obtain a newer version you may not need to make the following changes.
For some reason qemu-launcher-1.3.2 gives a command line option –keyboard, which is now obsolete.
sudo vi /usr/bin/qemu-launcher
In this file, search for every instance of “keyboard” And put a # at the front of every line.
For this make sure you comment out the entire section.
# if( $config->{'keyboard'} ) {
# push @parts,'-keyboard';
# push @parts,lc($config->{'keyboard'});
# }
Launch qemu-launcher
Application=>System Tools=>Qemu Launcher
11 Using qemu-launcher
Qemu-launcher is fairly straight forward. Once loaded:
Name: ie “WindowsXP” Change this to create a new VM Profile (This is all your settings for a particular VM
Boot disk: If you need to boot from a cdrom (Install Disk), change the “Boot Disk” drop down box to “cdrom”
Floppy A: Who even uses these anymore?
IDE disk 0: If this is a new VM you can create a new Virtual Hard disk by clicking “Create Image” next to the corresponding IDE disk. If you don't know what to choose it is best to use the default.
CDROM: The first cdrom device is /dev/cdrom
RAM size: If you have a gig of ram, its pretty safe to allocate up to 512mb. For windowsXP you should not have less than 128mb
“Network” Tab
If you performed steps 6,7 and 8 then select “Tun/Tap”. There is no need to specify a script as we have already set up the default script.
If you skipped steps 6,7 and 8, you can choose “User mode” This option will give you network connectivity, but you will not be able to access the VM from other devices on your LAN.
“Launcher Setings”
“Default data directory” $HOME/qemu-dir #You can create a dir for this.
“Path to Qemu” = /usr/local/bin/qemu
12 Credits and why
Over my years of stuffing around with linux, I have read hundreds of howtos and learnt heaps. The community has given a lot to me and I thought it about time to give some back. This is my first guide. I know there are other guides around for qemu (Thanks, they helped me write this one) But I couldn't find anything that gave me a bridged network. So thats the main focus of this. Please leave comments.
Thanks to:
Lunde, for his handy ubuntu guide
A fair chunk of the proceedure comes from Lunde. I hope he doesn't get mad that I used it.
There were some debian specific guides about Bridgeing networks in Linux, and I can't remember where/who made them. The bridge-utils sourceforge site was helpful
http://bridge.sourceforge.net/howto.html
I have tested this setup by installing
Windows XP with SP2
Ubuntu Hoary
I have also tested this guide on a brand new copy of Ubuntu. Worked like a charm. Within a VM btw.
Cheers
Jesse Harris



Adv Reply




Bookmarks