Compare commits

..

No commits in common. "2b543fbff6ae7367d6864805794c4c46e4a3e245" and "42f9b20c255db0f5990c7f6376ec9849ee646310" have entirely different histories.

9 changed files with 63 additions and 73 deletions

View File

@ -1,13 +0,0 @@
# VMs
## HOW-TO
To start (or create) a VM, go in the desired folder and run
```console
$ ./run.sh
```
## USB Passthrough
If you need USB passthrough, uncomment and fill in the corresponding line in
`run.sh`.
[You may need root privileges](https://wiki.archlinux.org/title/QEMU#Pass-through_host_USB_device).

18
arch/create.sh Executable file
View File

@ -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[@]}"

6
arch/download_isos.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash -e
arch=''
curl -LC- \
-o arch.iso "$arch"

23
arch/lib.sh Normal file
View File

@ -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
)

View File

@ -1,20 +1,12 @@
#!/bin/bash -e #!/bin/bash -e
cd "$(dirname "$0")" cd "$(dirname "$0")"
. ../lib.sh . ./lib.sh
hda='https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-basic.qcow2'
if ! [ -f hda.qcow2 ]; then
ask_yn "hda does not exist. Download?" \
&& curl -LC- -o hda.qcow2 "$hda" \
|| exit 1
fi
CMD=( CMD=(
"${CMD[@]}" "${CMD[@]}"
-nic user,model=virtio-net-pci -nic user,model=virtio-net-pci
# USB passthrough, might need root privileges # usb passthrough, might need root privileges
#-device usb-host,vendorid=0xffff,productid=0xffff #-device usb-host,vendorid=0x058f,productid=0x6387
) )
"${CMD[@]}" "${CMD[@]}"

View File

@ -1,20 +0,0 @@
#!/bin/bash -e
cd "$(dirname "$0")"
. ../lib.sh
hda='https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-amd64.qcow2'
if ! [ -f hda.qcow2 ]; then
ask_yn "hda does not exist. Download?" \
&& curl -LC- -o hda.qcow2 "$hda" \
|| exit 1
fi
CMD=(
"${CMD[@]}"
-nic user,model=virtio-net-pci
# USB passthrough, might need root privileges
#-device usb-host,vendorid=0xffff,productid=0xffff
)
"${CMD[@]}"

15
win2k22/create.sh Normal file → Executable file
View File

@ -1,19 +1,20 @@
#!/bin/bash -e #!/bin/bash -e
cd "$(dirname "$0")" cd "$(dirname "$0")"
. ../lib.sh . ./lib.sh
if ! [ -f win2k22.iso ] || ! [ -f virtio.iso ]; then if [ -f hda.qcow2 ]; then
ask_yn "win2k22.iso and/or virtio.iso not found, download?" \ echo -e "Disk file exists. Are you sure you don't want" \
&& bash ./download_isos.sh \ "\e[1m\e[31m./run.sh\e[0m?\nCtrl-C to interrupt" >&2
|| exit 1 read -r
fi fi
qemu-img create -f qcow2 hda.qcow2 40G qemu-img create -f qcow2 hda.qcow2 40G
CMD=( CMD=(
"${CMD[@]}" "${CMD[@]}"
-drive file=win2k22.iso,media=cdrom,readonly=on -drive file=win2k22.iso,index=1,media=cdrom,readonly=on
-drive file=virtio.iso,media=cdrom,readonly=on -drive file=virtio.iso,index=2,media=cdrom,readonly=on
#-drive file.driver=http,file.filename=http://example.com/image.qcow2
-nic none # you don't want internet access for a windows installation -nic none # you don't want internet access for a windows installation
) )

View File

@ -1,16 +1,5 @@
#!/bin/bash -e #!/bin/bash -e
function ask_yn() {
local ans
printf "$1 (Y/n) " >&2
read -r ans
case "${ans,,}" in
y*|'') return 0 ;;
*) return 1 ;;
esac
}
RAM="$(free -g | awk '/^Mem:/{print $2 - 2}')" RAM="$(free -g | awk '/^Mem:/{print $2 - 2}')"
if [ "$RAM" -le 2 ]; then RAM=2 if [ "$RAM" -le 2 ]; then RAM=2
@ -22,12 +11,12 @@ CMD=(
qemu-system-x86_64 qemu-system-x86_64
-accel kvm -accel kvm
-M q35 -M q35
# usb
-device qemu-xhci
-cpu host -cpu host
-m "2G,maxmem=$RAM" -m "2G,maxmem=$RAM"
-vga virtio -vga virtio
-drive if=virtio,file=hda.qcow2 -drive if=virtio,file=hda.qcow2
# usb
-device qemu-xhci
# shared memory # shared memory
-object memory-backend-ram,id=mem,size=2G,share=on -object memory-backend-ram,id=mem,size=2G,share=on
-numa node,memdev=mem -numa node,memdev=mem

View File

@ -1,18 +1,12 @@
#!/bin/bash -e #!/bin/bash -e
cd "$(dirname "$0")" cd "$(dirname "$0")"
. ../lib.sh . ./lib.sh
if ! [ -f hda.qcow2 ]; then
ask_yn "hda.qcow2 not found, create?" \
&& bash ./create.sh \
|| exit 1
fi
CMD=( CMD=(
"${CMD[@]}" "${CMD[@]}"
-nic user,model=virtio-net-pci -nic user,model=virtio-net-pci
# USB passthrough, might need root privileges # usb passthrough, might need root privileges
#-device usb-host,vendorid=0xffff,productid=0xffff -device usb-host,vendorid=0x058f,productid=0x6387
) )
"${CMD[@]}" "${CMD[@]}"