Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Linux guest, QEMU, Laptop
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
lefsha
Veteran
Veteran


Joined: 30 Aug 2004
Posts: 1234
Location: Burgas, Bulgaria

PostPosted: Tue Oct 13, 2020 1:47 pm    Post subject: Linux guest, QEMU, Laptop Reply with quote

Sometimes Gentoo is not enough...

I personally got tied to build some programs from sources. Not easy work I must say...

So there I setup CAELINUX (XUBUNTU based) running under QEMU.
Performance under VBOX seems to be worse, than QEMU.

Generally installation is done accordingly wiki: https://wiki.gentoo.org/wiki/QEMU and
https://wiki.gentoo.org/wiki/QEMU/Options

But then there are some issues how to setup network, file access and copy/paste properly.

I was looking how to get IP for VM to be on the same network with host, but didn't find any.
May be it is possible, but not easy on a laptop with wifi connection.

There are many options available with qemu (vde, macvtap etc) , but none of them worked for me.
Finally I end up with simple tap interface and bridging using iproute2 only interface.

Here the script:

mtap0_up.sh
Code:
#!/bin/sh

HWLINK=wlan0
TAPDEV=mtap0
BRIDGE=bkvm0
IP="192.168.199.1/24"

echo 1 > /proc/sys/net/ipv4/conf/all/proxy_arp
echo 1 > /proc/sys/net/ipv4/ip_forward

# setting up $TAPDEV interface
ip tuntap add dev $TAPDEV mode tap group kvm
ip link set $TAPDEV up promisc on address 52:54:00:12:34:56
ip addr add 0.0.0.0 dev $TAPDEV

# setting up BRIDGE interface
ip link add $BRIDGE type bridge
ip link set $BRIDGE up
ip link set dev $TAPDEV master $BRIDGE
ip addr add $IP dev $BRIDGE

iptables -A FORWARD -i $BRIDGE -o $HWLINK -j ACCEPT
iptables -A FORWARD -i $HWLINK -o $BRIDGE -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -o $HWLINK -j MASQUERADE

for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done
ip -c route show
ip -c addr


mtap0_down.sh
Code:
#!/bin/sh

HWLINK=wlan0
TAPDEV=mtap0
BRIDGE=bkvm0

if ip link show | grep "$BRIDGE" > /dev/null
then
   ip link show $TAPDEV
   ip route flush dev $TAPDEV
   ip link set $TAPDEV down
   ip link delete $TAPDEV

   ip link show $HWLINK
   ip route flush dev $HWLINK
   ip link set $HWLINK down
   ip link delete $HWLINK

   ip link show $BRIDGE
   ip route flush dev $BRIDGE
   ip link set $BRIDGE down
   ip link delete $BRIDGE

   ip -c route
fi

/etc/init.d/iwd restart


I run it manually, but it can be integrated as well.
It is mostly trivial, but no wiki use new iproute2 interface consequently.
People offer to use bridge-tools and/or tunctl util, although it is not necessary.
These 2 scripts are compatible with new network interface. There is no net.eth0
or similar old scripts.

I wish the network related wiki will use only or mostly newer interface and remove old one.

I've built QEMU with these flags:
Code:
[binary   R    ] app-emulation/qemu-5.1.0-r1::gentoo  USE="-accessibility aio -alsa -bzip2 caps -capstone -curl -debug -doc fdt -filecaps -glusterfs -gnutls gtk -infiniband io-uring -iscsi -jack -jemalloc -jpeg -lzo -multipath ncurses -nfs -nls -numa opengl -oss pin-upstream-blobs plugins -png -pulseaudio -python -rbd -sasl -sdl -sdl-image -seccomp (-selinux) -slirp -smartcard -snappy spice -ssh -static -static-user -systemtap -test -usb -usbredir -vde vhost-net -vhost-user-fs virgl virtfs -vnc vte xattr -xen -xfs xkb -zstd" PYTHON_TARGETS="-python3_6 -python3_7 python3_8" QEMU_SOFTMMU_TARGETS="-aarch64 -alpha -arm -avr -cris -hppa -i386 -lm32 -m68k -microblaze -microblazeel -mips -mips64 -mips64el -mipsel -moxie -nios2 -or1k -ppc -ppc64 -riscv32 -riscv64 -rx -s390x -sh4 -sh4eb -sparc -sparc64 -tricore -unicore32 x86_64 -xtensa -xtensaeb" QEMU_USER_TARGETS="-aarch64 -aarch64_be -alpha -arm -armeb -cris -hppa -i386 -m68k -microblaze -microblazeel -mips -mips64 -mips64el -mipsel -mipsn32 -mipsn32el -nios2 -or1k -ppc -ppc64 -ppc64abi32 -ppc64le -riscv32 -riscv64 -s390x -sh4 -sh4eb -sparc -sparc32plus -sparc64 -tilegx x86_64 -xtensa -xtensaeb"


Then to run VM I am using:

caelinux.sh
Code:
#!/bin/sh

ISO=caelinux2020
TAPDEV=mtap0

mkdir -p /tmp/$ISO

qemu-system-x86_64 -enable-kvm \
   -boot d -cdrom $ISO.iso \
   -drive file=$ISO.img,format=raw,index=0,cache=none,aio=threads,if=virtio \
   -machine q35 -cpu max -smp $(nproc) -m 8G \
   -netdev tap,ifname=$TAPDEV,script=no,downscript=no,id=mynet0 \
   -device virtio-net,netdev=mynet0,mac=00:12:35:56:78:9a \
   -virtfs local,path=/tmp/$ISO,mount_tag=host0,security_model=mapped,id=host0 \
   -device virtio-serial \
   -chardev spicevmc,id=vdagent,name=vdagent \
   -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \
   -device virtio-vga,virgl=on \
   -spice gl=on,unix,addr=/tmp/vm_spice.socket,disable-ticketing \
   -display spice-app \
;
exit


After installation the line " -boot d -cdrom $ISO.iso \"
can be removed.

I haven't found how to use copy-paste with simple gtk interface, therefore have to use spice
even locally.

Under guest one need to install qemu-guest-agent and mount the host drive like that:

Code:
mount -t 9p -o trans=virtio,version=9p2000.L host0 /anypath



The resume. I am not 100% happy how it works for me, but it works.
I am also always missing which action is host or guest related.
It's not always clear or obvious.

There are different ways to get video working and it is not clear which performance is the best.
So I didn't test it yet.

That was written, because I wasn't able to find a complete and working config elsewhere.

Cheers,
_________________
Lefsha
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum