Packer configuration for building RaspiOS Lite image with Cloud-Init and Netplan included for first-boot provisioning
-
Open latest release and download an image with required architecture.
-
(Optional) Download file with
.sha256
extension and runsha256sum --check raspios-cloudinit*.zip.sha256
to verify that downloaded image is intact. -
Extract
.img
file from downloaded zip. -
Run
lsblk -pdo name,tran,size,label
to find path to SD card that you intend for use. It should be simular to/dev/sda
and haveusb
transfer type. -
CAREFUL! (this step can overwrite data on any device)
sudo dd if={Extracted .img file} of={Path from previous step} conv=fsync bs=8M status=progress
- Open
boot
partition on SD card and editnetwork-config
anduser-data
for first boot setup. Syntax foruser-data
is documented at cloudinit.readthedocs.io and fornetwork-config
at netplan.io
- Add Hashicorp keys and repository to install packer:
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
- Add Ansible PPA for newest release
sudo add-apt-repository --yes --update ppa:ansible/ansible
- Install packer and ansible:
sudo apt-get update
sudo apt-get install -y packer ansible
- Add Hashicorp repository to install packer:
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
- Install packer and ansible:
sudo dnf install packer ansible-core ansible-collection-community-general
You are on your own, open PR if you want to add support for other platform
packer
ansible-core
ansible-collection-community-general
-
Make any changes in
group_vars/all.yml
for image settings. -
Make any needed changes in
./config
for cloud-init. -
Run
sudo packer build -var arch=arm64 .
(You can replace arch witharmhf
for 32bit version). Resulting image will be put into./output-raspios-cloudinit
directory.
Makefile includes simple script to flash and verify built image.
-
Run
make lsblk
to find name of SD Card, it should have an "usb" transfer type. -
CAREFUL! (this step can overwrite data on any device) run
sudo make flash SD_CARD=/dev/sd*
where "/dev/sd*" is a name from previous step