Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Custom initramfs: misc. questions
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3  
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
sunox
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jan 2022
Posts: 136

PostPosted: Fri Dec 22, 2023 2:34 am    Post subject: Reply with quote

I think I understand what file, dir, and nod do. 'dir' creates a directory. 'file' copies from the source to a destination, where the destinations path is relative to the root of the initramfs source. 'nod' creates a device node. I'm a bit fuzze on nodes but I think that's good enough for now.

However, I don't really understand what is happening below:

NeddySeagoon wrote:

Code:
#

# for raid on lvm
# Output file name              Input file name
file /sbin/lvm.static           /root/initramfs/bins/sbin/lvm.static    755 0 0

# Moved out of the init script
slink /sbin/vgchange                    /sbin/lvm.static                777 0 0
slink /sbin/vgscan                      /sbin/lvm.static                777 0 0

slink /bin/cat                          /bin/busybox                    777 0 0
slink /bin/cut                          /bin/busybox                    777 0 0
slink /bin/findfs                       /bin/busybox                    777 0 0
slink /bin/ln                           /bin/busybox                    777 0 0
slink /sbin/switch_root                 /bin/busybox                    777 0 0

slink /lib64/libdl.so.2                 /lib64/libdl-2.33.so            777 0 0

# libraries required by /sbin/fsck.ext4 and /sbin/fsck
# The /lib -> /lib64 symlink is mostly harmless but its not right on arm64
slink   /lib                            /lib64                          777 0 0


It seems like the slinks are creating 'shortcuts' for the commands in the binary referenced. This means you don't have to call 'lvm vgchange' but rather just 'vgchange'; 'busybox cut' -> 'cut'.

Assuming I have that right (a longshot), is this the main use for symbolic links here?

And I have no clue what the lib -> lib64 symlink does.
Back to top
View user's profile Send private message
sunox
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jan 2022
Posts: 136

PostPosted: Fri Dec 22, 2023 2:37 am    Post subject: Reply with quote

And Mr @pietinger, these come from the example you shared earlier:

file /lib64/libkeyutils.so.1.10 /lib64/libkeykeyutils.so.1.10 755 0 0
slink /lib64/libkeyutils.so.1 /lib64/libkeyutils.so.1.10 777 0 0
file /usr/lib64/libimaevm.so.3.0.0 /usr/libimaevm.so.3.0.0 755 0
slink /usr/lib64/libimaevm.so.3 /usr/libimaevm.so.3.0.0 777 0

These symlinks just look like shortcuts that maybe follow a naming scheme that the initramfs prefers?

I wish I didn't have to pester with so many questions but the documentation on this really seems scarce.
Back to top
View user's profile Send private message
sunox
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jan 2022
Posts: 136

PostPosted: Fri Dec 22, 2023 5:03 am    Post subject: Reply with quote

I think I got it to work using the file list, though it was suspiciously trouble-free.

Here is the file list I used, borrowing heavily from pietinger and NeddySeagoon, just in case someone in the same situation stumbles on this thread:

[bad file deleted]

I learned a lot today. Thanks again lads.


Last edited by sunox on Fri Dec 22, 2023 6:03 pm; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54266
Location: 56N 3W

PostPosted: Fri Dec 22, 2023 10:16 am    Post subject: Reply with quote

sunox,

busybox and lvm2 sun whatever command they are called as.

You can write
Code:
busybox cut ...
or create a symbolic link (slink) named cut that points to busybox. They do the same thing.
In recent years, busybox has got cleverer, so just cut works.

The aim of the slink directives, is to create the links.

Busybox also has
Code:
ln -s
so you can script the link creation if you wish.

Code:
# busybox
file /bin/busybox         /bin/busybox

This copies /bin/busybox from your main install to the initramfs, not from an alternate ROOT=
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4167
Location: Bavaria

PostPosted: Fri Dec 22, 2023 12:44 pm    Post subject: Reply with quote

sunox wrote:
And Mr @pietinger, these come from the example you shared earlier:

file /lib64/libkeyutils.so.1.10 /lib64/libkeykeyutils.so.1.10 755 0 0
slink /lib64/libkeyutils.so.1 /lib64/libkeyutils.so.1.10 777 0 0
file /usr/lib64/libimaevm.so.3.0.0 /usr/libimaevm.so.3.0.0 755 0
slink /usr/lib64/libimaevm.so.3 /usr/libimaevm.so.3.0.0 777 0

These symlinks just look like shortcuts that maybe follow a naming scheme that the initramfs prefers?

I wish I didn't have to pester with so many questions but the documentation on this really seems scarce.

It is easier than you think:

Most applications (not compiled as static) will need some libraries ... and ... some applications (here: /usr/bin/evmctl) are linked to the main version of a library (e.g. libkeyutils.so.1) which DOES NOT exist because it is only a SOFTLINK to the real library (== libkeykeyutils.so.1.10). You will get this information with "ldd /usr/bin/evmctl" (and "ls -l /usr/lib64/libkeyutils*"). And then you have to make the same in your initramfs: Copy the real library (== 1.10) into the initramfs AND make a softlink from 1.10 to 1 because the application is linked to 1 :lol:
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
sunox
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jan 2022
Posts: 136

PostPosted: Fri Dec 22, 2023 3:47 pm    Post subject: Reply with quote

pietinger wrote:
sunox wrote:
And Mr @pietinger, these come from the example you shared earlier:

file /lib64/libkeyutils.so.1.10 /lib64/libkeykeyutils.so.1.10 755 0 0
slink /lib64/libkeyutils.so.1 /lib64/libkeyutils.so.1.10 777 0 0
file /usr/lib64/libimaevm.so.3.0.0 /usr/libimaevm.so.3.0.0 755 0
slink /usr/lib64/libimaevm.so.3 /usr/libimaevm.so.3.0.0 777 0

These symlinks just look like shortcuts that maybe follow a naming scheme that the initramfs prefers?

I wish I didn't have to pester with so many questions but the documentation on this really seems scarce.

It is easier than you think:

Most applications (not compiled as static) will need some libraries ... and ... some applications (here: /usr/bin/evmctl) are linked to the main version of a library (e.g. libkeyutils.so.1) which DOES NOT exist because it is only a SOFTLINK to the real library (== libkeykeyutils.so.1.10). You will get this information with "ldd /usr/bin/evmctl" (and "ls -l /usr/lib64/libkeyutils*"). And then you have to make the same in your initramfs: Copy the real library (== 1.10) into the initramfs AND make a softlink from 1.10 to 1 because the application is linked to 1 :lol:


I see, thanks. And if you just copy the real library (so.1.10) as the name the executable expects (so.1.1) - not a symlink - will it get upset?
Back to top
View user's profile Send private message
sunox
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jan 2022
Posts: 136

PostPosted: Fri Dec 22, 2023 3:48 pm    Post subject: Reply with quote

NeddySeagoon wrote:
sunox,

busybox and lvm2 sun whatever command they are called as.

You can write
Code:
busybox cut ...
or create a symbolic link (slink) named cut that points to busybox. They do the same thing.
In recent years, busybox has got cleverer, so just cut works.

The aim of the slink directives, is to create the links.

Busybox also has
Code:
ln -s
so you can script the link creation if you wish.

Code:
# busybox
file /bin/busybox         /bin/busybox

This copies /bin/busybox from your main install to the initramfs, not from an alternate ROOT=


Thank you, very helpful. Without the documentation you all wrote this wouldn't have been possible.
Back to top
View user's profile Send private message
sunox
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jan 2022
Posts: 136

PostPosted: Fri Dec 22, 2023 3:59 pm    Post subject: Reply with quote

For anyone out there who does LUKS encryption I am wondering what kernel parameters should be passed when using a custom initramfs. My understanding is that certain parameters are expected when genkernel generates initramfs, and others for when dracut does it, but I haven't found anything about what is expected when initramfs is custom

I left my parameters the same after switching to custom, and I wondered if it needed anything at all, but when I try to boot with efi stub it doesn't work.

