Skip to content

Commit

Permalink
Implement workaround for low-mem models.
Browse files Browse the repository at this point in the history
The installer makes a backup (in memory) of itself to /bootfs, but after
restore to the new FAT32 partition doesn't remove that memory copy.
The 256MB model is so memory constrained that it fails, likely due to
an OOM problem. For those models (only), remove the RAM copy and when
the new boot partition gets mounted (to /rootfs/boot), make a
'mount --bind' to /bootfs, so if any code assumes the data/files to be
there, it'll still find them, so it won't break any code.

This fixes #520.

Signed-off-by: Diederik de Haas <[email protected]>
  • Loading branch information
diederikdehaas committed Jul 17, 2021
1 parent 44ed58e commit cbdef9a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions scripts/etc/init.d/rcS
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,23 @@ sync
umount /boot || fail
log_msg_end "OK"

model_memory=$(busybox free -m | grep "^Mem:" | awk '{print $2}')
low_mem_model=""
if [ "$model_memory" -le "260" ] ; then
low_mem_model="true"
else
low_mem_model="false"
fi
log_msg "Model memory in MB: '$model_memory' is a low mem model: '$low_mem_model'"

if [ "$low_mem_model" = "true" ] ; then
log_msg_start "Removing backup copy in /bootfs... "
rm -r -- /bootfs/*
log_msg_end "OK"
else
log_msg "Keeping backup copy in /bootfs"
fi

# only do modprobe if the module is NOT built into the kernel
if [ "$(grep -c $rootfstype /lib/modules/"$(uname -r)"/modules.builtin)" -eq 0 ]; then
log_msg_start "Loading $rootfstype module... "
Expand All @@ -1120,6 +1137,12 @@ mkdir /rootfs/boot || fail
mount $bootpartition /rootfs/boot || fail
log_msg_end "OK"

if [ "$low_mem_model" = "true" ] ; then
log_msg_start "Bind mount /rootfs/boot to /bootfs... "
mount --bind /rootfs/boot /bootfs
log_msg_end "OK"
fi

log_msg "Starting install process..."
# With 'cdebootstrap_cmdline we're actually using the word splitting what SC2086 warns us against
# This should probably be fixed at some point, but not in this run/branch.
Expand Down Expand Up @@ -1671,6 +1694,11 @@ chmod 0640 /rootfs/var/log/raspbian-ua-netinst.log

log_msg_start "Unmounting filesystems... "

if [ "$low_mem_model" = "true" ] ; then
log_msg_inline "removing bind mount to /bootfs... "
umount /bootfs
fi

umount /rootfs/boot
umount /rootfs
log_msg_end "OK"
Expand Down

0 comments on commit cbdef9a

Please sign in to comment.