diff options
Diffstat (limited to 'vm')
| -rw-r--r-- | vm/alpine-armv7.sh | 39 | ||||
| -rw-r--r-- | vm/alpine-x86_64.sh | 29 | ||||
| -rwxr-xr-x | vm/alpine/armv7/run.sh | 28 | ||||
| -rwxr-xr-x | vm/alpine/x86_64/run.sh | 25 | ||||
| -rw-r--r-- | vm/arch-armv7.sh | 52 | ||||
| -rwxr-xr-x | vm/archlinux/armv7/run.sh | 49 | ||||
| -rw-r--r--[-rwxr-xr-x] | vm/debian-armv7.sh (renamed from vm/debian/armv7/run.sh) | 14 | ||||
| -rw-r--r-- | vm/netbsd.sh | 32 | ||||
| -rwxr-xr-x | vm/netbsd/run.sh | 28 | ||||
| -rw-r--r-- | vm/openbsd.sh | 29 | ||||
| -rwxr-xr-x | vm/openbsd/run.sh | 26 | ||||
| -rwxr-xr-x | vm/run.sh | 25 | ||||
| -rw-r--r--[-rwxr-xr-x] | vm/win11.sh (renamed from vm/win11/run.sh) | 42 |
13 files changed, 229 insertions, 189 deletions
diff --git a/vm/alpine-armv7.sh b/vm/alpine-armv7.sh new file mode 100644 index 0000000..2d6e6e7 --- /dev/null +++ b/vm/alpine-armv7.sh @@ -0,0 +1,39 @@ +: ${VM_CACHE:?} ${VM_DATA:?} + +alpine_url=https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/armv7/alpine-uboot-3.18.4-armv7.tar.gz + +alpine_path=$VM_CACHE/$(basename -- "$alpine_url") +kernel_path=$VM_CACHE/vmlinuz-lts +initrd_path=$VM_CACHE/initramfs-lts + +image_path=$VM_DATA/alpine.qcow2 + + +if [ ! -f $alpine_path ]; then + curl -L -o $alpine_path $alpine_url +fi + +if [ ! -f $kernel_path ]; then + tar -x -f $alpine_path -C $(dirname $kernel_path) \ + --strip-components=2 ./boot/$(basename $kernel_path) +fi + +if [ ! -f $initrd_path ]; then + tar -x -f $alpine_path -C $(dirname $initrd_path) \ + --strip-components=2 ./boot/$(basename $initrd_path) +fi + +if [ ! -f $image_path ]; then + qemu-img create -f qcow2 $image_path 20G +fi + +exec qemu-system-arm \ + -M virt \ + -m 1G \ + -cpu cortex-a15 \ + -kernel $kernel_path \ + -initrd $initrd_path \ + -append "console=ttyAMA0" \ + -hda $image_path \ + -nographic \ + "$@" diff --git a/vm/alpine-x86_64.sh b/vm/alpine-x86_64.sh new file mode 100644 index 0000000..814977a --- /dev/null +++ b/vm/alpine-x86_64.sh @@ -0,0 +1,29 @@ +: ${VM_CACHE:?} ${VM_DATA:?} + +alpine_url=https://dl-cdn.alpinelinux.org/alpine/v3.14/releases/x86_64/alpine-virt-3.14.1-x86_64.iso + +iso_path=$VM_CACHE/alpine.iso + +image_path=$VM_DATA/alpine.qcow2 + + +if [ ! -f $iso_path ]; then + curl -L -o $iso_path $alpine_url +fi + +if [ ! -f $image_path ]; then + qemu-img create -f qcow2 $image_path 20G +fi + +exec qemu-system-x86_64 \ + -enable-kvm \ + -cpu host \ + -hda $image_path \ + -cdrom $iso_path \ + -m 2G \ + -device e1000,netdev=net0 \ + -netdev user,id=net0 \ + -usb \ + -device usb-tablet \ + -nographic \ + "$@" diff --git a/vm/alpine/armv7/run.sh b/vm/alpine/armv7/run.sh deleted file mode 100755 index 8e5f16d..0000000 --- a/vm/alpine/armv7/run.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -set -e - -cd $(dirname -- "$0") - -[ -f alpine.tar.gz ] || \ - curl -L -o alpine.tar.gz https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/armv7/alpine-uboot-3.18.4-armv7.tar.gz - -[ -f vmlinuz-lts ] || \ - tar -x -f alpine.tar.gz --strip-components=2 ./boot/vmlinuz-lts - -[ -f initramfs-lts ] || \ - tar -x -f alpine.tar.gz --strip-components=2 ./boot/initramfs-lts - -[ -f alpine.qcow2 ] || \ - qemu-img create -f qcow2 alpine.qcow2 20G - -exec qemu-system-arm \ - -M virt \ - -m 1G \ - -cpu cortex-a15 \ - -kernel vmlinuz-lts \ - -initrd initramfs-lts \ - -append "console=ttyAMA0" \ - -hda alpine.qcow2 \ - -nographic \ - "$@" diff --git a/vm/alpine/x86_64/run.sh b/vm/alpine/x86_64/run.sh deleted file mode 100755 index 8681b9d..0000000 --- a/vm/alpine/x86_64/run.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -e - -cd $(dirname -- "$0") - -if [ ! -f alpine.iso ]; then - curl -L -o alpine.iso https://dl-cdn.alpinelinux.org/alpine/v3.14/releases/x86_64/alpine-virt-3.14.1-x86_64.iso -fi - -if [ ! -f alpine.qcow2 ]; then - qemu-img create -f qcow2 alpine.qcow2 20G -fi - -exec qemu-system-x86_64 \ - -enable-kvm \ - -cpu host \ - -hda alpine.qcow2 \ - -cdrom alpine.iso \ - -m 2G \ - -device e1000,netdev=net0 \ - -netdev user,id=net0 \ - -usb \ - -device usb-tablet \ - "$@" diff --git a/vm/arch-armv7.sh b/vm/arch-armv7.sh new file mode 100644 index 0000000..41b3a1a --- /dev/null +++ b/vm/arch-armv7.sh @@ -0,0 +1,52 @@ +: ${VM_CACHE:?} ${VM_DATA:?} ${VM_TMP:?} + +arch_url=http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz + +arch_path=$VM_CACHE/$(basename -- "$arch_url") +kernel_path=$VM_CACHE/zImage +initrd_path=$VM_CACHE/initramfs-linux.img + +image_path=$VM_DATA/image + + +if [ ! -f $arch_path ]; then + curl -L -o $arch_path $arch_url +fi + +if [ ! -f $kernel_path ]; then + bsdtar -x -f $arch_path -C $(dirname $kernel_path) \ + --strip-components=2 ./boot/$(basename $kernel_path) +fi + +if [ ! -f $initrd_path ]; then + bsdtar -x -f $arch_path -C $(dirname $initrd_path) \ + --strip-components=2 ./boot/$(basename $initrd_path) +fi + +if [ ! -f $image_path ]; then + truncate -s 2G $image_path + mkfs.ext4 -q $image_path + mkdir -p $VM_TMP/mnt + doas mount -o loop $image_path $VM_TMP/mnt + doas bsdtar -xpf $arch_path -C $VM_TMP/mnt + doas umount $VM_TMP/mnt + rmdir $VM_TMP/mnt +fi + +exec qemu-system-arm \ + -machine virt \ + -cpu cortex-a15 \ + -m 2G \ + -kernel $kernel_path \ + -initrd $initrd_path \ + -append "root=/dev/sda rw" \ + -drive if=none,file=$image_path,format=raw,id=drive0 \ + -netdev user,id=netdev0 \ + -device virtio-scsi-pci,id=scsi \ + -device virtio-blk-pci,drive=drive0 \ + -device virtio-net-pci,netdev=netdev0 \ + -nographic \ + "$@" + + + diff --git a/vm/archlinux/armv7/run.sh b/vm/archlinux/armv7/run.sh deleted file mode 100755 index c53adb7..0000000 --- a/vm/archlinux/armv7/run.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -set -e - -cd $(dirname -- "$0") - -ROOT_URL=http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz -IMG_PATH=archlinuxarm.img -KERNEL_PATH=boot/zImage -INITRAMFS_PATH=boot/initramfs-linux.img - -ROOT_PATH=$(basename $ROOT_URL) - -if [ ! -f $ROOT_PATH ]; then - curl -L -o $ROOT_PATH $ROOT_URL -fi - -if [ ! \( \( -f $KERNEL_PATH \) -a \ - \( -f $INITRAMFS_PATH \) \) ]; then - bsdtar -xf $ROOT_PATH $KERNEL_PATH $INITRAMFS_PATH -fi - -if [ ! -f $IMG_PATH ]; then - truncate -s 2G $IMG_PATH - mkfs.ext4 -q $IMG_PATH - mkdir -p mnt - doas mount -o loop $IMG_PATH mnt - doas bsdtar -xpf $ROOT_PATH -C mnt - doas umount mnt - rmdir mnt -fi - -exec qemu-system-arm \ - -machine virt \ - -cpu cortex-a15 \ - -m 2G \ - -kernel $KERNEL_PATH \ - -initrd $INITRAMFS_PATH \ - -append "root=/dev/sda rw" \ - -drive if=none,file=$IMG_PATH,format=raw,id=drive0 \ - -netdev user,id=netdev0 \ - -device virtio-scsi-pci,id=scsi \ - -device virtio-blk-pci,drive=drive0 \ - -device virtio-net-pci,netdev=netdev0 \ - -nographic \ - "$@" - - - diff --git a/vm/debian/armv7/run.sh b/vm/debian-armv7.sh index 33f3ff3..aa407e6 100755..100644 --- a/vm/debian/armv7/run.sh +++ b/vm/debian-armv7.sh @@ -1,18 +1,14 @@ -#!/bin/sh - -set -e - -cd $(dirname -- "$0") +: ${VM_CACHE:?} ${VM_DATA:?} ISO_URL=https://cdimage.debian.org/debian-cd/current/armhf/iso-cd/debian-11.6.0-armhf-netinst.iso KERNEL_URL=http://ftp.us.debian.org/debian/dists/stable/main/installer-armhf/current/images/cdrom/vmlinuz INITRD_URL=http://ftp.us.debian.org/debian/dists/stable/main/installer-armhf/current/images/cdrom/initrd.gz -ISO_PATH=$(basename $ISO_URL) -KERNEL_PATH=$(basename $KERNEL_URL) -INITRD_PATH=$(basename $INITRD_URL) +ISO_PATH=$VM_CACHE/$(basename $ISO_URL) +KERNEL_PATH=$VM_CACHE/$(basename $KERNEL_URL) +INITRD_PATH=$VM_CACHE/$(basename $INITRD_URL) -IMG_PATH=debian.qcow2 +IMG_PATH=$VM_DATA/debian.qcow2 if [ ! -f $ISO_PATH ]; then curl -L -o $ISO_PATH $ISO_URL diff --git a/vm/netbsd.sh b/vm/netbsd.sh new file mode 100644 index 0000000..18aef3b --- /dev/null +++ b/vm/netbsd.sh @@ -0,0 +1,32 @@ +: ${VM_CACHE:?} ${VM_DATA:?} + +netbsd_url=https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.3/images/NetBSD-9.3-amd64.iso + +iso_path=$VM_CACHE/$(basename -- "$netbsd_url") + +image_path=$VM_DATA/netbsd.qcow2 + + +if [ ! -f $iso_path ]; then + curl -L -o $iso_path $netbsd_url +fi + +if [ ! -f $image_path ]; then + qemu-img create -f qcow2 $image_path 20G +fi + +exec qemu-system-x86_64 \ + -enable-kvm \ + -cpu host \ + -hda $image_path \ + -cdrom $iso_path \ + -m 2G \ + -device e1000,netdev=net0 \ + -netdev user,id=net0 \ + -usb \ + -device usb-tablet \ + -display curses \ + -vga std \ + "$@" + + diff --git a/vm/netbsd/run.sh b/vm/netbsd/run.sh deleted file mode 100755 index d487259..0000000 --- a/vm/netbsd/run.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -set -e - -cd $(dirname -- "$0") - -if [ ! -f netbsd.iso ]; then - curl -L -o netbsd.iso https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.3/images/NetBSD-9.3-amd64.iso -fi - -if [ ! -f netbsd.qcow2 ]; then - qemu-img create -f qcow2 netbsd.qcow2 20G -fi - -exec qemu-system-x86_64 \ - -enable-kvm \ - -cpu host \ - -hda netbsd.qcow2 \ - -cdrom netbsd.iso \ - -m 2G \ - -device e1000,netdev=net0 \ - -netdev user,id=net0 \ - -usb \ - -device usb-tablet \ - -display curses \ - "$@" - - diff --git a/vm/openbsd.sh b/vm/openbsd.sh new file mode 100644 index 0000000..eed668a --- /dev/null +++ b/vm/openbsd.sh @@ -0,0 +1,29 @@ +: ${VM_CACHE:?} ${VM_DATA:?} + +openbsd_url=https://cdn.openbsd.org/pub/OpenBSD/7.3/i386/cd73.iso + +iso_path=$VM_CACHE/openbsd.iso + +image_path=$VM_DATA/openbsd.qcow2 + + +if [ ! -f $iso_path ]; then + curl -L -o $iso_path $openbsd_url +fi + +if [ ! -f $image_path ]; then + qemu-img create -f qcow2 $image_path 20G +fi + +exec qemu-system-x86_64 \ + -enable-kvm \ + -cpu host \ + -hda $image_path \ + -cdrom $iso_path \ + -m 2G \ + -device e1000,netdev=net0 \ + -netdev user,id=net0 \ + -usb \ + -device usb-tablet \ + -display curses \ + "$@" diff --git a/vm/openbsd/run.sh b/vm/openbsd/run.sh deleted file mode 100755 index 69cbcca..0000000 --- a/vm/openbsd/run.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -set -e - -cd $(dirname -- "$0") - -if [ ! -f openbsd.iso ]; then - curl -L -o openbsd.iso https://cdn.openbsd.org/pub/OpenBSD/7.3/i386/cd73.iso -fi - -if [ ! -f openbsd.qcow2 ]; then - qemu-img create -f qcow2 openbsd.qcow2 20G -fi - -exec qemu-system-x86_64 \ - -enable-kvm \ - -cpu host \ - -hda openbsd.qcow2 \ - -cdrom openbsd.iso \ - -m 2G \ - -device e1000,netdev=net0 \ - -netdev user,id=net0 \ - -usb \ - -device usb-tablet \ - -nographic \ - "$@" diff --git a/vm/run.sh b/vm/run.sh new file mode 100755 index 0000000..70a796d --- /dev/null +++ b/vm/run.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +set -e + +VM_ROOT=$(dirname "$(realpath "$0")") +VM_NAME=$1 + +if [ ! -f "$VM_ROOT/$VM_NAME.sh" ]; then + echo "invalid vm name" >&2 + exit 1 +fi + +shift + +VM_CACHE=$HOME/.local/vm/cache/$VM_NAME +VM_DATA=$HOME/.local/vm/data/$VM_NAME +VM_TMP=$HOME/.local/vm/tmp/$VM_NAME + +rm -rf $VM_TMP +mkdir -p $VM_CACHE $VM_DATA $VM_TMP + +trap "exit 1" HUP INT PIPE QUIT TERM +trap "rm -rf $VM_TMP" EXIT + +. $VM_ROOT/$VM_NAME.sh diff --git a/vm/win11/run.sh b/vm/win11.sh index 195bbed..3e6410d 100755..100644 --- a/vm/win11/run.sh +++ b/vm/win11.sh @@ -1,18 +1,14 @@ -#!/bin/sh - -set -e - +: ${VM_CACHE:?} ${VM_DATA:?} ${VM_TMP:?} WIN11_ZIP_URL="https://aka.ms/windev_VM_virtualbox" -ROOT_PATH=$(cd; pwd)/vm/win11 -WIN11_ZIP_PATH=$ROOT_PATH/win11.zip -WIN11_IMG_PATH=$ROOT_PATH/win11.qcow2 -TMP_PATH=$ROOT_PATH/tmp -OVMF_PATH=$ROOT_PATH/OVMF.fd -TPM_PATH=$ROOT_PATH/tpm -INIT_ISO_PATH=$ROOT_PATH/init.iso -SHARE_PATH=$ROOT_PATH/share # \\10.0.2.4\qemu +WIN11_ZIP_PATH=$VM_CACHE/win11.zip +OVMF_PATH=$VM_CACHE/OVMF.fd +INIT_ISO_PATH=$VM_CACHE/init.iso + +WIN11_IMG_PATH=$VM_DATA/win11.qcow2 +TPM_PATH=$VM_DATA/tpm +SHARE_PATH=$VM_DATA/share # \\10.0.2.4\qemu SAVE= @@ -24,18 +20,17 @@ while getopts s flag; do done -mkdir -p $ROOT_PATH $SHARE_PATH +mkdir -p $SHARE_PATH if [ ! -f $WIN11_ZIP_PATH ]; then wget --show-progress -q -c -O $WIN11_ZIP_PATH $WIN11_ZIP_URL fi if [ ! -f $WIN11_IMG_PATH ]; then - rm -rf $TMP_PATH - mkdir -p $TMP_PATH - unzip -p $WIN11_ZIP_PATH *.ova | tar -x -C $TMP_PATH - qemu-img convert -p -c -f vmdk -O qcow2 $TMP_PATH/*.vmdk $WIN11_IMG_PATH - rm -rf $TMP_PATH + mkdir -p $VM_TMP/img + unzip -p $WIN11_ZIP_PATH *.ova | tar -x -C $VM_TMP/img + qemu-img convert -p -c -f vmdk -O qcow2 $VM_TMP/img/*.vmdk $WIN11_IMG_PATH + rm -rf $VM_TMP/img fi if [ ! -f $OVMF_PATH ]; then @@ -43,12 +38,11 @@ if [ ! -f $OVMF_PATH ]; then fi if [ ! -f $INIT_ISO_PATH ]; then - rm -rf $TMP_PATH - mkdir -p $TMP_PATH - cat > $TMP_PATH/init.bat << EOF + mkdir -p $VM_TMP/iso + cat > $VM_TMP/iso/init.bat << EOF powershell -executionpolicy bypass d:\\_init.ps1 EOF - cat > $TMP_PATH/_init.ps1 << EOF + cat > $VM_TMP/iso/_init.ps1 << EOF Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False Set-MpPreference -DisableRealtimeMonitoring \$true Set-Service -Name wuauserv -StartupType Disabled @@ -80,8 +74,8 @@ cmd.exe /C "pacman -Syu --noconfirm" cmd.exe /C "pacman -Syu --noconfirm" cmd.exe /C "pacman -Syu --noconfirm base-devel git mingw-w64-x86_64-toolchain socat" EOF - mkisofs -J -l -R -V "init" -iso-level 4 -o $INIT_ISO_PATH $TMP_PATH - rm -rf $TMP_PATH + mkisofs -J -l -R -V "init" -iso-level 4 -o $INIT_ISO_PATH $VM_TMP/iso + rm -rf $VM_TMP/iso fi if [ ! -z $SAVE ]; then |
