LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Bedrock Linux
User Name
Password
Bedrock Linux This forum is for the discussion of Bedrock Linux.

Notices


Reply
  Search this Thread
Old 10-22-2019, 01:21 PM   #1
ychaouche
LQ Newbie
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 26

Rep: Reputation: 1
Getting the stratum init ?


In the installer's archive, in bedrock/sbin/init, around line 371, this block of code

Code:
if [ -n "${def_tuple}" ] && [ -d "/bedrock/strata/${def_stratum}" ]; then
	sproc="/bedrock/strata/${def_stratum}/proc"
	mkdir -p "${sproc}" 2>/dev/null || true
	mount -t proc proc "${sproc}"
	if def_link="$(chroot "/bedrock/strata/${def_stratum}" "/proc/1/root/bedrock/libexec/busybox" realpath "${def_cmd}" 2>/dev/null)"; then
		def_path="/bedrock/strata/${def_stratum}${def_link}"
	fi
	umount "${sproc}"
fi
The difficult part for me was to understand what this assignement does :

Quote:
def_link="$(chroot "/bedrock/strata/${def_stratum}" "/proc/1/root/bedrock/libexec/busybox" realpath "${def_cmd}" 2>/dev/null)";
it seems to be trying to retrive the stratum's init binary but in a somewhat convoluted way. I'm sure it is necessary to do it this way, but I was wondering if anyone would like to explain the details of what's going on there ?
 
Old 10-22-2019, 05:06 PM   #2
ParadigmComplex
Bedrock Linux Founder
 
Registered: Feb 2016
Distribution: Bedrock Linux
Posts: 123

Rep: Reputation: Disabled
Consider a distro "foo" which, in its normal non-Bedrock usage, has a symlink at /sbin/init pointing to /usr/lib/systemd/systemd.

If it's added to Bedrock as a new stratum, there will be a symlink at /bedrock/strata/foo/sbin/init, but it will be pointing at /usr/lib/systemd/systemd rather than /bedrock/strata/foo/usr/lib/systemd/systemd. That symlink only works if you're chrooted to /bedrock/strata/foo.

If we know foo contains a "realpath" command, we could run:

Code:
chroot /bedrock/strata/foo realpath /sbin/init
to see where /sbin/init points, then append that to /bedrock/strata/foo to find the actual path we're interested in:

Code:
echo "/bedrock/strata/foo/$(chroot /bedrock/strata/foo realpath /sbin/init)"
However, we don't know if the stratum has realpath in it. We could copy a portable busybox realpath into the stratum:

Code:
cp /bedrock/libexec/busybox /bedrock/strata/foo/busybox
chroot /bedrock/strata/foo /busybox realpath /sbin/init
but I don't want to cause unnecessary disk writes.

Linux's /proc/<PID>/root points to a given process' root directory. In this case, we know PID 1 is running in the bedrock stratum and has /bedrock/libexec/busybox. So instead of copying it, mount proc and go through there:

Code:
mount -t proc proc /bedrock/strata/foo/proc
chroot /bedrock/strata/foo /proc/1/root/bedrock/libexec/busybox realpath /sbin/init
That's what this bit of code is doing. It's definitely convoluted.

There's work towards a proper test suite. Once that's in place with adequate tests to confirm changes here won't break things, I plan on making a small C utility which resolves symlinks as though they were chrooted. I'll then refactor code like this to use them, which should simplify things. Once RESOLVE_IN_ROOT becomes available I can use it and improve performance in some parts of the code as well for people on new enough kernels.
 
1 members found this post helpful.
Old 10-23-2019, 12:26 PM   #3
ychaouche
LQ Newbie
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 26

Original Poster
Rep: Reputation: 1
All clear, thanks a lot paradigmcomplex. If I understand correctly, you are using proc as a backdoor to let commands from the chrooted stratum access the real root filesystem (where busybox is), more or less ?
 
Old 10-23-2019, 01:37 PM   #4
ParadigmComplex
Bedrock Linux Founder
 
Registered: Feb 2016
Distribution: Bedrock Linux
Posts: 123

Rep: Reputation: Disabled
Affirmative
 
  


Reply

Tags
chroot, init, proc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NTP-server with incorrent time and with stratum 1-3 PIKNIK Linux - Server 5 08-14-2015 04:00 AM
Allow NTP client to synchronise any stratum lvnt Linux - Software 3 04-20-2014 10:52 AM
Stratum One server configuration user1020 Linux - Software 2 07-20-2010 03:17 PM
The peer's stratum is less than the host's stratum. (NTP) procfs Linux - General 2 04-17-2006 10:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Bedrock Linux

All times are GMT -5. The time now is 08:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration