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

Goto page 1, 2, 3  Next  
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: Thu Dec 21, 2023 4:11 pm    Post subject: Custom initramfs: misc. questions Reply with quote

I've just started trying to setup a custom initramfs. I've successfully installed a static version busybox to /usr/src/initramfs, and I want to do the same for lvm2.

Code:
ROOT=/usr/src/initramfs USE="static" emerge -av sys-apps/busybox


I try this, and portage complains that I should also set the flag "-udev". I did this and tried to re-emerge, and now portage wants a dozen or so new entries in package.use. I do this, and portage says it wants another entry: >=sys-apps/systemd-utils-254.5-r2 udev. I add this to package.use, and portage complains yet again about this same use flag.

I'm a little confused as to what's going on. I've never installed statically linked packages before, nor have i installed packages to a new ROOT like this, so maybe I am doing something wrong.

I did some searching and found a few threads from the time that this -udev requirement a few years back, and it seemed like a major issue for creating static binaries but I don't fully understand what it means.

Edit: I'm wondering if I maybe need to do a world update after making the new USE flag entries in package.use? I am trying to do this with minimal disruption to my system as possible but maybe I'm cutting corners.


Last edited by sunox on Fri Dec 22, 2023 9:11 pm; edited 1 time in total
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21644

PostPosted: Thu Dec 21, 2023 4:41 pm    Post subject: Reply with quote

What instructions are you following that led you down this path? You do not need static linking if you include in the initramfs the dynamic libraries required by the program(s) you put in the initramfs. Similarly, there is no need to install anything to a special root. The kernel's initramfs support can copy files directly from the live filesystem into the initramfs, without the need for a staging area. This is also convenient since it eliminates the need to elevate to root to prepare your initramfs files. The only caveat to this is that you become slightly more susceptible to changes in the consumed programs. I build my kernels this way, and have on occasion had an initramfs that failed because an included program had been updated to a newer version with additional dependencies that I had not previously bundled. Once I added those new libraries to my initramfs, it worked again.

At various times, I have had an initramfs with support for LVM, LUKS, or both, all with dynamic linking.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Thu Dec 21, 2023 4:57 pm    Post subject: Reply with quote

Hu,

I'll guess its Initramfs - make your own. I'm the original perpetrator of that.
As you say, dynamic liking in the intrd works as long as all the bits are there, along with the dynamic linker.

Everyone should have a static busybox though for when glibc is broken.

I don't have an initrd on this system at the moment. I made dm-mod.create= work instead for root in LVM.
I should fix that.

My /etc/portage/package.use/static contains
Code:
# required by sys-apps/busybox-1.33.1-r2::gentoo[static]
# required by busybox (argument)
>=virtual/libcrypt-2 static-libs
# required by virtual/libcrypt-2::gentoo
# required by sys-apps/busybox-1.33.1-r2::gentoo
# required by busybox (argument)
>=sys-libs/libxcrypt-4.4.26 static-libs

sys-apps/busybox -pam static


As I don't use udev, I don't get any problems with it.
_________________
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
pingtoo
l33t
l33t


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

PostPosted: Thu Dec 21, 2023 5:23 pm    Post subject: Reply with quote

sunox,

Initramfs is known as early userspace It actually can be think as rootfs. Most Linux distro (Gentoo included) that use initramfs will eventually replace the rootfs(initramfs) in memory with another file system on storage.

What you did is trying (not intentionally) change your current rootfs into initramfs, that is why you got into many difficulty.

If you want to build custom initramfs you can use sys-kernel/genkernel or sys-kernel/dracut. However if you really want to manually do it, I suggest you use emerge <any emerge options> --root /path/to/stage/initramfs/.

As Hu said, static binary is not necessary for building initramfs anymore unless you made you kernel not understand how to use "interpreter" (this is very unusual)
It is possible to install all the necessary dynamic link libraries into /path/to/stage/initramfs use the emerge with '--root' (or ROOT environment variable)
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: Thu Dec 21, 2023 5:27 pm    Post subject: Reply with quote

I've seen the suggestion to build static binaries for a custom initramfs in a few places, e.g. here https://wiki.gentoo.org/wiki/Custom_Initramfs it says to build a static busybox. I am not really a programmer and this is uncharted territory for me, and the idea of having one automagically-generated file seems simpler than many files in various places.

I'm certainly not against the idea of dynamic linking. Is the process of gathering up all the needed libraries pretty straightforward? I don't know exactly how to read the output of lddtree but I will look into it.

Also my statically-compiled busybox shows
Code:
/usr/bin/ldd: line 159: /lib/ld-linux.so.2: cannot execute binary file: Exec format error not a dynamic executable
when I call "ldd busybox", but it shows nothing when I call "lddtree busybox". Does this mean it is indeed static?

I have udev installed apparently as openrc and a couple othe rapps seem to depend on it by default, but I'm not sure I actually need it.
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: Thu Dec 21, 2023 5:34 pm    Post subject: Reply with quote

pingtoo wrote:
sunox,

Initramfs is known as early userspace It actually can be think as rootfs. Most Linux distro (Gentoo included) that use initramfs will eventually replace the rootfs(initramfs) in memory with another file system on storage.

What you did is trying (not intentionally) change your current rootfs into initramfs, that is why you got into many difficulty.

If you want to build custom initramfs you can use sys-kernel/genkernel or sys-kernel/dracut. However if you really want to manually do it, I suggest you use emerge <any emerge options> --root /path/to/stage/initramfs/.

As Hu said, static binary is not necessary for building initramfs anymore unless you made you kernel not understand how to use "interpreter" (this is very unusual)
It is possible to install all the necessary dynamic link libraries into /path/to/stage/initramfs use the emerge with '--root' (or ROOT environment variable)


I actually have a working initramfs via genkernel but I thought I would try to make my own for fun / education. I don't use initramfs on my other gentoo machine so I've never had to think about it before, and I didn't like that I didn't understand what it was doing, and that it was possibly doing unnecessary things, etc. (Not that I understand all that much about regular booting either, but anyway...)

And your last paragraph raises something I had overlooked. If I do like you say and pass the root flag to emerge will it bring in all the dynamically linked files for me? That actually sounds better than building things statically.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4167
Location: Bavaria

PostPosted: Thu Dec 21, 2023 5:41 pm    Post subject: Reply with quote

sunox,

reading https://wiki.gentoo.org/wiki/Custom_Initramfs is fine ... may I suggest also:
https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Initramfs_Overview
In this article you will find also a link to:
https://wiki.gentoo.org/wiki/Early_Userspace_Mounting (take this as an example)

A static "busybox" is also fine. You will get it with:
Code:
# USE="static static-libs -pam" emerge -pv busybox

(of course you have to edit /etc/portage/package.use later)

If you need more applications in your initramfs, it is almost better to keep the dynamic linking and copy all necessary libraries also into your initramfs. Be aware that some libraries are only a link ... THEN you must create the same link. An example you will find in my "initramfs_list" in my (german) post here: https://forums.gentoo.org/viewtopic-t-1159297.html

In every case you have to work with "ldd" ;-)
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Thu Dec 21, 2023 5:43 pm    Post subject: Reply with quote

sunox,

Before you dive in and try to make an initrd have a read of PC Boot Process.

An initrd is only really required if you need user space tools to expose the root filesystem.
With proper kernel configuration, so that no modules need be loaded to mount root, no initrd is required.

Distros use and initrd, full of modules, so that the kernel will be small and boot almost anywhere
They are general purpose kernels and initrds.
_________________
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
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21644

PostPosted: Thu Dec 21, 2023 5:53 pm    Post subject: Reply with quote

Busybox is a bit special. Its most popular purpose is to be functional when everything else has failed, and making it static aids that purpose. As a result, static linking busybox is generally very well supported. Most other projects seem to view static linking as something that they will tolerate, but not spend much effort on, so widespread static linking can be more challenging to implement.
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: Thu Dec 21, 2023 6:15 pm    Post subject: Reply with quote

NeddySeagoon wrote:
sunox,

Before you dive in and try to make an initrd have a read of PC Boot Process.

An initrd is only really required if you need user space tools to expose the root filesystem.
With proper kernel configuration, so that no modules need be loaded to mount root, no initrd is required.

Distros use and initrd, full of modules, so that the kernel will be small and boot almost anywhere
They are general purpose kernels and initrds.


Sorry, I forgot to mention that I have a LUKS encrypted volume which is why I need initrd. I don't need anything else so I was hoping the it would be relatively simple. From the reading I have done it looked like I might be able to get away with a ~10 line init script. I will take a look at that link, thanks.
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: Thu Dec 21, 2023 6:17 pm    Post subject: Reply with quote

pietinger wrote:
sunox,

reading https://wiki.gentoo.org/wiki/Custom_Initramfs is fine ... may I suggest also:
https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Initramfs_Overview
In this article you will find also a link to:
https://wiki.gentoo.org/wiki/Early_Userspace_Mounting (take this as an example)

A static "busybox" is also fine. You will get it with:
Code:
# USE="static static-libs -pam" emerge -pv busybox

(of course you have to edit /etc/portage/package.use later)

If you need more applications in your initramfs, it is almost better to keep the dynamic linking and copy all necessary libraries also into your initramfs. Be aware that some libraries are only a link ... THEN you must create the same link. An example you will find in my "initramfs_list" in my (german) post here: https://forums.gentoo.org/viewtopic-t-1159297.html

In every case you have to work with "ldd" ;-)


Thanks, I will check out the tutorial. The option of feeding a ROOT to emerge, which then does all of the library copying for me, seemed really appealing. I'm concerned that if I manually copy I'll leave something out etc.
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


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

PostPosted: Thu Dec 21, 2023 6:21 pm    Post subject: Reply with quote

sunox wrote:
And your last paragraph raises something I had overlooked. If I do like you say and pass the root flag to emerge will it bring in all the dynamically linked files for me? That actually sounds better than building things statically.


The emerge "root" setting is to direct emerge install into an alternative location. And the alternative location is consider "root" file system. therefor anything required and missing will get installed. So Yes all the missing dynamic libraries will be installed (And some more, not necessary required for initramfs :P

I would suggest you follow pietinger post, read all those links to understand what is initramfs. this topic is well deserved Linux learning experience.
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: Thu Dec 21, 2023 6:33 pm    Post subject: Reply with quote

pingtoo wrote:
sunox wrote:
And your last paragraph raises something I had overlooked. If I do like you say and pass the root flag to emerge will it bring in all the dynamically linked files for me? That actually sounds better than building things statically.


The emerge "root" setting is to direct emerge install into an alternative location. And the alternative location is consider "root" file system. therefor anything required and missing will get installed. So Yes all the missing dynamic libraries will be installed (And some more, not necessary required for initramfs :P

I would suggest you follow pietinger post, read all those links to understand what is initramfs. this topic is well deserved Linux learning experience.


I just tried to install lvm2 by passing --root and it seems to want to build just about every package on my system. I guess manually copying might be easier after all. I haven't found a clear guide on how to 'migrate' a bin and its shared libraries to initramfs yet but maybe it's in one of these links. I'm sure this is just knowledge that is taken for granted for anyone attempting this stuff.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Thu Dec 21, 2023 6:55 pm    Post subject: Reply with quote

sunox,

You can use the installed packages on your system to build your initrd.
There are two advantages of the alternate ROOT build.

1. You may use different flags there.
2. In six months, when you want to make a trivial change to the init script, the files that will go into the initrd will still be there unchanged.

The initrd need not be kept up to date as its not normally an attack vector.
Its possible but few people bring up networking in the initrd. That would be a threat.

-- edit --

Don't expect it to work first time.
Use echo statements and the busybox shell to debug.
_________________
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: Thu Dec 21, 2023 7:16 pm    Post subject: Reply with quote

NeddySeagoon wrote:
sunox,

You can use the installed packages on your system to build your initrd.
There are two advantages of the alternate ROOT build.

1. You may use different flags there.
2. In six months, when you want to make a trivial change to the init script, the files that will go into the initrd will still be there unchanged.

The initrd need not be kept up to date as its not normally an attack vector.
Its possible but few people bring up networking in the initrd. That would be a threat.

-- edit --

Don't expect it to work first time.
Use echo statements and the busybox shell to debug.


I do quite like the idea of letting portage handle all the library dependency stuff by specifying an alternate root. I tried it with lvm
Code:
sudo emerge --root=/usr/src/initramfs -va lvm2
and it wanted to build about a hundred packages which scared me off.

I am back to trying to figure out how to manually copy over all the needed libraries, using strace to try to look for errors. The executable in /usr/src/initramfs (e.g. /sbin/lvm) seems (to me) to be referencing the shared libraries in /lib64, not /usr/src/initramfs/lib64 by default. I set LD_LIBRARY_PATH to try to force it to look in the initramfs dir instead.

Rough going so far but I will keep trying. Doesn't seem like any easy way to know if your binary will work in early boot or not. [/code]
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


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

PostPosted: Thu Dec 21, 2023 7:29 pm    Post subject: Reply with quote

sunox wrote:
pingtoo wrote:
sunox wrote:
And your last paragraph raises something I had overlooked. If I do like you say and pass the root flag to emerge will it bring in all the dynamically linked files for me? That actually sounds better than building things statically.


The emerge "root" setting is to direct emerge install into an alternative location. And the alternative location is consider "root" file system. therefor anything required and missing will get installed. So Yes all the missing dynamic libraries will be installed (And some more, not necessary required for initramfs :P

I would suggest you follow pietinger post, read all those links to understand what is initramfs. this topic is well deserved Linux learning experience.


I just tried to install lvm2 by passing --root and it seems to want to build just about every package on my system. I guess manually copying might be easier after all. I haven't found a clear guide on how to 'migrate' a bin and its shared libraries to initramfs yet but maybe it's in one of these links. I'm sure this is just knowledge that is taken for granted for anyone attempting this stuff.


May I introduce a different precept :) Have you consider why your try install lvm2 with --root install everything? (Hint the alternative location is empty (root))

It actually demonstrated Linux system (or what I call OSE -- Operating System Environment) complexity, If you want to go deep to know how a system work, Learning initrd is actually a very good start, you will wonder if a very minimal rootfs in memory can work than why is all those Linux distro spent so much effort and IMHO some of overly thinking engineering design.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Thu Dec 21, 2023 7:42 pm    Post subject: Reply with quote

sunox,

My initrd/bins//var/db/pgk says that I have
Code:
# ls initramfs/bins/var/db/pkg/*
initramfs/bins/var/db/pkg/app-arch:
bzip2-1.0.8-r1  gzip-1.11

initramfs/bins/var/db/pkg/dev-libs:
expat-2.4.3  libaio-0.3.112  libpcre-8.45  libpcre2-10.39  libunistring-0.9.10-r1

initramfs/bins/var/db/pkg/net-dns:
libidn2-2.3.2

initramfs/bins/var/db/pkg/sys-apps:
acl-2.3.1  attr-2.5.1  baselayout-2.7-r3  busybox-1.34.1  gentoo-functions-0.14  grep-3.7  systemd-tmpfiles-249.9  util-linux-2.37.2-r1

initramfs/bins/var/db/pkg/sys-auth:
pambase-20210201.1  passwdqc-2.0.2-r1

initramfs/bins/var/db/pkg/sys-block:
thin-provisioning-tools-0.9.0-r1

initramfs/bins/var/db/pkg/sys-fs:
e2fsprogs-1.46.4  lvm2-2.02.188-r2  mdadm-4.2-r1

initramfs/bins/var/db/pkg/sys-libs:
e2fsprogs-libs-1.46.4-r1  glibc-2.33-r7  libcap-2.62  libxcrypt-4.4.25-r1  ncurses-6.2_p20210619  pam-1.5.1_p20210622-r1  readline-8.1_p1-r1  timezone-data-2021a-r1  zlib-1.2.11-r4

initramfs/bins/var/db/pkg/virtual:
awk-1  libcrypt-2  libiconv-0-r2  libintl-0-r2  tmpfiles-0-r1
installed in the initrd binaries.

However only a few files end up in the initrd
Code:
# directory structure
dir /proc       755 0 0
dir /usr        755 0 0
dir /bin        755 0 0
dir /sys        755 0 0
dir /var        755 0 0
#dir /lib        755 0 0
dir /lib64      755 0 0
dir /sbin       755 0 0
dir /mnt        755 0 0
dir /mnt/root   755 0 0
dir /etc        755 0 0
dir /root       700 0 0
dir /dev        755 0 0

nod /dev/null   666 0 0 c 1 3
nod /dev/tty    666 0 0 c 5 0
nod /dev/console        600 0 0 c 5 1

# busybox
# Output file name              Input file name
file /bin/busybox               /root/initramfs/bins/bin/busybox        755 0 0
# Need real mount as busybox did not support UUID
file /bin/mount                 /root/initramfs/bins/bin/mount          755 0 0

# for raid on lvm
# Output file name              Input file name
file /sbin/mdadm                /root/initramfs/bins/sbin/mdadm         755 0 0
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

# Output file name                      Input file name
file    /lib/ld-linux-aarch64.so.1      /root/initramfs/bins/lib/ld-linux-aarch64.so.1      755 0 0
file    /lib64/libext2fs.so.2           /root/initramfs/bins/lib64/libext2fs.so.2           755 0 0
file    /lib64/libcom_err.so.2          /root/initramfs/bins/lib64/libcom_err.so.2          755 0 0
file    /lib64/libpthread.so.0          /root/initramfs/bins/lib64/libpthread.so.0          755 0 0
file    /lib64/libblkid.so.1            /root/initramfs/bins/lib64/libblkid.so.1            755 0 0
file    /lib64/libuuid.so.1             /root/initramfs/bins/lib64/libuuid.so.1             755 0 0
file    /lib64/libe2p.so.2              /root/initramfs/bins/lib64/libe2p.so.2              755 0 0
file    /lib64/libc.so.6                /root/initramfs/bins/lib64/libc.so.6                755 0 0
file    /lib64/libmount.so.1            /root/initramfs/bins/lib64/libmount.so.1            755 0 0
file    /lib64/libdl-2.33.so            /root/initramfs/bins/lib64/libdl-2.33.so            755 0 0


file    /sbin/fsck              /sbin/fsck                      755 0 0
file    /sbin/fsck.ext4         /sbin/fsck.ext4                 755 0 0

# our init script
file    /init                   /root/initramfs/init               755 0 0

_________________
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: Thu Dec 21, 2023 7:45 pm    Post subject: Reply with quote

Quote:
May I introduce a different precept :) Have you consider why your try install lvm2 with --root install everything? (Hint the alternative location is empty (root))


Intuitively: emerge can't differentiate between "I want this package and its library dependencies installed here" and "this is the root for a full system: install this package and also everything else the user of a full system will need". Just my guess.

This did not happen when I installed busybox (with the ROOT= env variable set to the initramfs dir), I assume, because of the static flag.

It's been a good learning experience already. I choose to use gentoo partially to make things harder on myself so I learn more in the long run.
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: Thu Dec 21, 2023 7:52 pm    Post subject: Reply with quote

NeddySeagoon wrote:
sunox,

My initrd/bins//var/db/pgk says that I have
[code]# ls initramfs/bins/var/db/pkg/*
initramfs/bins/var/db/pkg/app-arch:
bzip2-1.0.8-r1 gzip-1.11


Thanks, that's helpful. I have seen this syntax before and I was confused by it previously, but it now just looks like the 'initrd' way of doing things as opposed to initramfs?

Also I have about 15 library files in total for dmsetup, cryptsetup, and lvm , which seems like an appropriate number consider what I see here.

I think I'm ready to start thinking about the init script, which will hopefully be fairly straightforward.
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


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

PostPosted: Thu Dec 21, 2023 8:01 pm    Post subject: Reply with quote

sunox wrote:
Quote:
May I introduce a different precept :) Have you consider why your try install lvm2 with --root install everything? (Hint the alternative location is empty (root))


Intuitively: emerge can't differentiate between "I want this package and its library dependencies installed here" and "this is the root for a full system: install this package and also everything else the user of a full system will need". Just my guess.

This did not happen when I installed busybox (with the ROOT= env variable set to the initramfs dir), I assume, because of the static flag.

It's been a good learning experience already. I choose to use gentoo partially to make things harder on myself so I learn more in the long run.


You are correct 8)

I suggest using emerge --root is give you the idea on that initramfs is really a root file system. And emerge have the ability to fill a root file system all the necessary support.

Busybox itself was design to fulfil a minimal root file system need that is why it does not install much into the alternative location. I don't recall at which version of LVM2 did change to require more, but in the early day of LVM2 with Gentoo (especially when genkernel always use "static" creation) it actually only install one binary file lvm2 into initramfs.

In think it is still possible to install a very simple version of lvm2 but you just can not use Gentoo's ebuild, the maintainer of gentoo lvm2 package choose not to support such setup any more.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Thu Dec 21, 2023 8:05 pm    Post subject: Reply with quote

sunox,

/var/db/pgk is where portage keeps track of what is installed, how its installed and the files each package installed.
Its present in every ROOT, including any alternative ROOT= that you use.

There are two aspects to the init script.
1. Making it do the things that are required.
2. The error handling and debug when 1. goes wrong.

The second is required until it works and is by far the most difficult part.
_________________
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: Thu Dec 21, 2023 8:06 pm    Post subject: Reply with quote

pingtoo wrote:


You are correct 8)

I suggest using emerge --root is give you the idea on that initramfs is really a root file system. And emerge have the ability to fill a root file system all the necessary support.

Busybox itself was design to fulfil a minimal root file system need that is why it does not install much into the alternative location. I don't recall at which version of LVM2 did change to require more, but in the early day of LVM2 with Gentoo (especially when genkernel always use "static" creation) it actually only install one binary file lvm2 into initramfs.

In think it is still possible to install a very simple version of lvm2 but you just can not use Gentoo's ebuild, the maintainer of gentoo lvm2 package choose not to support such setup any more.


Interesting, very good to know, thanks. :))
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: Thu Dec 21, 2023 8:42 pm    Post subject: Reply with quote

So I wrote the init script, and then added a path in CONFIG_INITRAMFS_SOURCE (i.e. /usr/src/initramfs), recompiled the kernel, and.... I booted successfully, but I'm wondering if it just fell back to my genkernel initramfs.

After selecting the newest kernel (the one with my custom initramfs) I see this warning:

Code:
Warning: unable to open an initial console.


And I am shown the usual luksOpen prompt. I enter my password and it unlocks and boots fine.

A few things give me pause:

    - The warning
    - None of my echos were printed out
    - My /boot still has a genkernel initramfs file corresponding to the same kernel version that I am trying to boot now. I am not sure if it can 'fall back' to this or not in the even of a failed initramfs.


I'll try moving the genkernel initramfs file and boot again.

Edit: sure enough I get a kernel panic when the genkernel initramfs image isn't there. It complains that the initramfs file is missing. I haven't changed my grub config, so it has the cmdline entries needed to make genkernel initramfs work, and I wonder if this is why.

Here is the script I use which shows echos.
Code:
#!/bin/busybox sh

# mount here
mount -t proc      none /proc
mount -t sysfs      none /sys
mount -t devtmpfs none /dev

echo "Initializing the initramfs..."

rescue_shell() {
    echo "Oh no!!! Something wrong.... here shell:"
    busybox --install -s
    exec /bin/sh
}

# Password
echo "Enter LUKS passphrase:"
cryptsetup luksOpen /dev/nvme0n1p5 root || rescue_shell()

# activate LVM stuff
vgchange -ay || rescue_shell()

# mount root
mount /dev/mapper/gentoo-root /mnt || rescue_shell()

# unmount here
umount /proc
umount /sys
umount /dev

#switch root
echo "Switching to the root filesystem"
switch_root /mnt /sbin/init

# For emergencies
rescue_shell()
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4167
Location: Bavaria

PostPosted: Thu Dec 21, 2023 9:06 pm    Post subject: Reply with quote

sunox wrote:
So I wrote the init script, and then added a path in CONFIG_INITRAMFS_SOURCE (i.e. /usr/src/initramfs), recompiled the kernel, and.... I booted successfully, but I'm wondering if it just fell back to my genkernel initramfs.

Do you start your kernel with a bootmanager or (directly) with UEFI ?

If you use a bootmanager (like grub) please check that this bootmanager dont give BAD kernel command like options (e.g. initrd=...) POINTING to your (external) initramfs from genkernel.

Do you use a file-list for making your initramfs or do you use a directory with all necessary files inside ?

Embedded or as external CPIO ?
_________________
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: Thu Dec 21, 2023 9:11 pm    Post subject: Reply with quote

Sorry, I have seen this too late:
sunox wrote:
[...] I haven't changed my grub config, so it has the cmdline entries needed to make genkernel initramfs work, and I wonder if this is why.

You msut do a "grub-mkconfig" after a kernel-change ... make sure your old initramfs (from genkernel) is not find from grub-mkconfig (because grub-mkconfig adds all necessary KernelCmmandLineParms depending of the existence of an CPIO archive).
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
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 1, 2, 3  Next
Page 1 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