LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices

Reply
 
Search this Thread
Old 12-29-2009, 01:23 PM   #1
AndrewGaven
LQ Newbie
 
Registered: Dec 2009
Location: Venezuela
Distribution: Slackware 13, Gentoo 2.6.34, Ubuntu 11.04
Posts: 10

Rep: Reputation: 0
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?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 12-29-2009, 06:44 PM   #2
Chuck56
Member
 
Registered: Dec 2006
Location: Colorado
Distribution: Slackware
Posts: 421

Rep: Reputation: 58
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.
 
Old 12-30-2009, 07:26 PM   #3
AndrewGaven
LQ Newbie
 
Registered: Dec 2009
Location: Venezuela
Distribution: Slackware 13, Gentoo 2.6.34, Ubuntu 11.04
Posts: 10

Original Poster
Rep: Reputation: 0
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
 
Old 12-30-2009, 08:02 PM   #4
Chuck56
Member
 
Registered: Dec 2006
Location: Colorado
Distribution: Slackware
Posts: 421

Rep: Reputation: 58
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
 
1 members found this post helpful.
Old 12-31-2009, 06:01 AM   #5
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,192

Rep: Reputation: 101Reputation: 101
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
 
Old 12-31-2009, 01:06 PM   #6
Chuck56
Member
 
Registered: Dec 2006
Location: Colorado
Distribution: Slackware
Posts: 421

Rep: Reputation: 58
Quote:
Originally Posted by phil.d.g View Post
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.
 
Old 12-31-2009, 01:35 PM   #7
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,192

Rep: Reputation: 101Reputation: 101
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)

Last edited by phil.d.g; 12-31-2009 at 01:43 PM.
 
Old 12-31-2009, 05:15 PM   #8
Chuck56
Member
 
Registered: Dec 2006
Location: Colorado
Distribution: Slackware
Posts: 421

Rep: Reputation: 58
Quote:
Originally Posted by phil.d.g View Post
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.
 
Old 12-31-2009, 07:04 PM   #9
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,192

Rep: Reputation: 101Reputation: 101
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.
 
Old 01-01-2010, 10:29 AM   #10
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,192

Rep: Reputation: 101Reputation: 101
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.
 
3 members found this post helpful.
Old 01-01-2010, 03:30 PM   #11
Chuck56
Member
 
Registered: Dec 2006
Location: Colorado
Distribution: Slackware
Posts: 421

Rep: Reputation: 58
Quote:
Originally Posted by phil.d.g View Post
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.
 
Old 01-01-2010, 05:27 PM   #12
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,192

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by Chuck56 View Post
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.
 
Old 01-05-2010, 12:56 AM   #13
AndrewGaven
LQ Newbie
 
Registered: Dec 2009
Location: Venezuela
Distribution: Slackware 13, Gentoo 2.6.34, Ubuntu 11.04
Posts: 10

Original Poster
Rep: Reputation: 0
Sorry for the late reply

Happy new year!!!
I followed your instructions and they work marvelously.

About:
Quote:
Originally Posted by phil.d.g View Post
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 View Post

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.
 
Old 01-28-2010, 01:59 PM   #14
robinherbots
LQ Newbie
 
Registered: Jul 2009
Distribution: Slackware
Posts: 4
Blog Entries: 2

Rep: Reputation: 0
Thumbs up

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
 
Old 01-29-2010, 03:36 AM   #15
robinherbots
LQ Newbie
 
Registered: Jul 2009
Distribution: Slackware
Posts: 4
Blog Entries: 2

Rep: Reputation: 0
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!!

Last edited by robinherbots; 01-29-2010 at 03:37 AM.
 
  


Reply

Tags
kvm, qemu, slackware


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Qemu (KVM) and Vista. ComputerGreek Linux - Software 53 07-06-2012 12:47 AM
Kvm/ qemu + spice nixfreakz Linux - Virtualization and Cloud 1 12-17-2009 08:17 AM
Loading kvm-intel module for qemu-kvm 0.11.0 alkos333 Slackware 6 11-13-2009 10:01 PM
After qemu-img, qemu is not capable to detect the C drive (empty) frenchn00b Linux - General 3 10-18-2009 05:39 AM
emulate slackware install over serial console using kvm/qemu [GOD]Anck Slackware 5 04-05-2009 03:31 AM


All times are GMT -5. The time now is 09:12 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration