dotfiles/.local/bin/vm
2025-07-21 13:08:28 +00:00

33 lines
799 B
Bash
Executable File

#!/bin/bash -eu
ISO="$1"; shift
DISK="$HOME/${ISO%.*}.qcow2"
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
) fi
(set -x
qemu-system-x86_64 \
-accel kvm \
-M q35 \
-bios /usr/share/edk2/x64/OVMF.4m.fd \
-monitor stdio \
-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=$RAM,share=on" \
-numa node,memdev=mem \
-drive "if=virtio,file=$DISK" \
-drive "file=$ISO,media=cdrom,readonly=on" \
"$@"
)