| Rich ( @ 2005-11-27 20:53:00 |
Qemu with kernel acceleration
Basic directions for installing qemu with kernel acceleration and bridged networking. For image space I recommend an LVM configuration. (The steps for checkinstall are somewhat optional. I've had mixed results using this.)
Go to http://fabrice.bellard.free.fr/qemu/dow nload.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)
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
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
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.
sudo vi /etc/modules
Add to the bottom:
kqemu
tun
Load them manually for now:
sudo modprobe kqemu
sudo modprobe tun
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.
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
# The primary network interface
auto br0
iface br0 inet dhcp
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!
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
As a last bit the /dev/kqemu device may not survive a reboot, to fix this...
vi /etc/init.d/bootmisc.sh
At the bottom add:
mknod /dev/kqemu c 250 0
chmod 666 /dev/kqemu
## TODO ##
Add content about not running qemu in bridged mode, include basic natting instructions. (Test network setup)
Basic directions for installing qemu with kernel acceleration and bridged networking. For image space I recommend an LVM configuration. (The steps for checkinstall are somewhat optional. I've had mixed results using this.)
Go to http://fabrice.bellard.free.fr/qemu/dow
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)
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
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
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.
sudo vi /etc/modules
Add to the bottom:
kqemu
tun
Load them manually for now:
sudo modprobe kqemu
sudo modprobe tun
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.
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
# The primary network interface
auto br0
iface br0 inet dhcp
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!
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
As a last bit the /dev/kqemu device may not survive a reboot, to fix this...
vi /etc/init.d/bootmisc.sh
At the bottom add:
mknod /dev/kqemu c 250 0
chmod 666 /dev/kqemu
## TODO ##
Add content about not running qemu in bridged mode, include basic natting instructions. (Test network setup)