You are not logged in.

#1 2006-11-26 15:46:10

enrique
Member
Registered: 2005-10-25
Posts: 95
Website

qemu tun/tap networking and problem with 2.6.18

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

Offline

#2 2006-11-28 20:59:24

kant1
Member
Registered: 2006-11-28
Posts: 57

Re: qemu tun/tap networking and problem with 2.6.18

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.

Offline

#3 2006-11-29 19:23:28

enrique
Member
Registered: 2005-10-25
Posts: 95
Website

Re: qemu tun/tap networking and problem with 2.6.18

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

/etc/qemu-ifup:

#!/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

Offline

#4 2006-11-29 19:35:57

kant1
Member
Registered: 2006-11-28
Posts: 57

Re: qemu tun/tap networking and problem with 2.6.18

Hmm.

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.

whaddya think?

Offline

#5 2006-12-15 03:43:46

kant1
Member
Registered: 2006-11-28
Posts: 57

Re: qemu tun/tap networking and problem with 2.6.18

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!

http://mychael.gotdns.com/blog/2006/12/14/qemu-setup/

Last edited by kant1 (2007-10-18 23:08:51)

Offline

#6 2007-02-16 11:14:39

Jacek Poplawski
Member
From: Poland
Registered: 2006-01-10
Posts: 736
Website

Re: qemu tun/tap networking and problem with 2.6.18

Where is tunctl?
I can't find such package in Arch.

Offline

#7 2007-03-07 18:54:52

kant1
Member
Registered: 2006-11-28
Posts: 57

Re: qemu tun/tap networking and problem with 2.6.18

pacman -S uml_utilities

Offline

Board footer

Powered by FluxBB