# building a kernel using genkernel

## juniper

I am trying to build a custom kernel and I am running into trouble (NOTE:  I know that genkernel is NOT the way to do this, but bear with me).

I installed my initial kernel for gentoo using genkernel.  It made a usable though likely bloated kernel, so I tried to build my own kernel without success.

Here is what I did.

1)  I have a usable 5.15.52-gentoo kernel.  This is the one that genkernel built on installation.

2)  I have a somewhat unusable 5.15.69-gentoo kernel, but it has issues.

So I am using the first kernel.  The weird thing is that the sources directory doesn't have a Makefile for 5.15.52.  Why is that?  did I accidentally erase it?  Shouldn't it have a Makefile?  I guess I must have erased it.  Anyway, when I emerge things emerge complains that there is no Makefile.  Can I cheekly replace by just grabbing the Makefile from my 5.15.69 sources?

anyway, the way I built my new 5.15.69 kernel is that I typed make oldconfig and then tweaked.  Does that grab the config file from 5.15.52?  I don't really understand what that does.

So back to genkernel.  Before I start tweaking and making my own kernel, I thought that I would update my kernel using genkernel.  Do I just go in the 5.15.69 directory and type genkernel all?  My point here is to build a usable kernel here.  I don't need to tweak it at this point.  I just want a generic kernel that works.

----------

## Juippisi

Take a look at /etc/genkernel.conf for configuring some basic stuff. Or "genkernel -h"

You just use --kernel-config=/... option to select the working config file, then genkernel should build an exact image (of course depending on your choices in /etc/genkernel.conf)

"genkernel --menuconfig --kernel-config=/... --install all" to invoke menuconfig so you can see what's enabled and what's not before building your kernel image. By default genkernel saves config files to /etc/kernels so you can use those when updating your kernel if you managed to build a working one previously.

----------

## Hu

 *juniper wrote:*   

> The weird thing is that the sources directory doesn't have a Makefile for 5.15.52.  Why is that?  did I accidentally erase it?

 You probably used emerge --depclean or similar to uninstall the sources for that version. *juniper wrote:*   

> Can I cheekly replace by just grabbing the Makefile from my 5.15.69 sources?

 You can try, and within a minor version that might work, but I would not recommend it.  More generally, if you are missing the Makefile, you are probably missing all the sources for 5.15.52.

It's unlikely that your problem is actually related to v5.15.52 vs v5.15.69; it is more likely that your configuration of v5.15.69 is not yet right, so you are missing some required feature.  If so, then resurrecting sources for v5.15.52 is not useful.  You would be better off taking your v5.15.52 .config, porting it to v5.15.69, and adjusting from there. *juniper wrote:*   

> anyway, the way I built my new 5.15.69 kernel is that I typed make oldconfig and then tweaked.  Does that grab the config file from 5.15.52?

 make oldconfig will update your input .config for any changes between the two versions.  I did not remember exactly how it works, so I looked it up for you.  As I read scripts/kconfig/confdata.c, it will read the file named by $KCONFIG_CONFIG or, if no such variable is set, the file named .config.  If you put the v5.15.52 configuration in one of those places, then yes.  Otherwise, no.

----------

## pietinger

 *Hu wrote:*   

>  *juniper wrote:*   anyway, the way I built my new 5.15.69 kernel is that I typed make oldconfig and then tweaked.  Does that grab the config file from 5.15.52? 
> 
> make oldconfig will update your input .config for any changes between the two versions. [...]

 

juniper,

you should copy your old .config from /usr/src/linux-5.15.52 INTO /usr/src/linux-5.15.69 before you do a "make oldconfig", because:

IF there is no .config in /usr/src/linux-5.15.69 and you do a "make oldconfig", THEN it searches in /boot for config-files (and maybe finds some very old configs ...  :Sad:  )

If you want start new you should do:

```
# cd /usr/src/linux-5.15.69

# make distclean

# cp /usr/src/linux-5.15.52/.config .

# make oldconfig

# make .... etc.
```

----------

## Hu

 *pietinger wrote:*   

> IF there is no .config in /usr/src/linux-5.15.69 and you do a "make oldconfig", THEN it searches in /boot for config-files (and maybe finds some very old configs ...  )

 What performs this search?  I admit I only read the code enough to answer juniper's question, but I didn't see anything that looked like the kernel build tools could search /boot to find a configuration.

----------

## juniper

 *Hu wrote:*   

