From d7c9f7f33eaac99f0c93ff307c7aff1f6b413095 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 30 Dec 2017 18:13:28 -0200 Subject: Initial bridge support thanks to kvm-manager --- kvmx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/kvmx b/kvmx index 81b62e5..3e71802 100755 --- a/kvmx +++ b/kvmx @@ -371,9 +371,21 @@ function kvmx_up { shared_folders_cache="none" fi + if [ -z "$net" ] || [ "$net" == "user" ]; then + net_opts="user,hostfwd=tcp:127.0.0.1:$SSH-:22,hostfwd=udp:127.0.0.1:$XDMCP_PORT-:177$hostfwd" + elif [ "$net" == "tap" ]; then + # Thanks kvm-manager + tap="${VM}0" + # MAC address is derived from a hash of the host's name and the guest's name: + mac_address="$(printf "02:%s" "$(printf "%s\0%s" "$(hostname)" "${VM}" | sha256sum | sed 's/\(..\)/\1:/g' | cut -f1-5 -d:)")" + bridge="br0" + net_opts="tap,ifname=$tap,script=no,downscript=no,vlan=0,name=hostnet0" + fi + # Run virtual machine # See https://en.wikipedia.org/wiki/Nohup#Overcoming_hanging - nohup kvm -m $memory -name $VM -drive file=$image,if=$drive_interface $graphics $shared \ + nohup kvm -m $memory -name $VM \ + -drive file=$image,if=$drive_interface $graphics $shared \ -spice port=$PORT,addr=127.0.0.1,disable-ticketing,streaming-video=off,jpeg-wan-compression=never,playback-compression=off,zlib-glz-wan-compression=never,image-compression=off \ -device virtio-serial-pci \ -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ @@ -382,7 +394,8 @@ function kvmx_up { -chardev "socket,id=serial0,path=$CONSOLEFILE,server" -device isa-serial,chardev=serial0 \ -smp $smp -soundhw ac97 -cpu host -balloon virtio \ -net nic,model=$nic_model \ - -net user,hostfwd=tcp:127.0.0.1:$SSH-:22,hostfwd=udp:127.0.0.1:$XDMCP_PORT-:177$hostfwd $qemu_opts &> $LOGFILE < /dev/null & + -net $net_opts \ + $qemu_opts &> $LOGFILE < /dev/null & PID="$!" @@ -1384,8 +1397,7 @@ function kvmx_mv { kvmx_rename $* } -# Interface to QEMU monitor -# Thanks kvm-manager for the idea +# Interface to QEMU monitor (thanks kvm-manager) function kvmx_monitor { if ! kvmx_running; then echo "$BASENAME: guest $VM is not running" -- cgit v1.2.3