I have an embedded device where I want to overlay the rootfs. So far my initramfs script looks like this:
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
mount -t proc proc /proc
mount -t devtmpfs none /dev
mount -t sysfs sysfs /sys
rootdev_ro=""
rootdev_rw=""
factory_reset=""
[ ! -f /etc/platform-preboot ] || . /etc/platform-preboot
if [ -z "$rootdev_ro" ]; then
for bootarg in `cat /proc/cmdline`; do
echo "${bootarg}"
arg=`expr "x$bootarg" : 'x[^=]*=\(.*\)' || echo ''`
case "$bootarg" in
root=*) rootdev_ro="${arg}" ;;
rootrw=*) rootdev_rw="${arg}" ;;
factoryreset=*) factory_reset="yes";;
esac
done
fi
mkdir -p /mnt/lowerdev
mkdir -p /mnt/overlaydev
mkdir -p /mnt/overlay
mount -t ext4 -o "ro" "${rootdev_ro}" /mnt/lowerdev
mount -t ext4 -o "rw" "${rootdev_rw}" /mnt/overlaydev
# Here's factory reset
if [ "$factoryreset" == "yes" ]; then
echo "Applying factory defaults..."
rm -fr /mnt/overlaydev/*
fi
# Upper and work folders must be on the same mount
mkdir -p /mnt/overlaydev/upper
mkdir -p /mnt/overlaydev/work
mount -t overlay overlay -o lowerdir=/mnt/lowerdev,upperdir=/mnt/overlaydev/upper,workdir=/mnt/overlaydev/work /mnt/overlay
echo "Switching to rootfs on overlay..."
mount --move /sys /mnt/overlay/sys
mount --move /proc /mnt/overlay/proc
mount --move /dev /mnt/overlay/dev
exec switch_root /mnt/overlay /sbin/init
The overlay works nicely there but I'd like to be able to change the kernel init boot parameters on the lowerdir file /boot/extlinux/extlinux.conf to add the factoryreset argument when needed.
If I try to mount the lowerdir partition when the system is running to modify the file, I get an error
already mounted or mount point busy
Is there the to specify the lowerdir to exclude the /boot directory, or do I have to overlay the folders one by one?