Skip to content

Commit

Permalink
Support Bookworm Raspberry Pi OS's /boot/firmware directory
Browse files Browse the repository at this point in the history
The DOS partition of a Raspberry Pi OS install used to be mounted at /boot,
but is mounted at /boot/firmware since Bookworm. Since this is where
TeslaUSB expects the config file to be, and where it puts the setup log and
various marker files, make /teslausb a symlink to either /boot/firmware (for
Bookworm-based Raspberry Pi OS) or /boot (for older Raspberry Pi OS and other
distributions), and access all the files through this symlink.
  • Loading branch information
marcone committed Nov 30, 2024
1 parent 49df42f commit 562be33
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 74 deletions.
14 changes: 7 additions & 7 deletions doc/OneStepSetup.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The Pi should be available for `ssh` at `[email protected]`, over Wifi (if autom
If plugged into just a power source, or your car, give it a few minutes until the LED starts pulsing steadily which means the archive loop is running and you're good to go.
You should see in `/boot` the `TESLAUSB_SETUP_FINISHED` and `WIFI_ENABLED` files as markers of headless setup success as well.
You should see in `/teslausb` the `TESLAUSB_SETUP_FINISHED` and `WIFI_ENABLED` files as markers of headless setup success as well.
## Security
Expand All @@ -96,16 +96,16 @@ Given that the Pi contains sensitive information like your home wifi password an
### Troubleshooting
- If everything seems to be working, but you still don't see the USB drive(s) either on your local machine, or in the car, check that you are indeed using a USB data cable, and not a charge-only cable. Also ensure you are plugged into the USB port on the Raspberry PI, and not the power port.
- `ssh` to `[email protected]` (assuming Wifi came up, or your Pi is connected to your computer via USB) and look at the `/boot/teslausb-headless-setup.log`.
- `ssh` to `[email protected]` (assuming Wifi came up, or your Pi is connected to your computer via USB) and look at the `/teslausb/teslausb-headless-setup.log`.
- Try `sudo -i` and then run `/etc/rc.local`. The scripts are fairly resilient to restarting and not re-running previous steps, and will tell you about progress/failure.
- If Wifi didn't come up:
- Double-check the SSID and WIFIPASS variables in `teslausb_setup_variables.conf`, and remove `/boot/WIFI_ENABLED`, then booting the SD in your Pi to retry automatic Wifi setup.
- Double-check the SSID and WIFIPASS variables in `teslausb_setup_variables.conf`, and remove `WIFI_ENABLED`, then boot the SD in your Pi to retry automatic Wifi setup.
- If you are using a WiFi network with a _hidden SSID_, edit `/boot/wpa_supplicant.conf.sample` and uncomment the line `scan_ssid=1` in the `network={...}` block.
- If still no go, re-run `/etc/rc.local`
- If all else fails, copy `/boot/wpa_supplicant.conf.sample` to `/boot/wpa_supplicant.conf` and edit out the `TEMP` variables to your desired settings.
- Note: if you get an error about `read-only filesystem`, you may have to `sudo -i` and run `/root/bin/remountfs_rw`.
- Try `date` to ensure the system clock is set correctly. If it is too far off, SSL/TLS Authentication will fail, preventing the installation from completing. You can set the date like `date -s "2 JAN 2022 15:04:05"`
- Try `tail -f /boot/teslausb-headless-setup.log` to watch the logs during installation, which may shed some light on any errors occurring. Press `Ctrl-C` to stop watching logs.
- Try `tail -f /teslausb/teslausb-headless-setup.log` to watch the logs during installation, which may shed some light on any errors occurring. Press `Ctrl-C` to stop watching logs.
More troubleshooting information in the [wiki](https://github.com/marcone/teslausb/wiki/Troubleshooting)
Expand All @@ -115,9 +115,9 @@ More troubleshooting information in the [wiki](https://github.com/marcone/teslau
When the Pi boots the first time:
- A `/boot/teslausb-headless-setup.log` file will be created and stages logged.
- Marker files will be created in `boot` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress.
- Wifi is detected by looking for `/boot/WIFI_ENABLED` and if not, creates the `wpa_supplicant.conf` file in place, using `SSID` and `WIFIPASS` from `teslausb_setup_variables.conf` and reboots.
- A `/teslausb/teslausb-headless-setup.log` file will be created and stages logged.
- Marker files will be created in `teslausb` like `TESLA_USB_SETUP_STARTED` and `TESLA_USB_SETUP_FINISHED` to track progress.
- Wifi is detected by looking for `/teslausb/WIFI_ENABLED` and if not, creates the `wpa_supplicant.conf` file in place, using `SSID` and `WIFIPASS` from `teslausb_setup_variables.conf` and reboots.
- The Pi LED will flash patterns (2, 3, 4, 5) as it gets to each stage (labeled in the setup-teslausb script).
- After the final stage and reboot the LED will go back to normal. Remember, the step to remount the filesystem takes a few minutes.
Expand Down
47 changes: 29 additions & 18 deletions pi-gen-sources/00-teslausb-tweaks/files/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,26 @@ then
printf "My IP address is %s\n" "$_IP"
fi

if [ -f /boot/run_once ]
if [ ! -L /teslausb ]
then
cp /boot/run_once /tmp/
rm -rf /teslausb
if [ -d /boot/firmware ] && findmnt --fstab /boot/firmware &> /dev/null
then
ln -s /boot/firmware /teslausb
else
ln -s /boot /teslausb
fi
fi

if [ -f /teslausb/run_once ]
then
cp /teslausb/run_once /tmp/
chmod +x /tmp/run_once
/tmp/run_once || echo "run_once failed"
mv /boot/run_once /boot/ran_once || true
mv /teslausb/run_once /teslausb/ran_once || true
fi

SETUP_LOGFILE=/boot/teslausb-headless-setup.log
SETUP_LOGFILE=/teslausb/teslausb-headless-setup.log

function write_all_leds {
for led in /sys/class/leds/*
Expand Down Expand Up @@ -79,17 +90,17 @@ function enable_wifi () {
setup_progress "Detecting whether to update wpa_supplicant.conf"
if [[ -n "$SSID" ]] && [[ -n "$WIFIPASS" ]]
then
if [ ! -e /boot/WIFI_ENABLED ]
if [ ! -e /teslausb/WIFI_ENABLED ]
then
if [ -e /root/bin/remountfs_rw ]
then
/root/bin/remountfs_rw
fi
setup_progress "Wifi variables specified, and no /boot/WIFI_ENABLED. Building wpa_supplicant.conf."
cp /boot/wpa_supplicant.conf.sample /boot/wpa_supplicant.conf
sed -i -e "sTEMPSSID${SSID}g" /boot/wpa_supplicant.conf
sed -i -e "sTEMPPASS${WIFIPASS}g" /boot/wpa_supplicant.conf
cp /boot/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
setup_progress "Wifi variables specified, and no /teslausb/WIFI_ENABLED. Building wpa_supplicant.conf."
cp /teslausb/wpa_supplicant.conf.sample /teslausb/wpa_supplicant.conf
sed -i -e "sTEMPSSID${SSID}g" /teslausb/wpa_supplicant.conf
sed -i -e "sTEMPPASS${WIFIPASS}g" /teslausb/wpa_supplicant.conf
cp /teslausb/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf

# set the host name now if possible, so it's effective immediately after the reboot
local old_host_name
Expand All @@ -108,7 +119,7 @@ function enable_wifi () {
done
systemctl enable ssh

touch /boot/WIFI_ENABLED
touch /teslausb/WIFI_ENABLED
setup_progress "Rebooting..."
exec reboot
fi
Expand All @@ -134,19 +145,19 @@ EOF
source "$1"
}

if [ -e "/boot/teslausb_setup_variables.conf" ]
if [ -e "/teslausb/teslausb_setup_variables.conf" ]
then
if [ -e /root/bin/remountfs_rw ]
then
/root/bin/remountfs_rw
fi
mv /boot/teslausb_setup_variables.conf /root/
mv /teslausb/teslausb_setup_variables.conf /root/
dos2unix /root/teslausb_setup_variables.conf
fi
if [ -e "/root/teslausb_setup_variables.conf" ]
then
safesource /root/teslausb_setup_variables.conf
elif [ -e "/boot/teslausb_setup_variables.conf.sample" ]
elif [ -e "/teslausb/teslausb_setup_variables.conf.sample" ]
then
setup_progress "no config file found, but sample file is present."
else
Expand All @@ -159,19 +170,19 @@ enable_wifi

# This begins the Headless Setup loop
# If the FINISHED file does not exist then we start setup. Otherwise passes on to normal loop
if [ ! -e "/boot/TESLAUSB_SETUP_FINISHED" ]
if [ ! -e "/teslausb/TESLAUSB_SETUP_FINISHED" ]
then
if [ -e /root/bin/remountfs_rw ]
then
/root/bin/remountfs_rw
fi
touch "/boot/TESLAUSB_SETUP_STARTED"
touch "/teslausb/TESLAUSB_SETUP_STARTED"

# Grab the setup variables. Should still be there since setup isn't finished.
# This is a double check to cover various scenarios of mixed headless/not headless setup attempts
if [ -e "/boot/teslausb_setup_variables.conf" ] && [ ! -e "/root/teslausb_setup_variables.conf" ]
if [ -e "/teslausb/teslausb_setup_variables.conf" ] && [ ! -e "/root/teslausb_setup_variables.conf" ]
then
mv /boot/teslausb_setup_variables.conf /root/
mv /teslausb/teslausb_setup_variables.conf /root/
dos2unix /root/teslausb_setup_variables.conf
fi
if [ -e "/root/teslausb_setup_variables.conf" ]
Expand Down
12 changes: 7 additions & 5 deletions run/remountfs_rw
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash

echo "Remounting / as read/write"
echo "Making root partition writeable"
mount / -o remount,rw
echo "Remounting /boot as read/write"
mount /boot -o remount,rw
echo "Done. Make any changes needed, and reboot the Pi when ready."
echo "Filesystems / and /boot will be mounted as read only after reboot."

if findmnt /teslausb > /dev/null
then
echo "Making boot/firmware partition writeable"
mount /teslausb -o remount,rw
fi
echo "Done. Make any changes needed, and reboot the Pi when ready."
44 changes: 25 additions & 19 deletions setup/generic/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ then
exit 1
fi

if [ ! -L /teslausb ]
then
rm -rf /teslausb
if [ -d /boot/firmware ] && findmnt --fstab /boot/firmware &> /dev/null
then
ln -s /boot/firmware /teslausb
else
ln -s /boot /teslausb
fi
fi

function error_exit {
echo "STOP: $*"
exit 1
Expand Down Expand Up @@ -88,23 +99,18 @@ then
chmod a+x /etc/rc.local

# The user should have configured networking manually, so disable wifi setup
touch /boot/WIFI_ENABLED
touch /teslausb/WIFI_ENABLED

if [ ! -e "/boot/initrd.img-$(uname -r)" ]
then
# This device did not boot using an initramfs. If we're running
# Raspberry Pi OS, we can switch it over to using initramfs first,
# then revert back after.
ISSUE=/boot/issue.txt
if [ -f /boot/firmware/issue.txt ]
then
ISSUE=/boot/firmware/issue.txt
fi
if [ -f "$ISSUE" ] && grep -q Raspberry "$ISSUE" && [ -e /boot/config.txt ]
if [ -f /etc/os-release ] && grep -q Raspbian /etc/os-release && [ -e /teslausb/config.txt ]
then
echo "Temporarily switching Rasspberry Pi OS to use initramfs"
update-initramfs -c -k "$(uname -r)"
echo "initramfs initrd.img-$(uname -r) followkernel # TESLAUSB-REMOVE" >> /boot/config.txt
echo "initramfs initrd.img-$(uname -r) followkernel # TESLAUSB-REMOVE" >> /teslausb/config.txt
else
error_exit "can't automatically shrink root partition for this OS, please shrink it manually before proceeding"
fi
Expand All @@ -127,10 +133,10 @@ then

echo "${rootpartstartsector},${fsnumsectors}" | sfdisk --force "${rootdev}" -N "${partnum}"

if [ -e /boot/config.txt ] && grep -q TESLAUSB-REMOVE /boot/config.txt
if [ -e /teslausb/config.txt ] && grep -q TESLAUSB-REMOVE /teslausb/config.txt
then
# switch Raspberry Pi OS back to not using initramfs
sed -i '/TESLAUSB-REMOVE/d' /boot/config.txt
sed -i '/TESLAUSB-REMOVE/d' /teslausb/config.txt
rm -rf "/boot/initrd.img-$(uname -r)"
else
# restore initramfs without the resize code that debian-resizefs.sh added
Expand All @@ -142,18 +148,18 @@ then
fi

# Copy the sample config file from github
if [ ! -e /boot/teslausb_setup_variables.conf ] && [ ! -e /root/teslausb_setup_variables.conf ]
if [ ! -e /teslausb/teslausb_setup_variables.conf ] && [ ! -e /root/teslausb_setup_variables.conf ]
then
while ! curl -o /boot/teslausb_setup_variables.conf https://raw.githubusercontent.com/marcone/teslausb/main-dev/pi-gen-sources/00-teslausb-tweaks/files/teslausb_setup_variables.conf.sample
while ! curl -o /teslausb/teslausb_setup_variables.conf https://raw.githubusercontent.com/marcone/teslausb/main-dev/pi-gen-sources/00-teslausb-tweaks/files/teslausb_setup_variables.conf.sample
do
sleep 1
done
fi

# and the wifi config template
if [ ! -e /boot/wpa_supplicant.conf.sample ]
if [ ! -e /teslausb/wpa_supplicant.conf.sample ]
then
while ! curl -o /boot/wpa_supplicant.conf.sample https://raw.githubusercontent.com/marcone/teslausb/main-dev/pi-gen-sources/00-teslausb-tweaks/files/wpa_supplicant.conf.sample
while ! curl -o /teslausb/wpa_supplicant.conf.sample https://raw.githubusercontent.com/marcone/teslausb/main-dev/pi-gen-sources/00-teslausb-tweaks/files/wpa_supplicant.conf.sample
do
sleep 1
done
Expand Down Expand Up @@ -196,7 +202,7 @@ then
if [ ! -e "/home/$DEFUSER/.bashrc" ] || ! grep -q "SETUP_FINISHED" "/home/$DEFUSER/.bashrc"
then
cat <<- EOF >> "/home/$DEFUSER/.bashrc"
if [ ! -e /boot/TESLAUSB_SETUP_FINISHED ]
if [ ! -e /teslausb/TESLAUSB_SETUP_FINISHED ]
then
echo "+-------------------------------------------+"
echo "| To continue teslausb setup, run 'sudo -i' |"
Expand All @@ -210,13 +216,13 @@ fi
if ! grep -q "SETUP_FINISHED" /root/.bashrc
then
cat <<- EOF >> /root/.bashrc
if [ ! -e /boot/TESLAUSB_SETUP_FINISHED ]
if [ ! -e /teslausb/TESLAUSB_SETUP_FINISHED ]
then
echo "+------------------------------------------------------------------------+"
echo "| To continue teslausb setup, edit the file |"
echo "| /boot/teslausb_setup_variables.conf with your favorite |"
echo "| editor, e.g. 'nano /boot/teslausb_setup_variables.conf' and fill in |"
echo "| the required variables. Instructions are in the file, and at |"
echo "| /teslausb/teslausb_setup_variables.conf with your favorite |"
echo "| editor, e.g. 'nano /teslausb/teslausb_setup_variables.conf' and fill |"
echo "| in the required variables. Instructions are in the file, and at |"
echo "| https://github.com/marcone/teslausb/blob/main-dev/doc/OneStepSetup.md |"
echo "| (though ignore the Raspberry Pi specific bits about flashing and |"
echo "| mounting the sd card on a PC) |"
Expand Down
2 changes: 1 addition & 1 deletion setup/pi/configure-web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ umount /var/www/html/fs/LightShow &> /dev/null || true
umount /var/www/html/fs/Boombox &> /dev/null || true
find /var/www/html -mount \( -type f -o -type l \) -print0 | xargs -0 rm
cp -r "$SOURCE_DIR/teslausb-www/html" /var/www/
ln -sf /boot/teslausb-headless-setup.log /var/www/html/
ln -sf /teslausb/teslausb-headless-setup.log /var/www/html/
ln -sf /mutable/archiveloop.log /var/www/html/
ln -sf /tmp/diagnostics.txt /var/www/html/
mkdir -p /var/www/html/TeslaCam
Expand Down
26 changes: 16 additions & 10 deletions setup/pi/envsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ then
exit 1
fi

if [ ! -L /teslausb ]
then
mount / -o remount,rw
rm -rf /teslausb
if [ -d /boot/firmware ] && findmnt --fstab /boot/firmware &> /dev/null
then
ln -s /boot/firmware /teslausb
else
ln -s /boot /teslausb
fi
fi

function safesource {
cat <<EOF > /tmp/checksetupconf
#!/bin/bash -eu
Expand Down Expand Up @@ -182,22 +194,16 @@ then
mkdir -p "$STATUSLED"
fi

if [ -f /boot/firmware/cmdline.txt ]
if [ -f /teslausb/cmdline.txt ]
then
export CMDLINE_PATH=/boot/firmware/cmdline.txt
elif [ -f /boot/cmdline.txt ]
then
export CMDLINE_PATH=/boot/cmdline.txt
export CMDLINE_PATH=/teslausb/cmdline.txt
else
export CMDLINE_PATH=/dev/null
fi

if [ -f /boot/firmware/config.txt ]
then
export PICONFIG_PATH=/boot/firmware/config.txt
elif [ -f /boot/config.txt ]
if [ -f /teslausb/config.txt ]
then
export PICONFIG_PATH=/boot/config.txt
export PICONFIG_PATH=/teslausb/config.txt
else
export PICONFIG_PATH=/dev/null
fi
Expand Down
7 changes: 6 additions & 1 deletion setup/pi/make-root-fs-readonly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ apt-get -y --force-yes install ntp busybox-syslogd; dpkg --purge rsyslog

log_progress "Configuring system..."

# Add fsck.mode=auto, noswap and/or ro to end of /boot/cmdline.txt
# Add fsck.mode=auto, noswap and/or ro to end of cmdline.txt
# Remove the fastboot parameter because it makes fsck not run
remove_cmdline_txt_param fastboot
append_cmdline_txt_param fsck.mode=auto
Expand Down Expand Up @@ -141,6 +141,11 @@ then
sed -i -r "s@(/boot\s+vfat\s+\S+)@\1,ro@" /etc/fstab
fi

if ! grep -P -q "/boot/firmware\s+vfat\s+.+?(?=,ro)" /etc/fstab
then
sed -i -r "s@(/boot/firmware\s+vfat\s+\S+)@\1,ro@" /etc/fstab
fi

if ! grep -P -q "/\s+ext4\s+.+?(?=,ro)" /etc/fstab
then
sed -i -r "s@(/\s+ext4\s+\S+)@\1,ro@" /etc/fstab
Expand Down
Loading

0 comments on commit 562be33

Please sign in to comment.