install works

This commit is contained in:
nora 2024-03-09 22:25:58 +01:00
parent f6c4997f01
commit c27807e86f
2 changed files with 36 additions and 6 deletions

25
create-vms.sh Normal file → Executable file
View file

@ -2,25 +2,42 @@
set -eu set -eu
DIR="$(dirname "$(realpath "$0")")"
NAME="$1" NAME="$1"
mkdir -p tmp mkdir -p tmp
mkdir -p vm-state mkdir -p vm-state
IMG=debian-12-genericcloud-amd64.qcow2 # https://mop.koeln/blog/creating-a-local-debian-vm-using-cloud-init-and-libvirt/
# > DO NOT DOWNLOAD THE GENERICCLOUD IMAGE
IMG=debian-12-generic-amd64.qcow2
if ! [ -f "tmp/$IMG" ]; then if ! [ -f "tmp/$IMG" ]; then
curl -L -o "tmp/$IMG" https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2 curl -L -o "tmp/$IMG" https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2
fi fi
DISK="vm-state/$NAME.qcow2" DISK="vm-state/$NAME.qcow2"
cp "tmp/$IMG" "$DISK" cp "tmp/$IMG" "$DISK"
meta_data=$(mktemp)
cat >"$meta_data" <<EOF
instance-id: $NAME
local-hostname: $NAME
EOF
virt-install -n "$NAME" \ virt-install -n "$NAME" \
--os-variant=debian12 \ --os-variant=debian12 \
--ram=2048 --vcpus=2 \ --ram=2048 --vcpus=2 \
--import --disk "path=$DISK,bus=virtio" \ --import --disk "path=$DISK,bus=virtio" \
--network network=default,model=virtio \ --network network=default,model=virtio \
--graphics=none --rng /dev/urandom \ --graphics=none --rng /dev/urandom \
--cloud-init=user-data=user-data "--cloud-init=user-data=$DIR/user-data,meta-data=$meta_data" \
#--noautoconsole --noautoconsole
rm "$meta_data"
echo "Successfully created $NAME"
virsh domifaddr "$NAME"

View file

@ -1,2 +1,15 @@
ssh_authorized_keys: #cloud-config
chpasswd:
list: |
root: hello-world123
expire: false
users:
- name: chef
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
ssh_authorized_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG0n1ikUG9rYqobh7WpAyXrqZqxQoQ2zNJrFPj12gTpP nilsh@PC-Nils - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG0n1ikUG9rYqobh7WpAyXrqZqxQoQ2zNJrFPj12gTpP nilsh@PC-Nils
ssh_pwauth: true