You are not logged in.

#1 2017-07-05 05:14:52

bytefire
Member
Registered: 2017-07-05
Posts: 4

[SOLVED] host-guest networking using qemu

Hi,

I am trying to get host (arch linux) and qemu guest (busybox initramfs linux) connect with each other. Wider LAN access on guest is not needed - just host-guest networking.

Following is the basic command I am using. I have tried its different variations.

 qemu-system-x86_64 -enable-kvm -m 1024 -kernel ./vmlinuz -initrd ./initramfs.igz -append "console=ttyS0" -nographic -net nic,vlan=0 -net tap,ifname=tap0,script=no,downscript=no 

Before running this, on host I created a tap interface tap0 and set its user to my logged in user (`whoami`). Brought up the interface in promisc mode.

QEMU started with a warning about -net deprecated in favour of netdev. But only shows loopback interface. There might be issues around dhcp which is not set up, or some other problem. But I can't find a way to see what the problem is. There is -d switch for qemu logs but that has many options and I am not sure which one to use for the types of logs i want.

Also, I can set up a bridge interface br0 on host and enslave tap0 to br0 but that, to me, seems pointless because there is nothing else enslaved to br0. On my laptop, there is wlan0 but it won't be mastered to a bridge - it fails with Operation not supported. Plus I am not interested in wider LAN access anyway.

Thanks

Last edited by bytefire (2017-07-07 10:08:36)

Offline

#2 2017-07-05 08:47:28

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: [SOLVED] host-guest networking using qemu

You can tell qemu to use a bridge with '-netdev bridge,id=bridge,br=brkvm -device virtio-net-pci,netdev=bridge'. You will have to create the bridge yourself and give it an IP but systemd can take care of that with .netdev and .network files. Here I've called the bridge brkvm.

Don't forget to add this name to /etc/qemu/bridge.conf with 'allow brkvm' otherwise you might not be able to have qemu use the bridge without running as root.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#3 2017-07-05 18:56:39

bytefire
Member
Registered: 2017-07-05
Posts: 4

Re: [SOLVED] host-guest networking using qemu

Thanks for getting back.

So I got no errors, a tap0 device was created and enslaved to brkvm. But inside the guest itself, no interface other than lo. Just to be sure, here is what I did:

brctl addbr brkvm
ip addr add 192.168.56.101/24 dev brkvm
ip link set brkvm up
mkdir /etc/qemu
touch /etc/qemu/bridge.conf
echo "allow brkvm" >> /etc/qemu/bridge.conf
qemu-system-x86_64 -enable-kvm -m 1024 -kernel ./vmlinuz -initrd ./initramfs.igz -append "console=ttyS0" -nographic -netdev bridge,id=bridge,br=brkvm -device virtio net-pci,netdev=bridge

Please note that I am running rudimentary user space inside the guest - busybox from initramfs. Is there something I need to do inside guest? I checked the output of qemu and there wasn't any error. Haven't checked logs though.

Offline

#4 2017-07-05 19:02:15

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [SOLVED] host-guest networking using qemu

Has the guest's kernel got VirtIO modules enabled?

Offline

#5 2017-07-05 20:03:00

bytefire
Member
Registered: 2017-07-05
Posts: 4

Re: [SOLVED] host-guest networking using qemu

brebs wrote:

Has the guest's kernel got VirtIO modules enabled?

Right they are not compiled into kernel. Just modules. So I can re-compile the kernel with all of them set to y instead of m. Will post here how it went.

Appreciate the help here : )

Offline

#6 2017-07-05 20:40:01

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: [SOLVED] host-guest networking using qemu

Depends on what your initramfs includes, if it is a regular arch initramfs you might get away with just including the drivers in the initramfs image.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#7 2017-07-06 09:48:58

bytefire
Member
Registered: 2017-07-05
Posts: 4

Re: [SOLVED] host-guest networking using qemu

Perfect! I added the relevant virtio modules to /etc/mkinitcpio.conf which solved it. There is now eth0 in guest. I can bring it up, set ip address and successfully ping the ip address of brkvm. Thanks very much.

Is there a way for me to mark this as resolved?

Offline

#8 2017-07-06 12:08:09

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: [SOLVED] host-guest networking using qemu

bytefire wrote:

Is there a way for me to mark this as resolved?

Edit your first post and add [SOLVED] to the title.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

Board footer

Powered by FluxBB