feat: add cloud-init and virt-customize method

This commit is contained in:
Matthieu Bessat 2024-06-21 11:28:42 +02:00
parent 32bf78edbe
commit 30c76bf9c5
17 changed files with 119 additions and 0 deletions

2
virt-customize_method/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.qcow2
vm

View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBeNeE0gk6mO0Bz9dDvKQrhA2Oo7x05FicCQJivxqIyi sandbox

View file

@ -0,0 +1,7 @@
# Initial setup of debian VM with virt-customize + netplan
This method consist of using the debian generic cloud image and just customizing it before first boot with the [virt-customize](https://man.archlinux.org/man/virt-customize.1.en) util.
Then for the network config, we will be using [netplan](https://netplan.readthedocs.io/en/stable/).

15
virt-customize_method/init.sh Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/sh
base="$(pwd)"
mkdir -p vm
cd vm
wget -N https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2
virt-customize \
--add ./debian-12-generic-amd64.qcow2 \
--root-password password:root \
--hostname "sandbox05" \
--firstboot-install "procps,psmisc,vim,net-tools,curl,dnsutils,file,tmux" \
--copy-in "$base/netplan:/etc" \
--copy-in "$base/.ssh:/root" \
--firstboot-command 'netplan apply && ssh-keygen -A && systemctl restart sshd'

View file

@ -0,0 +1,9 @@
network:
version: 2
ethernets:
all-en:
match:
name: "en*"
dhcp4: true
dhcp6: true

9
virt-customize_method/run.sh Executable file
View file

@ -0,0 +1,9 @@
cd vm
qemu-system-x86_64 \
-net nic \
-net user \
-machine accel=kvm \
-cpu host \
-m 512 \
-nographic \
-hda ./debian-12-generic-amd64.qcow2