summaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-03-18 08:48:16 +0530
committersinanmohd <sinan@firemail.cc>2023-03-18 21:10:48 +0530
commit224c0ee94e9df68d48b88f822cef47ae50508545 (patch)
tree7ee8d306e565c2125be3f7177bded42c5af798a3 /.local
parentd8d213d3bd34afb718e1f0530cfbd3b83c4945c4 (diff)
livevm: initial commit: a wrapper for qemu
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/livevm61
1 files changed, 61 insertions, 0 deletions
diff --git a/.local/bin/livevm b/.local/bin/livevm
new file mode 100755
index 0000000..638386b
--- /dev/null
+++ b/.local/bin/livevm
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+data_dir="${XDG_DATA_HOME:-${HOME}/.local/share}/vm"
+storage="${data_dir}/livevm.qcow2"
+
+# allocate half of available memory and cores to vm
+mem="$(($(cat /proc/meminfo | grep MemAvailable | grep -o '[0-9]*')/2))"
+cores="$(($(nproc)/2))"
+cmd="qemu-system-x86_64 -boot menu=on -enable-kvm -device intel-hda -device hda-duplex -m ${mem}k -cpu host -smp $cores -drive file=$storage"
+
+[ ! -d "${data_dir}" ] &&
+ mkdir -p "${data_dir}"
+[ ! -f "$storage" ] &&
+ qemu-img create -f qcow2 livevm.img 30G
+
+while getopts "wehc:d:" f
+do
+ case "$f" in
+ w)
+ cmd="${cmd} -device qxl -display gtk"
+ ;;
+ e)
+ [ ! -f "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd" ] &&
+ die "ovmf not found, install it"
+
+ [ ! -f "${data_dir}/OVMF_VARS.fd" ] &&
+ cp "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd" "${data_dir}/OVMF_VARS.fd"
+
+ cmd="${cmd} -drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd"
+ cmd="${cmd} -drive if=pflash,format=raw,file=${data_dir}/OVMF_VARS.fd"
+ ;;
+ c)
+ cmd="${cmd} -cdrom ${OPTARG}"
+ ;;
+ d)
+ cmd="${cmd} -drive file=${OPTARG}"
+ ;;
+ h)
+ cat <<- EOF
+ Usage: ${0##*/} command
+ a wrapper for qemu
+ Commands:
+ -e use efi
+ -w run wangblows
+ -c [cdrom]
+ -d [drive]
+ EOF
+ exit
+ ;;
+ ?)
+ echo "usage: ${0##*/} [ -weh ] [ -c cdrom ] [ -d drive ]"
+ exit 1
+ ;;
+ esac
+done
+
+# use virgl by default if wangblows is not set
+[ -n "${cmd##*device qxl*}" ] &&
+ cmd="${cmd} -device virtio-vga-gl -display gtk,gl=on"
+
+eval "$cmd"