You are not logged in.

#1 2022-06-29 19:35:09

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Assign Qemu to a specific network card (eth1)

Hello,

I use virt-manager and now I would like to switch to Qemu cli. I need to assign a USB network card to certain VMs (I have a router from my employer for home office).

Under virt-manager I select "Macvtab-device" in the settings for "NIC" and assign eth1 to it. When I now start the VM, a "macvtab" device is automatically created. At VM end it is removed again. All this works as user.

I have created two screenshots of the settings.
https://imgur.com/a/Gn92hZh

I created a macvtap (as root) with (https://bbs.archlinux.org/viewtopic.php?id=233496):

doas ip link add link eth1 name macvtap0 type macvtap
doas ip link set macvtap0 up

When I try to do this as a user, it comes up:

RTNETLINK answers: Operation not permitted

Unfortunately I can't start qemu as user with the network device. The guest is an arch:

qemu-system-x86_64 -boot menu=on -drive file=$hdf,format=qcow2,if=virtio -cdrom $cdr -enable-kvm -machine q35 -device intel-iommu -cpu host -device virtio-vga-gl -display sdl, gl=on -device intel-hda -device hda-duplex -m 4G -fsdev local,id=test_dev,path=/home/marcus/Downloads, security_model=none -device virtio-9p-pci,fsdev=test_dev,mount_tag=/sharepoint -device virtio-balloon -usb -device usb-tablet -net nic,model=virtio,macaddr=$(cat /sys/class/net/macvtap0/address) -net tap,fd=3 3<>/dev/tap$(cat /sys/class/net/macvtap0/ifindex)

zsh: permission denied: /dev/tap8

Question: How can I create macvtap as a user? How can I start Qemu with a macvtap network device?


my machine:

inxi -FAZ --no-host
System:
  Kernel: 5.15.50-1-lts arch: x86_64 bits: 64 Desktop: KDE Plasma v: 5.25.2
    Distro: Arch Linux
Machine:
  Type: Laptop System: TUXEDO product: TUXEDO Book XP14 Gen12 v: N/A
    serial: <superuser required>
  Mobo: NB01 model: NV4XMB,ME,MZ serial: <superuser required> UEFI: INSYDE
    v: 1.07.14NRTR1 date: 08/24/2021
Battery:
  ID-1: BAT0 charge: 44.9 Wh (100.0%) condition: 44.9/49.4 Wh (91.0%)
CPU:
  Info: quad core model: 11th Gen Intel Core i7-1165G7 bits: 64 type: MT MCP
    cache: L2: 5 MiB
  Speed (MHz): avg: 844 min/max: 400/4700 cores: 1: 1163 2: 960 3: 728
    4: 648 5: 1024 6: 702 7: 582 8: 950
Graphics:
  Device-1: Intel TigerLake-LP GT2 [Iris Xe Graphics] driver: i915 v: kernel
  Device-2: Chicony USB2.0 Camera type: USB driver: uvcvideo
  Display: x11 server: X.Org v: 21.1.3 with: Xwayland v: 22.1.2 driver: X:
    loaded: modesetting gpu: i915 resolution: 1: 3840x2160 2: N/A
  OpenGL: renderer: Mesa Intel Xe Graphics (TGL GT2) v: 4.6 Mesa 22.1.2
Audio:
  Device-1: Intel Tiger Lake-LP Smart Sound Audio driver: snd_hda_intel
  Device-2: Realtek USB Audio type: USB driver: hid-generic,usbhid
  Sound Server-1: ALSA v: k5.15.50-1-lts running: yes
  Sound Server-2: PipeWire v: 0.3.52 running: yes
Network:
  Device-1: Intel Wi-Fi 6 AX201 driver: iwlwifi
  IF: wlan0 state: down mac: 3a:a7:25:33:2e:33
  Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet
    driver: r8169
  IF: enp53s0 state: up speed: 1000 Mbps duplex: full
    mac: 80:fa:5b:87:db:87
  Device-3: Realtek RTL8153 Gigabit Ethernet Adapter type: USB
    driver: r8152
  IF: eth1 state: up speed: 1000 Mbps duplex: full mac: 00:e0:1b:80:0e:2c
  Device-4: Realtek RTL8153 Gigabit Ethernet Adapter type: USB
    driver: r8152
  IF: enp4s0u2u3 state: down mac: 48:bd:0e:00:04:81
  IF-ID-1: macvtap0 state: down mac: 76:08:2a:88:17:32
  IF-ID-2: macvtap1 state: up speed: 1000 Mbps duplex: full
    mac: 52:54:00:fe:03:45
  IF-ID-3: macvtap3 state: up speed: 1000 Mbps duplex: full
    mac: 06:25:42:a7:a9:01
  IF-ID-4: virbr0 state: up speed: 10 Mbps duplex: unknown
    mac: 52:54:00:82:75:8d
  IF-ID-5: vnet0 state: unknown speed: 10 Mbps duplex: full
    mac: fe:54:00:e6:90:eb
Bluetooth:
  Device-1: Intel AX201 Bluetooth type: USB driver: btusb
  Report: rfkill ID: hci0 state: up address: see --recommends
Drives:
  Local Storage: total: 931.51 GiB used: 528.96 GiB (56.8%)
  ID-1: /dev/nvme0n1 vendor: Samsung model: SSD 970 EVO Plus 1TB
    size: 931.51 GiB
Partition:
  ID-1: / size: 931.01 GiB used: 528.78 GiB (56.8%) fs: btrfs
    dev: /dev/nvme0n1p2
  ID-2: /boot size: 510 MiB used: 181.2 MiB (35.5%) fs: vfat
    dev: /dev/nvme0n1p1
  ID-3: /home size: 931.01 GiB used: 528.78 GiB (56.8%) fs: btrfs
    dev: /dev/nvme0n1p2
  ID-4: /var/log size: 931.01 GiB used: 528.78 GiB (56.8%) fs: btrfs
    dev: /dev/nvme0n1p2
Swap:
  Alert: No swap data was found.
Sensors:
  System Temperatures: cpu: 48.0 C mobo: N/A
  Fan Speeds (RPM): N/A
Info:
  Processes: 286 Uptime: 8h 58m Memory: 31.14 GiB used: 11.97 GiB (38.4%)
  Shell: Zsh inxi: 3.3.19

Last edited by treeh0rse (2022-06-29 19:44:27)

Offline

#2 2022-07-01 19:34:47

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Assign Qemu to a specific network card (eth1)

#qemu-system-x86_64 -runas user -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no

No?

#ip link set macvtap0 up

Maybe ..

#ip link add link eth1 name macvtap0 type macvtap mode bridge

Try...
BTW> I don't see that mac addr.(52:54:00:32:58:20) from the picture; in the inxi data?

edit: Oh and I forgot the runas;)
You don't want to be root so runas to the rescue! .. I hope...
(see)man --pager='less -p -runas\ \user' qemu

Last edited by qinohe (2022-07-01 20:05:33)

Offline

#3 2022-07-09 17:26:52

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

Unfortunately, I have not had time so far, so I'm a little late. smile

> BTW> I don't see the mac adr.(52:54:00:32:58:20) on the image; in the inxi data?

Virt-manager creates the macvtaps at VM startup and deleted it on VM shutdown.


Here's what I do:

doas ip link add link eth1 name macvtap12 type macvtap mode bridge
doas ip link set macvtap12 up

ip adr
[....]
32: macvtap12@eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 500
    link/ether d6:df:ec:fe:e4:67 brd ff:ff:ff:ff:ff:ff
    inet6 fd01:67c:2ed8:1001:d4df:ecff:fefe:e467/64 scope global dynamic mngtmpaddr 
       valid_lft 86399sec preferred_lft 14399sec
    inet6 2001:67c:2ed8:1001:d4df:ecff:fefe:e467/64 scope global dynamic mngtmpaddr 
       valid_lft 86399sec preferred_lft 14399sec
    inet6 fe80::d4df:ecff:fefe:e467/64 scope link 
       valid_lft forever preferred_lft forever
doas qemu-system-x86_64 -runas username -m 4G -cdrom archlinux-2022.06.01-x86_64.iso -net nic,model=virtio -net tap,ifname=macvtab12,script=no,downscript=no -vnc :10

It starts, but the VM (archlinux iso) gets no connection to the outside. (I connect to :5910 using a VNC viewer).

root@archiso ~ # ping 8.8.8.8
ping: connect: Network is unreachable

ip addr
[...]
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
    altname enp0s3
    inet6 fe80::5054:ff:fe12:3456/64 scope link
       valid_lft forever preferred_lft foerevver





