Fix for shutdown using overlayfs
EasyOS version 7.0.8 was briefly available, enough time for some people to update to it and discover issues. Forum member thinkpadfreak reported being unable to shutdown, and Caramel found the cause:
https://forum.puppylinux.com/viewtopic.php?p=156130#p156130
But, there is another potential problem; EasyOS has two mechanisms for saving the session, one of which might be dicey. If the user chooses to save the session while Easy is running, via the "save" desktop icon, the actual save is delayed until next bootup.
That delayed mechanism is handled by /usr/bin/ask-save-zram1 script calling rw-merge script:
mkdir -p /mnt/${WKG_DEV}/${WKG_DIR}.session-transit
/etc/rc.d/rw-merge '.session-transit'
That ".session-transit" folder is in the working-partition, outside of the overlayfs. rw-merge will create in it sub-folders, for the main desktop and all the containers. At next bootup, the 'init' script in the initrd will see this folder exists, and will merge it to the save-folders of the main desktop and containers (each of these is named ".session").
However, if the user chooses to save the session at shutdown, the /etc/rc.d/rc.shutdown script does a direct merge of the rw-layer of overlayfs to the ro ".session" folder. This is allowed to be done with aufs, but will break overlayfs.
Despite not being allowed with overlayfs, I did it that way and got away with it, due to the operation being done right before poweroff. So, corrupting overlayfs, but getting away with it.
That direct write of rw-layer to ro-layer is working, but probably asking for trouble. So, I have decided to implement the indirect method when save at shutdown...
Here is the end of /etc/rc.d/rc.shutdown, with changes in bold:
if [ "$EOS_TOP_LEVEL_ZRAM" == "1" ];then
#20220716 copy-up these files before removing .session layer...
touch /var/local/zram1-save-shutdown-auto
touch /tmp/ask-save-zram1-answer
sync
/usr/sbin/kill-pids '/files' #20220524 probably not needed.
#20221110 attempt to kill anything preventing remount of .session folder...
if [ "${EOS_LAYERFS}" == "aufs" ];then #20250911
fuser -mk /mnt/${WKG_DEV}/${WKG_DIR}.session
sleep 0.1
#attempt to remove .session layer...
busybox mount -o remount,del:/mnt/${WKG_DEV}/${WKG_DIR}.session / 2>/dev/console
fi
#20230409 /files no longer a symlink (refs: init in initrd, rc.sysinit)...
#busybox umount /files 2>/dev/console
#20220531 "save" saves into sub-folder mainrw...
if [ -f /mnt/${WKG_DEV}/${WKG_DIR}.session-transit/mainrw/root/.XLOADED ];then #20220529
#.XLOADED will cause an error msg at next bootup. it is intended when crash.
rm -f /mnt/${WKG_DEV}/${WKG_DIR}.session-transit/mainrw/root/.XLOADED
fi
#...even if these failed, merge rw layer to .session ...
#20220526 see /usr/sbin/ask-save-zram1, called from wmpoweroff, wmreboot...
SAVEflg=0
if [ "$(cat /var/local/zram1-save-shutdown-auto 2>/dev/null)" == "true" ];then #20220527
SAVEflg=1
elif [ "$(cat /tmp/ask-save-zram1-answer 2>/dev/null)" == "yes" ];then
SAVEflg=1
fi
if [ $SAVEflg -eq 1 ];then
echo "Saving session..." >/dev/console
#20220527 if an earlier save to .session-transit via "save" icon, dump it...
if [ -d /mnt/${WKG_DEV}/${WKG_DIR}.session-transit ];then
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}.session-transit
fi
if [ "$EOS_SUPPORT_CONTAINERS" != "0" ];then #20220529
STcont="$(find /mnt/${WKG_DEV}/${WKG_DIR}containers -mindepth 2 -maxdepth 2 -type d -name '.session-transit' | tr '\n' ' ')"
for aST in $STcont
do
aDIR="${aST%/*}"
rm -rf ${aDIR}/.session-transit #precaution delete.
done
fi
if [ "${EOS_LAYERFS}" == "aufs" ];then #20250911
/etc/rc.d/rw-merge 2>/dev/console
else #overlay...
mkdir -p /mnt/${WKG_DEV}/${WKG_DIR}.session-transit
/etc/rc.d/rw-merge '.session-transit'
#...initrd will complete saving the session (including containers).
fi
fi
#attempt unmount, so f.s. without journal marked clean...
#20221110 this fails, but try remount ro...
busybox umount /mnt/${WKG_DEV} 2>/dev/null
if [ $? -ne 0 ];then
busybox umount -r /mnt/${WKG_DEV} 2>/dev/null
fi
fi
busybox umount -ar > /dev/null 2>&1
With aufs, a ro-layer can be extracted, which overlayfs cannot do. If extraction of the ro .session folder fails with aufs, it is still ok to merge the rw-layer down to the .session ro-layer, also what overlayfs cannot do.
So, the above code does not attempt to extract the .session folder if running overlayfs, and calls rw-merge with the ".session-transit" parameter, which will save the .session folders (of main desktop and containers) outside of overlayfs, then the merge will take place in the initrd at next bootup.
There is a possible alternative mechanism, to pivot_root out of
overlayfs, then save the sessions. However, that might be tricky.
Tags: easy