Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make boot mount-point configurable #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions raspi-config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
INTERACTIVE=True
ASK_TO_REBOOT=0
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf
CONFIG=/boot/config.txt
BOOT="/boot"
CONFIG="$BOOT"/config.txt

USER=${SUDO_USER:-$(who -m | awk '{ print $1 }')}

Expand All @@ -20,7 +21,7 @@ is_pi () {
}

if is_pi ; then
CMDLINE=/boot/cmdline.txt
CMDLINE="$BOOT"/cmdline.txt
else
CMDLINE=/proc/cmdline
fi
Expand Down Expand Up @@ -676,7 +677,7 @@ No other symbols, punctuation characters, or blank spaces are permitted.\
}

do_memory_split() { # Memory Split
if [ -e /boot/start_cd.elf ]; then
if [ -e "$BOOT"/start_cd.elf ]; then
# New-style memory split setting
## get current memory split from /boot/config.txt
arm=$(vcgencmd get_mem arm | cut -d '=' -f 2 | cut -d 'M' -f 1)
Expand Down Expand Up @@ -732,7 +733,7 @@ get_current_memory_split() {
AVAILABLE_SPLITS="128 192 224 240"
MEMSPLIT_DESCRIPTION=""
for SPLIT in $AVAILABLE_SPLITS;do
if [ -e /boot/arm${SPLIT}_start.elf ] && cmp /boot/arm${SPLIT}_start.elf /boot/start.elf >/dev/null 2>&1;then
if [ -e "$BOOT"/arm${SPLIT}_start.elf ] && cmp "$BOOT"/arm${SPLIT}_start.elf "$BOOT"/start.elf >/dev/null 2>&1;then
CURRENT_MEMSPLIT=$SPLIT
MEMSPLIT_DESCRIPTION="Current: ${CURRENT_MEMSPLIT}MiB for ARM, $((256 - $CURRENT_MEMSPLIT))MiB for VideoCore"
break
Expand All @@ -741,7 +742,7 @@ get_current_memory_split() {
}

set_memory_split() {
cp -a /boot/arm${1}_start.elf /boot/start.elf
cp -a "$BOOT"/arm${1}_start.elf "$BOOT"/start.elf
sync
}

Expand Down Expand Up @@ -1758,7 +1759,7 @@ get_camera() {
}

do_camera() {
if [ $(deb_ver) -le 10 ] && [ ! -e /boot/start_x.elf ]; then
if [ $(deb_ver) -le 10 ] && [ ! -e "$BOOT"/start_x.elf ]; then
whiptail --msgbox "Your firmware appears to be out of date (no start_x.elf). Please update" 20 60 2
return 1
fi
Expand Down Expand Up @@ -1910,7 +1911,7 @@ do_legacy() {
}

do_gldriver() {
if [ ! -e /boot/overlays/vc4-kms-v3d.dtbo ]; then
if [ ! -e "$BOOT"/overlays/vc4-kms-v3d.dtbo ]; then
whiptail --msgbox "Driver and kernel not present on your system. Please update" 20 60 2
return 1
fi
Expand Down Expand Up @@ -2443,10 +2444,10 @@ get_json_string_val() {

# TODO: This is probably broken
do_apply_os_config() {
[ -e /boot/os_config.json ] || return 0
NOOBSFLAVOUR=$(get_json_string_val /boot/os_config.json flavour)
NOOBSLANGUAGE=$(get_json_string_val /boot/os_config.json language)
NOOBSKEYBOARD=$(get_json_string_val /boot/os_config.json keyboard)
[ -e "$BOOT"/os_config.json ] || return 0
NOOBSFLAVOUR=$(get_json_string_val "$BOOT"/os_config.json flavour)
NOOBSLANGUAGE=$(get_json_string_val "$BOOT"/os_config.json language)
NOOBSKEYBOARD=$(get_json_string_val "$BOOT"/os_config.json keyboard)

if [ -n "$NOOBSFLAVOUR" ]; then
printf "Setting flavour to %s based on os_config.json from NOOBS. May take a while\n" "$NOOBSFLAVOUR"
Expand Down Expand Up @@ -2514,17 +2515,17 @@ get_overlay_now() {
}

get_overlay_conf() {
grep -q "boot=overlay" /boot/cmdline.txt
grep -q "boot=overlay" "$BOOT"/cmdline.txt
echo $?
}

get_bootro_now() {
findmnt /boot | grep -q " ro,"
findmnt "$BOOT" | grep -q " ro,"
echo $?
}

get_bootro_conf() {
grep /boot /etc/fstab | grep -q "defaults.*,ro[ ,]"
grep "$BOOT" /etc/fstab | grep -q "defaults.*,ro[ ,]"
echo $?
}

Expand All @@ -2538,7 +2539,7 @@ enable_overlayfs() {

# mount the boot partition as writable if it isn't already
if [ $(get_bootro_now) -eq 0 ] ; then
if ! mount -o remount,rw /boot 2>/dev/null ; then
if ! mount -o remount,rw "$BOOT" 2>/dev/null ; then
echo "Unable to mount boot partition as writable - cannot enable"
return 1
fi
Expand Down Expand Up @@ -2611,21 +2612,21 @@ EOF
update-initramfs -c -k "$KERN"

# rename it so we know it has overlay added
mv /boot/initrd.img-"$KERN" /boot/"$INITRD"
mv /boot/initrd.img-"$KERN" "$BOOT"/"$INITRD"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the delay

I'm guessing the /boot on this particular line is expected because update-initramfs will always write to /boot?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw: When patching cmdline.txt (after init_resize) scripts should really check the overlay_prefix parameter from /proc/device-tree/chosen should be checked.

https://www.raspberrypi.com/documentation/computers/configuration.html#part4

Otherwise, it's possible that the wrong cmdline.txt will be patched

Copy link
Member

@XECDesign XECDesign Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the overlay_prefix parameter from /proc/device-tree/chosen should be checked.

overlay_prefix or os_prefix?

Also, wouldn't the whole mechanism be broken on Pi OS, which assumes that /boot is THE place where everything is?

In either case, I think that one is for @spl237, since the overlayfs parts of raspi-config are his.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've now spent ten minutes scratching my head about this...

What does the overlay_prefix parameter from /proc/device-tree (which is used for loading kernel overlays) have to do with patching cmdline.txt (which is used for adding a file system overlay)? Are those things not completely different, with the only common factor being the word "overlay"? Or am I missing something?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I mean os_prefix

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Now fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Now fixed.

I'm pretty sure it only breaks things. All the related packages install files to /boot and it's hardcoded all over the place (which is reasonable).

If things are instead in a subdirectory, nothing is going to work. The system should be set up to bind /boot to the appropriate subdirectory instead.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is now in a global variable in raspi-config which is used instead of /boot/cmdline.txt throughout. So if it does break things, it's trivial to remove - just hard-code PREFIX to an empty string on line 24.

I've got no idea what this breaks or doesn't break - I just do what I'm told... ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a chat with Tim and yeah, it breaks things, but not in the context os_prefix is expected to be used in. I'll move it to public and get this PR sorted when I've got a spare moment.

Thanks


# there is now a modified initramfs ready for use...

# modify config.txt
sed -i /boot/config.txt -e "/initramfs.*/d"
echo initramfs "$INITRD" >> /boot/config.txt
sed -i "$BOOT"/config.txt -e "/initramfs.*/d"
echo initramfs "$INITRD" >> "$BOOT"/config.txt

# modify command line
if ! grep -q "boot=overlay" /boot/cmdline.txt ; then
sed -i /boot/cmdline.txt -e "s/^/boot=overlay /"
if ! grep -q "boot=overlay" "$BOOT"/cmdline.txt ; then
sed -i "$BOOT"/cmdline.txt -e "s/^/boot=overlay /"
fi

if [ "$BOOTRO" = "yes" ] ; then
if ! mount -o remount,ro /boot 2>/dev/null ; then
if ! mount -o remount,ro "$BOOT" 2>/dev/null ; then
echo "Unable to remount boot partition as read-only"
fi
fi
Expand All @@ -2635,7 +2636,7 @@ disable_overlayfs() {
KERN=$(uname -r)
# mount the boot partition as writable if it isn't already
if [ $(get_bootro_now) -eq 0 ] ; then
if ! mount -o remount,rw /boot 2>/dev/null ; then
if ! mount -o remount,rw "$BOOT" 2>/dev/null ; then
echo "Unable to mount boot partition as writable - cannot disable"
return 1
fi
Expand All @@ -2645,14 +2646,14 @@ disable_overlayfs() {
fi

# modify config.txt
sed -i /boot/config.txt -e "/initramfs.*/d"
sed -i "$BOOT"/config.txt -e "/initramfs.*/d"
update-initramfs -d -k "${KERN}-overlay"

# modify command line
sed -i /boot/cmdline.txt -e "s/\(.*\)boot=overlay \(.*\)/\1\2/"
sed -i "$BOOT"/cmdline.txt -e "s/\(.*\)boot=overlay \(.*\)/\1\2/"

if [ "$BOOTRO" = "yes" ] ; then
if ! mount -o remount,ro /boot 2>/dev/null ; then
if ! mount -o remount,ro "$BOOT" 2>/dev/null ; then
echo "Unable to remount boot partition as read-only"
fi
fi
Expand All @@ -2663,15 +2664,15 @@ enable_bootro() {
echo "Overlay in use; cannot update fstab"
return 1
fi
sed -i /etc/fstab -e "s/\(.*\/boot.*\)defaults\(.*\)/\1defaults,ro\2/"
sed -i /etc/fstab -e "s@\(.*$BOOT.*\)defaults\(.*\)@\1defaults,ro\2@"
}

disable_bootro() {
if [ $(get_overlay_now) -eq 0 ] ; then
echo "Overlay in use; cannot update fstab"
return 1
fi
sed -i /etc/fstab -e "s/\(.*\/boot.*\)defaults,ro\(.*\)/\1defaults\2/"
sed -i /etc/fstab -e "s@\(.*$BOOT.*\)defaults,ro\(.*\)@\1defaults\2@"
}

do_overlayfs() {
Expand Down