Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.kernel > #73213 > unrolled thread
| Started by | Christoph Anton Mitterer <calestyo@scientia.net> |
|---|---|
| First post | 2021-10-06 18:00 +0200 |
| Last post | 2021-10-07 12:40 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.debian.kernel
recommended way to find out whether one is "within" the initramfs? Christoph Anton Mitterer <calestyo@scientia.net> - 2021-10-06 18:00 +0200
Re: recommended way to find out whether one is "within" the initramfs? Romain Perier <romain.perier@gmail.com> - 2021-10-06 19:00 +0200
Re: recommended way to find out whether one is "within" the initramfs? Christoph Anton Mitterer <calestyo@scientia.net> - 2021-10-07 02:00 +0200
Re: recommended way to find out whether one is "within" the initramfs? Romain Perier <romain.perier@gmail.com> - 2021-10-07 12:40 +0200
| From | Christoph Anton Mitterer <calestyo@scientia.net> |
|---|---|
| Date | 2021-10-06 18:00 +0200 |
| Subject | recommended way to find out whether one is "within" the initramfs? |
| Message-ID | <D5huP-1sM-27@gated-at.bofh.it> |
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 Thanks, Chris.
[toc] | [next] | [standalone]
| From | Romain Perier <romain.perier@gmail.com> |
|---|---|
| Date | 2021-10-06 19:00 +0200 |
| Message-ID | <D5iqS-22h-9@gated-at.bofh.it> |
| In reply to | #73213 |
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
[toc] | [prev] | [next] | [standalone]
| From | Christoph Anton Mitterer <calestyo@scientia.net> |
|---|---|
| Date | 2021-10-07 02:00 +0200 |
| Subject | Re: recommended way to find out whether one is "within" the initramfs? |
| Message-ID | <D5oZj-60n-1@gated-at.bofh.it> |
| In reply to | #73214 |
Hey Romain. Thanks for your ideas: On Wed, 2021-10-06 at 18:49 +0200, Romain Perier wrote: > 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) That sounds like a pretty nice idea. I guess for the iniramfs it would be always: none / rootfs ? Or maybe the "none" could be anything in theory. > 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) > These two seem IMO a bit less "stable"... people might not use systemd (at least in derivates) and checking for the binaries sounds a bit ugly. So maybe I do a combination and check for several indicators: /scripts, /conf/initramfs.conf (which seems to be always there, update- initramfs fails if the main initramfs.conf is missing or empty) and the fs-type of the / fs. Thanks, Chris.
[toc] | [prev] | [next] | [standalone]
| From | Romain Perier <romain.perier@gmail.com> |
|---|---|
| Date | 2021-10-07 12:40 +0200 |
| Message-ID | <D5yYG-42U-9@gated-at.bofh.it> |
| In reply to | #73215 |
Hey, Le jeu. 7 oct. 2021 à 01:38, Christoph Anton Mitterer <calestyo@scientia.net> a écrit : > > Hey Romain. > > Thanks for your ideas: > > On Wed, 2021-10-06 at 18:49 +0200, Romain Perier wrote: > > 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) > > That sounds like a pretty nice idea. > I guess for the iniramfs it would be always: > none / rootfs > ? Don't remember in details, an initrd is /dev/root on /, normally > Or maybe the "none" could be anything in theory. > > > > 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) > > > > These two seem IMO a bit less "stable"... people might not use systemd > (at least in derivates) and checking for the binaries sounds a bit > ugly. Yeah the point 3. about systemd is not generic enough, I agree. For busybox that basically means resolving a symlink :) . Just resolve if /sbin/init is a symlink to busybox or not : but checking for the rootfs is definitively better, imho. > > > > So maybe I do a combination and check for several indicators: > /scripts, /conf/initramfs.conf (which seems to be always there, update- > initramfs fails if the main initramfs.conf is missing or empty) and the > fs-type of the / fs. I would say, just check a single indicator if you're sure about it, and then test (several times) Regards, Romain
[toc] | [prev] | [standalone]
Back to top | Article view | linux.debian.kernel
csiph-web