PXE boot using qemu

4,124 views
Skip to first unread message

Michael Pope

unread,
Sep 1, 2011, 10:32:37 AM9/1/11
to mlu...@googlegroups.com
I've got a need to boot pxe using qemu and I've heard it can be done, but I've spent a few hours tonight on it and haven't got far.

Here are my notes so far.

Connect to PXE server

I have a LTSP system setup on 10.1.1.10 under ubuntu and have tested booting that with a diskless PXE bootable machine and it works. I have a notebook which has qemu installed connected wirelessly to the network. I would like to use this notebook to connect to my pxe machine using qemu. It has wlan0 setup on 10.1.1.101. The DHCP server is my LTSP server and here is my dhcpd.conf file:
default-lease-time 600;
max-lease-time 7200;

# Internal subnet
subnet 10.1.1.0 netmask 255.255.255.0 {
    range 10.1.1.100 10.1.1.200;
    option domain-name-servers 10.1.1.1;
    option domain-name "lan";
    option routers 10.1.1.1;
    option broadcast-address 10.1.1.255;
    default-lease-time 72000;
    max-lease-time 72000;
}

ddns-update-style none;

# For Mythserver (PXE Boot lines)
authoritative;
option domain-name-servers 10.1.1.1;
option broadcast-address 10.1.1.255;
option routers 10.1.1.1;
option root-path "/opt/ltsp/i386";
next-server 10.1.1.10;
if substring( option vendor-class-identifier, 0, 9 ) = "PXEClient" {
    filename "/ltsp/i386/pxelinux.0";
} else {
    filename "/ltsp/i386/nbi.img";
}


Here is what I've done so far on my notebook:

$ sudo aptitude install qemu-kvm kvm-pxe
$ sudo modprobe kvm

Add user to kvm group
$ sudo adduser <my user> kvm

Download gpxe.dsk (Floppy disk image to boot off PXE machine)
http://rom-o-matic.net/gpxe/gpxe-1.0.1/contrib/rom-o-matic/

Test PXE booting over the internet!!!  Ref: http://www.etherboot.org/wiki/qemu
$ qemu -fda gpxe.pdsk -net nic -net user -bootp http://etherboot.org/gtest/gtest.gpxe

This has some great notes on pxe booting through qemu.
http://wiki.debian.org/DebianEdu/HowTo/TestCDinstall


I've tried a few different combinations of qemu to boot, but without any success. It keeps getting the wrong IP, ie: 10.0.2.2.

My notebook is using Ubuntu 11.04 64bit, I'm trying to connect to a PXE image which is i386.

Do I have to setup a bridge? If so how would I go about this?
What qemu commands should I try? has anyone got this working?

from
Michael

hannah commodore

unread,
Sep 1, 2011, 1:30:44 PM9/1/11
to mlu...@googlegroups.com

On 02/09/2011, at 0:32, Michael Pope <ma...@corsairsolutions.com.au> wrote:

> I've got a need to boot pxe using qemu and I've heard it can be done, but I've spent a few hours tonight on it and haven't got far.

...

> I've tried a few different combinations of qemu to boot, but without any success. It keeps getting the wrong IP, ie: 10.0.2.2.
>

> Do I have to setup a bridge? If so how would I go about this?
> What qemu commands should I try? has anyone got this working?

It seems that 10.0.2 is coming from the dhcp server internal to qemu.

This page shows how to config bridging with qemu using tap interfaces: http://www.linux-kvm.org/page/Networking#public_bridge

but... you are likely not able to properly bridge Ethernet with a WLAN interface, especially if it's using WPA. Even if the WLAN card and drivers support it, the AP may drop frames from the bridged qemu MAC address, because it's only expecting your laptop MAC on that association

it's worth a try though. I've had success with atheros chips and bridges, but without encryption

map7

unread,
Sep 1, 2011, 6:36:32 PM9/1/11
to mlug-au
to get around the mac address problem should i set the qemu net device
to the same mac address as my card? i've done this before with my
wireless router with mac filtering turned on.

from
mick

On Sep 2, 3:30 am, hannah commodore <han...@tinfoilhat.net> wrote:

hannah commodore

unread,
Sep 1, 2011, 7:35:42 PM9/1/11
to mlu...@googlegroups.com

On 02/09/2011, at 8:36, map7 <map...@gmail.com> wrote:

> to get around the mac address problem should i set the qemu net device
> to the same mac address as my card? i've done this before with my
> wireless router with mac filtering turned on.

did that work for you? I'd imagine having the same MAC on two interfaces may cause trouble. though if you only need to forward IP over the bridge, it might be able to overcome the issue.

there is also ebtables which could allow you to do a sort of NAT a la iptables MASQUERADE at the Ethernet layer. I recently read a HOWTO on using ebtables to have multiple bridged computers share the same Mac upstream. I'll try and find it

did you try just creating a bridge with wlan0 and the qemu tap device, with no extra tricks?

