Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Question about init conception
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Fulgurance
Veteran
Veteran


Joined: 15 Feb 2017
Posts: 1239

PostPosted: Sun Jan 12, 2025 6:51 pm    Post subject: Question about init conception Reply with quote

Hi guys, I am actually doing test under virtualbox with an init system I am coding.

I just have one question.

Is it possible to compile an init system dynamically or not ?

Because if I compile my init dynamically, bascially it can't find the libraries. I have to compile it statically. Are there anyway to do ?
_________________
My actual project: https://github.com/Fulgurance/ISM

Ingenius Software Manager is a tool to build and manage a Linux system from scratch.
It will able to manage a linux installation just with a given path to the futur root path
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1381
Location: Richmond Hill, Canada

PostPosted: Sun Jan 12, 2025 6:59 pm    Post subject: Reply with quote

How you start your init?

Usually init start after rootfs already mounted so runtime libraries usually available.

But as you already experienced, init is better statically linked to support all kinds of condition.
Back to top
View user's profile Send private message
Fulgurance
Veteran
Veteran


Joined: 15 Feb 2017
Posts: 1239

PostPosted: Sun Jan 12, 2025 7:28 pm    Post subject: Reply with quote

So by your explanation, I guess my init should first mount the root filesystem ? I thought will be already mounted.
_________________
My actual project: https://github.com/Fulgurance/ISM

Ingenius Software Manager is a tool to build and manage a Linux system from scratch.
It will able to manage a linux installation just with a given path to the futur root path
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22981

PostPosted: Sun Jan 12, 2025 7:29 pm    Post subject: Reply with quote

/sbin/init from sysvinit is dynamically linked, so yes, it is possible, and on a stock Gentoo system, it seems to work without user intervention.
Back to top
View user's profile Send private message
Fulgurance
Veteran
Veteran


Joined: 15 Feb 2017
Posts: 1239

PostPosted: Sun Jan 12, 2025 7:34 pm    Post subject: Reply with quote

So how should I proceed ? Because there is not really documentation or anything about this.

So I just would like to make the rootfs available for my init system. How should I proceed exactly ?
_________________
My actual project: https://github.com/Fulgurance/ISM

Ingenius Software Manager is a tool to build and manage a Linux system from scratch.
It will able to manage a linux installation just with a given path to the futur root path
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1381
Location: Richmond Hill, Canada

PostPosted: Sun Jan 12, 2025 7:40 pm    Post subject: Reply with quote

Fulgurance wrote:
So how should I proceed ? Because there is not really documentation or anything about this.

So I just would like to make the rootfs available for my init system. How should I proceed exactly ?


This is why I ask you how you start init.

Normally init (the program) reside on rootfs, kernel usually got rootfs mounted then call /sbin/init by default.
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1784
Location: South America

PostPosted: Sun Jan 12, 2025 7:41 pm    Post subject: Re: Question about init conception Reply with quote

Fulgurance wrote:
Is it possible to compile an init system dynamically or not

"Init system" means several components these days. In particular, yes, the PID 1 program can be (and, as Hu said, on Gentoo is) dynamically linked if:
  • The filesystem that contains the expected location of the dynamic linker (/lib64/ld-linux-x86-64.so.2 for amd64 systems with GNU libc) is mounted by the time the kernel or initramfs' init file invokes the PID 1 program.
  • The filesystem(s) that contain the locations where the dynamic linker searches for the PID 1 program's shared libraries are mounted by the time the kernel or initramfs' init file invokes the PID 1 program.

For the rest of the init system's components it depends.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)


Last edited by GDH-gentoo on Sun Jan 12, 2025 8:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
Fulgurance
Veteran
Veteran


Joined: 15 Feb 2017
Posts: 1239

PostPosted: Sun Jan 12, 2025 7:54 pm    Post subject: Reply with quote

So to make sure it's clear.

When the kernel finish to initialize all it need, it give the hand to the program located (by default) at /sbin/init, with the PID 1 right ?
So normally at this stage, rootfs should be mounted yet isn't it ? ( and I think it make sens because to call /sbin/init, root should be mounted)

So my question now is, why I get this error (screenshot):

https://global.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/6/67f17012d1d552d6614cd31ee22798ccad4aedf2.png

Because the rootfs is mounted, and this file exist: /lib64/ld-linux-x86-64.so.2 (I checked by booting bash as init process)

And why /proc/stat isn't mounted ?
_________________
My actual project: https://github.com/Fulgurance/ISM

Ingenius Software Manager is a tool to build and manage a Linux system from scratch.
It will able to manage a linux installation just with a given path to the futur root path
Back to top
View user's profile Send private message
zen_desu
Tux's lil' helper
Tux's lil' helper


Joined: 25 Oct 2024
Posts: 101

PostPosted: Sun Jan 12, 2025 8:08 pm    Post subject: Reply with quote

If an initramfs is not being used, and the kernel is able to mount the root and run the init, you must be sure your init is doing things such as mounting a devtmpfs on /dev/, procfs on /proc, sysfs on /sys, etc. The devtmpfs can be avoided if you add static nodes for devices.
_________________
µgRD dev
Wiki writer
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1784
Location: South America

PostPosted: Sun Jan 12, 2025 8:20 pm    Post subject: Reply with quote

In other words, if no initramfs is used, the only things that the PID 1 program can assume are:
  • That the rootfs, and only the rootfs, is mounted. Nothing else, not even the proc or devtmpfs filesystems.
  • That standard input, output and error are already open and redirected to the console.

_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)


Last edited by GDH-gentoo on Sun Jan 12, 2025 8:39 pm; edited 1 time in total
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1381
Location: Richmond Hill, Canada

PostPosted: Sun Jan 12, 2025 8:26 pm    Post subject: Reply with quote

Fulgurance wrote:
So to make sure it's clear.

When the kernel finish to initialize all it need, it give the hand to the program located (by default) at /sbin/init, with the PID 1 right ?
So normally at this stage, rootfs should be mounted yet isn't it ? ( and I think it make sens because to call /sbin/init, root should be mounted)

So my question now is, why I get this error (screenshot):

https://global.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/6/67f17012d1d552d6614cd31ee22798ccad4aedf2.png

Because the rootfs is mounted, and this file exist: /lib64/ld-linux-x86-64.so.2 (I checked by booting bash as init process)

And why /proc/stat isn't mounted ?


How did you determine /lib64/ld-linux-x86-64.so.2 was missed in init start up? you screen shut does not show that.

rootfs (/) does not include /proc. /proc is just a mount point for pseudo file system proc. usually it is init job to invoke other program(s) to perform mounting of supporting pseudo file systems (for example sys, proc, devtmpfs, etc...

Not sure which "init" system you are using, but for example openrc on gentoo you can read /lib/rc/sh/init.sh for some idea.
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1784
Location: South America

PostPosted: Sun Jan 12, 2025 8:41 pm    Post subject: Reply with quote

pingtoo wrote:
Not sure which "init" system you are using, [...]

The OP says Fulgurance is making one.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1381
Location: Richmond Hill, Canada

PostPosted: Sun Jan 12, 2025 9:32 pm    Post subject: Reply with quote

GDH-gentoo wrote:
pingtoo wrote:
Not sure which "init" system you are using, [...]

The OP says Fulgurance is making one.


Yes, I understand. however I believe he is refer to the binary program because OP is specific about run time linked library.

I think at this OP is yet to understand the "init" as whole is not just about binary program. It is entire system that describe a life cycle of OSE (Operating System Environment)

I am not saying init system cannot a single binary program, it just that if you programmed entire life cycle of OSE in single binary you lost many opportunity for later enhancement to OSE. because otherwise the init binary need to reprogrammed for new changes. it is just not very well engineering design.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum