diff --git a/lib.sh b/lib.sh index e9f1275..a4a6658 100644 --- a/lib.sh +++ b/lib.sh @@ -28,14 +28,6 @@ download_isos() { "${curl[@]}" } -_getmaxram() { - local ram; ram="$(free -g | awk '/^Mem:/{print $2 - 2}')" - - if [ "$ram" -le 2 ]; then ram=2 - elif [ "$ram" -gt 32 ]; then ram=32; fi - echo "${ram}G" -} - _getnet() { local net=user @@ -49,18 +41,18 @@ _getnet() { } qemu() { - local ram=2G - local maxram; maxram="$(_getmaxram)" - local net; net="$(_getnet)" + local ram net + ram="$(free -g | awk '/^Mem:/{t=$2 / 2; print(t < 2 ? 2 : t)"G"}')" + net="$(_getnet)" (set -x qemu-system-x86_64 \ -accel kvm \ -M q35 \ -bios /usr/share/edk2/x64/OVMF.4m.fd \ -monitor stdio \ - -cpu host \ - -m "$ram,maxmem=$maxram" \ + -smp "$(nproc --ignore 4)" \ + -m "$ram" \ -vga virtio \ -audio pipewire,model=hda \ -nic "model=virtio-net-pci,type=$net" \ diff --git a/startnat.sh b/startnat.sh index c8171d6..7c342df 100755 --- a/startnat.sh +++ b/startnat.sh @@ -1,15 +1,14 @@ #!/bin/bash -eu -DIR="$(dirname "${BASH_SOURCE[0]}")" fix_nft_drops() { local j s='"add chain \(.family) \(.table) \(.name) { policy \(.policy); }"' - if [ -f "$DIR/restore-nft.conf" ]; then - nft -f "$DIR/restore-nft.conf" + if [ -f /tmp/restore-nft.conf ]; then + nft -f /tmp/restore-nft.conf fi j="$(nft -j list chains | jq '.[][].chain | select(.policy == "drop")')" jq -r ".policy=\"accept\" | $s" <<< "$j" - jq -r "$s" <<< "$j" > "$DIR/restore-nft.conf" + jq -r "$s" <<< "$j" > /tmp/restore-nft.conf } command -V dnsmasq > /dev/null @@ -29,7 +28,6 @@ if ! ip link show "$BRIDGE" 2> /dev/null; then ip link add "$BRIDGE" type bridge fi ip link set dev "$BRIDGE" up -ip address flush dev "$BRIDGE" ip address add 192.168.123.1/24 dev "$BRIDGE" nft -f- <