LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (http://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   On qemu-kvm, qemu-ifup script not found on Slackware 13 (http://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/on-qemu-kvm-qemu-ifup-script-not-found-on-slackware-13-a-778741/)

AndrewGaven 12-29-2009 01:23 PM

On qemu-kvm, qemu-ifup script not found on Slackware 13
 
I have successfully installed qemu-kvm from Slackbuild.org on a Slackware 13 and created two Win xp virtual machines and one with Gentoo, however i'm not able to conect my Guest OS network with my host.

i have followed the instruction set on

http://www.linux-kvm.org/page/Networking

and create a qemu-ifup script and place it under /etc with the permissions an all, however it doesn't seen to be found by qemu, so where does qemu searches for qemu-ifup on Slackware?

I have also read Alien bob wiki http://alien.slackbook.org/dokuwiki/...slackware:qemu , but he uses VDE, is this the only way on Slackware?

Chuck56 12-29-2009 06:44 PM

IMHO the best way to do this is to install the tunctl package from Slackbuilds and use tap interfaces with brctl to gain access to your LAN. Then your guest and hosts will be able to see each other.

AndrewGaven 12-30-2009 07:26 PM

Thank for answering
 
Thanks for answering, i already downloaded the tun package, loaded the tun module and created a bridge, but my problem is with the qemu-ifup script which is not found by qemu, what i want to know is where does qemu search the qemu-ifup script by default (on Slackware 13) since it is certainly that is not looking for it on the /etc folder.

I have also try with the -net tap "script" option, but couldn't set the network connection, this option also mess up the internet connection of my host and guest, just in case this is my qemu-ifup script

#!/bin/sh
set -x

switch=br0

echo "entre"
if [ -n "$1" ];then
tunctl -u 'whoami' -t $1
ip link set $1 up
sleep 0.5s
brctl addif $switch $1
exit 0
else
echo "Error: no interface specified"
exit 1
fi

Chuck56 12-30-2009 08:02 PM

I wrote my own network script to start and stop the bridge and tap interfaces. I use it with both 32 & 64 bit Slackware 13 installations. I use dhclient instead of dhcpcd so you'll need to reset your rc.inet1.conf so USE_DHCP[0]="" and dhcpcd doesn't start up.

Code:

#!/bin/sh
#
# /etc/rc.d/rc.netbr
#
# Start/stop the KVM TUN/TAP BRIDGE.
#
# To make NETBR start automatically at boot, make this
# file executable:  chmod 755 /etc/rc.d/rc.netbr
# and add "/etc/rc.d/rc.netbr start" to /etc/rc.d/rc.local
#

case "$1" in
  'start')

    ip addr flush eth0
    ifconfig eth0 0.0.0.0

    brctl addbr br0
    brctl stp br0 off
    brctl setfd br0 0
    brctl sethello br0 1
    brctl addif br0 eth0

    tunctl -t tap0 -u username
    ifconfig tap0 0.0.0.0
    brctl addif br0 tap0

    tunctl -t tap1 -u username
    ifconfig tap1 0.0.0.0
    brctl addif br0 tap1

    tunctl -t tap2 -u username
    ifconfig tap2 0.0.0.0
    brctl addif br0 tap2

    dhclient br0

    ;;
  'stop')

    brctl delif br0 tap2
    tunctl -d tap2

    brctl delif br0 tap1
    tunctl -d tap1

    brctl delif br0 tap0
    tunctl -d tap0

    brctl delif br0 eth0
    ip addr flush br0
    ifconfig br0 down
    brctl delbr br0
    ifconfig eth0 0.0.0.0

    dhclient eth0

    ;;
  *)
    echo "usage $0 start|stop" ;;
esac


phil.d.g 12-31-2009 06:01 AM

look at the man page for qemu-kvm to find out where the qemu-ifup script should go, for example on debian

Code:

$ man kvm
...
FILES
      /etc/kvm/kvm-ifup, called at startup to configure the host-side network
      /usr/share/kvm/, BIOS files are by default loaded from this directory
      /usr/share/kvm/keymaps, keymap files


...

However there is still an error in your script.
Can you monitor the output of dmesg while you setup your tap device and add it the bridge and post the contents here? The output should look like this:

Code:

[61795.121139] device tap1 entered promiscuous mode
[61795.121145] br0: port 3(tap1) entering learning state
[61804.505539] br0: topology change detected, propagating
[61804.505543] br0: port 3(tap1) entering forwarding state
[61806.052285] tap1: no IPv6 routers present


Chuck56 12-31-2009 01:06 PM

Quote:

Originally Posted by phil.d.g (Post 3809815)
look at the man page for qemu-kvm to find out where the qemu-ifup script should go

Slackware doesn't have a qemu-kvm man page and neither do the qemu-kvm sources from what I can tell. Maybe it's a debian specific man page.

phil.d.g 12-31-2009 01:35 PM

ok, my bad - seems it is debian specifc

Does qemu/qemu-kvm/kvm --help give you the default location for the script.

Example:
Code:

                hostname 'host' to DHCP clients
-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,downscript=dfile]
                connect the host TAP network interface to VLAN 'n' and use the
                network scripts 'file' (default=/etc/kvm/kvm-ifup)


Chuck56 12-31-2009 05:15 PM

Quote:

Originally Posted by phil.d.g (Post 3810221)
ok, my bad - seems it is debian specifc

Does qemu/qemu-kvm/kvm --help give you the default location for the script.

Not really. There is script in the source named qemu-ifup that's kinda basic and not used in Slackware.

/usr/doc/qemu-kvm-0.12.1.2/scripts/qemu-ifup
Code:

#!/bin/sh

switch=$(/sbin/ip route list | awk '/^default / { print $5 }')
/sbin/ifconfig $1 0.0.0.0 up
/usr/sbin/brctl addif ${switch} $1

That script doesn't take into account tap interfaces.

phil.d.g 12-31-2009 07:04 PM

OK, well let's leave the default location until someone with slackware comes along, or I can engage my backside long enough to get a slackware vm going.

Can you elaborate more on this please:
Code:

I have also try with the -net tap "script" option, but couldn't set the network connection, this option also mess up the internet connection of my host and guest, just in case this is my qemu-ifup script

Your script looks ok to me, however most scripts prefer to use ifconfig rather than ip.

the script option simply overrides the default so we need to face the second issue regardless of whether we can find the default location.

phil.d.g 01-01-2010 10:29 AM

Hi,

I installed slackware 13, a full install with the exception of kde, kdei and emacs, I also installed tunctl and qemu-kvm from slackbuild.org. So hopefully I have a setup pretty similar to yours.

From `qemu --help`:
Quote:

-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile][,sndbuf=nbytes][,vnet_hdr=on|off]
connect the host TAP network interface to VLAN 'n' and use the
network scripts 'file' (default=/etc/qemu-ifup)
and 'dfile' (default=/etc/qemu-ifdown);

ok, so I made a file /etc/qemu-ifup and added your script, from that tutorial you linked to, and made the file executable. I then created a bridge and added my physical device to it and got a new ip for the bridge. The commands are as follows:

Code:

# cat << eof > /etc/qemu-ifup
> #!/bin/sh
> set -x
>
> switch=br0
>
> if [ -n "$1" ];then
>    tunctl -u 'whoami' -t $1
>    ip link set $1 up
>    sleep 0.5s
>    brctl addif $switch $1
>    exit 0
> else
>    echo "Error: no interface specified"
>    exit 1
> fi
> eof
# chmod +x /etc/qemu-ifup
# ifconfig eth0 0.0.0.0
# brctl addbr br0
# brctl addif br0 eth0
# dhclient br0
# qemu -net nic -net tap -cdrom /tmp/dsl-4.4.10.iso -vnc :0

Now that gave an error saying the tap device is busy, and the reason is because qemu creates the tap device for you and passes the name of that to the script, so your script needs to be modified to look like this:

Code:

#!/bin/sh
set -x

switch=br0

if [ -n "$1" ];then
    ip link set $1 up
    sleep 0.5s
    brctl addif $switch $1
    exit 0
else
    echo "Error: no interface specified"
    exit 1
fi

After that change, everything works perfectly. Here is the output from running qemu with the new script:

Code:

# qemu -net nic -net tap -cdrom /tmp/dsl-4.4.10.iso -vnc :0
open /dev/kvm: No such file or directory
Could not initialize KVM, will disable KVM support
+ switch=br0
+ '[' -n tap0 ']'
+ ip link set tap0 up
+ sleep 0.5s
+ brctl addif br0 tap0
+ exit 0

Please disregard the errors about KVM, that won't change anything. The reason kvm support doesn't work here is because I'm running Slackware in a vm.

Chuck56 01-01-2010 03:30 PM

Quote:

Originally Posted by phil.d.g (Post 3810866)
I installed slackware 13, a full install with the exception of kde, kdei and emacs, I also installed tunctl and qemu-kvm from slackbuild.org. So hopefully I have a setup pretty similar to yours.

Above and beyond! Nicely done Phil.

I learned a bit more about KVM tap networking with your post.

phil.d.g 01-01-2010 05:27 PM

Quote:

Originally Posted by Chuck56 (Post 3811051)
Above and beyond! Nicely done Phil

It's not as impressive as it sounds. All this was done in a virtual machine, less than an hours work all in. Plus it was worth it from my pov to see how Slackware had changed from 9 or 10 when I last used it.

Just a few more notes:

The above assumes your running qemu as root, something I don't actually do in practice. However the qemu-ifup script quoted by the OP assumes qemu is running as root. When run as root, qemu doesn't actually require tunctl as it creates and destroys the tap devices.

However, if you want to run qemu as a normal user then you'll need tunctl and the ability to run that as root, normally via sudo. You will need to use tunctl before you run qemu and pass the tap device to qemu, then destroy it once qemu exits. For example

Code:

$ tap=$(sudo tunctl -b -u `whoami`)
$ qemu -net nic -net tap,ifname=$tap -cdrom /tmp/dsl-4.4.10.is -vnc :0
$ sudo tunctl -d $tap

However /etc/qemu-ifup needs changing to:

Code:

#!/bin/sh
set -x

switch=br0

if [ -n "$1" ];then
    sudo ip link set $1 up
    sleep 0.5s
    sudo brctl addif $switch $1
    exit 0
else
    echo "Error: no interface specified"
    exit 1
fi

However I prefer to do everything in a wrapper/manager script, create the tap device, add it the bridge launch qemu, then cleanup after. In this case qemu is run somewhat like this:

Code:

qemu -net nic -net tap,ifname=$tap,script=no,downscript=no ...
I'll post the script if there is any interest, but it doesn't accomplish anything something like libvirt doesn't, and libvirt does much more. However, it doesn't require a daemon to be running all the time, and a vm config file is much simpler.

AndrewGaven 01-05-2010 12:56 AM

Sorry for the late reply
 
Happy new year!!!
I followed your instructions and they work marvelously.

About:
Quote:

Originally Posted by phil.d.g (Post 3810416)
OK, well let's leave the default location until someone with slackware comes along, or I can engage my backside long enough to get a slackware vm going.

Can you elaborate more on this please:

I though that qemu could search for a qemu-ifup script by default in /etc simply by using
Code:

qemu-system-x86_64 vdisk.img
Thanks to your reply I realize i was wrong since it need the -net tap option to search for the ifup script, the script option i was talking about is the the one that change the qemu-ifup path.

Quote:

Originally Posted by phil.d.g (Post 3810866)

Please disregard the errors about KVM, that won't change anything. The reason kvm support doesn't work here is because I'm running Slackware in a vm.


After the installation of tuncl and qemu-kvm, slackware doesn't load their modules by default so you have to load then manually, in my case i add then on the /etc/rc.d/rc.modules
Code:

/sbin/modprobe kvm
/sbin/modprobe kvm-intel
/sbin/modprobe tun

After loading these modules the folder /dev/kvm is created

Of course, this is not your case since you are using a vm, but if you got this error on a slackware host this might be the reason.

In case anyone need then later this are my qemu-ifup script
Code:

#!/bin/sh
set -x

switch=br0
sudo ifconfig eth0 0.0.0.0
sudo brctl addbr $switch
brctl addif $switch eth0
sudo dhclient $switch
echo "entre"
if [ -n "$1" ];then

        sudo ip link set $1 up
        sleep 0.5s
        sudo brctl addif $switch $1
 
        exit 0
else
        echo "Error: no interface specified"
        exit 1
fi

and my qemu-ifdown script
Code:

#!/bin/sh

echo "entre"
ETHX=eth0
sudo ifconfig ${ETHX} down
sudo ifconfig br0 down
# Delete the bridge
sudo brctl delbr br0
# bring up eth0 in "normal" mode
sudo ifconfig ${ETHX} 0.0.0.0
sudo dhclient

Thanks for your time.

robinherbots 01-28-2010 01:59 PM

To load the KVM modules automatically you can also use udev.

Create a file 65-kvm.rules

Content:

KERNEL=="kvm", MODE="0660", GROUP="kvm"
ACTION=="add|change", SUBSYSTEM=="dmi", KERNEL=="id", RUN+="/bin/sh -c 'grep -q vmx /proc/cpuinfo && /sbin/modprobe kvm-intel; grep -q svm /proc/cpuinfo && /sbin/modprobe kvm-amd'"

and put it in /etc/udev/rules.d/

You can also find the file in
kvm-kmod-2.6.32.3.tar.bz2 under scripts.

Thx for the qemu-ifup and qemu-ifdown script !

Robin

robinherbots 01-29-2010 03:36 AM

Well I tried the approach of using VDE (Virtual Distributed Ethernet) as described on the wiki of Alien Bob (slackware)

http://alien.slackbook.org/dokuwiki/...=slackware:vde

It works very well and is really easy to setup. Just download the vde package from the wiki.

Copy the script /usr/share/doc/vde-2.2.2/rc.vdenetwork to /etc/rc.d/
Change it's permission. Start the script through a call in rc.local.

and in qemu you add the -net vde option.

Don't forget to compile the qemu source with vde enabled.

BTW all is clearly described in the above mentioned WIKI!!


All times are GMT -5. The time now is 01:11 AM.