>
> On Sep 2, 3:30 am, hannah commodore <han...@tinfoilhat.net> wrote:
>> On 02/09/2011, at 0:32, Michael Pope <m...@corsairsolutions.com.au> wrote:
>>
>>> I've got a need to boot pxe using qemu and I've heard it can be done, but I've spent a few hours tonight on it and haven't got far.
>>
>> ...
>>
>>> I've tried a few different combinations of qemu to boot, but without any success. It keeps getting the wrong IP, ie: 10.0.2.2.
>>
>>> Do I have to setup a bridge? If so how would I go about this?
>>> What qemu commands should I try? has anyone got this working?
>>
>> It seems that 10.0.2 is coming from the dhcp server internal to qemu.
>>
>> This page shows how to config bridging with qemu using tap interfaces:http://www.linux-kvm.org/page/Networking#public_bridge
>>
>> but... you are likely not able to properly bridge Ethernet with a WLAN interface, especially if it's using WPA. Even if the WLAN card and drivers support it, the AP may drop frames from the bridged qemu MAC address, because it's only expecting your laptop MAC on that association
>>
>> it's worth a try though. I've had success with atheros chips and bridges, but without encryption
>

> --
> You received this message because you are subscribed to the Google Groups "mlug-au" group.
> To post to this group, send email to mlu...@googlegroups.com.
> To unsubscribe from this group, send email to mlug-au+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mlug-au?hl=en.
>

hannah commodore

unread,
Sep 1, 2011, 7:37:43 PM9/1/11
to mlu...@googlegroups.com
also I don't know I your situation permits, but virtualbox has native bridging support and pxe booting on the guest, even on wifi, without needing bridge-utils style setup

On 02/09/2011, at 8:36, map7 <map...@gmail.com> wrote:

Michael Pope

unread,
Sep 1, 2011, 9:08:21 PM9/1/11
to mlu...@googlegroups.com
I've taken a step back and I'm just trying to get this qemu working with a bridge on a wired network.

I started following the tutorial you gave me in the last email and I keep getting stuck on an error:

$ sudo qemu-system-i386 -net nic,macaddr=DE:AD:BE:EF:5C:D5 -net tap
+ switch=br0
+ [ -n tap6 ]
+ echo Setup tap dev
Setup tap dev
+ whoami
+ /usr/bin/sudo /usr/sbin/tunctl -u root -t tap0
TUNSETIFF: Device or resource busy


If I try starting it as my user (which is part of the kvm group) I get this error:
$  qemu-system-i386 -net nic,macaddr=DE:AD:BE:EF:5C:D5 -net tap
qemu-system-i386: -net tap: could not configure /dev/net/tun (tap%d): Operation not permitted
qemu-system-i386: -net tap: Device 'tap' could not be initialized


Permissions on files and devices are:
$ ll /dev/net
crw-rw-rw-  1 root kvm  10, 200 2011-09-02 10:46 tun


$ ll /etc | grep qemu
lrwxrwxrwx 1 root root      20 2011-09-02 09:31 qemu-ifdown -> /usr/bin/qemu-ifdown*
-rwxr-xr-x 1 test test     333 2011-09-02 10:59 qemu-ifup*


Note: The user is called 'test' on this machine.

I have tried removing all tap devices with this:
$ sudo tunctl -d tap{0,1,2,3,4,5,6}

Should I be running the qem-system-i386 as the user or root? There seems to be mixed opinions on this. Mind you I just want to get something working for now.

If I run the command: /usr/bin/sudo /usr/sbin/tunctl -u root -t tap0 on the command line it works! So it doesn't like it when qemu is trying to start it through the script for some reason.

from
Michael

hannah commodore

unread,
Sep 1, 2011, 10:04:08 PM9/1/11
to mlu...@googlegroups.com
On 02/09/2011, at 11:08, Michael Pope <ma...@corsairsolutions.com.au> wrote:

If I run the command: /usr/bin/sudo /usr/sbin/tunctl -u root -t tap0 on the command line it works! So it doesn't like it when qemu is trying to start it through the script for some reason.

try running this again, replacing -u root with the username which you run qemu. 

/dev/tap0 (or /dev/net/tap0) should be created, with you as the owner. then, qemu should be able to run and use the pre existing tap device. 
hopefully the qemu net script will just use it, and not try to create a new one. adding "script=" to qemu -net tap should ensure that 

Michael Pope

unread,
Sep 1, 2011, 10:15:07 PM9/1/11
to mlu...@googlegroups.com
I just tried to run that command as my user and this is what I'm getting:

test@test-G1:~$ /usr/bin/sudo /usr/sbin/tunctl -u test -t tap0

TUNSETIFF: Device or resource busy
test@test-G1:~$ /usr/bin/sudo /usr/sbin/tunctl -u test -t tap1

TUNSETIFF: Device or resource busy
test@test-G1:~$ /usr/bin/sudo /usr/sbin/tunctl -u test -t tap2

TUNSETIFF: Device or resource busy
test@test-G1:~$ /usr/bin/sudo /usr/sbin/tunctl -u test -t tap3
Set 'tap3' persistent and owned by uid 1000
test@test-G1:~$ /usr/bin/sudo /usr/sbin/tunctl -u test -t tap3
Set 'tap3' persistent and owned by uid 1000

If I look in the /dev there is no tap devices.
In /dev/net there is only 'tun'

First I thought NetworkManager was using the devices, so I uninstalled NetworkManger completely and setup the network manually. This didn't change anything.

I do have VirtualBox also on this machine maybe it's using up some of the resources, I'll uninstall that.  In the end I plan on using qemu instead of Virtualbox for many reasons.

from
Michael
Reply all
Reply to author
Forward
0 new messages