For comparison, this macvtap2 has virt-manager created on the host:

id addr
[...]
9: macvtap2@eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 500
    link/ether 52:54:00:fe:03:45 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::5054:ff:fefe:345/64 scope link 
       valid_lft forever preferred_lft forever

This is what it looks like in a virt-manager VM (archlinux):

2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1280 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:fe:03:45 brd ff:ff:ff:ff:ff:ff
    inet 10.84.19.179/20 brd 10.84.31.255 scope global dynamic noprefixroute enp2s0
       valid_lft 270sec preferred_lft 270sec
    inet 10.84.18.213/20 metric 100 brd 10.84.31.255 scope global secondary dynamic enp2s0
       valid_lft 268sec preferred_lft 268sec
    inet6 fd01:67c:2ed8:1001:b884:1ed6:25bf:e23a/64 scope global dynamic noprefixroute 
       valid_lft 86398sec preferred_lft 14398sec
    inet6 2001:67c:2ed8:1001:57c8:9173:5272:3aa8/64 scope global dynamic noprefixroute 
       valid_lft 86398sec preferred_lft 14398sec
    inet6 2001:67c:2ed8:1001:5054:ff:fefe:345/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 86396sec preferred_lft 14396sec
    inet6 fd01:67c:2ed8:1001:5054:ff:fefe:345/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 86396sec preferred_lft 14396sec
    inet6 fe80::cb5a:8086:e93b:b26f/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Offline

#4 2022-07-09 18:51:56

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Assign Qemu to a specific network card (eth1)

Hmm, works fine here.. with a fully updated system.
Are you using systemd networking?
Did you setup a bridge and network device?
You may need to advertise the network device in eth.network:

[Network]
MACVLAN=vmbridge

Now you may need to reboot, I don't know!

You should now be able to add the card to the bridge and start it.

sudo ip link add link eno1 name macvtap0 type macvtap mode bridge
sudo ip link set macvtap0 up

Please try this(for me) working line:

qemu-system-x86_64 -enable-kvm -cpu host,hv-relaxed,hv-vapic,hv-spinlocks=0x1fff,hv-time -runas username \
        -device qemu-xhci -device usb-tablet -net nic -net user,hostname=windows1064 \
        -drive file=/path/to/image,index=0,cache=none,aio=threads,if=virtio \
        -boot d -net nic,model=virtio,macaddr="$(cat /sys/class/net/macvtap0/address)" \
        -net tap,fd=3 3<>/dev/tap"$(cat /sys/class/net/macvtap0/ifindex)" \
        -m 4G

This line work with a Win-10 virtual-HD.
You need to tweak it to work with your VM;)

edit: mind the line-breaks it's a function from a script!

Last edited by qinohe (2022-07-09 18:55:33)

Offline

#5 2022-07-09 20:47:39

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

It's all so bad..... It could have worked a week ago. The problem was doas.... Now I installed sudo, it starts Qemu with GUI interface and macvtap.... Wonderful, no problem....

But now audio does not work... As a user without sudo audio works.... But no macvtap...

I have to ask for help again unfortunately, do you know how I can start Arch with macvtap as user? The one with "-runas username" doesn't seem to work. I also read a lot, there should be as few programs as possible started as sudo (root).

I have a script file called "vmscript.sh" with the following content:

 hdf="/home/username/arch.qcow2"
cdr="/home/username/archlinux-2022.06.01-x86_64.iso"
shf="/home/username/downloads"


qemu-system-x86_64 -boot menu=on -drive file=$hdf,format=qcow2,if=virtio -cdrom $cdr -enable-kvm -machine q35 -device intel-iommu -cpu host -device virtio-vga-gl -display sdl,gl=on -device intel-hda -device hda-duplex -m 4G -fsdev local,id=test_dev,path=$shf, security_model=none -device virtio-9p-pci,fsdev=test_dev,mount_tag=/sharepoint -device virtio-balloon -usb -device usb-tablet -net nic, model=virtio,macaddr="$(cat /sys/class/net/macvtap25/address)" -net tap,fd=3 3<>/dev/tap"$(cat /sys/class/net/macvtap25/ifindex)" -runas username

You can delete the "-fsdev local,id=test_dev,path=$shf,security_model=none -device virtio-9p-pci,fsdev=test_dev,mount_tag=/sharepoint", it's just a "shared folder". You can simply mount it with:

cat /etc/fstab
/sharepoint /sharedfolderinvm 9p

Add it to the /etc/fstab. Maybe you didn't know this before and I could show you something good.

I start the VM with:

"/usr/bin/sudo sh vmscript.sh" <- Macvtap works, audio does not.
"sh vmscript.sh" <- Macvtap does not work, audio works.

Thanks for your code to start windows. Windows is stuck in a boot loop there. Start, reboot, boot, reboot, repair mode.... I would probably have to reinstall windows with just qemu. smile

Offline

#6 2022-07-09 22:23:01

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Assign Qemu to a specific network card (eth1)

Nice to see you have it working somewhat;)
I know about the sharing options, but thanks anyway, always other users that didn't, now they do...
Mostly I use a qcow image with a fat partition that I mount to the guest or host OC, works fine too.
I have one experience with a VM using audio, but you could try to 'daemonize' on root(see: man --pager='less -p daemonize' pulseaudio)

#pulseaudio -D

There are other users that may have a better solution for that;)

edit: Played a little more with the tap device, if you start is as your user you may not need '#qemu-system-x86_64 -runas user' but can start it as your regular user;

#ip tuntap add dev tap0 mode tap user usename

The pulse issue would also be solved,,;)

Last edited by qinohe (2022-07-10 01:40:31)

Offline

#7 2022-07-10 06:01:49

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

I can not link eth1 to tap0.... sad

I don't even know what to look for. It's like I'm the first person to look for something like this.

Offline

#8 2022-07-10 12:52:04

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Assign Qemu to a specific network card (eth1)

treeh0rse wrote:

I can not link eth1 to tap0.... sad

I don't even know what to look for. It's like I'm the first person to look for something like this.

Definitely not the first wink
Anyway I thought you already had tap0 working.., I guess not!

Show the commands (in a descending order!)you used to create bridge and tap device and how you bind them together.

Offline

#9 2022-07-10 14:07:29

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

Here it is: https://wiki.qemu.org/Documentation/Net … s_on_Linux


/usr/bin/sudo ip link add br0 type bridge
/usr/bin/sudo ip tuntap add dev tap0 mode tap user username
/usr/bin/sudo ip link set dev tap0 master br0
/usr/bin/sudo ip link set dev eth1 master br0
RTNETLINK responds: Device or resource busy

eth1 is already assigned to macvtap1 (virt-manager VM1) and macvtap2 (virt-manager VM2).

Offline

#10 2022-07-11 10:40:31

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 12,899

Re: Assign Qemu to a specific network card (eth1)

treehorse, it looks like you're mixing instructions for different methods .

You did notice that macvtap is not mentioned anywhere on that qemu network documentation page ?
Archwiki only shows 3 references to macvtap : on libvirt page, pci passthrough page and one that looks like a translated version of the libvirt page.

The most recent documentation about macvtap on the webs appears to deal with centos which is rather different from archlinux.

I suggest we go back to basics and focus on getting a clear problem description first.

This is my effort to start with that :

- You have a device that provides network over an usb port and want to use that inside a virtual machine
- libvirt can use the device through 'macvtap' and make it available to qemu VMs
- you want to use the device in a qemu VM started from cli


What is brand and model of the device ?

( ensure libvirt is not started automatically or active in any way )
- boot without the device plugged in, plug it in and post dmesg (run as root)
- with the device plugged in post

$ lsusb --tree --verbose

Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#11 2022-07-11 16:54:28

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

> treehorse, it looks like you're mixing instructions for different methods .

You're right, I'm probably getting things mixed up. I want to do a clean start:

I suggest we go back to basics and focus on getting a clear problem description first.

This is my effort to start with that :

- You have a device that provides network over an usb port and want to use that inside a virtual machine
- libvirt can use the device through 'macvtap' and make it available to qemu VMs
- you want to use the device in a qemu VM started from cli

That is right, with my words:

- I have a USB network card, there is a seperate router on it.
- I want to use the network of the USB network card in different VMs at the same time.
- would like to start it with Qemu from the CLI as user.
- The network of the USB network card should not be usable in the main system. Only on VMs

What is brand and model of the device ?
( ensure libvirt is not started automatically or active in any way )
- boot without the device plugged in, plug it in and post dmesg (run as root)
- with the device plugged in post

