diff --git a/doc/OneStepSetup.md b/doc/OneStepSetup.md index 150f025f..bde993b8 100644 --- a/doc/OneStepSetup.md +++ b/doc/OneStepSetup.md @@ -74,7 +74,7 @@ The Pi should be available for `ssh` at `pi@teslausb.local`, 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 @@ -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 `pi@teslausb.local` (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 `pi@teslausb.local` (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) @@ -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. diff --git a/pi-gen-sources/00-teslausb-tweaks/files/rc.local b/pi-gen-sources/00-teslausb-tweaks/files/rc.local index f53263ab..42a39122 100755 --- a/pi-gen-sources/00-teslausb-tweaks/files/rc.local +++ b/pi-gen-sources/00-teslausb-tweaks/files/rc.local @@ -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/* @@ -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 @@ -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 @@ -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 @@ -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" ] diff --git a/run/remountfs_rw b/run/remountfs_rw index 9638b11f..424ab5d1 100644 --- a/run/remountfs_rw +++ b/run/remountfs_rw @@ -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." diff --git a/setup/generic/install.sh b/setup/generic/install.sh index 7a5f717c..22d15efc 100644 --- a/setup/generic/install.sh +++ b/setup/generic/install.sh @@ -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 @@ -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 @@ -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 @@ -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 @@ -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' |" @@ -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) |" diff --git a/setup/pi/configure-web.sh b/setup/pi/configure-web.sh index 3bfc6a5c..c30b7e42 100644 --- a/setup/pi/configure-web.sh +++ b/setup/pi/configure-web.sh @@ -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 diff --git a/setup/pi/envsetup.sh b/setup/pi/envsetup.sh index 6a949663..807ed34c 100755 --- a/setup/pi/envsetup.sh +++ b/setup/pi/envsetup.sh @@ -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 < /tmp/checksetupconf #!/bin/bash -eu @@ -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 diff --git a/setup/pi/make-root-fs-readonly.sh b/setup/pi/make-root-fs-readonly.sh index f47e2d94..47a1f857 100644 --- a/setup/pi/make-root-fs-readonly.sh +++ b/setup/pi/make-root-fs-readonly.sh @@ -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 @@ -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 diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index a2e48be5..e8330980 100755 --- a/setup/pi/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -28,7 +28,7 @@ then fi function setup_progress () { - local setup_logfile=/boot/teslausb-headless-setup.log + local setup_logfile=/teslausb/teslausb-headless-setup.log if [ -w $setup_logfile ] then echo "$( date ) : $*" >> "$setup_logfile" @@ -133,9 +133,9 @@ then REBOOT=true fi -BOOT_DISK=$(lsblk -dpno pkname "$(findmnt -D -no SOURCE --target /boot)") +BOOT_DISK=$(lsblk -dpno pkname "$(findmnt -D -no SOURCE --target /teslausb)") declare -rx BOOT_DISK -BOOT_PARTITION_DEVICE=$(lsblk -dpno name "$(findmnt -D -no SOURCE --target /boot)") +BOOT_PARTITION_DEVICE=$(lsblk -dpno name "$(findmnt -D -no SOURCE --target /teslausb)") readonly BOOT_PARTITION_DEVICE readonly BOOT_DEVICE_PARTITION_PREFIX=${BOOT_PARTITION_DEVICE%?} export BOOT_DEVICE_PARTITION_PREFIX @@ -175,9 +175,9 @@ then fi function headless_setup_mark_setup_success () { - rm -f /boot/TESLAUSB_SETUP_FAILED - rm -f /boot/TESLAUSB_SETUP_STARTED - touch /boot/TESLAUSB_SETUP_FINISHED + rm -f /teslausb/TESLAUSB_SETUP_FAILED + rm -f /teslausb/TESLAUSB_SETUP_STARTED + touch /teslausb/TESLAUSB_SETUP_FINISHED } function flash () { @@ -518,7 +518,7 @@ function cmd_selfupdate { } function cmd_upgrade { - if [ ! -e /boot/TESLAUSB_SETUP_FINISHED ] + if [ ! -e /teslausb/TESLAUSB_SETUP_FINISHED ] then echo "STOP: previous setup didn't finish, can't upgrade unfinished install" exit 1 @@ -542,6 +542,18 @@ function cmd_upgrade_prepare { umount /mnt/archive /mnt/musicarchive || true /root/bin/disable_gadget.sh || true /root/bin/remountfs_rw + # a previous bookworm install may have the makers in /boot, so move + # them to /teslausb (/boot/firmware) + if [ ! /boot -ef /teslausb ] + then + for i in WIFI_ENABLED TESLAUSB_SETUP_STARTED TESLAUSB_SETUP_FINISHED + do + if [ -e "/boot/$i" ] + then + mv "/boot/$i" /teslausb + fi + done + fi ) &> /dev/null } @@ -575,7 +587,7 @@ function checkfsrw() { } function boot_is_not_on_root { - [ "$(stat -c "%d" /)" -ne "$(stat -c "%d" /boot)" ] + [ "$(stat -c "%d" /)" -ne "$(stat -L -c "%d" /teslausb)" ] } function diagnose { @@ -669,7 +681,7 @@ function diagnose { numsnapshots=$( mount | grep -c snapshot ) echo "$numsnapshots snapshots mounted" - if [ ! -e /boot/TESLAUSB_SETUP_FINISHED ] + if [ ! -e /teslausb/TESLAUSB_SETUP_FINISHED ] then echo 'ERROR: setup did not finish' fi @@ -708,7 +720,7 @@ function diagnose { checkfsrw / ro if boot_is_not_on_root then - checkfsrw /boot ro + checkfsrw /teslausb ro fi checkfsrw /backingfiles rw checkfsrw /mutable rw @@ -749,7 +761,7 @@ function diagnose { else echo "no boombox disk image found" fi - df -h /boot/ / /backingfiles/ /mutable/ + df -h /teslausb/ / /backingfiles/ /mutable/ echo -e "====== network ======" ifconfig iwconfig wlan0 | grep Link @@ -781,9 +793,9 @@ function diagnose { journalctl -u rc-local echo -e "====== setup log ======" - if [ -e /boot/teslausb-headless-setup.log ] + if [ -e /teslausb/teslausb-headless-setup.log ] then - cat /boot/teslausb-headless-setup.log + cat /teslausb/teslausb-headless-setup.log else echo "no setup log found" fi @@ -1000,6 +1012,14 @@ then fi EOC fi + if grep -q "/boot/TESLAUSB_SETUP_FINISHED" "/home/$DEFUSER/.bashrc" + then + sed -i "s@/boot/TESLAUSB_SETUP_FINISHED@/teslausb/TESLAUSB_SETUP_FINISHED@" "/home/$DEFUSER/.bashrc" + fi + if grep -q "/boot/TESLAUSB_SETUP_FINISHED" "/root/.bashrc" + then + sed -i "s@/boot/TESLAUSB_SETUP_FINISHED@/teslausb/TESLAUSB_SETUP_FINISHED@" "/root/.bashrc" + fi fi make_root_fs_readonly