From 42f9b20c255db0f5990c7f6376ec9849ee646310 Mon Sep 17 00:00:00 2001 From: ange Date: Tue, 27 Feb 2024 21:08:33 +0100 Subject: [PATCH] feat: arch --- arch/create.sh | 18 ++++++++++++++++++ arch/download_isos.sh | 6 ++++++ arch/lib.sh | 23 +++++++++++++++++++++++ arch/run.sh | 12 ++++++++++++ 4 files changed, 59 insertions(+) create mode 100755 arch/create.sh create mode 100755 arch/download_isos.sh create mode 100644 arch/lib.sh create mode 100755 arch/run.sh diff --git a/arch/create.sh b/arch/create.sh new file mode 100755 index 0000000..c375e23 --- /dev/null +++ b/arch/create.sh @@ -0,0 +1,18 @@ +#!/bin/bash -e +cd "$(dirname "$0")" +. ./lib.sh + +if [ -f hda.qcow2 ]; then + echo -e "Disk file exists. Are you sure you don't want" \ + "\e[1m\e[31m./run.sh\e[0m?\nCtrl-C to interrupt" >&2 + read -r +fi + +qemu-img create -f qcow2 hda.qcow2 10G + +CMD=( + "${CMD[@]}" + -drive file=arch.iso,index=1,media=cdrom,readonly=on +) + +"${CMD[@]}" diff --git a/arch/download_isos.sh b/arch/download_isos.sh new file mode 100755 index 0000000..39df8b8 --- /dev/null +++ b/arch/download_isos.sh @@ -0,0 +1,6 @@ +#!/bin/bash -e + +arch='' + +curl -LC- \ + -o arch.iso "$arch" diff --git a/arch/lib.sh b/arch/lib.sh new file mode 100644 index 0000000..a320ecd --- /dev/null +++ b/arch/lib.sh @@ -0,0 +1,23 @@ +#!/bin/bash -e + +RAM="$(free -g | awk '/^Mem:/{print $2 - 2}')" + +if [ "$RAM" -le 2 ]; then RAM=2 +elif [ "$RAM" -gt 32 ]; then RAM=32; fi + +RAM="${RAM}G" + +CMD=( + qemu-system-x86_64 + -accel kvm + -M q35 + # usb + -device qemu-xhci + -cpu host + -m "2G,maxmem=$RAM" + -vga virtio + #-drive if=virtio,file=hda.qcow2 + # shared memory + -object memory-backend-ram,id=mem,size=2G,share=on + -numa node,memdev=mem +) diff --git a/arch/run.sh b/arch/run.sh new file mode 100755 index 0000000..c2c066e --- /dev/null +++ b/arch/run.sh @@ -0,0 +1,12 @@ +#!/bin/bash -e +cd "$(dirname "$0")" +. ./lib.sh + +CMD=( + "${CMD[@]}" + -nic user,model=virtio-net-pci + # usb passthrough, might need root privileges + #-device usb-host,vendorid=0x058f,productid=0x6387 +) + +"${CMD[@]}"