It is a simple USB-Adapther
https://www.amazon.com/Anker-Gigabit-Et … B014ZOJX7W

https://external-content.duckduckgo.com … f=1&nofb=1

dmesg:
https://pastebin.mozilla.org/Kk2Ydons

lsusb:
https://pastebin.mozilla.org/EBX10Whm

This is it:

                |__ Port 3: Dev 9, If 0, Class=Vendor Specific Class, Driver=r8152, 480M
                    ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter

Edit: libvirt is turned off

systemctl status libvirtd                                          ✔ 
○ libvirtd.service - Virtualization daemon
     Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; disabled; vendor p>
     Active: inactive (dead)
TriggeredBy: ○ libvirtd-admin.socket
             ○ libvirtd-ro.socket
             ○ libvirtd.socket
       Docs: man:libvirtd(8)
             https://libvirt.org

Last edited by treeh0rse (2022-07-11 18:40:14)

Offline

#12 2022-07-11 17:50:42

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Assign Qemu to a specific network card (eth1)

I looked to the answer of Lone_Wolf and think I'm part of the mess-up:(
I'm going watch out for things I did different/wrong to clear this mess, for I like to do this correct too;

Offline

#13 2022-07-12 10:02:22

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 12,899

Re: Assign Qemu to a specific network card (eth1)

dmesg & lsusb look fine and confirm this should be usable for linux as any other physical network interface .

I read up on macvtap and although majority of the available info assumes people are using libvirt to manage the macvtap devices, some don't .
macvtap turns out to be a kernel module that can be managed through iproute2 commands .

https://virt.kernelnewbies.org/MacVTap  gives clear information,

We need to know with 100% accuracy what name the kernel associated with the rtl1853 ethernet device and whether it's active.

post ip link & ip address output .

execute as user the 3 commans listed on the kernel newbies page under "Setting up macvtap" and post the output .
make sure to replace eth1 in those commands with the name for the rtl1853 found through ip link ~ .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#14 2022-07-12 16:53:42

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

Here are the informations:

post ip link & ip address output .

https://pastebin.com/4r0r7h0E

https://pastebin.com/CbAePMzM

execute as user the 3 commans listed on the kernel newbies page under "Setting up macvtap" and post the output .
make sure to replace eth1 in those commands with the name for the rtl1853 found through ip link ~ .

ip link add link eth2 name macvtap0 type macvtap
RTNETLINK answers: Operation not permitted

/usr/bin/sudo ip link add link eth2 name macvtap0 type macvtap

/usr/bin/sudo ip link set macvtap0 address 1a:46:0b:ca:bc:7b up

ip link show macvtap0
6: macvtap0@eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 500
    link/ether 1a:46:0b:ca:bc:7b brd ff:ff:ff:ff:ff:ff

Offline

#15 2022-07-12 18:04:02

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 12,899

Re: Assign Qemu to a specific network card (eth1)

I wasn't sure if ip link add/set required root access but now we know they do.

Looking good, try adding it to a qemu guest as described on kernelnewbies section 'qemu on macvatap' .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#16 2022-07-12 18:43:01

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

I have no "qemu" I have "qemu-system-x86_64"

qemu-system-x86_64 -net nic,model=virtio,addr=1a:46:0b:ca:bc:7b -net tap,fd=3 3<>/dev/tap6
zsh: permission denied: /dev/tap6

/usr/bin/sudo sh qemu-system-x86_64 -net nic,model=virtio,addr=1a:46:0b:ca:bc:7b -net tap,fd=3 3<>/dev/tap6
zsh: permission denied: /dev/tap6

cat vmscript2.sh
qemu-system-x86_64 -net nic,model=virtio,addr=1a:46:0b:ca:bc:7b -net tap,fd=3 3<>/dev/tap6
 
/usr/bin/sudo sh vmscript2.sh
qemu-system-x86_64: Invalid PCI device address 1a:46:0b:ca:bc:7b for device virtio-net-pci

So i replaced the command (see posting 4 this topic) :

cat vmscript2.sh
qemu-system-x86_64 -net nic,model=virtio,macaddr="$(cat /sys/class/net/macvtap0/address)" -net tap,fd=3 3<>/dev/tap"$(cat /sys/class/net/macvtap0/ifindex)"

/usr/bin/sudo sh vmscript2.sh

Qemu starts with this:

https://imgur.com/a/2bGMO9e

https://i.imgur.com/POOnfCm.png



Mod Edit - Replaced oversized images with links.
CoC - Pasting pictures and code

Last edited by Slithery (2022-07-12 19:11:22)

Offline

#17 2022-07-12 19:48:02

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 12,899

Re: Assign Qemu to a specific network card (eth1)

In both screenshots the VM gets an ip address in the 10.84.18.1 / 20 range with the gateway on 10.84.18.1 .

Does that match the network provided by the router connected to the usb hub ?

If yes, i'd say basic functionality works as intended and we can look at finetuning .

Last edited by Lone_Wolf (2022-07-12 19:48:39)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#18 2022-07-12 19:53:06

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

Does that match the network provided by the router connected to the usb hub ?

Yes that is right. smile

Offline

#19 2022-07-13 11:37:38

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 12,899

Re: Assign Qemu to a specific network card (eth1)

great, some live testing in a VM with a working install seems to be next step.

Some additonal thoughts & comments

To remove the macvtap0 interface reversing the ip link commands should be enough, bring the device down & delete it .

Setting the mac address of the interface is crucial and the value can't be changed afterwards.
I remember mentions that if you don't set it explicitly a random one will bew generated, which should work fine.
Can't confirm that however, maybe someone else can.

The "/dev/tapn"  device used in qemu appears to be created by udev and it should be possible to assign it to a specific user or group.
(I know very little about udev rules and it may be better to start a new thread for this part.)

arch wiki wrote:

Warning: QEMU should never be run as root. If you must launch it in a script as root, you should use the -runas option to make QEMU drop root privileges.

Sorry,. no clue how to do that.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#20 2022-07-14 16:30:47

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

arch wiki wrote:
    Warning: QEMU should never be run as root. If you must launch it in a script as root, you should use the -runas option to make QEMU drop root privileges.

Sorry,. no clue how to do that.

-runas username as command parameter.

cat vmscript.sh

hdf="/home/username/arch.qcow2"
cdr="/home/username/archlinux-2022.06.01-x86_64.iso"
shf="/home/username/downloads"


ip link add link eth0 name macvtap0 type macvtap
sleep 1
ip link set macvtap0 address 1a:46:0b:ca:bc:7b up
sleep 1
ip link show macvtap0
sleep 1

qemu-system-x86_64  -boot menu=on -drive file=$hdf,format=qcow2,if=virtio,aio=native,cache.direct=on -cdrom $cdr -enable-kvm -machine q35 -device intel-iommu -cpu host -device virtio-vga-gl -display sdl,gl=on -m 4G -fsdev local,id=test_dev,path=$shf,security_model=none -device virtio-9p-pci,fsdev=test_dev,mount_tag=/sharepoint -device virtio-balloon -usb -device usb-tablet -device intel-hda -device hda-duplex -runas username -net nic,model=virtio,macaddr="$(cat /sys/class/net/macvtap0/address)" -net tap,fd=3 3<>/dev/tap"$(cat /sys/class/net/macvtap0/ifindex)"

It works:

/usr/bin/sudo sh vmscript.sh

Only as root the sound in Qemu does not work. Not even with the "-runas username" parameter. I need sound for video conferencing.

When I start the script as user, the sound works, but I can not use macvtap.

But thanks anyway, I have to see what I try now.

Offline

#21 2022-07-14 16:34:50

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

>The "/dev/tapn"  device used in qemu appears to be created by udev and it should be possible to assign it to a specific user or group.



I tried this (second posting)

https://unix.stackexchange.com/question … net-device

does not work. And the gentoo link is offline. sad

/dev/tap8: Permission denied


> (I know very little about udev rules and it may be better to start a new thread for this part.)

Which forum section do you recommend?

Offline

#22 2022-07-20 11:06:37

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 12,899

Re: Assign Qemu to a specific network card (eth1)

Which forum section do you recommend?

My first response is "Kernel & Hardware" , but as udev questions go this one feels rather basic .
Newbie corner may be more appropriate .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#23 2022-07-23 06:08:45

treeh0rse
Member
Registered: 2022-06-09
Posts: 31

Re: Assign Qemu to a specific network card (eth1)

Thank you very much. smile


If you are interested in how it turns out:

https://bbs.archlinux.org/viewtopic.php?id=278315

Offline

Board footer

Powered by FluxBB