[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: recommended way to find out whether one is "within" the initramfs?



Hey,

Le mer. 6 oct. 2021 à 17:57, Christoph Anton Mitterer
<calestyo@scientia.net> a écrit :
>
> Hey.
>
> I've just wondered whether there is recommended way to find out whether
> one is currently "within" the initramfs (i.e. early boot) as generated
> by Debians initramfs-tools, or not?
>
> I'd have probably done something like checking for:
> if [ -f /conf/initramfs.conf ] && [ -f /scripts/init-top/ORDER ] && [ ! -e /usr/bin/dpkg ]; then
>         echo within initramfs
> else
>         echo not within initramfs
> fi
>
> Or are /conf/initramfs.conf and /scripts/init-top/ORDER not necessarily
> included?
>
> The check for dpkg (which shouldn't be present in the initramfs, unless
> someone includes it for whichever reason) would have been to rule out
> the cases where someone created the other files in his normal
> userspace.
>
>
> Any better ideas? :D

Quickly, few ideas (perhaps not the perfect ones):
1. Check for what is currently mounted as "/" ? (which technically
should differ between initramfs or real rootfs)
2. Check if your binaries are running inside a klibc or busybox
context (both are supported via an initramfs) ?
3. Check if systemd is running ? (so you have started userspace
processes part of your real rootfs)
>
>
> Thanks,
> Chris.
>

Regards,
Romain


Reply to: