Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to avoid the need for initramfs
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
kiigass
n00b
n00b


Joined: 21 Nov 2018
Posts: 65

PostPosted: Tue Oct 13, 2020 8:08 pm    Post subject: How to avoid the need for initramfs Reply with quote

Hi,

I had an initramfs in my previous precious gentoo until... well Windows destroyed it =((
Now I am going to reinstall gentoo and I was wondering about the initramfs. As far as I understood what I read I am better off without initramfs, because the boot process is quicker and there is the risk to make a mistake, when updating kernel+initramfs, which results in problems on next reboot.

Different sources tell me different things, though: Most agree that, if I put /usr/ on a separate partition, I will need an initramfs. But what about /var/? Do I need an initramfs, if I put that on a separate partition? Are there other points I need to take care of?

By the way: I am going to make a Raid1 with LVM on top of it. So my questions of different partitions are rather questions of different logical volumes.

PS: Do I get into trouble (i.e. need of initramfs) because I use Raid/LVM?

thanks
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Tue Oct 13, 2020 8:40 pm    Post subject: Reply with quote

kiigass,

Provided you can build everything into the kernel to mount root and usr is on root, no initrd is required.
With a separate /usr, you either mount it in an initrd.

With raid, its not quite so clear cut. With mdadm metadata=0.90, the kernel can do raid autoassembly.
With mdadm metadata=1.2, the default, the raid needs to be assembled in an initrd as mdadm is a user space tool.

For root in LVM, you need to do vgchange -ay in the initrd as again LVM is userspace.

You may be able to use localmount to mount /usr but to do that udev cannot be allowed to start before localmount.
here may be other things now too. Several upstreams have broken /usr on its own partition now and I've not kept up.
_________________
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
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 3664

PostPosted: Wed Oct 14, 2020 12:27 pm    Post subject: Reply with quote

NeddySeagoon wrote:
Provided you can build everything into the kernel to mount root and usr is on root, no initrd is required.

And it's also possible to have the initramfs built into the kernel: https://wiki.gentoo.org/wiki/User:Charles17/custom_initramfs
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Wed Oct 14, 2020 1:42 pm    Post subject: Reply with quote

charles17,

Yep, also the kernel command line.

Build on what you know works. Start with the three separate pieces.
Once it all works, put the bits together.

If you must have an initrd, I must as I have root inside LVM on top of raid5, its possible to make it kernel agnostic by avoiding putting any kernel modules into the the initrd.

I made mine in April 2009. I've probably forgotten how to do it by now :)
_________________
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
kiigass
n00b
n00b


Joined: 21 Nov 2018
Posts: 65

PostPosted: Wed Oct 14, 2020 4:50 pm    Post subject: Reply with quote

Thanks for the answers!

Ok, that means, if I want to avoid the need for initramfs/initrd, I need to:

  • make sure /usr/ is on the same partition as /
  • stick to metadata=0.90 if I use raid
  • go without lvm (at least on the system directories)

Is that correct?

NeddySeagoon wrote:
I made mine in April 2009. I've probably forgotten how to do it by now :)

Caution, silly question incoming: I do not need to update my initramfs every time I update my kernel?
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3131

PostPosted: Wed Oct 14, 2020 5:18 pm    Post subject: Reply with quote

Quote:
Caution, silly question incoming: I do not need to update my initramfs every time I update my kernel?

No, unless it contains a kernel module required by your boot sequence. E.g. filesystem support, hard disk controller support, or NIC drivers for PXE.
Once you get to userspace and you can see your real root, you can load everything else.

Still, in order to make linux boot user-friendly, there is a tendency to build everything as modules, put all those modules inside a huge initramfs along with some hardware discovery scripts, and load whatever is required during early boot. Those kernels absolutely do require initramfs and initramfs for a kernel like that must contain the correct modules (same version) and thus must be rebuilt with every single update.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Wed Oct 14, 2020 5:29 pm    Post subject: Reply with quote

kiigass,

The kernel must be able to mount the root filesystem without needing any user space tools.
There needs to be enough on the root filesystem to be able to boot, that means bits of /usr.
Bits of /usr in practice means all of it.
So no LVM for root.

stick to metadata=0.90 if I use raid. Yes and set raid autodetect in the kernel.

The only silly question is the one you don't ask but be on your guard for silly answers :)

If your initrd contained kernel modules that needed to be loaded to mount the root filesystem, then it is bound to the kernel its compiled for.
... but you won't have an initrd :)
Provided its only user space tools, its kernel agnostic.

My initrd contains
Code:
# for raid on lvm
file /sbin/mdadm                /sbin/mdadm              755 0 0
file /sbin/lvm.static           /sbin/lvm.static         755 0 0

# libraries required by /sbin/fsck.ext4 and /sbin/fsck

slink   /lib                            /lib64                          777 0 0
file    /lib64/ld-linux-x86-64.so.2     /lib64/ld-linux-x86-64.so.2     755 0 0
file    /lib64/libext2fs.so.2           /lib64/libext2fs.so.2           755 0 0
file    /lib64/libcom_err.so.2          /lib64/libcom_err.so.2          755 0 0
file    /lib64/libpthread.so.0          /lib64/libpthread.so.0          755 0 0
file    /lib64/libblkid.so.1            /lib64/libblkid.so.1            755 0 0
file    /lib64/libuuid.so.1             /lib64/libuuid.so.1             755 0 0
file    /lib64/libe2p.so.2              /lib64/libe2p.so.2              755 0 0
file    /lib64/libc.so.6                /lib64/libc.so.6                755 0 0
file    /lib64/libmount.so.1            /lib64/libmount.so.1            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/initrd/init

Its all put together by a script supplied with the kernel.
_________________
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
GDH-gentoo
Veteran
Veteran


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

PostPosted: Wed Oct 14, 2020 5:43 pm    Post subject: Re: How to avoid the need for initramfs Reply with quote

kiigass wrote:
Now I am going to reinstall gentoo and I was wondering about the initramfs.
[...]
Different sources tell me different things, though:

To give a general answer:

1) You don't need an initramfs to mount the rootfs if you have a setup that doesn't require running userspace programs in order to do so.
2) You don't need an initramfs to mount /usr if:
2a) /usr is part of the rootfs (i.e. there is nothing to mount), or
2b) the rootfs hosts all the tools needed to mount /usr, and execution of programs that need files stored in /usr, or have their own executables stored there, is scheduled by the init system after mounting /usr.

Unless the boot sequence does overly complicated things, mounting filesystems other than the one containing /usr does not require an initramfs. What makes /usr special is simply the convention of using it to store programs and libraries. For example, I cannot think of a case in which you would need to run a program simultaneously complex enough to require files in /var, and essential enough to run early in the boot sequence.

The real issue here is determining whether requirements 1) and 2) can be satisfied by the setup you want. For some of them doing so is impossible, so using an initramfs in those cases is unavoidable.

Possible reasons that make 1) impossible to satisfy:
  • The rootfs is an LVM logical volume. Reason: to be able to mount the rootfs, you need to run vgchange to activate the volume group that contains it.
  • The rootfs is a LUKS encrypted volume. Reason: to be able to mount the rootfs, you need to run cryptsetup to decrypt the volume that contains it.
  • The physical device that hosts the rootfs needs a kernel driver that was compiled as a module. Reason: to be able to mount the rootfs, you need to run a userspace program to have the kernel load the modules, and you need a filesystem to hold the modules' *.ko files.
  • Etc.
The two most 'popular' reasons I can think of that make 2b) impossible to satisfy are:
  • usr-merge. Reason: it essentially consists in deliberately having a semi-empty rootfs; therefore, there would be no place to store the tools needed to mount /usr.
  • Certain udev rules usage practices. Reason: one of the things that make using an udev daemon attractive is automatic loading of needed kernel modules (in combination with kernel mechanisms), and because of that, it is scheduled to run quite early in the boot sequence. But on the other hand, udev rules are capable of having the udev daemon run arbitrary programs... and some packages have the habit of running programs that need files stored in /usr, or have their own executables stored there, from udev rules. Udev rules are processed at a time where, without an initramfs, most filesystems have not been mounted yet.
It is still possible to have a Gentoo system, even one where /usr is not part of the rootfs despite that not being officially supported, where 1) and 2b) can be satisfied, and that therefore does not need an initramfs. But it depends on how it is set up and which packages are installed.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Wed Oct 14, 2020 8:33 pm    Post subject: Reply with quote

Team,

For completness, you can have raid without an initrd or you can have root on LVM without an initrd.
For LVM on raid without an initrd, the kernel would need to start raid before it went looking for the LVM.
It does it in the wrong order.

I wrote up my findings on the wiki.
_________________
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
Goverp
Veteran
Veteran


Joined: 07 Mar 2007
Posts: 1998

PostPosted: Thu Oct 15, 2020 9:37 am    Post subject: Reply with quote

FWIW: if you build your initramfs into the kernel, you'll need a script that's run every time you make a new kernel. Hence your initramfs is as current as your kernel. In my case, I use ~amd64 gentoo-sources, which means I seem to have a new kernel every week, so my initramfs is never more than a week out of date.
_________________
Greybeard
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21606

PostPosted: Thu Oct 15, 2020 4:00 pm    Post subject: Reply with quote

If you configure the kernel to embed the initramfs, the kernel build system will take care of collecting the files. There is no script to write, unless you want a custom verifier (such as checking that your list of files to include provides all supporting libraries for the programs you embedded).
Back to top
View user's profile Send private message
kiigass
n00b
n00b


Joined: 21 Nov 2018
Posts: 65

PostPosted: Thu Oct 15, 2020 6:53 pm    Post subject: Reply with quote

@Team: Thanks alot! I learned so much, just by reading your posts. My impression now is: I might get better performance without initramfs/initrd, but it's a bad idea, because so many things might go wrong, that my system won't boot at all some day.

NeddySeagoon wrote:

My initrd contains
Code:
# for raid on lvm


You have a raid on lvm? I though one would build a lvm on a raid?

You told me, that I might not need to update my initramfs if it is kernal agnostic. Could you elaborate on that? How do I make a kernal agnostic initramfs?
Is there a way to know if my kernel would boot without initramfs or is there a way to try? (I mean of course I could just try and if the kernel cannot boot without an initramfs I am screwed.. :P )
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4130
Location: Bavaria

PostPosted: Thu Oct 15, 2020 8:44 pm    Post subject: Reply with quote

First of all: I hate initramfs. So, I am not objectiv ...

kiigass wrote:
I though one would build a lvm on a raid?

I recommend to do so. See also: https://serverfault.com/questions/217666/what-is-better-lvm-on-raid-or-raid-on-lvm

kiigass wrote:
Is there a way to know if my kernel would boot without initramfs or is there a way to try?

If your root-partition is outside your lvm-partitions you dont need initramfs and you will have much less troubles, if you have a problem with your raid or lvm (so I recommend this ...). Using lvm only for /home, /data, /var is IMHO the only sensible reason for it.
It is also much easier to configure; see also here: https://wiki.gentoo.org/wiki/Raid1_with_LVM_from_scratch
Another way to build such a system, you will find here: https://wiki.archlinux.org/index.php/LVM_on_software_RAID

I dont know why private people need a RAID1 (it is only needed for high availability systems, like servers), but please keep in mind that a RAID1 is NOT an alternative for backups (you have to do always).

P.S.: I found an old article about mdadm vs. lvm (for raid0), if you are interested look here: https://www.linuxtoday.com/blog/pick-your-pleasure-raid-0-mdadm-striping-or-lvm-striping.html
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Thu Oct 15, 2020 10:15 pm    Post subject: Reply with quote

kiigass,

Thats a typo in my comment. Its LVM on top of raid.

Lets get an understanding of what an initrd is. Its a root filesystem that holds all the things needed to mount the real root filesystem.
In days of old it was actually an ext2 filesystem in a file, then compressed.
You can still do that. Make an empty file, make a filesystem in the file. loop mount the file, copy things to it ...
Whatever filesystem type you choose for the initrd must be built into the kernel, or the kernel won't be able to read the filesystem.

What we do today in properly called an initramfs. Its a compressed CPIO archive of other CPIO archives.

To keep the initrd kernel agnostic, it must only contain user space tools. Never any kernel code.
If you need to load CPU microcode, you can build that into the kernel, it need not go in the initrd.

This wiki page tells how to make an initrd without the use of any autoblackmagic tools.

It can be improved. It uses binaries out of the live filesystem. That's bad as the live filesystem can change and depend on new libs.
e.g. lvm.static no longer builds. It should force the use of binaries in /root/initrd/fs, say, so that repeated runs years apart generate the same binary.
That requires the user to copy the structure to /root/initrd/fs, just like the orignal fs in a file.
plus ça change, plus c'est la même chose, as the French say. :)
_________________
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
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3267
Location: Canada

PostPosted: Fri Oct 16, 2020 5:15 am    Post subject: Reply with quote

IMHO. the easiest way to avoid initrd is to have / with /usr on a separate drive, nowadays preferably SSD. And then you can play with raids, llvm etc for /var /home /usr/local /opt whatever.
Back to top
View user's profile Send private message
Goverp
Veteran
Veteran


Joined: 07 Mar 2007
Posts: 1998

PostPosted: Fri Oct 16, 2020 8:52 am    Post subject: Reply with quote

Hu wrote:
If you configure the kernel to embed the initramfs, the kernel build system will take care of collecting the files. There is no script to write, unless you want a custom verifier (such as checking that your list of files to include provides all supporting libraries for the programs you embedded).

I thought I had to write (or borrow) a busybox shell script to invoke (in my case) mdadm before calling switchrooot, and also create the appropriate list of files and nodes etc. for the initramfs. Of course it works, but are you saying some or all of this is handled by the kernel make? Or is this some genkernel stuff, which I don't use?

If it's part of kernel build, can you point me at the documentation for this?
_________________
Greybeard
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Fri Oct 16, 2020 10:18 am    Post subject: Reply with quote

Goverp,

Code:
  ┌───────────────────────────────────── Initramfs source file(s) ─────────────────────────────────────┐
  │ CONFIG_INITRAMFS_SOURCE:                                                                           │ 
  │                                                                                                    │ 
  │ This can be either a single cpio archive with a .cpio suffix or a                                  │ 
  │ space-separated list of directories and files for building the                                     │ 
  │ initramfs image.  A cpio archive should contain a filesystem archive                               │ 
  │ to be used as an initramfs image.  Directories should contain a                                    │ 
  │ filesystem layout to be included in the initramfs image.  Files                                    │ 
  │ should contain entries according to the format described by the                                    │ 
  │ "usr/gen_init_cpio" program in the kernel tree.                                                    │ 
  │                                                                                                    │ 
  │ When multiple directories and files are specified then the                                         │ 
  │ initramfs image will be the aggregate of all of them.                                              │ 
  │                                                                                                    │ 
  │ See <file:Documentation/driver-api/early-userspace/early_userspace_support.rst> for more details.  │ 
  │                                                                                                    │ 
  │ If you are not sure, leave it blank.                                                               │ 
  │                                                                                                    │ 
  │ Symbol: INITRAMFS_SOURCE [=]                                                                       │ 
  │ Type  : string                                                                                     │ 
  │ Defined at usr/Kconfig:6                                                                           │ 
  │   Prompt: Initramfs source file(s)                                                                 │ 
  │   Depends on: BLK_DEV_INITRD [=y]                                                                  │ 
  │   Location:                                                                                        │ 
  │     -> General setup                                                                               │ 
  │       -> Initial RAM filesystem and RAM disk (initramfs/initrd) support (BLK_DEV_INITRD [=y])      │ 
  │                                                                                                    │ 
  │                                                                                                    │ 

You can either make your own initrd and have the kernel include it or tell the kernel how to build the initrd.
Either way, fixing it if it fails is a kernel rebuild.
_________________
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: 21606

PostPosted: Fri Oct 16, 2020 4:39 pm    Post subject: Reply with quote

Goverp wrote:
Hu wrote:
If you configure the kernel to embed the initramfs, the kernel build system will take care of collecting the files. There is no script to write, unless you want a custom verifier (such as checking that your list of files to include provides all supporting libraries for the programs you embedded).

I thought I had to write (or borrow) a busybox shell script to invoke (in my case) mdadm before calling switchrooot, and also create the appropriate list of files and nodes etc. for the initramfs. Of course it works, but are you saying some or all of this is handled by the kernel make? Or is this some genkernel stuff, which I don't use?

If it's part of kernel build, can you point me at the documentation for this?
Maybe there is a terminology confusion here. You previously wrote:
Goverp wrote:
FWIW: if you build your initramfs into the kernel, you'll need a script that's run every time you make a new kernel.
My point was that you do not need to write or borrow a script that will run when you build the kernel, because the kernel build system can handle embedding your initramfs into the kernel. However, you are correct that the initramfs must contain a script, which will run at boot time, to do the work.
Back to top
View user's profile Send private message
msst
Apprentice
Apprentice


Joined: 07 Jun 2011
Posts: 259

PostPosted: Fri Oct 16, 2020 7:13 pm    Post subject: Reply with quote

By the way, you can get most of the benefits of LVM also by simply using btrfs.

But the limitations are the same: Single disk btrfs can be booted directly by the kernel. Multi disk aka raid (which btrfs supports natively) requires a device scan and therefore an initramfs.
Note that RAID5/6 is still not considered stable, but is nowadays anyway almost obsolete.

I use on one computer an kernel with bulid-in initramfs (better-initramfs). This initramfs file is once build and then static, e.g. requires no rebuilding during kernel updates if you compile sufficient stuff in. I use it for luks-multidisk-btrfs. I also use a conventional initramfs on another computer. This requires one new script run of the initramfs per kernel update then.
Back to top
View user's profile Send private message
Goverp
Veteran
Veteran


Joined: 07 Mar 2007
Posts: 1998

PostPosted: Sat Oct 17, 2020 9:51 am    Post subject: Reply with quote

Hu wrote:
..Maybe there is a terminology confusion here. You previously wrote:
Goverp wrote:
FWIW: if you build your initramfs into the kernel, you'll need a script that's run every time you make a new kernel.
My point was that you do not need to write or borrow a script that will run when you build the kernel, because the kernel build system can handle embedding your initramfs into the kernel. However, you are correct that the initramfs must contain a script, which will run at boot time, to do the work.

Ah, indeed, I was talking about the script in the initramfs; not sure why I said it needed to be run every time it's built, that's rubbish.

As an aside, I'm surprised nobody's mentioned that GRUB can boot many kernels in circumstances that used to require an initramfs such as RAID, LVM, etc.
_________________
Greybeard
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Sat Oct 17, 2020 10:13 am    Post subject: Reply with quote

Goverp,

Grub has to make its own arrangements for reading the boot files from the HDD. Grub2 can indeed pick them out from raid, LVM etc.
This is just grub getting the kernel and initrd loaded though.

Once the kernel is loaded its all on its own if there is no initrd. It has to be able to mount root itself.
Only the initrd can help. Grub is gone.
_________________
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
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo 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