Skip to content

Instantly share code, notes, and snippets.

@wkgcass
Created May 29, 2026 11:24
Show Gist options
  • Select an option

  • Save wkgcass/60b6bfd414a69180a2392aa038e755d9 to your computer and use it in GitHub Desktop.

Select an option

Save wkgcass/60b6bfd414a69180a2392aa038e755d9 to your computer and use it in GitHub Desktop.
kvm.sh
#!/bin/bash
USAGE="Usage: ./kvm.sh <qcow2-img-path>"
IMG="$1"
if [ "$IMG" == "" ]; then
echo "$USAGE"
exit 0
fi
set -x
rm -f tmp.qcow2
cp $IMG ./tmp.qcow2
rm -f vars.fd
dd if=/dev/zero of=./vars.fd bs=1M count=64
set +e
# virt-4.1,accel=kvm,gic-version=3
qemu-kvm -machine virt,gic-version=3 -cpu host \
-display none \
-drive file=/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw,if=pflash,format=raw,unit=0,readonly=on \
-drive file=`pwd`/vars.fd,if=pflash,format=raw,unit=1 \
-smp cpus=8,sockets=1,threads=8 \
-object memory-backend-memfd,id=mem0,size=20G,share=on,prealloc=yes,hugetlb=yes,hugetlbsize=1G \
-numa node,memdev=mem0 \
-m 20G \
-drive if=none,file=./tmp.qcow2,id=drive-virtio-disk0,cache=none,format=qcow2 \
-device virtio-blk-pci,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 \
-chardev stdio,id=char0,mux=on,signal=off \
-mon chardev=char0,mode=readline \
-device pci-serial,chardev=char0,id=serial0 \
-D qemu_debug.log
set -e
rm tmp.qcow2
#!/bin/bash
USAGE="Usage: ./kvm.sh <qcow2-img-path>"
IMG="$1"
if [ "$IMG" == "" ]; then
echo "$USAGE"
exit 0
fi
set -x
rm -f ./tmp.qcow2
cp $IMG ./tmp.qcow2
set +e
qemu-kvm -nographic \
-smp cpus=8,sockets=1,threads=8 \
-object memory-backend-memfd,id=mem0,size=20G,share=on,prealloc=yes,hugetlb=yes,hugetlbsize=1G \
-numa node,memdev=mem0 \
-m 20G \
-drive if=virtio,file=./tmp.qcow2,media=disk
set -e
rm -f tmp.qcow2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment