-
Get a pristine image of the Alpine Linux 3.19 disk with cloud-init support.
wget https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.6-x86_64.iso
-
Add your SSH keys to
user-data
. You can find your SSH keys with:ssh-add -L
Copy them into the lines of
ssh-rsa ...
inuser-data
below. -
Create your own
user-data
file. Example is in another file in this gist. Also create ameta-data
file:echo "hostname: my-test-infra" > meta-data
-
Run the libvirt installer
virt-install --connect qemu:///session \ --osinfo alpinelinux3.19 \ --name my-test-infra \ --network user \ --location alpine-virt-3.19.6-x86_64.iso,kernel=boot/vmlinuz-virt,initrd=boot/initramfs-virt \ --extra-args console=ttyS0 \ --graphics none \ --console pty,target_type=serial \ --cloud-init meta-data=meta-data,user-data=user-data \ --noreboot
-
Start the guest:
virsh --connect qemu:///session start my-test-infra
-
Run a QEMU monitor command to forward the port.
virsh --connect qemu:///session qemu-monitor-command my-test-infra --hmp --cmd "hostfwd_add tcp::2222-:22"
-
SSH to the VM without saving the keys (you will keep rebuilding this host to test, right?)
ssh localhost -l root -p 2222 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
- Destroy the running instance
virsh --connect qemu:///session destroy my-test-infra
- Undefine the guest
virsh --connect qemu:///session undefine my-test-infra --storage vda