Skip to content

Instantly share code, notes, and snippets.

@arif-ali
Last active November 13, 2020 13:46
Show Gist options
  • Save arif-ali/2828585c0139612ad6edf026167d68e9 to your computer and use it in GitHub Desktop.
Save arif-ali/2828585c0139612ad6edf026167d68e9 to your computer and use it in GitHub Desktop.
user_data cloud-init file for 20.10 raspi image
#cloud-config
ssh_import_id:
- lp:arif-ali
## Update apt database and upgrade packages on first boot
package_update: true
package_upgrade: true
## Install additional packages on first boot
packages:
- openssh-server
- snapd
- salt-minion
- byobu
- rpi-eeprom
- aptitude
- ubuntu-minimal
- ubuntu-release-upgrader-core
- git
## Write arbitrary files to the file-system (including binaries!)
write_files:
- path: /root/reset.sh
content: |
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
export APT_LISTCHANGES_FRONTEND=none
hold_apps="openssh-server snapd salt-minion byobu rsync ubuntu-release-upgrader-core git rpi-eeprom"
sudo -E apt-get update
sudo -E aptitude markauto '~i!~nubuntu-minimal'
sudo -E apt-mark hold ${hold_apps}
sudo -E apt-get -yq autoremove
dpkg -l | grep ^rc | awk '{print $2}' | xargs -i sudo -E dpkg --force-all -P "{}"
sudo -E apt-mark unhold ${hold_apps}
sudo -E apt-get -y install ${hold_apps}
sudo -E apt-get update
sudo -E apt-get -y upgrade
#sudo -E salt-call state.highstate
permissions: '0755'
owner: root:root
runcmd:
- [ /root/reset.sh ]
swap:
filename: /swap.img
size: 8589934592
@arif-ali
Copy link
Author

mkdir mnt
cp ubuntu-20.10-preinstalled-server-arm64+raspi.img ubuntu-20.10-preinstalled-server-arm64+raspi-custom.img
mount -o loop,offset=1048576 ubuntu-20.10-preinstalled-server-arm64+raspi-custom.img mnt

Now update mnt/user-data with the above contents, and enter your SD card to PC/laptop. My device was /dev/sdb

umount mnt
dd if=ubuntu-20.10-preinstalled-server-arm64+raspi-custom.img of=/dev/sdb bs=1M

Remove SD card from PC, and add to rpi4, and the cloud-init will do the job that was required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment