Hey Guilhem.

> There might be a better way to detect an initramfs-tools environment

I once faced the same question when writing a (cryptsetup) keyscript,
i.e. how to definitely find out whether one's "within" the initramfs.


With crypsetup it may seem easy - check for e.g. /scripts/local-
top/cryptroot - but that, as well as similar files (like
/conf/initramfs.conf) may in principle also exist after the system has
booted.

The best I could find was checking whether / is of type rootfs:

Something like:

# `grep`’s `-q`-option is not used as it may cause an exit status of `0` even
# when an error occurred.
grep -E '^[^ ]+ [^ ]+ [^ ]+ [^ ]+ / [^ ]+ ([^ ]+ )*- rootfs [^ ]+ [^ ]+$' 
/proc/self/mountinfo >/dev/null 2>/dev/null;  [ "$?" -ne 1 ];



But checking as you do may in practise fully suffice.


Cheers,
Chris.

Reply via email to