Difference between pages "Initramfs" and "Building a Kernel from Source"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
== What is initramfs? ==
Setting up a proper kernel yourself - lean, mean and tailored to your hardware, is the challenge by which a linux user can graduate to becoming a Funtoo knight ;-)
[http://en.wikipedia.org/wiki/Initramfs Wikipedia] defines initramfs as:
<blockquote>
initramfs, abbreviated from "initial ram file system", is the successor of initrd. It is a cpio archive of the initial file system that gets loaded into memory during the Linux startup process. The Linux kernel mounts it as root file system and starts the init process from it. This will complete certain tasks before the real root file system is loaded; thus, initramfs needs to contain all of the device drivers and tools needed to mount the real root filesystem.
</blockquote>


== Do I need an initramfs? ==
Even though many of us are using enterprise-ready kernels in datacenters, there is almost nobody who hasn't at least considered building a kernel for his laptop / PC.
The reason to build a kernel with an initramfs is mostly for interoperability (e.g. live-cd's) and special features like an included busybox, ssh, etc. But mostly, and that's why we are doing this here now, to have a proper kernel up and running quick'n dirty in a reasonable time without fighting hours and days until a more or less exotic hardware is perfectly run by the kernel. After having a proper basic kernel running with the help of an initramfs, I really recommend you to go a step further and build a true kernel with all features includes without an initramfs. However, relying only on a kernel to boot a system can be quite time consuming, so we have provided several initramfs options for Funtoo. If you have decided to use an initramfs, not just a kernel, check out the options below and choose the one that you like the most.
We are showing here how an intermediate Linux user can use an alternative to the standard beginners "genkernel" approach, to compile a custom kernel, in a relatively speedy and easy set up.


== better-initramfs ==
== Minimum Requirements ==
Piotr's better-initramfs is a popular approach among Funtoo'ers to building an initramfs. It is quick, nice, and shiny. The biggest plus is that, once built, it is kernel version independent.
* '''Understand the command line'''
* '''Know where the kernel files are located'''


=== Installation ===
== Assumptions ==
To install better-initramfs on your system, change to the <code>/opt</code> directory (or any other directory that you deem suitable) and clone the better-initramfs repository from bitbucket.
You start from an installed Funtoo system on the disk, or at least, you are on stage3 in a chrooted environment from a live cd, following somehow the Funto [[Installation (Tutorial)|Installation Tutorial]].
 
== Less advanced version ==
=== Emerging the kernel sources ===
To begin, we have to figure out which kernel sources we will use. If you are unsure about which sources are available and what their benefits and drawbacks are, check out the [[Funtoo_Linux_Kernels| Kernels]] page.
 
After you have made a decsion as to which kernel you want to install, emerge it:
<console>
###i## emerge vanilla-sources
</console>
Portage will now go about installing the sources to ''/usr/src''. It will also symlink the kernel-version directory to a directory called ''linux''.
 
=== Configuring the kernel ===
Now that the kernel sources are on your system, you should configure them. To do this, change your directory to ''/usr/src/linux''
<console>
###i## cd /usr/src/linux
</console>
As we are now in the kernel sources directory, we can run a script that allows us to modify them. Run:
<console>
<console>
###i## cd /opt
###i## make menuconfig
###i## git clone https://bitbucket.org/piotrkarbowski/better-initramfs.git
</console>
</console>
While you edit the sources, keep the following in mind:
* To build something into your kernel, press y when you have it selected.
* To exclude something from your kernel, press n when you have it selected.
* To build something as a module, press m.


=== Building <code>/initramfs.cpio.gz</code> ===
Things that you may need to include in your kernel:
Now that you have better-initramfs on your system, we can make the <code>initramfs.cpio.gz</code> image and move it to <code>/boot</code>.
* Wireless/LAN drivers
{{fancynote| do not run <code>make prepare</code> or <code>make image</code> until you have configured your kernel. If you have not installed / configured a kernel yet, check out: [[Building_a_Kernel_from_Source| Building a Kernel From Source]] and [[Funtoo_Linux_Kernels| Funtoo Linux Kernels]].}}
* Support for your graphics card
* Support for your audio card
* Support for USB devices
{{fancynote| Many pages on the wiki will tell you the kernel requirements for the application that they are about. Keep your eyes open for the blue background, white text sections of pages. Like on this one: [[uvesafb| uvesafb]]}}
 
=== Building and installing the kernel sources ===
After you finish configuring your kernel sources, you will need to build them. To build your sources, run the following:
<console>
<console>
###i## cd better-initramfs
###i## make
###i## bootstrap/bootstrap-all
###i## make prepare
###i## make image
###i## cp output/initramfs.cpio.gz /boot
</console>
</console>
{{fancytip| You can add -j<number of processing cores + 1> after make to build the kernel more quickly.}}
When the kernel and its modules finish building, install them:
<console>
###i## make install modules_install
</console>
Now that you have installed your kernel and modules, it is a good idea to install an initramfs. If your system has a separate ''/usr'' partition, is encrypted, or uses some other non-standard configuration, it will probably not boot without an initramfs. See [[Building_a_Kernel_from_Source#Initramfs| Initramfs]].
== Advanced version ==
=== Getting ready to start ===
{{fancynote| In this case we are building a kernel that is booting root in LVM over encrypted LUKS container.
If you don't have this setup, don't worry, you just don't need all the modules, but everything else is similar.}}
First, there is the decision which linux kernel sources we need.
There are plenty of them in the repositories around, often it is not easy to distinguish between them.
I would always trust my distribution of choice and take what is has to offer - and funtoo has a lot to offer!
I really do recommend (especially if it is your first time) to build a debian-sourced genkernel like described in chapter 5 "Using Debian-Sources with Genkernel" in the [[Funtoo_Linux_Kernels| Funtoo Kernels Tutorial]].
From there you should have a running system booting nicely from your own build (just little bit bloated) kernel. This is more than you can expect from any other ready to go distribution.
{{fancynote| We are using RedHat's dracut in order to build a nice initramfs (containing all the necessary tools and extra drivers our kernel might need to start the system). Although dracut is the way to go, more sophisticated and not as buggy as gentoo's genkernel approach, more and more funtoo geeks start using slashbeast's better-initramfs, which we will cover at the end of this howto! So after having set up a genkernel from debian or gentoo sources we are going to build a kernel with either (or both) dracut or/and better-initramfs. So gentoo sources with genkernel is always my backup if anything is not working correctly on my system. For the slightly more geeky approach with my own initram I am using pf-sources, ck-sources or any other more or less heavily patched sources.}}
Let's go!
=== Kernel Sources ===
The source you use on your system is up to you. For a laptop or desktop system, the following are recommended:
* '''{{Package|sys-kernel/pf-sources}}'''
* '''{{Package|sys-kernel/ck-sources}}'''
* '''{{Package|sys-kernel/gentoo-sources}}'''
* '''{{Package|sys-kernel/git-sources}}'''
* '''{{Package|sys-kernel/sysrescue-std-sources}}'''
* '''{{Package|sys-kernel/debian-sources}}'''
{{fancynote| If you are unsure of which sources you would like to use, emerge <code>gentoo-sources</code>. That's always a safe bet for a general system. For more information on available kernels, check out: [[Funtoo Linux Kernels]]}}
=== Prerequisites ===
Regardless of the tools you already have installed, it is recommended to follow the steps below, even if you find them to be redundant.
First, we edit our <code>/etc/portage/make.conf</code>:


=== Configuring <code>/etc/boot.conf</code> ===
<pre>
Now that the <code>initramfs.cpio.gz</code> file is in <code>/boot</code>, we can configure what we want the initramfs to do for us when the system boots. Below is a table of options that better-initramfs supports (from [https://bitbucket.org/piotrkarbowski/better-initramfs better-initramfs Bitbucket page]):
#These compiler flags are just tweaking (optimazation) and NOT necessary:
==== Options ====
CFLAGS="-O2 -pipe -march=native -ftracer -fforce-addr"
{| {{table}}
CXXFLAGS="${CFLAGS} -fpermissive -fomit-frame-pointer"
!Option
KDIR=/usr/src/linux
!Description
KERNEL="symlink build"
|-
USE="$KERNEL ....here are your use flags...."
|rescueshell
## These modules are available:
|Drop to the rescueshell before mounting rootfs to <code>/newroot</code>
## DRACUT_MODULES="dracut_modules_biosdevname dracut_modules_btrfs dracut_modules_caps dracut_modules_crypt dracut_modules_crypt-gpg dracut_modules_dmraid dracut_modules_dmsquash-live dracut_modules_gensplash dracut_modules_iscsi dracut_modules_livenet dracut_modules_lvm dracut_modules_mdraid dracut_modules_multipath dracut_modules_nbd dracut_modules_nfs dracut_modules_plymouth dracut_modules_ssh-client dracut_modules_syslog"
|-
## We will use these modules for LVM / LUKS:
|sshd
DRACUT_MODULES="crypt lvm plymouth biosdevname dmraid crypt-gpg dmsquash-live ssh-client syslog"
|Run the sshd server when the initramfs loads. This allows you to ssh into your initramfs to fix any errors that may have occurred while booting.
</pre>
|-
|sshd_wait=x
|Wait x number of seconds after starting sshd to continue booting the system.
|-
|sshd_port=x
|Change the port that sshd "listens" on. The default port for sshd is port 22.
|-
|binit_net_if=interface
|Choose which interface the network should be configured on. For example: wlan0, eth0, etc.
|-
|binit_net_addr=<ipaddr/cidr>
|Configure <code>ipaddr</code> with <code>cidr</code> netmask. For example: <code>11.11.11.2/24</code>. If you do not add a netmask, the netmask is assumed to be 32. Furthermore, you will have to configure <code>binit_net_gw</code>.
|-
|binit_net_gw=ipaddr
|The address of your gateway. Only needed if you want to connect to WAN.
|-
|rw
|Mount the rootfs as read-write. By default, the rootfs is mounted as read only.
|-
|mdev
|Use mdev instead of devtmpfs. This option can prove handy on older kernels.
|-
|softraid
|Detect and run RAID arrays.
|-
|init=
|Change the init system. For example, if you are using systemd, change this to <code>/usr/lib/systemd/systemd</code>. The default for this option (<code>/sbin/init</code>) will work fine with OpenRC.
|-
|tuxonice
|Try resuming with TuxOnIce.
|-
|uswsusp
|Try resuming the system with userspace software suspend. This depends on the <code>resume</code> option.  
|-
|swsusp
|Try resuming the system with in-kernel suspend. This depends on the <code>resume</code> option.
|-
|resume=<device/path>
|Specify the device and path from which you want to resume.
|-
|lvm
|Scan for volume groups. If any are found, activate them.
|-
|luks
|Run <code>cryptsetup luksOpen</code> on the <code>enc_root</code> variable.
|-
|luks_trim
|Enable support for TRIM on your LUKS encrypted root device. This option is very helpful for those using SSDs.
|-
|enc_root=<device>
|The device that you wish to decrypt using <code>cryptsetup luksOpen</code>.
|-
|root=<device>
|The name of your root device.
|-
|rootfstype=<fstype>
|Specify the type of filesystem that your rootfs uses.
|-
|rootdelay=<time (as integer)>
|How long the initramfs should wait before attempting to mount devices.
|-
|rootflags=x
|Pass x flags to <code>mount</code> as it mounts your rootfs.
|}


==== Examples ====
Next, we set the package keywords by adding the following to <code>/etc/portage/package.use</code>:
Below are examples of different use cases for better-initramfs and how your <code>/etc/boot.conf</code> should be configured for them.  
{{fancynote| Realize that your <code>enc_root</code>, <code>root</code>, and <code>rootfstype</code> variables may be different from the examples provided below.}}


==== Regular ext4 root ====
<pre>
{{file|name=/etc/boot.conf|desc= |body=
sys-kernel/dracut dm net device-mapper crypt lvm
"Funtoo Linux" {
</pre>
kernel vmlinuz[-v]
initrd /initramfs.cpio.gz
params += root=/dev/sdaX rootfstype=ext4
}
}}


==== Encrypted root with lvm ====
{{fancynote| If you don't have lvm over encrypted LUKS you just add the "net" keyword here, or "selinux".}}
{{file|name=/etc/boot.conf|desc= |body=
"Funtoo Linux" {
kernel vmlinuz[-v]
initrd /initramfs.cpio.gz
params += enc_root=/dev/sdaX lvm luks luks_trim root=/dev/mapper/funtoo--vg-root rootfstype=ext4
}
}}


==== Encrypted root with lvm and RAID ====
{{file|name=/etc/boot.conf|desc= |body=
"Funtoo Linux" {
kernel vmlinuz[-v]
initrd /initramfs.cpio.gz
params += enc_root=/dev/md0 lvm luks luks_trim softraid root=/dev/mapper/funtoo--vg-root rootfstype=ext4
}
}}


== Dracut ==
Next, we build our packages:
=== Installation ===
To install Dracut, simply emerge it:
<console>
<console>
###i## emerge dracut
###i## emerge -av app-portage/gentoolkit sys-kernel/pf-sources sys-kernel/dracut sys-boot/plymouth sys-boot/plymouth-openrc-plugin
</console>
</console>


=== Build the initramfs ===
=== Preparing the kernel ===
To build the initrd with dracut, we just execute:
 
We go now to the sources directory and enter the following commands to update the kernel's  .config  file:
<console>
<console>
###i## dracut -f --fstab --xz /boot/initramfs-3.2.6-pf.img  3.2.6-pf
###i## cd /usr/src/linux/
###i## make clean
  CLEAN  .
  CLEAN  arch/x86/kernel/acpi/realmode
  CLEAN  arch/x86/kernel/cpu
  CLEAN  arch/x86/kernel
  CLEAN  arch/x86/vdso
  CLEAN  arch/x86/lib
  CLEAN  drivers/gpu/drm/radeon
  CLEAN  drivers/net/wan
  CLEAN  drivers/scsi/aic7xxx
  CLEAN  drivers/tty/vt
  CLEAN  drivers/video/logo
  CLEAN  firmware
  CLEAN  kernel
  CLEAN  lib/raid6
  CLEAN  lib
  CLEAN  security/apparmor
  CLEAN  security/selinux
  CLEAN  usr
  CLEAN  arch/x86/boot/compressed
  CLEAN  arch/x86/boot
  CLEAN  .tmp_versions
  CLEAN  vmlinux System.map .tmp_kallsyms2.S .tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms1.S .tmp_vmlinux1 .tmp_vmlinux2 .tmp_System.map
###i## zcat /proc/config.gz > /usr/src/linux/.config
</console>
</console>


Generally, this should be enough!
Next, we run <tt>make localmodconfig</tt>. You will get some questions which you can answer mostly with either M (compiled as a module) or Y (compiled directly into the kernel). If you are not sure what to choose, press enter, and the default option will be selected.
If you experience booting problems like missing modules / drivers then just boot from your livecd and fix Dracut or consider changing to another initramfs. You can look into the man page to tweak the command a bit (e.g. --add-drivers "xz dm_crypt" etc...).
<console>
###i## make localmodconfig
Enable different security models (SECURITY) [Y/n/?] y
Enable the securityfs filesystem (SECURITYFS) [Y/?] y
Socket and Networking Security Hooks (SECURITY_NETWORK) [Y/?] y
Security hooks for pathname based access control (SECURITY_PATH) [Y/?] y
Low address space for LSM to protect from user allocation (LSM_MMAP_MIN_ADDR) [65536] 65536
NSA SELinux Support (SECURITY_SELINUX) [Y/n/?] y
  NSA SELinux boot parameter (SECURITY_SELINUX_BOOTPARAM) [N/y/?] n
  NSA SELinux runtime disable (SECURITY_SELINUX_DISABLE) [N/y/?] n
  NSA SELinux Development Support (SECURITY_SELINUX_DEVELOP) [Y/n/?] y
  NSA SELinux AVC Statistics (SECURITY_SELINUX_AVC_STATS) [Y/n/?] y
  NSA SELinux checkreqprot default value (SECURITY_SELINUX_CHECKREQPROT_VALUE) [1] 1
  NSA SELinux maximum supported policy format version (SECURITY_SELINUX_POLICYDB_VERSION_MAX) [Y/n/?] y
    NSA SELinux maximum supported policy format version value (SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE) [19] 19
TOMOYO Linux Support (SECURITY_TOMOYO) [Y/n/?] y
  Default maximal count for learning mode (SECURITY_TOMOYO_MAX_ACCEPT_ENTRY) [2048] 2048
  Default maximal count for audit log (SECURITY_TOMOYO_MAX_AUDIT_LOG) [1024] 1024
  Activate without calling userspace policy loader. (SECURITY_TOMOYO_OMIT_USERSPACE_LOADER) [Y/n/?] y
AppArmor support (SECURITY_APPARMOR) [Y/n/?] y
  AppArmor boot parameter default value (SECURITY_APPARMOR_BOOTPARAM_VALUE) [1] 1
Integrity Measurement Architecture(IMA) (IMA) [Y/n/?] y
EVM support (EVM) [N/y/?] (NEW)
Default security module
  1. SELinux (DEFAULT_SECURITY_SELINUX)
  2. TOMOYO (DEFAULT_SECURITY_TOMOYO)
  3. AppArmor (DEFAULT_SECURITY_APPARMOR)
> 4. Unix Discretionary Access Controls (DEFAULT_SECURITY_DAC)
choice[1-4?]: 4
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
#
# configuration written to .config
#
warning: (GFS2_FS) selects DLM which has unmet direct dependencies (EXPERIMENTAL && INET && SYSFS && CONFIGFS_FS && (IPV6 || IPV6=n))
warning: (IMA) selects TCG_TPM which has unmet direct dependencies (HAS_IOMEM && EXPERIMENTAL)
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
</console>
 
Now comes the most adventurous part!


=== Configuring <code>/etc/boot.conf</code> ===
=== Building the Kernel ===
==== Examples ====
<console>
###i## make -j8  bzImage
###i## make -j8 modules
###i## make modules_install
###i## make install
</console>


==== Encrypted root with lvm ====
== Initramfs ==
{{file|name=/etc/boot.conf|desc= |body=
{{fancywarning| Make sure that you have built and installed your kernel sources / modules before building an initramfs.}}
boot {
To get your initramfs up and running, check out the [http://www.funtoo.org/Initramfs Initramfs] page. After following all the directions on the page to get your initramfs set up, continue following the ones here.
        generate grub
 
        default "Funtoo Linux dracut"
Update the <tt>grub.cfg</tt> with boot update, then reboot and see how it works!
        timeout 3
<console>
}
###i## boot-update -v
###i## reboot
</console>


"Funtoo Linux dracut" {
[[Category:HOWTO]]
        kernel vmlinuz[-v]
[[Category:Featured]]
        initrd initramfs[-v].img
        params  = quiet rootfstype=ext4
        params += luks enc_root=/dev/sda3
        params += lvm root=/dev/mapper/vg-root
}
}}
[[Category:Kernel]]
[[Category:Kernel]]

Revision as of 17:22, August 5, 2014

Setting up a proper kernel yourself - lean, mean and tailored to your hardware, is the challenge by which a linux user can graduate to becoming a Funtoo knight ;-)

Even though many of us are using enterprise-ready kernels in datacenters, there is almost nobody who hasn't at least considered building a kernel for his laptop / PC. We are showing here how an intermediate Linux user can use an alternative to the standard beginners "genkernel" approach, to compile a custom kernel, in a relatively speedy and easy set up.

Minimum Requirements

  • Understand the command line
  • Know where the kernel files are located

Assumptions

You start from an installed Funtoo system on the disk, or at least, you are on stage3 in a chrooted environment from a live cd, following somehow the Funto Installation Tutorial.

Less advanced version

Emerging the kernel sources

To begin, we have to figure out which kernel sources we will use. If you are unsure about which sources are available and what their benefits and drawbacks are, check out the Kernels page.

After you have made a decsion as to which kernel you want to install, emerge it:

root # emerge vanilla-sources 

Portage will now go about installing the sources to /usr/src. It will also symlink the kernel-version directory to a directory called linux.

Configuring the kernel

Now that the kernel sources are on your system, you should configure them. To do this, change your directory to /usr/src/linux

root # cd /usr/src/linux

As we are now in the kernel sources directory, we can run a script that allows us to modify them. Run:

root # make menuconfig

While you edit the sources, keep the following in mind:

  • To build something into your kernel, press y when you have it selected.
  • To exclude something from your kernel, press n when you have it selected.
  • To build something as a module, press m.

Things that you may need to include in your kernel:

  • Wireless/LAN drivers
  • Support for your graphics card
  • Support for your audio card
  • Support for USB devices
   Note
Many pages on the wiki will tell you the kernel requirements for the application that they are about. Keep your eyes open for the blue background, white text sections of pages. Like on this one:  uvesafb

Building and installing the kernel sources

After you finish configuring your kernel sources, you will need to build them. To build your sources, run the following:

root # make
   Tip
You can add -j<number of processing cores + 1> after make to build the kernel more quickly.

When the kernel and its modules finish building, install them:

root # make install modules_install

Now that you have installed your kernel and modules, it is a good idea to install an initramfs. If your system has a separate /usr partition, is encrypted, or uses some other non-standard configuration, it will probably not boot without an initramfs. See Initramfs.

Advanced version

Getting ready to start

   Note
In this case we are building a kernel that is booting root in LVM over encrypted LUKS container.

If you don't have this setup, don't worry, you just don't need all the modules, but everything else is similar.

First, there is the decision which linux kernel sources we need. There are plenty of them in the repositories around, often it is not easy to distinguish between them.

I would always trust my distribution of choice and take what is has to offer - and funtoo has a lot to offer!

I really do recommend (especially if it is your first time) to build a debian-sourced genkernel like described in chapter 5 "Using Debian-Sources with Genkernel" in the Funtoo Kernels Tutorial.

From there you should have a running system booting nicely from your own build (just little bit bloated) kernel. This is more than you can expect from any other ready to go distribution.

   Note
We are using RedHat's dracut in order to build a nice initramfs (containing all the necessary tools and extra drivers our kernel might need to start the system). Although dracut is the way to go, more sophisticated and not as buggy as gentoo's genkernel approach, more and more funtoo geeks start using slashbeast's better-initramfs, which we will cover at the end of this howto! So after having set up a genkernel from debian or gentoo sources we are going to build a kernel with either (or both) dracut or/and better-initramfs. So gentoo sources with genkernel is always my backup if anything is not working correctly on my system. For the slightly more geeky approach with my own initram I am using pf-sources, ck-sources or any other more or less heavily patched sources.

Let's go!

Kernel Sources

The source you use on your system is up to you. For a laptop or desktop system, the following are recommended:

   Note
If you are unsure of which sources you would like to use, emerge gentoo-sources. That's always a safe bet for a general system. For more information on available kernels, check out: Funtoo Linux Kernels

Prerequisites

Regardless of the tools you already have installed, it is recommended to follow the steps below, even if you find them to be redundant. First, we edit our /etc/portage/make.conf:

#These compiler flags are just tweaking (optimazation) and NOT necessary:
CFLAGS="-O2 -pipe -march=native -ftracer -fforce-addr"
CXXFLAGS="${CFLAGS} -fpermissive -fomit-frame-pointer"
KDIR=/usr/src/linux
KERNEL="symlink build"
USE="$KERNEL ....here are your use flags...."
## These modules are available:
## DRACUT_MODULES="dracut_modules_biosdevname dracut_modules_btrfs dracut_modules_caps dracut_modules_crypt dracut_modules_crypt-gpg dracut_modules_dmraid dracut_modules_dmsquash-live dracut_modules_gensplash dracut_modules_iscsi dracut_modules_livenet dracut_modules_lvm dracut_modules_mdraid dracut_modules_multipath dracut_modules_nbd dracut_modules_nfs dracut_modules_plymouth dracut_modules_ssh-client dracut_modules_syslog"
## We will use these modules for LVM / LUKS:
DRACUT_MODULES="crypt lvm plymouth biosdevname dmraid crypt-gpg dmsquash-live ssh-client syslog"

Next, we set the package keywords by adding the following to /etc/portage/package.use:

sys-kernel/dracut dm net device-mapper crypt lvm
   Note
If you don't have lvm over encrypted LUKS you just add the "net" keyword here, or "selinux".


Next, we build our packages:

root # emerge -av app-portage/gentoolkit sys-kernel/pf-sources sys-kernel/dracut sys-boot/plymouth sys-boot/plymouth-openrc-plugin

Preparing the kernel

We go now to the sources directory and enter the following commands to update the kernel's .config file:

root # cd /usr/src/linux/
root # make clean
  CLEAN   .
  CLEAN   arch/x86/kernel/acpi/realmode
  CLEAN   arch/x86/kernel/cpu
  CLEAN   arch/x86/kernel
  CLEAN   arch/x86/vdso
  CLEAN   arch/x86/lib
  CLEAN   drivers/gpu/drm/radeon
  CLEAN   drivers/net/wan
  CLEAN   drivers/scsi/aic7xxx
  CLEAN   drivers/tty/vt
  CLEAN   drivers/video/logo
  CLEAN   firmware
  CLEAN   kernel
  CLEAN   lib/raid6
  CLEAN   lib
  CLEAN   security/apparmor
  CLEAN   security/selinux
  CLEAN   usr
  CLEAN   arch/x86/boot/compressed
  CLEAN   arch/x86/boot
  CLEAN   .tmp_versions
  CLEAN   vmlinux System.map .tmp_kallsyms2.S .tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms1.S .tmp_vmlinux1 .tmp_vmlinux2 .tmp_System.map
root # zcat /proc/config.gz > /usr/src/linux/.config

Next, we run make localmodconfig. You will get some questions which you can answer mostly with either M (compiled as a module) or Y (compiled directly into the kernel). If you are not sure what to choose, press enter, and the default option will be selected.

root # make localmodconfig
Enable different security models (SECURITY) [Y/n/?] y
Enable the securityfs filesystem (SECURITYFS) [Y/?] y
Socket and Networking Security Hooks (SECURITY_NETWORK) [Y/?] y
Security hooks for pathname based access control (SECURITY_PATH) [Y/?] y
Low address space for LSM to protect from user allocation (LSM_MMAP_MIN_ADDR) [65536] 65536
NSA SELinux Support (SECURITY_SELINUX) [Y/n/?] y
  NSA SELinux boot parameter (SECURITY_SELINUX_BOOTPARAM) [N/y/?] n
  NSA SELinux runtime disable (SECURITY_SELINUX_DISABLE) [N/y/?] n
  NSA SELinux Development Support (SECURITY_SELINUX_DEVELOP) [Y/n/?] y
  NSA SELinux AVC Statistics (SECURITY_SELINUX_AVC_STATS) [Y/n/?] y
  NSA SELinux checkreqprot default value (SECURITY_SELINUX_CHECKREQPROT_VALUE) [1] 1
  NSA SELinux maximum supported policy format version (SECURITY_SELINUX_POLICYDB_VERSION_MAX) [Y/n/?] y
    NSA SELinux maximum supported policy format version value (SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE) [19] 19
TOMOYO Linux Support (SECURITY_TOMOYO) [Y/n/?] y
  Default maximal count for learning mode (SECURITY_TOMOYO_MAX_ACCEPT_ENTRY) [2048] 2048
  Default maximal count for audit log (SECURITY_TOMOYO_MAX_AUDIT_LOG) [1024] 1024
  Activate without calling userspace policy loader. (SECURITY_TOMOYO_OMIT_USERSPACE_LOADER) [Y/n/?] y
AppArmor support (SECURITY_APPARMOR) [Y/n/?] y
  AppArmor boot parameter default value (SECURITY_APPARMOR_BOOTPARAM_VALUE) [1] 1
Integrity Measurement Architecture(IMA) (IMA) [Y/n/?] y
EVM support (EVM) [N/y/?] (NEW)
Default security module
  1. SELinux (DEFAULT_SECURITY_SELINUX)
  2. TOMOYO (DEFAULT_SECURITY_TOMOYO)
  3. AppArmor (DEFAULT_SECURITY_APPARMOR)
> 4. Unix Discretionary Access Controls (DEFAULT_SECURITY_DAC)
choice[1-4?]: 4
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
root #
root # configuration written to .config
root #
warning: (GFS2_FS) selects DLM which has unmet direct dependencies (EXPERIMENTAL && INET && SYSFS && CONFIGFS_FS && (IPV6 || IPV6=n))
warning: (IMA) selects TCG_TPM which has unmet direct dependencies (HAS_IOMEM && EXPERIMENTAL)
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)

Now comes the most adventurous part!

Building the Kernel

root # make -j8  bzImage
root # make -j8 modules
root # make modules_install
root # make install

Initramfs

   Warning
Make sure that you have built and installed your kernel sources / modules before building an initramfs.

To get your initramfs up and running, check out the Initramfs page. After following all the directions on the page to get your initramfs set up, continue following the ones here.

Update the grub.cfg with boot update, then reboot and see how it works!

root # boot-update -v
root # reboot