Skip to content

Instantly share code, notes, and snippets.

@teknoraver
Created September 24, 2021 15:54
Show Gist options
  • Save teknoraver/80082ad7bac1a5e878808dc743e5e272 to your computer and use it in GitHub Desktop.
Save teknoraver/80082ad7bac1a5e878808dc743e5e272 to your computer and use it in GitHub Desktop.
Install Debian via a serial console
#!/bin/sh
[ $# -eq 2 ] || exec echo "Usage: $0 <install.iso> <disk.img>"
for k in qemu kvm qemu-kvm; do
which $k 2>/dev/null >/dev/null && kvm=$k && break
done
[ -n "$kvm" ] || exec echo "error: KVM not found!"
cores=$(nproc)
[ $cores -gt 4 ] && cpus="-smp cpus=$((cores / 2))"
root=/tmp/${0##*/}.$$
mkdir $root
sudo mount -r -oloop "$1" $root
$kvm -machine q35,accel=kvm -m 512 -no-reboot -nographic $cpus \
-boot d -cdrom "$1" \
-drive "file=$2,media=disk,format=raw,if=virtio" \
-netdev user,id=hostnet0 \
-device virtio-net-pci,netdev=hostnet0 \
-kernel $root/install.*/vmlinuz -initrd $root/install.*/initrd.gz -append console=ttyS0
sudo umount $root
rmdir $root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment