Skip to content

Instantly share code, notes, and snippets.

@olavmrk
Last active January 15, 2022 09:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save olavmrk/7a0e98802bab91d8b944 to your computer and use it in GitHub Desktop.
Save olavmrk/7a0e98802bab91d8b944 to your computer and use it in GitHub Desktop.
kvm boot debian from initramfs
#!/bin/bash
set -e
cd /tmp
mkdir testroot
debootstrap wheezy testroot http://http.debian.net/debian
chroot testroot env LC_ALL=C apt-get install --no-install-recommends linux-image-amd64
rm -rf testroot/var/cache/apt/*
ln -s bin/bash testroot/init
echo 'T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100' >>testroot/etc/inittab
passwd -R "$(pwd)"/testroot -d root
echo 'testroot' >testroot/etc/hostname
echo 'auto eth0' >>testroot/etc/network/interfaces
echo 'iface eth0 inet dhcp' >>testroot/etc/network/interfaces
( cd testroot && find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../testroot.gz )
kvm -m 1024 -kernel testroot/boot/vmlinuz-* -initrd testroot.gz -append 'console=ttyS0' -nographic -net nic,model=virtio -net user
# To continue with normal init, run:
# exec /sbin/init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment