Kernel 2.6.18 introduced some security restrictions so that tun devices can't be created by normal users (see: http://www.friedhoff.org/fscaps.html#Qemu)
So if you start qemu now you will get the following error:
warning: could not configure /dev/net/tun: no virtual network emulation Could not initialize device 'tap'
According to this post you have to use tunctl in order to fix that (or run qemu as root, or patch the kernel, I think neither of these options are a real solution)
I have the following wrapper script for qemu (called qemu.sh) (I have also tried the full script from the post mentioned above):
#!/bin/sh sudo tunctl -u enrique qemu $@ -net nic -net tap sudo tunctl -d tap0
enrique is my user name. The tun module has been loaded. It still fails with the above error when I run qemu like this:
qemu.sh -m 128 -hda hda.img -boot c
Kind regards, enrique
Thanks for your message. You helped me get qemu working after a long time of sudo to get networking.
I followed your links and got my setup here functional. It looks to me like the only thing you're missing is the part where you pass the interface name to qemu.
Here's what I use:
USERID=`whoami` iface=`sudo tunctl -b -u $USERID` qemu -hda /path/to/image -m 512 -kernel-kqemu -localtime -snapshot -net ni c -net tap,ifname=$iface -usbdevice tablet sudo tunctl -d $iface &>/dev/null
So, grab the interface from your tunctl call, paste the ",ifname=$iface" in to your code, and call your last tunctl with the interface name again, and you should be all set.
Hope it works for you.
Hm, I'm glad that it works for you, but it still does not work for me. And as I said in my initial post, I have tried the full script from that qemu forum, and it did not work either.
Mayby I have made a stupid mistake somewhere, so here is my complete current setup:
my qemu wrapper script (qemu.sh):
#!/bin/sh echo "Loading kqemu" sudo modprobe kqemu major=0 echo "Loading tun" sudo modprobe tun sudo chgrp users /dev/kqemu sudo chmod g+rw /dev/kqemu USERID=`whoami` iface=`sudo tunctl -b -u $USERID` sudo tunctl -u $USERID -t $iface qemu $@ -net nic -net tap,ifname=$iface sudo tunctl -d $iface
#!/bin/sh echo "Executing /etc/qemu-ifup" sudo ifconfig eth0 down sudo brctl addbr br0 sudo ifconfig eth0 0.0.0.0 up sudo ifconfig br0 192.168.0.2 sudo brctl stp br0 off sudo brctl setfd br0 1 sudo brctl sethello br0 1 sudo brctl addif br0 eth0 sudo route add default gw 192.168.0.1 echo "Bringing up $1 for bridged mode..." sudo ifconfig $1 up sudo brctl addif br0 $1
when I run qemu.sh I use the following parameters:
qemu.sh -kernel-kqemu -m 128 -hda debian-hda.img -boot c
I get the following output: (please notice that qemu never reaches /etc/qemu-ifup)
Loading kqemu Loading tun Set 'tap0' persistent and owned by uid 1001 warning: could not open /dev/net/tun: no virtual network emulation Could not initialize device 'tap' Set 'tap0' nonpersistent
(uid 1001 is my correct uid)
ls -l /dev/net/tun:
crw-rw---- 1 root root 10, 200 29 nov 20:18 /dev/net/tun
Last part of my dmest:
QEMU Accelerator Module version 1.3.0, Copyright (c) 2005-2006 Fabrice Bellard This is a proprietary product. Read the LICENSE file for more information Redistribution of this module is prohibited without authorization KQEMU installed, max_locked_mem=517912kB. tun: Universal TUN/TAP device driver, 1.6 tun: (C) 1999-2004 Max Krasnyansky <maxk>
Kind regards, enrique
I remember reading through the qemu source code and finding that there is a difference between "could not open qemu" and "could not configure qemu".
You are getting the first one. My first question would be what does ls -l /dev/net/tun return? You may need to set up a udev rule to put the right permissions/group on it.
The other thing I noticed about your setup is that you are doing all the bridging stuff every time. I do that once when I boot. I have a script that sets up the bridge and gets all my interfaces set up for use in qemu. From then on I don't need to do that again.
Maybe you can take a look at my first question and see what you find. If you still have a problem, I can just post all the files that I use tomorrow.
Alright, as promised, here is my solution for getting qemu and kqemu to work with bridged networking.
I have posted all the files I use. This currently works for Windows 2000 and FreeBSD.
Let me know if you have any questions!
Last edited by kant1 (2007-10-18 23:08:51)
Where is tunctl?
I can't find such package in Arch.
pacman -S uml_utilities