Last active
September 22, 2023 09:15
-
-
Save sdwilsh/7a2aa0dd5ea77507e7a2996225ae9138 to your computer and use it in GitHub Desktop.
Packer Config for Network Booting a Pi 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"variables": { | |
"eth0_ipv4": "", | |
"eth0_ipv6": "", | |
"eth0_gateway": "", | |
"eth0_dns": "", | |
"hostname": "", | |
"iscsi_initiator_iqn": "", | |
"iscsi_target_iqn": "", | |
"iscsi_target_ip": "", | |
"ntpd_servers": "", | |
"root_pub_key": "" | |
}, | |
"builders": [{ | |
"type": "arm-image", | |
"image_type": "raspberrypi", | |
"iso_url": "http://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2020-05-28/2020-05-27-raspios-buster-lite-armhf.zip", | |
"iso_checksum_type": "sha256", | |
"iso_checksum": "f5786604be4b41e292c5b3c711e2efa64b25a5b51869ea8313d58da0b46afc64" | |
}], | |
"provisioners": [ | |
{ | |
"type": "shell", | |
"environment_vars": [ | |
"DEBIAN_FRONTEND=noninteractive", | |
"DEBCONF_NONINTERACTIVE_SEEN=true" | |
], | |
"inline": [ | |
"echo 'tzdata tzdata/Areas select US' | debconf-set-selections", | |
"echo 'tzdata tzdata/Zones/US select Pacific' | debconf-set-selections", | |
"rm /etc/timezone", | |
"rm /etc/localtime", | |
"dpkg-reconfigure -f noninteractive tzdata" | |
] | |
}, | |
{ | |
"type": "shell", | |
"inline": [ | |
"apt update", | |
"apt full-upgrade -y" | |
] | |
}, | |
{ | |
"type": "shell", | |
"inline": [ | |
"echo 'Setting up network...'", | |
"echo interface eth0 >> /etc/dhcpcd.conf", | |
"echo static ip_address={{user `eth0_ipv4`}} >> /etc/dhcpcd.conf", | |
"echo static ip6_address={{user `eth0_ipv6`}} >> /etc/dhcpcd.conf", | |
"echo static routers={{user `eth0_gateway`}} >> /etc/dhcpcd.conf", | |
"echo static domain_name_servers={{user `eth0_dns`}} >> /etc/dhcpcd.conf" | |
] | |
}, | |
{ | |
"type": "shell", | |
"inline": [ | |
"echo 'Setting up hostname...'", | |
"echo {{user `hostname`}} > /etc/hostname", | |
"sed -i -r -e 's/(.*)raspberrypi(.*?)$/\\1{{user `hostname`}}\\2/g' /etc/hosts" | |
] | |
}, | |
{ | |
"type": "shell", | |
"inline": [ | |
"echo 'Setting up NTP...'", | |
"sed -i -r -e 's/#?NTP.*?$/NTP={{user `ntpd_servers`}}/g' /etc/systemd/timesyncd.conf" | |
] | |
}, | |
{ | |
"type": "shell", | |
"inline": [ | |
"echo 'Setting up sshd...'", | |
"touch /boot/ssh", | |
"sed -i -r -e 's/#?.*?PermitRootLogin.*?$/PermitRootLogin without-password/g' /etc/ssh/sshd_config", | |
"sed -i -r -e 's/#?.*?PasswordAuthentication.*?$/PasswordAuthentication no/g' /etc/ssh/sshd_config", | |
"mkdir -p /root/.ssh/", | |
"chmod 700 /root/.ssh", | |
"echo {{user `root_pub_key`}} >> /root/.ssh/authorized_keys", | |
"chmod 644 /root/.ssh/authorized_keys" | |
] | |
}, | |
{ | |
"type": "shell", | |
"inline": [ | |
"echo 'Disabling wifi...'", | |
"echo 'dtoverlay=disable-wifi' >> /boot/config.txt" | |
] | |
}, | |
{ | |
"type": "shell", | |
"inline": [ | |
"echo 'Disabling bluetooth...'", | |
"echo 'dtoverlay=disable-bt' >> /boot/config.txt" | |
] | |
}, | |
{ | |
"type": "shell", | |
"inline": [ | |
"echo 'Installing additional packages...'", | |
"apt install -y initramfs-tools open-iscsi vim" | |
] | |
}, | |
{ | |
"type": "shell", | |
"inline": [ | |
"echo 'Setting up /etc/iscsi/iscsi.initramfs...'", | |
"echo ISCSI_INITIATOR={{user `iscsi_initiator_iqn`}} > /etc/iscsi/iscsi.initramfs", | |
"echo ISCSI_TARGET={{user `iscsi_target_iqn`}} >> /etc/iscsi/iscsi.initramfs", | |
"echo ISCSI_TARGET_IP={{user `iscsi_target_ip`}} >> /etc/iscsi/iscsi.initramfs", | |
"echo 'Setting up /etc/iscsi/initiatorname.iscsi...'", | |
"echo InitiatorName={{user `iscsi_initiator_iqn`}} > /etc/iscsi/initiatorname.iscsi" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment