What is QEMU ?
QEMU is an emulator for PC systems which can runs on x86 systems. The QEMU addon in IPFire is specially adapted for this system.
It provides the ability to emulate one or more operating systems. The great advantage of QEMU is that it can emulate other processors (like ARM) and even VMware images can be imported.
With enough computing power and memory you can to emulate all existing OSses: Windows, Linux, UNIX. In fact what ever you want.
Allow at least 256 MB for your host system (IPFire) to keep the system running.
Remember:
- It doesn't matter how powerful your CPU is, if your machine has less than 2 GB memory, you won't have much fun with QEMU!
QEMU is a brilliant idea, but it will consume a lot of memory.
Preparation
First, install this Addon, like always (;-)) Addons via Pakfire.
Now create a virtual disk" with 8 GB (this is as an example that may be suitable for a basic XP installation, if you try to install a full debian - 64 gb disk space may find your acceptance) with the following command:
qemu-img create /PATH/DATEINAME.img 8GB
it takes time - get a coffee - spend some time with your wife or children - it takes time
YEPP Done! Now we are ready to install the operating system:
To access your QEMU virtual machine, VNC may be a good idea.
Start the viewer and see:
install an operating system with QEMU
Start QEMU with the following options:
qemu -vnc :1 -hda /mnt/harddisk/testimage.img
-cdrom /mnt/harddisk/ubuntu-7.10-desktop-i386.iso
-m 256 -net nic -net user -boot d -usbdevice tablet &
Remember that this is an example - change it to your needs:
- In this example(!) the QEMU-harddisk (testimage.img) and the UBUNTU ISO (ubuntu-7.10-desktop-i386.iso) will be accesesed via a second harddisk which is mounted via ExtraHD - if you like just use your favourite CD/DVD-image as your ISO.image to boot from.
How to use the start parameters | |
---|---|
-vnc :1 | instructs the integrated VNC-server to send its output over port 5901 \ - be aware of your firewall settings |
-no-acpi | starts QEMU without any ACPI features |
-m 256 | allocates 256 MB MEMORY to your virtual machine; \ default is 128 MB, 512 MB for XP will be fine |
-net nic | emulates a Realtek RTL 8029(AS) PCI Ethernet |
-net nic,model=rtl8139 | emulates a Realtek RTL 8139 PCI Ethernet |
-net user | allows NAT on the network interface card |
-boot d | boots from drive D: ( your CDRom maybe) |
-usbdevice tablet | emulates a HID-mouse |
-daemonize | executes QEMU in the background |
-redir tcp:3389::3389 | allows the use of the RDP protocol for Windows clients \ -> access it on a win machine via: mstsc /V:IP_ADRESS /console |
-soundhw es1370,sb16,adlib | only one possible soundcard |
-localtime | gets the system time from the host system |
Note!
On some test systems we run QEMU with the option "-&" but they result in an unstable system.
Note!
and ! as always ! - be part of the system - share your knowledge - and let us know if you find a good combination of parameters
If you don't have a real NIC in your system
just create one virtual nic:
tunctl -t orange0
if the command does not exist please use:
modprobe tun
openvpn --mktun --dev tap0
ip link set tap0 name orange0
now you are able with the "setup" command to configure this nic with your needs like ip, gateway etc.
Setup store these information in "/var/ipfire/ethernet/settings" and they may look like:
ORANGE_DEV=orange0
ORANGE_MACADDR=76:02:ee:07:8c:69
ORANGE_DESCRIPTION='"tap: device on orange0"'
ORANGE_DRIVER=tap
ORANGE_ADDRESS=192.168.102.1
ORANGE_NETMASK=255.255.255.0
ORANGE_NETADDRESS=192.168.102.0
ORANGE_BROADCAST=192.168.102.255
The adress settings are important (not ORANGE_DRIVER). After a reboot the nic device has left. To make these settings permanent you have to create a init script with following content. (I named this script /etc/init.d/qemu-orange0)
#!/bin/sh
set +x
. /etc/sysconfig/rc
. $rc_functions
case "${1}" in
start)
boot_mesg "Create Network orange for qemu..."
modprobe tun
sleep 1
#tunctl -t orange0
openvpn --mktun --dev tap0
ip link set tap0 name orange0
ip link set orange0 up
;;
stop)
boot_mesg "Remove Network orange for qemu..."
ip link set orange0 down
#tunctl -d orange0
ip link set orange0 name tap0
openvpn --rmtun --dev tap0
;;
*)
echo "Usage: ${0} {start|stop}"
exit 1
;;
esac
This script needs to be started before ipfire initialize the nics and after the kernel has recognized them.
ln -s /etc/init.d/qemu-orange0 /etc/rc.d/rc3.d/S16orange
Now create a script named as /etc/init.d/qemu-owncloud with content like:
#!/bin/sh
set +x
. /etc/sysconfig/rc
. $rc_functions
case "${1}" in
start)
boot_mesg "starting qemu with owncloud ..."
qemu-system-x86_64 -enable-kvm \
-hda /mnt/raid/script/owncloud.img \
-m 1024 \
-netdev tap,id=net0,ifname=orange0,script=no,downscript=no \
-device virtio-net-pci,netdev=net0 \
-monitor unix:/var/run/owncloud.sock,server,nowait \
-daemonize \
-vnc :1 \
;;
stop)
boot_mesg "stopping qemu with owncloud..."
echo system_powerdown | socat STDIO UNIX:/var/run/owncloud.sock
;;
*)
echo "Usage: ${0} {start|stop}"
exit 1
;;
esac
Please note that the package "socat" must be installed to be able to press the "power down" button on the virtual machine while ipfire shuts down.
To make sure that this script is started and stopped in correct order add these links
ln -s /etc/init.d/qemu-owncloud /etc/rc.d/rc3.d/S22owncloud
ln -s /etc/init.d/qemu-owncloud /etc/rc.d/rc0.d/K10owncloud
ln -s /etc/init.d/qemu-owncloud /etc/rc.d/rc6.d/K10owncloud
You can connect the machine; just use
Please note that you don't have a dhcp server at orange0. On guest side you have to setup up fixed-ip setting. In this setting i used 192.168.102.2
If you run into trouble after reboot please check the ip adress at orange0 with:
ip a
when all was going fine the return looks like:
5: orange0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 500
link/ether be:89:41:fe:b3:d7 brd ff:ff:ff:ff:ff:ff
inet 192.168.102.1/24 brd 192.168.102.255 scope global orange0
valid_lft forever preferred_lft forever
but if you miss the part "inet 192.168.102.1/24 brd 192.168.102.255" the ntpd probably has removed the nic before the nic was going to UP state. (why ntpd remove virtual nics without UP state?).
In this case add in rc.local in the hope this helps....
add in /etc/sysconfig/rc.local following line
/etc/init.d/networking/orange start
You have a real NIC in your system
You need to set you NIC into bridge mode with edit file "/var/ipfire/ethernet/settings" and add for your nic that should have an qemu device attached.
ORANGE_MODE=bridge
reboot the IPFire.
now you need a script located in /etc/init.d/qemu-owncloud with content like:
#!/bin/sh
set +x
. /etc/sysconfig/rc
. $rc_functions
case "${1}" in
start)
boot_mesg "starting qemu with owncloud ..."
qemu-system-x86_64 -enable-kvm \
-hda /mnt/raid/script/owncloud.img \
-m 1024 \
-netdev tap,id=net0,ifname=tap0,br=orange0,script=no,downscript=no \
-device virtio-net-pci,netdev=net0 \
-monitor unix:/var/run/owncloud.sock,server,nowait \
-daemonize \
-vnc :1
sleep 1
ip link set tap0 master orange0
ip link set tap0 up
;;
stop)
boot_mesg "stopping qemu with owncloud..."
echo system_powerdown | socat STDIO UNIX:/var/run/owncloud.sock
sleep 1
ip link set tap0 nomaster
ip link set tap0 down
;;
*)
echo "Usage: ${0} {start|stop}"
exit 1
;;
esac
please note that this example differ with the above one. Please note too that the package "ncat" must be installed to be able to press the "power down" button on the virtual machine while ipfire shuts down.
Make sure that this script start and stop in correct order add these links
ln -s /etc/init.d/qemu-owncloud /etc/rc.d/rc3.d/S22owncloud
ln -s /etc/init.d/qemu-owncloud /etc/rc.d/rc0.d/K10owncloud
ln -s /etc/init.d/qemu-owncloud /etc/rc.d/rc6.d/K10owncloud
You can connect the machine; just use
Please note that you don't have a dhcp server at orange0. On guest side you have to setup a fixed-ip setting.
You can check if all is going fine with:
ip a
brctl show orange0
The "usual" start of QEMU
For normal operation of QEMU, the following parameters should be quite sufficient:
qemu -vnc :1 -hda /mnt/harddisk/testimage.img -m 256 -net nic -net user -boot c
-usbdevice tablet &
Emulated hardware
- IDE-Controller up to 4 IDE Festplatten (or Disk-Images)
- Floppy Drive
- CDROM
- Soundblaster 16 soundcard (aternativ ES1370)
- Cirrus Logic grafik card 5446 PCI (alternativ VESA-VGA)
- Standard PS2 Rad-mouse
- Realtek RTL 8029(AS) PCI Ethernet
- serial interface (COM 1)
- Parallel port (LPT 1)
- USB-UHCI (Intel SB82371)
- Gameport Joystick
Other commands
qemu-img create -f vmdk playdisk.vmdk 6000000
Creates a blank hard disk image VMWare formatted with 6GB memory.