diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2020-05-12 10:44:41 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2020-05-12 10:44:41 -0300 |
commit | b54bcfd68bcb854bf9733359de52f0df76e58713 (patch) | |
tree | 8d3c5564eb72362567a7dcaafe93632551971cda | |
parent | 3571ea4a5f71afbcdcd915f2a84a6622e3cb56be (diff) | |
download | kvmx-b54bcfd68bcb854bf9733359de52f0df76e58713.tar.gz kvmx-b54bcfd68bcb854bf9733359de52f0df76e58713.tar.bz2 |
Fix: more qemu/screen version handling
-rwxr-xr-x | kvmx | 54 |
1 files changed, 34 insertions, 20 deletions
@@ -456,23 +456,51 @@ function kvmx_up { boot_opts="-boot $boot" fi + # Check kvm version + if kvm --help | grep -q -- "^-balloon"; then + local new_qemu="0" + else + local new_qemu="1" + 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 -net nic,model=$nic_model" net_opts="user,hostfwd=tcp:127.0.0.1:$SSH-:22$hostfwd -net nic,model=$nic_model" elif [ "$net" == "tap" ]; then - # Thanks kvm-manager + # Thanks to 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 -device virtio-net-pci,vlan=0,id=net0,mac=$mac_address,bus=pci.0" + + if [ "$new_qemu" == "0" ]; then + net_opts="tap,ifname=$tap,script=no,downscript=no,vlan=0,name=hostnet0 -device virtio-net-pci,vlan=0,id=net0,mac=$mac_address,bus=pci.0" + else + #net_opts="tap,ifname=$tap,script=no,downscript=no,id=n1 -device virtio-net-pci,netdev=n1,id=net0,mac=$mac_address,bus=pci.0" + net_opts="tap,ifname=$tap,script=no,downscript=no,id=net0 -device virtio-net-pci,netdev=net0,mac=$mac_address,bus=pci.0" + fi fi if [ ! -z "$net_dns" ] && [ "$net_dns" != "host" ]; then net_opts="$net_opts,dns=$net_dns" fi - net_opts="-net $net_opts" + # Check screen version + if screen --help | grep -q -- "-Logfile"; then + local screen_log="-L -Logfile" + else + local screen_log="-L" + fi + + # Additional net and balloon options depending on qemu version + #if kvm --help | grep -q -- "^-balloon"; then + if [ "$new_qemu" == "0" ]; then + local balloon="-balloon virtio" + net_opts="-net $net_opts" + else + local balloon="-device virtio-balloon" + net_opts="-netdev $net_opts" + fi # Always run spice using a socket to provide some GUI isolation between guest # Otherwise any guest could open a spice connection to another guest using the host local IP (10.0.2.2) and the other guest spice port @@ -511,20 +539,6 @@ function kvmx_up { #usb_opts="$usb_opts -chardev spicevmc,name=usbredir,id=usbredirchardev3" #usb_opts="$usb_opts -device usb-redir,chardev=usbredirchardev3,id=usbredirdev3" - # Check screen version - if screen --help | grep -q -- "-Logfile"; then - local screen_log="-L -Logfile $LOGFILE" - else - local screen_log="-L $LOGFILE" - fi - - # Check kvm version - if kvm --help | grep -q -- "^-balloon"; then - local balloon="-balloon virtio" - else - local balloon="-device virtio-balloon" - fi - # Run virtual machine, nohup approach # See https://en.wikipedia.org/wiki/Nohup#Overcoming_hanging #nohup setsid kvm -m $memory -name $VM \ @@ -543,7 +557,7 @@ function kvmx_up { # Run virtual machine, screen approach # This is more immune to hangups - screen $screen_log -S kvmx-qemu-$VM -d -m kvm -m $memory -name $VM \ + screen $screen_log $LOGFILE -S kvmx-qemu-$VM -d -m kvm -m $memory -name $VM \ -chardev "socket,id=monitor,path=$MONITORFILE,server,nowait" -mon chardev=monitor,mode=readline \ -chardev "socket,id=serial0,path=$CONSOLEFILE,server,nowait" -device isa-serial,chardev=serial0 \ -smp $smp -cpu host \ @@ -574,8 +588,8 @@ function kvmx_up { sleep 1 # Thanks kvm-manager code for that portion - /usr/bin/screen -D -m -L $LOG_DIR/servicelog \ - -c $APP_BASE/share/screen/screenrc \ + /usr/bin/screen -D -m $screen_log $LOG_DIR/servicelog \ + -c $APP_BASE/share/screen/screenrc \ -S "kvmx-$VM" -t "kvmx-$VM" socat STDIO,raw,echo=0 "UNIX:${CONSOLEFILE},retry=30" & if [ "$run_spice_client" == "1" ]; then |