Note: I'm not asking about running a service (or whatever) when booting is completed (I know how to do that).
Background
System boots from an SDCard, which has the full system on it. Attached to it is either an external USB disk, or a SATA SSD – or in some cases nothing. I want to "outsource" some "stuff" to the external medium, including e.g. /var/log
, if that medium is available. If it's not available, the "internal" SD-card should be used. (And if you wonder: Yes, it's a small single-board computer).
Issue
Obviously, before the Init process starts, the usual directory structure must already be present. Mounting of file systems (from /etc/fstab
) is done by the kernel before that. Sticking to the example of /var/log
(which is not the only one to be dealt with) and one external drive mounted as /mnt/external
when present:
How can I put /var/log
(e.g. via symlink) on /mnt/external
if the drive is present, but put it below e.g. /mnt/local
otherwise – in a safe and clean way?
/etc/init.d/mountall-bootclean.sh
(where e.g./tmp
is cleaned up: this script is run immediately after all local file systems have been mounted). But it doesn't check for any*local*
script to call-if-exists, so I had to modify it directly – with the danger of my modifications being gone with some system update.