This commit is contained in:
ange 2025-07-21 13:08:28 +00:00
parent 17b03778ac
commit 5f1b118ff3
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
26 changed files with 164 additions and 160 deletions

View file

@ -1,16 +1,13 @@
#!/bin/bash -eu
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"
}
ISO="$1"; shift
DISK="$HOME/${ISO%.*}.qcow2"
MAXMEM="$(getmaxram)"
RAM="$(free -g | awk '/^Mem:/{t=$2 / 2; print(t < 2 ? 2 : t)"G"}')"
if ! [ -f "$ISO" ]; then
echo "$ISO does not exist" >&2
exit 1
fi
if ! [ -f "$DISK" ]; then (set -x
qemu-img create -f qcow2 "$DISK" 64G
@ -21,13 +18,13 @@ qemu-system-x86_64 \
-M q35 \
-bios /usr/share/edk2/x64/OVMF.4m.fd \
-monitor stdio \
-cpu host \
-m "2G,maxmem=$MAXMEM" \
-smp "$(nproc --ignore 4)" \
-m "$RAM" \
-vga virtio \
-audio pipewire,model=hda \
-nic model=virtio-net-pci,type=user \
-device qemu-xhci \
-object "memory-backend-ram,id=mem,size=2G,share=on" \
-object "memory-backend-ram,id=mem,size=$RAM,share=on" \
-numa node,memdev=mem \
-drive "if=virtio,file=$DISK" \
-drive "file=$ISO,media=cdrom,readonly=on" \