diff --git a/README.md b/README.md new file mode 100644 index 0000000..c431cb9 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# 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). diff --git a/arch/create.sh b/arch/create.sh deleted file mode 100755 index c375e23..0000000 --- a/arch/create.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/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 deleted file mode 100755 index 39df8b8..0000000 --- a/arch/download_isos.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -e - -arch='' - -curl -LC- \ - -o arch.iso "$arch" diff --git a/arch/lib.sh b/arch/lib.sh deleted file mode 100644 index a320ecd..0000000 --- a/arch/lib.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/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 index c2c066e..02427cc 100755 --- a/arch/run.sh +++ b/arch/run.sh @@ -1,12 +1,20 @@ #!/bin/bash -e 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[@]}" -nic user,model=virtio-net-pci - # usb passthrough, might need root privileges - #-device usb-host,vendorid=0x058f,productid=0x6387 + # USB passthrough, might need root privileges + #-device usb-host,vendorid=0xffff,productid=0xffff ) "${CMD[@]}" diff --git a/win2k22/lib.sh b/lib.sh similarity index 74% rename from win2k22/lib.sh rename to lib.sh index d9029e4..aa25d42 100644 --- a/win2k22/lib.sh +++ b/lib.sh @@ -1,5 +1,16 @@ #!/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}')" if [ "$RAM" -le 2 ]; then RAM=2 @@ -11,12 +22,12 @@ 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 + # usb + -device qemu-xhci # shared memory -object memory-backend-ram,id=mem,size=2G,share=on -numa node,memdev=mem diff --git a/win2k22/create.sh b/win2k22/create.sh old mode 100755 new mode 100644 index def5788..44afe2b --- a/win2k22/create.sh +++ b/win2k22/create.sh @@ -1,20 +1,19 @@ #!/bin/bash -e cd "$(dirname "$0")" -. ./lib.sh +. ../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 +if ! [ -f win2k22.iso ] || ! [ -f virtio.iso ]; then + ask_yn "win2k22.iso and/or virtio.iso not found, download?" \ + && bash ./download_isos.sh \ + || exit 1 fi qemu-img create -f qcow2 hda.qcow2 40G CMD=( "${CMD[@]}" - -drive file=win2k22.iso,index=1,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 + -drive file=win2k22.iso,media=cdrom,readonly=on + -drive file=virtio.iso,media=cdrom,readonly=on -nic none # you don't want internet access for a windows installation ) diff --git a/win2k22/run.sh b/win2k22/run.sh index e40b804..1993875 100755 --- a/win2k22/run.sh +++ b/win2k22/run.sh @@ -1,12 +1,18 @@ #!/bin/bash -e 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[@]}" -nic user,model=virtio-net-pci - # usb passthrough, might need root privileges - -device usb-host,vendorid=0x058f,productid=0x6387 + # USB passthrough, might need root privileges + #-device usb-host,vendorid=0xffff,productid=0xffff ) "${CMD[@]}"