Skip to content

Commit

Permalink
custom autoinstall iso
Browse files Browse the repository at this point in the history
  • Loading branch information
johnko committed Jan 21, 2025
1 parent 0e55a4b commit 3868516
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bin/macos-multipass-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fi
[[ -z "$CPUS" ]] && CPUS=1
[[ -z "$MEMS" ]] && MEMS=1
[[ -z "$STOR" ]] && STOR=10
[[ -z "$NIC" ]] && NIC=$(ifconfig | grep -v '127.0.0.1' | grep -E "(^en|inet )" | grep -B1 'inet ' | grep '^en' | cut -d: -f1)
[[ -z "$NIC" ]] && NIC=$(ifconfig | grep -v '127.0.0.1' | grep -E "(^en|inet )" | grep -B1 'inet ' | grep '^en' | tail -n 1 | cut -d: -f1)
echo "ACTN=$ACTN"
echo "NAME=$NAME"
echo "ISO =$ISO"
Expand Down
38 changes: 32 additions & 6 deletions bin/macos-utm-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ Usage:
${0##*/} [create|destroy|info|list|ps|restart|start|stop|unmount-boot-iso] -n NAME [-i iso-name] [-c 1-4] [-m 1-8] [-s 10-60]
Example:
${0##*/} create -n test -i ubuntu-22 -c 1 -m 4 -s 40
${0##*/} start -n test
${0##*/} unmount-boot-iso -n test
ubuntu-container.sh
ubuntu-create-cloudinit-iso.sh
${0##*/} create -n test -i ubuntu-22.04 -c 1 -m 4 -s 20
${0##*/} start -n test
bash bin/vm/ubuntu-create-autoinstall-iso.sh
${0##*/} destroy -n test
${0##*/} create -n vm01 -i autoinstall-22.04 -c 1 -m 4 -s 20
${0##*/} start -n vm01
EOS
exit 1
}
Expand Down Expand Up @@ -85,7 +91,7 @@ CLOUD_INIT_ISO=$( find ${HOME}/iso -name 'cloudinit.iso' )
[[ -z "$CPUS" ]] && CPUS=1
[[ -z "$MEMS" ]] && MEMS=1
[[ -z "$STOR" ]] && STOR=10
[[ -z "$NIC" ]] && NIC=$(ifconfig | grep -v '127.0.0.1' | grep -E "(^en|inet )" | grep -B1 'inet ' | grep '^en' | cut -d: -f1)
[[ -z "$NIC" ]] && NIC=$(ifconfig | grep -v '127.0.0.1' | grep -E "(^en|inet )" | grep -B1 'inet ' | grep '^en' | tail -n 1 | cut -d: -f1)
echo "ACTN=$ACTN"
echo "NAME=$NAME"
echo "ISO =$ISO"
Expand Down Expand Up @@ -164,7 +170,7 @@ end tell
;;
info)
utmctl status $NAME
utmctl ip-address $NAME
# utmctl ip-address $NAME
;;
list)
utmctl list
Expand All @@ -179,7 +185,26 @@ end tell
start)
utmctl start $NAME
set +x
echo "REMINDER: add 'autoinstall' on the 'linux' boot line"
INSTALLED=false
osascript -e '
tell application "UTM"
set vm to virtual machine named "'$NAME'"
set config to configuration of vm
log config
end tell
' 2>&1 | grep -q "notes:installed" && INSTALLED=true
[[ "false" == "$INSTALLED" ]] && echo "REMINDER: add 'autoinstall' on the 'linux' boot line"
STOPPED=false
for i in {1..30} ; do
[[ "true" == "$STOPPED" ]] && continue
[[ "true" == "$INSTALLED" ]] && continue
sleep 60
utmctl status $NAME | grep -q stopped && STOPPED=true
done
if [[ "true" == "$STOPPED" ]] && [[ "false" == "$INSTALLED" ]] ; then
${0##*/} unmount-boot-iso -n $NAME
${0##*/} start -n $NAME
fi
;;
stop)
utmctl stop $NAME
Expand All @@ -191,6 +216,7 @@ end tell
tell application "UTM"
set vm to virtual machine named "'$NAME'"
set config to configuration of vm
set notes of config to "installed"
set cloudinit to POSIX file "'$CLOUD_INIT_ISO'"
set i to id of item 1 of drives of config
set item 1 of drives of config to {id:i, source:cloudinit}
Expand Down
8 changes: 4 additions & 4 deletions bin/ubuntu-create-cloudinit-iso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ UBUNTU_CONTAINER_ID=$($DOCKER_BIN ps | grep ubuntu:24.04 | cut -d' ' -f1)

$DOCKER_BIN exec $UBUNTU_CONTAINER_ID apt update
$DOCKER_BIN exec $UBUNTU_CONTAINER_ID apt install -y cloud-image-utils
$DOCKER_BIN exec $UBUNTU_CONTAINER_ID mkdir -p cidata
$DOCKER_BIN exec $UBUNTU_CONTAINER_ID touch ./cidata/meta-data
$DOCKER_BIN cp $(dirname $0)/vm/cloud-init.yaml $UBUNTU_CONTAINER_ID:./cidata/user-data
$DOCKER_BIN exec $UBUNTU_CONTAINER_ID bash -c "cd cidata && cloud-localds ../cloudinit.iso user-data meta-data"
$DOCKER_BIN exec $UBUNTU_CONTAINER_ID mkdir -p cloudinit
$DOCKER_BIN exec $UBUNTU_CONTAINER_ID touch ./cloudinit/meta-data
$DOCKER_BIN cp $(dirname $0)/vm/cloud-init.yaml $UBUNTU_CONTAINER_ID:./cloudinit/user-data
$DOCKER_BIN exec $UBUNTU_CONTAINER_ID bash -c "cd cloudinit && cloud-localds ../cloudinit.iso user-data meta-data"
$DOCKER_BIN cp $UBUNTU_CONTAINER_ID:./cloudinit.iso ${HOME}/iso/cloudinit.iso
12 changes: 6 additions & 6 deletions bin/vm/cloud-init.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ autoinstall:
updates: all
shutdown: poweroff
late-commands:
# set random hostname
- echo vm-$(openssl rand -hex 2) > /target/etc/hostname
# add ip address to TTY login screen
# crete base64 with:
# cat bin/ubuntu-tty-update.sh | gzip -c - | base64
Expand All @@ -24,13 +26,11 @@ autoinstall:
- echo 'H4sIACWwjGcAA3WOMRKCMBBF+5yCCwROkEJHClvRsWAoAqyyY9hgdqPk9mZkLK3/vPdfeyGUTh2Ah4CLoCcT+0gSC5FUxGW0AuoEz4gB2BDI24eH9uSQoBQb7iBqdxMIfzbVNhBeOECnzmkB4wl48pKVs0X6kvWKYhKwqlcYmsyJqbhHqrYQnUP0FlLylIVHYrHOdepqSWDcJzNHJ6gjQ/jdfgAt+l2E1wAAAA==' | base64 -d | zcat > /target/etc/systemd/system/ubuntu-tty-update.service
- curtin in-target -- chmod 644 /etc/systemd/system/ubuntu-tty-update.service
- curtin in-target -- systemctl enable ubuntu-tty-update.service
# # temp cronjob to update TTY login screen
# - echo '* * * * * root /sbin/ubuntu-tty-update.sh' > /target/etc/cron.d/update_issue
# - curtin in-target -- chmod 644 /etc/cron.d/update_issue
# extend logical volume
- curtin in-target -- lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
- curtin in-target -- resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
user-data:
disable_root: true # disable root user interactive login
users:
- name: lab
homedir: /home/lab
Expand All @@ -43,6 +43,8 @@ autoinstall:
- gh:johnko
sudo: ALL=(ALL) NOPASSWD:ALL
- name: ubuntu
# disable ubuntu interactive login via expire
expiredate: "2000-01-01"
homedir: /home/ubuntu
shell: /bin/bash
lock_passwd: true
Expand All @@ -54,6 +56,4 @@ autoinstall:
package_upgrade: true
packages:
- openssh-server
- docker.io
- docker-compose
ssh_pwauth: false
ssh_pwauth: false # disable ssh interactive password auth
23 changes: 23 additions & 0 deletions bin/vm/grub.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set timeout=5

loadfont unicode

set menu_color_normal=red/black
set menu_color_highlight=black/light-gray

menuentry "AutoInstall Ubuntu Server" {
set gfxpayload=keep
linux /casper/vmlinuz quiet autoinstall ---
initrd /casper/initrd
}
menuentry "Ubuntu Server with the HWE kernel" {
set gfxpayload=keep
linux /casper/hwe-vmlinuz quiet ---
initrd /casper/hwe-initrd
}
menuentry 'Boot from next volume' {
exit 1
}
menuentry 'UEFI Firmware Settings' {
fwsetup
}
12 changes: 12 additions & 0 deletions bin/vm/ubuntu-create-autoinstall-iso.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -eux

ssh vm sudo apt update
ssh vm sudo apt install -y git python3 python3-pip xorriso
ssh vm sudo rm -fr livefs-editor
ssh vm git clone https://github.com/mwhudson/livefs-editor
ssh vm sudo python3 -m pip install ./livefs-editor/
rsync -virchlmP $(dirname $0)/grub.cfg vm:/tmp/grub.cfg
rsync -virchlmP ${HOME}/iso/arm/ubuntu-22.04.5-live-server-arm64.iso vm:./ubuntu-22.04.5-live-server-arm64.iso
ssh vm sudo python3 -m livefs_edit ubuntu-22.04.5-live-server-arm64.iso autoinstall-22.04.5-live-server-arm64.iso --cp /tmp/grub.cfg new/iso/boot/grub/grub.cfg
rsync -virchlmP vm:./autoinstall-22.04.5-live-server-arm64.iso ${HOME}/iso/arm/autoinstall-22.04.5-live-server-arm64.iso

0 comments on commit 3868516

Please sign in to comment.