Created
April 17, 2026 22:22
-
-
Save peterhellberg/bc4e267276e1cd96534851b353b0a54a to your computer and use it in GitHub Desktop.
Run script for my alpine VM created with https://github.com/keygenqt/skill-qemu-alpine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| set -eu | |
| PORT="2224" | |
| SCRIPT="$0" | |
| while [ -L "$SCRIPT" ]; do | |
| DIR="$(cd -P "$(dirname "$SCRIPT")" && pwd)" | |
| SCRIPT="$(readlink "$SCRIPT")" | |
| case "$SCRIPT" in | |
| /*) ;; # absolute | |
| *) SCRIPT="$DIR/$SCRIPT" ;; | |
| esac | |
| done | |
| SCRIPT_DIR="$(cd -P "$(dirname "$SCRIPT")" && pwd)" | |
| DISK_NAME="$SCRIPT_DIR/alpine.x86_64.qcow2" | |
| [ -f "$DISK_NAME" ] || { | |
| echo "Disk not found: $DISK_NAME" | |
| exit 1 | |
| } | |
| if nc -z localhost "$PORT" 2>/dev/null; then | |
| echo "VM already running → connecting via SSH" | |
| exec ssh -p "$PORT" localhost | |
| fi | |
| echo "Starting the VM..." | |
| qemu-system-x86_64 -enable-kvm \ | |
| -machine pc \ | |
| -cpu host -smp cores=4 \ | |
| -m 8192 \ | |
| -display none \ | |
| -daemonize \ | |
| -drive if=virtio,id=hd,format=qcow2,file=$DISK_NAME \ | |
| -nic user,hostfwd=tcp::$PORT-:22,model=virtio \ | |
| -device virtio-rng-pci \ | |
| -rtc base=utc,clock=host | |
| echo "Waiting for SSH..." | |
| until ssh -p "$PORT" \ | |
| -o ConnectTimeout=1 \ | |
| -o StrictHostKeyChecking=no \ | |
| -o UserKnownHostsFile=/dev/null \ | |
| localhost true 2>/dev/null; do | |
| sleep 0.3 | |
| done | |
| echo "Connecting..." | |
| ssh -p $PORT localhost |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The disk image was created via the
install.shfound at https://github.com/keygenqt/skill-qemu-alpine/tree/main/x86_64