Refactor
This commit is contained in:
2
packer/qemu/http/seed/meta-data
Normal file
2
packer/qemu/http/seed/meta-data
Normal file
@@ -0,0 +1,2 @@
|
||||
instance-id: "instance0"
|
||||
local-hostname: "localhost"
|
9
packer/qemu/http/seed/user-data
Normal file
9
packer/qemu/http/seed/user-data
Normal file
@@ -0,0 +1,9 @@
|
||||
#cloud-config
|
||||
|
||||
ssh_pwauth: true
|
||||
disable_root: false
|
||||
chpasswd: { list: ["root:toor"], expire: false }
|
||||
|
||||
runcmd:
|
||||
- printf '%s\n' 'PermitRootLogin yes' >> /etc/ssh/sshd_config
|
||||
- systemctl restart ssh.service
|
34
packer/qemu/start-vm.sh
Executable file
34
packer/qemu/start-vm.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
export LC_ALL=C
|
||||
|
||||
SRC_DIR=$(dirname "$(readlink -f "$0")")
|
||||
TMP_DIR=$(mktemp -d)
|
||||
trap 'rm -rf "${TMP_DIR:?}"' EXIT
|
||||
|
||||
CLOUDIMG_DISK=${SRC_DIR:?}/packer_output/wireguard.qcow2
|
||||
SNAPSHOT_DISK=${TMP_DIR:?}/cloudinit-snapshot.qcow2
|
||||
USERDATA_DISK=${TMP_DIR:?}/cloudinit-seed.img
|
||||
USERDATA_YAML=${TMP_DIR:?}/user-data
|
||||
|
||||
# Create a snapshot image to preserve the original cloud-image
|
||||
qemu-img create -b "${CLOUDIMG_DISK:?}" -f qcow2 "${SNAPSHOT_DISK:?}"
|
||||
qemu-img resize "${SNAPSHOT_DISK:?}" +2G
|
||||
|
||||
# Create a seed image with metadata using cloud-localds
|
||||
printf '%s\n' '#cloud-config' 'runcmd: ["ssh-import-id gh:hectorm"]' > "${USERDATA_YAML:?}"
|
||||
cloud-localds "${USERDATA_DISK:?}" "${USERDATA_YAML:?}"
|
||||
|
||||
# Remove keys from the known_hosts file
|
||||
ssh-keygen -R '[127.0.0.1]:2222'
|
||||
ssh-keygen -R '[localhost]:2222'
|
||||
|
||||
# Launch VM
|
||||
kvm \
|
||||
-smp 1 -m 512 \
|
||||
-nographic -serial mon:stdio \
|
||||
-device e1000,netdev=n0 \
|
||||
-netdev user,id=n0,hostfwd=tcp::2222-:22,hostfwd=udp::51820-:51820 \
|
||||
-drive file="${SNAPSHOT_DISK:?}",if=virtio,format=qcow2 \
|
||||
-drive file="${USERDATA_DISK:?}",if=virtio,format=raw
|
Reference in New Issue
Block a user