>  *pietinger wrote:*   IF there is no .config in /usr/src/linux-5.15.69 and you do a "make oldconfig", THEN it searches in /boot for config-files (and maybe finds some very old configs ...  ) What performs this search?  I admit I only read the code enough to answer juniper's question, but I didn't see anything that looked like the kernel build tools could search /boot to find a configuration.

 

I am at work now, and it appears this is correct.  That is, if you don't copy the .config file over from you older kernel make oldconfig will search for it.  I remember a message "getting default config from" some place /usr/src/something something something.  Anyway, I did figure this out last night and did a make, but I didn't do a make distclean first.  Don't know if that will cause a problem.

 *Hu wrote:*   

> 
> 
> You probably used emerge --depclean or similar to uninstall the sources for that version.
> 
> 

 

Ah.  you think that many things are missing, not just the Makefile?  I can check that.  emerge should tell me.

i will let you know what is up when I get home.

----------

## Hu

git grep 'getting default config' returns no hits, so I think some helper tool other than the core kernel build tools generated it.  That would explain why I found nothing in the kernel repository.

----------

## pietinger

 *Hu wrote:*   

> What performs this search?  I admit I only read the code enough to answer juniper's question, but I didn't see anything that looked like the kernel build tools could search /boot to find a configuration.

 

Hu, I took this information from @Josef.95 from this (german) thread:

https://forums.gentoo.org/viewtopic-p-8594688.html#8594688

Because I wanted to be sure I have tested it today on my machine, and I got a different output:

```
# cd /usr/src/linux

/usr/src/linux # mount /boot/

/usr/src/linux # mv .config /boot/config-5.15.72

/usr/src/linux # make oldconfig

#

# using defaults found in arch/x86/configs/x86_64_defconfig

#

*

* Restart config...

*

*

* General setup

*

Compile also drivers which will not load (COMPILE_TEST) [N/y/?] (NEW)
```

So, maybe this informatation is outdated and I have been sit on an old occurrence. My bad.

----------

## juniper

Yes.  IT appears that an emerge --depclean removed my Makefile (and no doubt other files).  I have no kernel-sources for my working kernel.

I also figured out the answer to one of my questions:  when "genkernel all" is executed, which kernel does it build?  It's the one pointed to by /usr/src/linux.

----------

## juniper

ok.  genkernel seems to have made a reasonable kernel.  What I did was type genkernel all, grub-install (to install it into the efi directory), and grub-mkconfig -o /boot/grub.

There is a .config file in my /usr/src/linux-5.15.69 directory now.  Is this therefore the config file that genkernel used to build this kernel?  I ask because can I use this config file to build a custom kernel via make menuconfig (then choosing my kernel options.  I've got a good idea of how to turn off a lot of support for stuff I don't need, but not perfect idea), and then make && make modules_install && make install.  I don't think I need an initramfs, because one of the bum kernels I built didn't have it, but the system booted.

So I think I learned my lesson.  Read the emerge --depclean is cleaning and make sure that the current working kernel's sources aren't in that list!

----------

## pietinger

 *juniper wrote:*   

> There is a .config file in my /usr/src/linux-5.15.69 directory now.  Is this therefore the config file that genkernel used to build this kernel? 

 

Yes.

If you ever want copy back a (backuped) .config into this dir and want to use it, dont forget to do a "make oldconfig" before you do your "make menuconfig".

(If you need a list of all threads for a kernel configuration you could take a look into my article: https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Manual_kernel_configuration#What_you_should_configure_at_minimum )

----------

## juniper

 *pietinger wrote:*   

>  *juniper wrote:*   There is a .config file in my /usr/src/linux-5.15.69 directory now.  Is this therefore the config file that genkernel used to build this kernel?  
> 
> Yes.
> 
> If you ever want copy back a (backuped) .config into this dir and want to use it, dont forget to do a "make oldconfig" before you do your "make menuconfig".
> ...

 

so make distclean, copy old config, make oldconfig, make menuconfig, mess with options, make, make modules_install and make install?

----------

## pietinger

 *juniper wrote:*   

> so make distclean, copy old config, make oldconfig, make menuconfig, mess with options, make, make modules_install and make install?

 

YES ... and dont forget to mount /boot at first ... and maybe some action for your bootmanager afterwards  :Wink: 

(If you use grub do a "grub-mkconfig -o /boot/grub/grub.cfg")

P.S.: See also here: https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Manual_kernel_configuration#Cheat_Sheets

----------

## juniper

My /boot is mounted automatically at boot.   Perhaps that is unnecessary?  I guess I only need /boot for kernel stuff.   I used to use ubuntu and kernels were constantly updated so I kept /boot mounted.

Yes, I also need to mount /boot/efi manually.

yes, after make install I do a grub-install and grub-mkconfg.

Thanks.Last edited by juniper on Mon Oct 17, 2022 10:56 pm; edited 1 time in total

----------

## pietinger

 *juniper wrote:*   

> yes, after make install I do a grub-install and grub-mkconfg.

 

A grub-install is only necessary one time ... the initial installation of grub ... later do only mkconfig   :Wink: 

----------

## juniper

So /boot/efi is updated with make install?

----------

## pietinger

 *juniper wrote:*   

> So /boot/efi is updated with make install?

 

No, in /boot/efi is only your /boot/efi/gentoo/grubx64.efi

All kernels (you do with "make install") will be in /boot/ (also all other grub files)

"grub-mkconfig" search in /boot for all kernels and make a list.

Later, when you boot (grub) you can select your kernel you want to boot (grub uses now this list).

----------

## GDH-gentoo

 *pietinger wrote:*   

> A grub-install is only necessary one time ... the initial installation of grub ...

 

Actually, grub-install is also necessary after an update of sys-boot/grub, or otherwise you would never actually boot with the updated GRUB. But yes, if /boot/grub/grub.cfg is managed with grub-mkconfig (which is what most people do), after a kernel upgrade only the latter is necessary.

----------

## juniper

Ok.  emerge just pulled in new sources, 5.15.74.  So I will copy the config from my 5.15.69 and do a make oldconfig, and then make menuconfig.

But my current working kernel is 5.15.69 and depclean wants to remove it.  I assume there is a way to tell depclean to not remove it?

EDIT:  Nevermind.  in the docs.  emerge -av --noreplace gentoo-sources:<kernel-number>

Also if i have a working kernel, can I just make distclean in that kernel directory?  Even if I used genkernel?  Yes, I will backup the .config file, but otherwise do I need all the stuff there?  I noticed that the source directory balloons like crazy after a compile.

----------

## pietinger

 *juniper wrote:*   

> Also if i have a working kernel, can I just make distclean in that kernel directory?  Even if I used genkernel?  Yes, I will backup the .config file, but otherwise do I need all the stuff there?  I noticed that the source directory balloons like crazy after a compile.

 

Yes, you could delete (clean up) your kernel source directory, but it has an disadvantage:

IF you want change your kernel configuration and you will do a "make" to compile it again, THEN ALL must compiled again.

IF you leave this directory as it is, next "make" does only your changes (in most cases).

It is your decision. I dont recommend it to delete it with "make distclean"; instead delete it completely only after emerging (and installing) a NEW kernel version (and booting the new kernel version successully).

----------

## juniper

My compute is fairly fast.  I can compile quickly.

Another question:  presumably genkernel --all simply executes make commands after it makes a .config file.  What commands does it do?  make, make modules_install, make install?  But it also installs initramfs.  What command does that?

Basically genkernel produces a working kernel for me.  I have yet to do that manually.

----------

## grknight

 *juniper wrote:*   

> Another question:  presumably genkernel --all simply executes make commands after it makes a .config file.  What commands does it do?  make, make modules_install, make install?  But it also installs initramfs.  What command does that?.

 

By default, the commands are:

make mrproper

copy config (either default or specified with --kernel-config=)

make

make modules_install install

a custom script internal to genkernel with many commands within to create the initramfs

----------

## juniper

Ok.  So I copied over my .config from my 5.15.69 sources that genkernel --all created.

I did a make oldconfig, make, make modules_install, make install.

But I got a kernel panic complaining that it could not mount the root fs on some block.

Is this because a initramfs was expected by the boot process?  I don't have a complicated setup, but since I am using the genkernel --all config file, is this likely the cause?  I am looking at the wiki page for manually creating an initramfs and yikes.  Bloody hell, I ain't Linus.

However, I am willing to learn.  I have a pretty standard box with standard hardware, so I doubt I need an initramfs file.  Some of the kernel I built didn't have this and booted (but had other problems like sound not working).

So I assume I should modify the config file by first doing a make oldconfig and then a make menuconfig and turning off any initramfs expectations.  is this correct?  And where should this be done?

Thanks grknight.  I see your post.  I assume initramfs is my issue.

----------

## pingtoo

juniper,

Using initramfs is depend on how you design your rootfs. and sometime how you specify your kernel command to discover how/where is rootfs.

initramfs primary design goal was to discover rootfs, later got extent is function to do more than just probe hardware and load necessary kernel modules.

So please share your kernel command line, as well lsblk -f and blkid. we might need kernel .config as well because if we not able to find correct device from those two command that mean likely you missing necessary driver to use for rootfs.

----------

## juniper

hey pingtoo,

I am happy to share all those things.  As I said, I got a working kernel (it boot, but sound didn't work), so I don't think I need initramfs.  It boot fine.

as for what you asked.

```

NAME    FSTYPE FSVER LABEL       UUID                                 FSAVAIL FSUSE% MOUNTPOINTS

sda                                                                                  

├─sda1  vfat   FAT32 SYSTEM_DRV  5ECA-7B2D                                           

├─sda2                                                                               

├─sda3  ntfs         Windows7_OS 88B6EA19B6EA0810                                    

├─sda4  ntfs                     48F670E4F670D3A2                                    

├─sda6  swap   1                 4a541332-776f-4ad7-a0d9-e7728c522773                [SWAP]

├─sda7  ext4   1.0   boot        568c8e88-a3ad-4bf5-a6b9-12491e10bfdb    2.4G     3% /boot

├─sda8  ext4   1.0   home        a0bcecdf-59cf-40c9-8c28-948c0f71ed51   26.1G    66% /home

├─sda9  ext4   1.0   slash       51b75f5a-2152-449b-9a87-1b0f30c12d0f      3G    83% /

└─sda10 ext4   1.0   var         27771d6c-af79-43b0-a48a-92a7d6c3911a      2G    53% /var

sr0

```

```

/dev/sda4: BLOCK_SIZE="512" UUID="48F670E4F670D3A2" TYPE="ntfs" PARTUUID="f231d7f2-0ee3-4eeb-9a7f-87b2a93d9f7e"

/dev/sda2: PARTLABEL="Microsoft reserved partition" PARTUUID="fa1f560d-a324-4d0d-b612-6ceac570cfcf"

/dev/sda9: LABEL="slash" UUID="51b75f5a-2152-449b-9a87-1b0f30c12d0f" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="6cb30d71-9bfe-ed4f-858b-fea37d7dbe38"

/dev/sda10: LABEL="var" UUID="27771d6c-af79-43b0-a48a-92a7d6c3911a" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="04d740c0-4f11-734d-bf90-b74d886ca9ef"

/dev/sda7: LABEL="boot" UUID="568c8e88-a3ad-4bf5-a6b9-12491e10bfdb" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="ec7c10b5-07e1-2347-a40a-213a0f3a6a29"

/dev/sda3: LABEL="Windows7_OS" BLOCK_SIZE="512" UUID="88B6EA19B6EA0810" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="d9539bed-dc6b-4244-90da-006fd90da127"

/dev/sda1: LABEL="SYSTEM_DRV" UUID="5ECA-7B2D" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="acf920e2-addf-4572-8d84-dde18c04a26e"

/dev/sda8: LABEL="home" UUID="a0bcecdf-59cf-40c9-8c28-948c0f71ed51" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="bf5f10f6-03f9-4b25-af55-f23eeaf3610d"

/dev/sda6: UUID="4a541332-776f-4ad7-a0d9-e7728c522773" TYPE="swap" PARTUUID="0b534ed0-061d-45ba-92df-3ae5ab9c0601"

```

I just noticed that I accidentally erased my kernel .config.  I can recreate it.  It was the one created by genkernel --all.  Do you want it?

I don't know what you mean by "kernel command line".

----------

## pietinger

 *juniper wrote:*   

> I don't know what you mean by "kernel command line".

 

If you look with "dmesg" into your systemlog, you will find a line like this:

```
Kernel command line: root=PARTUUID=99beb5b2-b529-40fb-b0bc-3250a5237491 [...] 
```

This is the information kernel NEEDS (and uses) to find its root partition (you can give also more commands to kernel with this).

Now from where comes this data  ?

If you boot your kernel with a boot manager (e.g. grub) this boot manager CAN give this data to kernel (if you configure your boot manager correct).

If you use UEFI to boot your kernel directly (kernel is then called "stub kernel") there exists two methods:

1. UEFI is able to give additionally data to your kernel (rarely used), or in most cases:

2. You configure this data INTO your kernel:

```
Processor type and features  --->

    [*] Built-in kernel command line

    (root=PARTUUID=99beb5b2-b529-40fb-b0bc-3250a5237491 ro loglevel=8 lsm.debug ima_appraise=enforce) Built-in kernel command string
```

(this is from my machine)

Maybe you want read also this wiki article (I have linked to this article from my article I have given you):

https://wiki.gentoo.org/wiki/PC_Boot_Process

----------

## juniper

```

Kernel command line: BOOT_IMAGE=/vmlinuz-5.15.75-gentoo-x86_64 root=UUID=51b75f5a-2152-449b-9a87-1b0f30c12d0f ro

```

I just compiled a kernel with genkernel.  Works like a charm.  big though.  .config is 9000 lines long.  .config was produced by genkernel.  I assume I shouldn't post this monster doc?  do you want to see it?

I use grub2 to boot.  The machine is dual boot.  Grub seems to work flawlessly.  It's a UEFI machine, but as I said, I don't use a stub kernel.

----------

## pietinger

juniper,

as far as I understand you wanted to build your own kernel with a smaller configuration and without initramfs (genkernel uses).

You have two choices to reach this goal:

1. Strip down your kernel config, OR

2. Build up your config from the (minimal) default config (default config is what gentoo-sources brings with; NOT what genkernel brings with).

For choice 2 I made a description (I already linked): 

https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Manual_kernel_configuration

In every case the first thing you must know is your machine. Therefore I recommended to do (and notice):

```
root #lspci -k

root #lsmod | more
```

after booting with our installation CD - OR - in your environment you have now with genkernel. Now you should have all information about all modules you will need.

In my opinion choice 1 is harder, because:

There are many modules configured as <M>odule because initramfs will laod them to reach the goal: kernel is able to reach its root partition. If you now want to change to a configuration without initramfs all these modules you must set static into your kernel configuration (this you have to do in every case - independent if you go way 1 or 2) AND you have to disable all unnecessary options / modules (this you have not to do with choice 2).

So, please read not only my article, read also all linked articles in chapter "More informations".

Note to config file:

After you have done choice 1 or 2 you will have a config file with almost the same length ... but now most of them will be a: "# CONFIG_[...] is not set"   :Wink: 

Note to your kernel command line: This data was given by grub to your kernel AND must be changed if you want to boot a kernel without initramfs  :Wink: 

----------

## pingtoo

juniper,

Since you can boot and got rootfs mounted, I am fine, no further information I need.

Please review pietinger suggestion.

Should you run into boot problem again, don't hesitate to ask help again.

Good luck.

----------

## juniper

 *pietinger wrote:*   

> juniper,
> 
> as far as I understand you wanted to build your own kernel with a smaller configuration and without initramfs (genkernel uses).
> 
> 

 

Correct.

 *Quote:*   

> 
> 
> You have two choices to reach this goal:
> 
> 1. Strip down your kernel config, OR
> ...

 

I am trying this option.  Forgive me for being a kernel moron, but what I did is take the config file produced by genkernel and did a make distclean, copied .config from genkernel, make oldconfig, make, make modules_install, make install and I got a kernel with kernel panic message.

I don't understand why that didn't work.  Perhaps the .config from genkernel needs an initramfs (which I did not produce)?  But I don't think that's how initramfs works.  Or i made a mistake.  I will try this properly when I got home and will post again tonight.

 *Quote:*   

> 
> 
> 2. Build up your config from the (minimal) default config (default config is what gentoo-sources brings with; NOT what genkernel brings with).
> 
> For choice 2 I made a description (I already linked): 
> ...

 

Aha!  I see you have already answered my initramfs question!  Ok.  I will try route 2 when I get home.

Stay tuned!

----------

## sublogic

For what it's worth, I successfully stripped my genkernel by running 'make localmodconfig'.  Run a 'make help' for an explanation.

(Manual tweaks: adding CONFIG_USB_STORAGE=m and compiling my root fs statically instead of modular.)

----------

## juniper

 *sublogic wrote:*   

> For what it's worth, I successfully stripped my genkernel by running 'make localmodconfig'.  Run a 'make help' for an explanation.
> 
> (Manual tweaks: adding CONFIG_USB_STORAGE=m and compiling my root fs statically instead of modular.)

 

I tried make localmodconfig, make, make modules_install, make install.  built a kernel that couldn't mount root fs.

So I think I need to do what you did.  How do I do that?

The weird thing is that it messed up my working kernel (same version).  I think this might have been an autorenaming thing.  I am currently compiling a working genkernel.

EDIT:  I use the guide at https://github.com/flexibeast/guides/blob/master/minimal-gentoo-kernel.md to make localmodconfig.

it doesn't say how to install the kernel after making the config file, so I assume you execute make, make modules_install, make install and then run the usual grup mkconfig command.  Is there a way to give the new kernel a custom name so it doesn't move around my old kernel with the same version?  Also I think I need to compile something directly into the kernel so it can find the root fs.

----------

## pingtoo

juniper,

Based on this port *juniper wrote:*   

> hey pingtoo,
> 
> I am happy to share all those things.  As I said, I got a working kernel (it boot, but sound didn't work), so I don't think I need initramfs.  It boot fine.
> 
> as for what you asked.
> ...

 

Your kernel command line should have

```
... root=PARTUUID=6cb30d71-9bfe-ed4f-858b-fea37d7dbe38 rootfstype=ext4 ...
```

Change root=UUID=... to root=PARTUUID=... is because you choose not to use initramfs, genkernel generated initramfs have function correctly parse kernel command line and use UUID to search, Linux kernel only can only parse PARTUUID. 

And hopefully your kernel already have ext4 module as buildin this is always needed with or without initramfs.

----------

## juniper

[quote="pingtoo"

Your kernel command line should have

```
... root=PARTUUID=6cb30d71-9bfe-ed4f-858b-fea37d7dbe38 rootfstype=ext4 ...
```

Change root=UUID=... to root=PARTUUID=... is because you choose not to use initramfs, genkernel generated initramfs have function correctly parse kernel command line and use UUID to search, Linux kernel only can only parse PARTUUID. 

And hopefully your kernel already have ext4 module as buildin this is always needed with or without initramfs.[/quote]

Do I add this line to /boot/grub/grub.cfg in the appropriate kernel line?  and then do I execute a command?

----------

## pingtoo

 *juniper wrote:*   

> Do I add this line to /boot/grub/grub.cfg in the appropriate kernel line?  and then do I execute a command?

 

Once you replace UUID with PARTUUID and correct PARTUUID value, I think you need to run some grub-xxx command to update actual file, and once you finish grub's update, you reboot, there is no executation of the command.

I am no grub expert, so I don't know what is the right grub command to run to update.

----------

## sublogic

 *juniper wrote:*   

>  *pingtoo wrote:*   Your kernel command line should have
> 
> ```
> ... root=PARTUUID=6cb30d71-9bfe-ed4f-858b-fea37d7dbe38 rootfstype=ext4 ...
> ```
> ...

 

It goes in /etc/default/grub , for example

```
GRUB_CMDLINE_LINUX="root=PARTUUID=6cb30d71-9bfe-ed4f-858b-fea37d7dbe38 rootfstype=ext4"
```

When you re-run grub-mkconfig, it will add those command-line options to the "linux" lines.

(I'm not sure you need the "rootfstype" option; including it anyway to show how the blank-separated options work.)

Since you don't use an initramfs, you need to make sure all drivers needed to boot are builtin, not modules.  After the "make localmodconfig" you need a "make menuconfig" to change the required drivers from "=m" to "=y".  How to find out the list of drivers ?

In my case the original kernel had everything as modules because of genkernel;  but it also had in initramfs from genkernel, with a /lib/modules whose content gets pulled in by udev.  What I did, from memory:reboot, adding a "debug" option by editing the command line from the grub menu; this starts the early userspace in a rescue shell;

type "exit" twice (?) to advance to the point where the root is mounted on /newroot but before the switch_root;

remount /newroot read-write;

lsmod > /newroot/root/needed-drivers;

remount /newroot read-only (just in case);

type "exit" one last time to do the switch_root and finish booting.

Now I had a file in "/root/needed-drivers" with a list of modules that were sufficient to mount the root filesystem.  I used that in my "make menuconfig" step.  With some discretion: things like the SATA driver and the ext4 are essential, but network interfaces can wait for final userspace.

An added advantage for me: the initramfs is now decoupled from the kernel since its /lib/modules is no longer needed.  I don't need to rebuild the initramfs when I upgrade the kernel, the old one works fine.  (I need an initramfs because full disk encryption.)

----------

## juniper

Hello all,

There is an alternative to make localmodconfig and that's make localyesconfig where everything is compiled into the kernel.

What are the downsides of using that?

----------

## sublogic

 *juniper wrote:*   

> What are the downsides of [localyesconfig]?

 Pretty minor.  Sometimes it is useful to unload and reload a module to reset a mildly buggy driver.  For example, sys-power/hibernate-script has many hacks for modules that don't play well with hibernation (for laptops).  But if everything works well as builtin, go for it.  You can always change them back to =m if need be.

----------

