diff --git a/run/disk.sh b/run/disk.sh index 8d664db..d69354d 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -1,11 +1,11 @@ #!/usr/bin/env bash set -eu -# Docker environment variabeles +# Docker environment variables -: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' -: ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD -: ${DISK_CACHE:='none'} # Caching mode, can be set to 'writeback' for better performance +: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' +: ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD +: ${DISK_CACHE:='none'} # Caching mode, can be set to 'writeback' for better performance BOOT="$STORAGE/boot.img" [ ! -f "$BOOT" ] && echo "ERROR: Boot image does not exist ($BOOT)" && exit 81 diff --git a/run/install.sh b/run/install.sh index 28883cf..4c4efbf 100644 --- a/run/install.sh +++ b/run/install.sh @@ -8,11 +8,13 @@ echo "Downloading ${BOOT} as boot image..." # Check if running with interactive TTY or redirected to docker log if [ -t 1 ]; then - wget "$BOOT" -O "$TMP" -q --no-check-certificate --show-progress --progress=bar:noscroll + PROGRESS="--progress=bar:noscroll" else - wget "$BOOT" -O "$TMP" -q --no-check-certificate --show-progress --progress=dot:giga + PROGRESS="--progress=dot:giga" fi +wget "$BOOT" -O "$TMP" -q --no-check-certificate --show-progress "$PROGRESS" + [ ! -f "$TMP" ] && echo "Failed to download ${BOOT}" && exit 61 SIZE=$(stat -c%s "$TMP") diff --git a/run/network.sh b/run/network.sh index 1a19c72..4a68011 100644 --- a/run/network.sh +++ b/run/network.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eu -# Docker environment variabeles +# Docker environment variables : ${VM_NET_TAP:='qemu'} : ${VM_NET_DEV:='eth0'} @@ -25,7 +25,11 @@ configureDHCP() { NETWORK=$(ip -o route | grep "${VM_NET_DEV}" | grep -v default | awk '{print $1}') IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) - ip l add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge + if ! ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge > /dev/null 2>&1 ; then + echo -n "ERROR: Capability NET_ADMIN has not been set. Please add the " + echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 15 + fi + ip address add "${IP}" dev "${VM_NET_VLAN}" ip link set dev "${VM_NET_VLAN}" up @@ -35,10 +39,14 @@ configureDHCP() { ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0 ip route add default via "${GATEWAY}" - echo "Info: Acquiring an IP address via DHCP using MAC address ${VM_NET_MAC}..." + echo "INFO: Acquiring an IP address via DHCP using MAC address ${VM_NET_MAC}..." - ip l add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge || true - ip l set "${VM_NET_TAP}" up + if ! ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge > /dev/null 2>&1 ; then + echo -n "ERROR: Capability NET_ADMIN has not been set. Please add the " + echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 16 + fi + + ip link set "${VM_NET_TAP}" up ip a flush "${VM_NET_DEV}" ip a flush "${VM_NET_TAP}" @@ -46,12 +54,12 @@ configureDHCP() { DHCP_IP=$(dhclient -v "${VM_NET_TAP}" 2>&1 | grep ^bound | cut -d' ' -f3) if [[ "${DHCP_IP}" == [0-9.]* ]]; then - echo "Info: Successfully acquired IP ${DHCP_IP} from the DHCP server..." + echo "INFO: Successfully acquired IP ${DHCP_IP} from the DHCP server..." else - echo "ERROR: Cannot acquire an IP address from the DHCP server" && exit 16 + echo "ERROR: Cannot acquire an IP address from the DHCP server" && exit 17 fi - ip a flush "${VM_NET_TAP}" + ip address flush "${VM_NET_TAP}" TAP_NR=$(>"$TAP_PATH"; then - echo -n "ERROR: Please add the following docker variables to your container: " - echo "--device=/dev/vhost-net --device-cgroup-rule='c ${MAJOR}:* rwm'" && exit 21 + echo -n "ERROR: Cannot create TAP interface. Please add the following docker settings to your " + echo "container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21 fi # Create /dev/vhost-net @@ -83,8 +91,8 @@ configureDHCP() { fi if ! exec 40>>/dev/vhost-net; then - echo -n "ERROR: VHOST can not be found. Please add the following docker " - echo "variable to your container: --device=/dev/vhost-net" && exit 22 + echo -n "ERROR: VHOST can not be found. Please add the following " + echo "docker setting to your container: --device=/dev/vhost-net" && exit 22 fi NET_OPTS="-netdev tap,id=hostnet0,vhost=on,vhostfd=40,fd=30" @@ -95,7 +103,12 @@ configureNAT () { VM_NET_IP='20.20.20.21' #Create bridge with static IP for the VM guest - ip link add dev dockerbridge type bridge + + if ! ip link add dev dockerbridge type bridge > /dev/null 2>&1 ; then + echo -n "ERROR: Capability NET_ADMIN has not been set. Please add the " + echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 23 + fi + ip addr add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge ip link set dockerbridge up @@ -181,7 +194,9 @@ GATEWAY=$(ip r | grep default | awk '{print $3}') if [ "$DEBUG" = "Y" ]; then IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) - echo "Info: Container IP is ${IP} with gateway ${GATEWAY}" && echo + echo "INFO: Container IP is ${IP} with gateway ${GATEWAY}" && echo + ifconfig + ip route && echo fi diff --git a/run/run.sh b/run/run.sh index 6567a2c..ca44bbc 100755 --- a/run/run.sh +++ b/run/run.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash set -eu -# Docker environment variabeles +# Docker environment variables -: ${BOOT:=''} # URL of the ISO file +: ${BOOT:=''} # URL of the ISO file : ${DEBUG:='N'} # Enable debug mode : ${ALLOCATE:='Y'} # Preallocate diskspace : ${CPU_CORES:='1'} # Amount of CPU cores @@ -31,33 +31,35 @@ fi # Configure shutdown . /run/power.sh +KVM_ERR="" KVM_OPTS="" if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then - if grep -q -e vmx -e svm /proc/cpuinfo; then - KVM_OPTS=",accel=kvm -enable-kvm -cpu host" + if ! grep -q -e vmx -e svm /proc/cpuinfo; then + KVM_ERR="(cpuinfo $(grep -c -e vmx -e svm /proc/cpuinfo))" fi +else + [ -e /dev/kvm ] && KVM_ERR="(no write access)" || KVM_ERR="(device file missing)" fi -if [ -z "${KVM_OPTS}" ]; then - echo "Error: KVM acceleration is disabled.." +if [ -n "${KVM_ERR}" ]; then + echo "ERROR: KVM acceleration not detected ${KVM_ERR}, please enable it." [ "$DEBUG" != "Y" ] && exit 88 +else + KVM_OPTS=",accel=kvm -enable-kvm -cpu host" fi -DEF_OPTS="-nographic -nodefaults" -KVM_OPTS="-machine type=q35,usb=off${KVM_OPTS}" +DEF_OPTS="-nographic -nodefaults -display none" RAM_OPTS=$(echo "-m ${RAM_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g') -CPU_OPTS="-smp ${CPU_CORES},sockets=1,cores=${CPU_CORES},threads=1" +CPU_OPTS="-smp ${CPU_CORES},sockets=1,dies=1,cores=${CPU_CORES},threads=1" +MAC_OPTS="-machine type=q35,usb=off,dump-guest-core=off,hpet=off${KVM_OPTS}" SERIAL_OPTS="-serial mon:stdio -device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3" EXTRA_OPTS="-device virtio-balloon-pci,id=balloon0 -object rng-random,id=rng0,filename=/dev/urandom -device virtio-rng-pci,rng=rng0" -ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${KVM_OPTS} ${MON_OPTS} ${SERIAL_OPTS} ${NET_OPTS} ${DISK_OPTS} ${EXTRA_OPTS}" +ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${MAC_OPTS} ${MON_OPTS} ${SERIAL_OPTS} ${NET_OPTS} ${DISK_OPTS} ${EXTRA_OPTS}" ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ') -if [ "$DEBUG" = "Y" ]; then - echo -n "qemu-system-x86_64 " - echo "${ARGS}" && echo -fi +[ "$DEBUG" = "Y" ] && echo "qemu-system-x86_64 ${ARGS}" && echo set -m (