When looking online for examples of working efi stub configs most of the examples seem to use what I believe is a dracut like scheme (e.g. 'rd.luks.name=....).
Back to top
View user's profile Send private message
Screenager
n00b
n00b


Joined: 26 Nov 2023
Posts: 37

PostPosted: Fri Dec 22, 2023 4:22 pm    Post subject: Reply with quote

Kernel parameters are nothing more than arguments(variables) passed to your init script in this context, you can use whatever you want if you write your own. There seems to be best practices here hence the rd.* naming scheme, but I couldn't find any hard definition for them either. kernel.org lists a bunch of kernel parameters that actually do have a function in the kernel here: https://docs.kernel.org/admin-guide/kernel-parameters.html
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54266
Location: 56N 3W

PostPosted: Fri Dec 22, 2023 5:17 pm    Post subject: Reply with quote

sunox,

Kernel command line parameters come in two sorts.
Those that are understood by the kernel (and will be used bf the kernel) and everything else. The entire kernel command can be read from /proc/cmdline.
Parsing it is left as an exercise for the reader.

Dracut and genkernel do their own things. So can you.

Picking parameter names that the kernel will use, without being aware of it, is a very bad thing.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
sunox
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jan 2022
Posts: 136

PostPosted: Fri Dec 22, 2023 5:59 pm    Post subject: Reply with quote

Ok, I suspected things went all-too-smoothly with the external file list and indeed it was. All of a sudden grub started to load the initramfs image at abcxyz.old - I think this coincided with me switching to trying to build the initramfs into the kernel - so as soon as I switched to the file list it stopped using my custom initramfs.

I saw today that you can pass the list itself to the kernel and it will build the cpio for you, which I did, and it threw a bunch of errors related to the "file" lines. It turns out I forgot to give the latter 3 arguments for each "file" line. I added them and things went well after that. Sharing my file list again just in case anyone else stumbles on this:

Code:

# dirs
dir /bin   755 0 0
dir /dev   755 0 0
dir /etc   755 0 0
dir /lib   755 0 0
dir /lib64   755 0 0
dir /mnt   755 0 0
dir /proc   755 0 0
dir /root   700 0 0
dir /run   755 0 0
dir /sbin   755 0 0
dir /sys   755 0 0
dir /tmp   755 0 0
dir /usr   755 0 0
dir /usr/lib   755 0 0
dir /usr/lib64   755 0 0
dir /usr/sbin   755 0 0
dir /var   755 0 0

# console node
nod /dev/console 600 0 0 c 5 1

# busybox
file /bin/busybox         /bin/busybox            755 0 0

# dmsetup
file /sbin/dmsetup         /sbin/dmsetup            755 0 0
file /lib64/libdevmapper.so.1.02   /lib64/libdevmapper.so.1.02      755 0 0
file /lib64/libudev.so.1      /lib64/libudev.so.1         755 0 0
file /lib64/libcap.so.2         /lib64/libcap.so.2         755 0 0
file /lib64/libm.so.6         /lib64/libm.so.6         755 0 0
file /lib64/libc.so.6         /lib64/libc.so.6         755 0 0
file /lib64/ld-linux-x86-64.so.2   /lib64/ld-linux-x86-64.so.2      755 0 0

# LUKS cryptsetup
file /sbin/cryptsetup         /sbin/cryptsetup         755 0 0
file /usr/lib64/libcryptsetup.so.12   /usr/lib64/libcryptsetup.so.12      755 0 0
file /usr/lib64/libssl.so.3      /usr/lib64/libssl.so.3         755 0 0
file /usr/lib64/libcrypto.so.3      /usr/lib64/libcrypto.so.3      755 0 0
file /usr/lib64/libargon2.so.1      /usr/lib64/libargon2.so.1      755 0 0
file /usr/lib64/libjson-c.so.5      /usr/lib64/libjson-c.so.5      755 0 0
file /usr/lib64/libpopt.so.0      /usr/lib64/libpopt.so.0         755 0 0
file /lib64/libuuid.so.1      /lib64/libuuid.so.1         755 0 0
file /lib64/libblkid.so.1      /lib64/libblkid.so.1         755 0 0

# lvm
file /sbin/lvm            /sbin/lvm            755 0 0
file /lib64/libdevmapper-event.so.1.02   /lib64/libdevmapper-event.so.1.02   755 0 0
file /lib64/libreadline.so.8      /lib64/libreadline.so.8         755 0 0
file /lib64/libtinfow.so.6      /lib64/libtinfow.so.6         755 0 0
file /lib64/libaio.so.1         /lib64/libaio.so.1         755 0 0

# random gcc file
file /lib64/libgcc_s.so.1      /usr/lib/gcc/x86_64-pc-linux-gnu/13/libgcc_s.so.1   755 0 0

# init
file /init            /usr/src/initramfs/init         0755 0 0
Back to top
View user's profile Send private message
sunox
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jan 2022
Posts: 136

PostPosted: Fri Dec 22, 2023 6:03 pm    Post subject: Reply with quote

Thanks for the information about kernel parameters: yet more new stuff learned.

It turns out that I don't have to pass any parameters at all when booting using the EFI stub method. I guess this makes sense as I hardcode info related to my partitions etc. right in the init file. I will take a look at the available parameters though to see if anything might be helpful. I might have to tell it to enable TRIM for my SSD for example.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4167
Location: Bavaria

PostPosted: Fri Dec 22, 2023 7:29 pm    Post subject: Reply with quote

sunox,

as you have asked for kernel command line parameters:

One parameter is ALWAYS necessary: Where/which is my ROOT partition ?

Now you have two choices WHO needs this information: Kernel OR initramfs ?
(see more here: https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Confusion_with_root%3DPARTUUID%3D_and_root%3DUUID%3D )
(yes, there is a rarely used 3. method IF you are using a self made initramfs: You can hardcode the info about root partition INTO the "init" of your initramfs)

You have two choices where you STORE this parameter - depending how you boot:
1. Booting with grub: a) in Kernel: CONFIG_CMDLINE= OR b) grub-mkconfig will find out and do all itself ;-)
2. Booting a stub kernel with UEFI: a) in Kernel: CONFIG_CMDLINE= OR b) as additional option when creating the UEFI entry
(see more here: https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Kernel_Commandline_Parameter
and here:
https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Boot_kernel_via_UEFI )


There is a second famous parameter: initrd=

This parameter tells the efistub where to load an external CPIO - and it is a very special parameter:
1. You will need it ONLY if you are using an external CPIO as initramfs ! (== not necessary if you have an embedded initrams AND not necessary if you have no initramfs)
2. This is one parameter you CANNOT build into the kernel (CONFIG_CMDLINE=) (because it is too late) (*) - it MUST come from a bootmanager (e.g. grub) OR directly from UEFI
(see more: https://forums.gentoo.org/viewtopic-p-8805827.html#8805827 )

*) Look into your dmesg. You will find TWO lines with kernel command line parameter: the first line is what kernel has got from UEFI OR bootmanager. The second line is the complete kernel command line parameter.

I am booting my kernel with UEFI ... and ... I have configured my root= INTO the kernel ... AND there is no parameter coming from UEFI ... and therefore my dmesg looks so:
Code:
[    0.000000] Command line:
...
[    0.075826] Kernel command line: root=PARTUUID=6979eed7-ffaf-425e-8ac7-2832f6d15e0a ro loglevel=8 lsm.debug ima_appraise=enforce i915.enable_guc=2 i915.enable_psr=0

(Yes, the first line is empty)
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4167
Location: Bavaria

PostPosted: Fri Dec 22, 2023 7:34 pm    Post subject: Reply with quote

sunox wrote:
[...] And if you just copy the real library (so.1.10) as the name the executable expects (so.1.1) - not a symlink - will it get upset?

Maybe not (= not tested) ... but there is a reason why some applications handle this in this way:

If you want update the library from 1.10 to 1.11 AND you dont want install a new version of the application using this library THEN you are fine with deleting 1.10, installing 1.11 AND making a softlink from 1 to 1.11 ... ;-)
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4167
Location: Bavaria

PostPosted: Fri Dec 22, 2023 7:47 pm    Post subject: Reply with quote

sunox wrote:
I saw today that you can pass the list itself to the kernel and it will build the cpio for you, [...]

Yes, this is only true if you build an embedded intramfs ... THEN the "make" of the kernel will do automatically everything (== start all necessary jobs) to build the initramfs with your list-file.

See in this chapter: https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Initramfs_Overview#Embedded_with_a_file-list

(If you want build an external CPIO with a file-list you have to do all the steps "make" would do, by yourself ... ;-) )
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4167
Location: Bavaria

PostPosted: Fri Dec 22, 2023 7:58 pm    Post subject: Reply with quote

P.S.: To say it clear:

Yes, it is possible to boot a kernel directly from UEFI (or from grub) without using ANY kernel command line parameter IF:

You are using an embedded initramfs where you have hardcoded the information about the root partition INTO the "init" of your (embedded) initramfs. 8)
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
sunox
Tux's lil' helper
Tux's lil' helper


Joined: 26 Jan 2022
Posts: 136

PostPosted: Fri Dec 22, 2023 9:05 pm    Post subject: Reply with quote

All very helpful, thank you. When working at this level it gets harder and harder to find answers for whatever questions you have, I suppose because there are so few people who are interested in this sort of thing. It's definitely nice to have this forum to ask quetions. I would feel more guilty about asking so many questions if it wasn't for the fact that anyone else who has the same issue can maybe now find answers. It's remarkable how often the Gentoo wiki and posts from this forum come up, and for this alone it seems like Gentoo contributors like you guys play a really important role imo. Anyway cheers.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4167
Location: Bavaria

PostPosted: Fri Dec 22, 2023 9:29 pm    Post subject: Reply with quote

sunox,

You are very Welcome ! :D

... and I agree with everything you said ... but there is never a reason to feel guilty ... or ... as our forums legend always says:

Quote:
There are no dumb questions, except the one you don't ask, as you never know the answer.


Have fun with Gentoo ! 8)
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


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

PostPosted: Sat Dec 23, 2023 12:55 pm    Post subject: Reply with quote

pietinger wrote:
sunox wrote:
[...] And if you just copy the real library (so.1.10) as the name the executable expects (so.1.1) - not a symlink - will it get upset?
Maybe not (= not tested)
Definitely not. It'll work just fine.

pietinger wrote:
... but there is a reason why some applications handle this in this way:
Exactly. Those symlinks facilitate updating shared libraries without breaking the programs that link to them on real filesystems.

But initramfs are special, modifying its contents (e. g. for upgrading a contained shared library) means regenerating the file anyway (and rebuilding the kernel if you embed the initramfs in it) so, for a custom initramfs, using those symlinks is not that appealing.
_________________
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
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
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