Skip to content

Commit

Permalink
pi-gen-sources: simplify and update for building bookworm image
Browse files Browse the repository at this point in the history
  • Loading branch information
marcone committed Dec 15, 2024
1 parent 657f17a commit d31b938
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 97 deletions.

This file was deleted.

10 changes: 0 additions & 10 deletions pi-gen-sources/00-teslausb-tweaks/00-patches/02-config-update.diff

This file was deleted.

2 changes: 0 additions & 2 deletions pi-gen-sources/00-teslausb-tweaks/00-patches/series

This file was deleted.

79 changes: 14 additions & 65 deletions pi-gen-sources/00-teslausb-tweaks/00-run.sh
Original file line number Diff line number Diff line change
@@ -1,74 +1,23 @@
#!/bin/bash -e
touch "${ROOTFS_DIR}/boot/ssh"
install -m 666 files/userconf.txt "${ROOTFS_DIR}/boot/"
install -m 755 files/rc.local "${ROOTFS_DIR}/etc/"
install -m 666 files/teslausb_setup_variables.conf.sample "${ROOTFS_DIR}/boot/teslausb_setup_variables.conf"
install -m 666 files/wpa_supplicant.conf.sample "${ROOTFS_DIR}/boot/"
install -m 666 files/run_once "${ROOTFS_DIR}/boot/"
install -m 666 files/teslausb_setup_variables.conf.sample "${ROOTFS_DIR}/boot/firmware/teslausb_setup_variables.conf"
install -m 666 files/wpa_supplicant.conf.sample "${ROOTFS_DIR}/boot/firmware"
install -m 666 files/run_once "${ROOTFS_DIR}/boot/firmware"
install -d "${ROOTFS_DIR}/root/bin"

# work around shortcoming in pi-gen that causes ca-certificates to be
# misconfigured
on_chroot << EOF
/usr/bin/c_rehash /etc/ssl/certs/
EOF
# ensure dwc2 module is loaded
echo "dtoverlay=dwc2" >> "${ROOTFS_DIR}/boot/firmware/config.txt"

# remove unwanted packages, disable unwanted services, and disable swap
on_chroot << EOF
apt-get remove -y --force-yes --purge triggerhappy bluez alsa-utils
rm -rf /boot/kernel8.img
rm -rf /lib/modules/*-v8+
echo "pi ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/pi-nopassword
EOF

# disable various interactive setup dialogs
on_chroot << EOF
apt-get remove -y --force-yes --purge triggerhappy bluez userconf-pi dphys-swapfile firmware-libertas firmware-realtek firmware-atheros mkvtoolnix
apt-get -y --force-yes autoremove
systemctl disable keyboard-setup
systemctl disable userconfig
systemctl disable resize2fs_once
systemctl disable dpkg-db-backup
update-rc.d resize2fs_once remove
rm /etc/init.d/resize2fs_once
rm /usr/share/initramfs-tools/scripts/local-premount/firstboot
update-initramfs -u
EOF

# Below here is the rest of the stage2 (builds the Stretch lite image)
# run script commented out just to give guidance on things that can be done.

# install -m 755 files/teslausb_setup_scripts/bin/* "${ROOTFS_DIR}/root/bin/"
# install -d "${ROOTFS_DIR}/root/bin/tmp"
# install -m 755 files/teslausb_setup_scripts/tmp/* "${ROOTFS_DIR}/root/bin/tmp/"

# on_chroot << EOF
# systemctl disable hwclock.sh
# systemctl disable nfs-common
# systemctl disable rpcbind
# systemctl disable ssh
# systemctl enable regenerate_ssh_host_keys
# EOF

# if [ "${USE_QEMU}" = "1" ]; then
# echo "enter QEMU mode"
# install -m 644 files/90-qemu.rules "${ROOTFS_DIR}/etc/udev/rules.d/"
# on_chroot << EOF
# systemctl disable resize2fs_once
# EOF
# echo "leaving QEMU mode"
# else
# on_chroot << EOF
# systemctl enable resize2fs_once
# EOF
# fi

# on_chroot << \EOF
# for GRP in input spi i2c gpio; do
# groupadd -f -r "$GRP"
# done
# for GRP in adm dialout cdrom audio users sudo video games plugdev input gpio spi i2c netdev; do
# adduser pi $GRP
# done
# EOF

# on_chroot << EOF
# setupcon --force --save-only -v
# EOF

# on_chroot << EOF
# usermod --pass='*' root
# EOF

# rm -f "${ROOTFS_DIR}/etc/ssh/"ssh_host_*_key*
1 change: 0 additions & 1 deletion pi-gen-sources/00-teslausb-tweaks/files/userconf.txt

This file was deleted.

18 changes: 4 additions & 14 deletions pi-gen-sources/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@ To build a ready to flash one-step setup image for CIFS, do the following:

1. Clone pi-gen from https://github.com/RPi-Distro/pi-gen
2. Follow the instructions in the pi-gen readme to install the required dependencies
3. In the pi-gen folder, run:
```
echo 'IMG_NAME=teslausb' > config
echo 'HOSTNAME=teslausb' >> config
echo 'STAGE_LIST="stage0 stage1 stage2 stage_teslausb"' >> config
rm -rf stage2/EXPORT_NOOBS stage2/EXPORT_IMAGE
mkdir stage_teslausb
touch stage_teslausb/EXPORT_IMAGE
cp stage2/prerun.sh stage_teslausb/prerun.sh
```
4. Copy teslausb/pi-gen-sources/00-teslausb-tweaks to the pi-gen/stage_teslausb folder
5. Adjust `DATA_SIZE` in scripts/qcow2_handling to have more free space on the root partition. For the prebuilt image, it was hardcoded to 2 GB by inserting `let DATA_SIZE=2*1024*1024*1024/$BLOCK_SIZE` before the call to `resize2fs -p`.
6. Run `build.sh` or `build-docker.sh`, depending on how you configured pi-gen to build the image
7. Sit back and relax, this could take a while (for reference, on a dual-core 2.6 Ghz Intel Core i3 and 50 Mbps internet connection, it took under an hour)
3. From the RPi-Distro/pi-gen folder, run the `prepare.sh` script from TeslaUSB's pi-gen-sources folder
4. If needed, adjust ROOT_MARGIN or ROOT_PART_SIZE in pi-gen/export-image/prerun.sh to ensure sufficient free space left on the root partition of the generated image
5. Run `build.sh` or `build-docker.sh`, depending on how you want to build the image. The Docker build is recommended
6. Sit back and relax, this could take a while (for reference, on a dual-core 2.6 Ghz Intel Core i3 and 50 Mbps internet connection, it took under an hour)
If all went well, the image will be in the `deploy` folder. Use Raspberry Pi Imager or a similar tool to flash it.
14 changes: 14 additions & 0 deletions pi-gen-sources/pi-gen-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
IMG_NAME=teslausb
PI_GEN_RELEASE=teslausb-prebuilt
LOCALE_DEFAULT=en_US.UTF-8
TARGET_HOSTNAME=teslausb
KEYBOARD_KEYMAP=us
KEYBOARD_LAYOUT="English (US)"
TIMEZONE_DEFAULT="America/Los_Angeles"
FIRST_USER_NAME=pi
FIRST_USER_PASS=raspberry
DISABLE_FIRST_BOOT_USER_RENAME=1
WPA_COUNTRY=US
ENABLE_SSH=1
STAGE_LIST="stage0 stage1 stage2 stage_teslausb"
RELEASE=bookworm
21 changes: 21 additions & 0 deletions pi-gen-sources/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -eu

SRC=$(dirname $(readlink -f $0))
DEST=$(readlink -f .)

if [[ "$DEST" != */pi-gen ]]
then
echo "$0 should be called from the RPi-Distro pi-gen folder"
exit 1
fi

cp "$SRC/pi-gen-config" config
rm -rf stage2/EXPORT_NOOBS stage2/EXPORT_IMAGE export-image/01-user-rename/00-packages
mkdir -p stage_teslausb
touch stage_teslausb/EXPORT_IMAGE
cp stage2/prerun.sh stage_teslausb/prerun.sh
cp -r "$SRC/00-teslausb-tweaks" stage_teslausb

echo 'Build config set. Now use "./build.sh" or "./build-docker.sh" to build the TeslaUSB image.'


0 comments on commit d31b938

Please sign in to comment.