Skip to content

Instantly share code, notes, and snippets.

@wedi
Last active January 27, 2021 14:33
Show Gist options
  • Save wedi/cba7465ee8280c0e75f94d2ef024a82e to your computer and use it in GitHub Desktop.
Save wedi/cba7465ee8280c0e75f94d2ef024a82e to your computer and use it in GitHub Desktop.
Test Ubuntu nocloud autoinstaller with Virtualbox
#!/bin/sh
VM_NAME=UbuntuAutoinstall
UBUNTU_ISO="$PWD/ubuntu-groovy-live-server-amd64.iso"
UBUNTU_DOWNLOAD_URL=http://cdimage.ubuntu.com/ubuntu-server/daily-live/current/groovy-live-server-amd64.iso
set -eux
[[ ! -e "$UBUNTU_ISO" ]] && wget -O "$UBUNTU_ISO" $UBUNTU_DOWNLOAD_URL
mkdir -p ./seed_minimal
cat > ./seed_minimal/user-data << 'EOF'
#cloud-config
autoinstall:
version: 1
identity:
hostname: ubuntu-server
# ubuntu
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
username: ubuntu
refresh-installer:
channel: edge
update: yes
EOF
touch ./seed_minimal/meta-data
rm -f ./seed_minimal.iso
hdiutil makehybrid -o ./seed_minimal.iso -hfs -joliet -iso -default-volume-name cidata ./seed_minimal/
if vboxmanage showvminfo "$VM_NAME" >/dev/null 2>&1; then
[[ $(vboxmanage showvminfo "$VM_NAME" | grep -c 'running (since') -eq 1 ]] && vboxmanage controlvm "$VM_NAME" poweroff
sleep 5
vboxmanage unregistervm "$VM_NAME" --delete
fi
rm -rf "$PWD/$VM_NAME"
vboxmanage createvm --name "$VM_NAME" --ostype Ubuntu_64 --register --basefolder "$PWD"
vboxmanage modifyvm "$VM_NAME" --memory 1024 --audio none --graphicscontroller vmsvga --vram 16 --pae off
vboxmanage modifyvm "$VM_NAME" --nic1 bridged --bridgeadapter1 en0 --macaddress1 080011111111
vboxmanage modifyvm "$VM_NAME" --boot1 dvd --boot2 dvd --boot3 disk --boot4 none
vboxmanage storagectl "$VM_NAME" --name IDE --add ide --bootable on --controller PIIX4
vboxmanage storagectl "$VM_NAME" --name SATA --add sata --bootable on --controller IntelAhci
vboxmanage storageattach "$VM_NAME" --storagectl IDE --port 0 --device 0 --type dvddrive --medium "$UBUNTU_ISO"
vboxmanage storageattach "$VM_NAME" --storagectl IDE --port 0 --device 1 --type dvddrive --medium "$PWD/seed_minimal.iso"
VM_DISK_FILE="$PWD/$VM_NAME/sda1.vdi"
[[ -e "$VM_DISK_FILE" ]] && (vboxmanage closemedium disk "$VM_DISK_FILE" --delete || rm "$VM_DISK_FILE")
vboxmanage createmedium disk --filename $VM_DISK_FILE --size 10240 --format VDI
vboxmanage storageattach "$VM_NAME" --storagectl SATA --port 0 --device 0 --type hdd --medium "$VM_DISK_FILE"
vboxmanage showmediuminfo "$VM_DISK_FILE"
vboxmanage startvm "$VM_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment