Sakaki's EFI Install Guide/Final Configuration Steps under OpenRC

From Gentoo Wiki
Jump to: navigation, search


Currently, your target system is using a kernel configuration largely based on that shipped with the Gentoo minimal installation image (with some necessary changes imposed by buildkernel). Since this configuration is (by design!) lightweight, it leaves many options disabled (including many device drivers). As a result, at this point in the installation a number of features that may be present on your machine (such as Bluetooth, WiFi, touchscreen etc.) may not yet be usable.

In this (penultimate) chapter, we'll address that, by enabling the relevant configuration options and recompiling the kernel (using the buildkernel tool's --menuconfig option).

Unfortunately, it's impossible to be precise about the exact options you'll need to enable, as these vary from machine to machine. Nevertheless, we'll cover a number of the most commonly encountered requirements (and by way of example, provide explicit instructions for WiFi, Bluetooth, touchscreen, audio, and integrated card reader on the CF-AX3).

This section of the tutorial has no precise analogue in the Gentoo manual, although elements of it are reflected in Chapter 7. You may also find it useful to refer to the "Gentoo Kernel Configuration Guide" on the wiki.

We will also address some additional miscellaneous issues at the end of this chapter, namely:

  • pruning your kernel image (by removing unused modules and firmware files);
  • getting suspend and hibernate working properly;
  • setting the system default python interpreter; and
  • disabling sshd (as we no longer need it).

Let's get started!

Important
This chapter is only for those users who decided earlier to target OpenRC init, rather than systemd. It is part of the 'alternative track' set of chapters. If you are here by mistake, click here to go to the default (systemd) version of this page.

General Approach

Important
In what follows, I am assuming that you know how to use the make menuconfig kernel configuration tool (which buildkernel invokes). You can find a short overview of make menuconfig in an earlier section of this tutorial; if you skipped over it before, you may wish to review it now (or at least, read the sub-section regarding "implementing a shorthand configuration fragment in make menuconfig"), before proceeding. Greg Kroah-Hartman's Linux Kernel in a Nutshell is also highly recommended.[1]

The general approach when looking to enable a feature which is physically supported on your machine (for example, Bluetooth), is as follows:

  • Obviously, check whether the feature already works (it's always possible that your current kernel already has the necessary options enabled or modularized). If it does, great, you're done!
  • Otherwise, ensure your boot USB key is inserted, then invoke (as root) buildkernel --menuconfig in a terminal (which will run the make menuconfig tool).
  • Collect as much information as possible about the physical device (vendor name, model name etc.), using tools such as hwinfo, lspci and lsusb (in a separate terminal window).
  • If the device description should match one given in the specific CF-AX3 instructions below, implement the given kernel configuration shorthand fragment (using the buildkernel --menuconfig interface).
  • Otherwise, search (still via the menuconfig interface; see the tutorial earlier) for a suitable option, and then enable (or modularize) it (and any dependencies). If you can't find anything suitable this way, do a web search based on the information collected. (Unfortunately, there is no automated tool to do this for you).
  • Once you have made all desired changes, exit and save make menuconfig, thereby allowing buildkernel to continue and create a new kernel; and then reboot. With luck, your desired feature should now be operational.
  • If all else fails, invoke buildkernel --menuconfig again, try modularizing all options under the appropriate sub-menu in the make menuconfig interface, then save and exit, to create a new kernel as before. If, after a reboot, the desired feature is operational, you should then be able to locate its driver using hwinfo --pci --usb (after which you can rerun buildkernel --menuconfig if you like, to turn off all other unneeded items and recompile). This approach (i.e., turn on pretty much everything so that something will work ^-^) is actually the one taken by many Linux distributions (such as Ubuntu) for their 'generic' kernels, so don't feel shy to try it if need be.

Tweaking your kernel configuration to enable machine features is one of the more frustrating tasks you have to do when bringing up a system under Linux. In this tutorial, I've deliberately postponed it till near the end - when you already have all the other elements of a functioning system in place.

Tip
Depending on the popularity of your target machine with other Linux users, you may also be able to find useful kernel — and other — configuration information by searching online.

To make the process concrete, I'll now lay out the changes necessary to enable the main features of the Panasonic CF-AX3 laptop. You will obviously need to adapt what follows depending on your particular target machine.

Specific Configuration Recipes (Using CF-AX3 as an Example)

In what follows, we will cover the following (common) features, using the Panasonic CF-AX3 as a (fairly typical) example (it is a reasonably feature-rich Ultrabook, so some of these may apply directly to your system too):

  1. WiFi;
  2. Bluetooth;
  3. Integrated touchscreen;
  4. Integrated webcam;
  5. Audio;
  6. Integrated (SD etc.) card reader;
  7. LCD screen backlight.

To reiterate, what follows is simply an example, for a particular PC (the CF-AX3). Where necessary, follow the steps above to set the necessary options for your particular choice of target machine.

Important
If you have decided to deblob your kernel (not the default route followed in this tutorial), then it's likely that many hardware features will be unusable no matter what you enable in the kernel, since there'll be no firmware (blobs) present for the drivers to upload to their respective devices.

Preliminaries

Ensure your boot USB key is inserted in the target machine, and then (at the terminal within the GNOME session that we opened earlier), issue:

koneko ~ #buildkernel --snapshot-backup

to create a 'last known good' backup of the current kernel (and configuration) on the boot USB key. Although buildkernel does create a backup of the previous version when it is run, that backup is not persistent, and will be overwritten the next time buildkernel is executed. Keeping a (timestamped) backup via --snapshot-backup ensures that there's no risk we run buildkernel twice between reboots, thereby losing our reference point.

Next, issue:

koneko ~ #buildkernel --menuconfig

Because you have not specified --ask here, but you have specified --menuconfig, the process will run through by itself (assuming no errors) to the point where you can modify the kernel configuration using the standard curses-based make menuconfig editor GUI. You can now use that interface to enable specific features as specified in the kernel configuration shorthand 'recipes' given below.

Now, because it will be useful to have a second terminal available (for emerge work etc.), open one now within GNOME. Click in the current terminal window (the one showing the make menuconfig interface, then press CtrlShiftn to spawn a new one. In this fresh window, log in as root:

sakaki@koneko ~ $su --login root
Password: <enter root password>

The password required here is the one you set up earlier in the tutorial (and have used when ssh-ing in previously).

WiFi

The CF-AX3 has integrated WiFi, based on an Intel 7260 device. To find out which network controllers you have on your machine, issue the following in the second terminal (the one not displaying the menuconfig interface):

koneko ~ #lspci | grep -i net
koneko ~ #lsusb | grep -i net

and observe the output.

In the case of the CF-AX3, this returns:

00:19.0 Ethernet controller: Intel Corporation Ethernet Connection I218-LM (rev 04)
02:00.0 Network controller: Intel Corporation Wireless 7260 (rev 6b)

(your machine will most likely differ).

On the CF-AX3, the built-in Ethernet adaptor is (obviously!) already working under the current kernel configuration, but the Intel 7260 wireless card is not.

Update: Jul 25, 2014: CONFIG_IWLMVM now Present in Default Configuration

CONFIG_IWLMVM is now turned on in the Gentoo minimal install image configuration, so WiFi on systems with the 7260 chipset (including the CF-AX3) should now work 'out of the box'. However, I've left this section in place, as the generic instructions regarding network card probing are still useful for those experiencing WiFi driver problems.

Now, while the firmware for this 7260 is already included in sys-kernel/linux-firmware (which we installed earlier), using it requires MVM firmware support (which, at the time of writing, the minimal-install kernel configuration has disabled).

Set the following options (within buildkernel) to rectify this, and thereby activate WiFi:

KERNEL Configuration options for 7260 wireless card (WiFi) on the CF-AX3
Device Drivers  --->
 -*- Network device support  --->
  [*]   Wireless LAN  --->
   <M>   Intel Wireless WiFi Next Gen AGN - Wireless-N/Advanced-N/Ultimate-N (iwlwifi)
   <M>	  Intel Wireless WiFi DVM Firmware support
   <M>    Intel Wireless WiFi MVM Firmware support
Note
Most of the time, it's equally fine to either modularize (M) or build in (*) a function, as desired; buildkernel copies all modules into the initramfs.

Incidentally, the 7260 device also supports WiMAX, but as of the time of writing, the ebuilds for net-misc/networkmanager do not, so I have not detailed its activation here.

Note
When you later restart under your new kernel and log in again to GNOME (see "Finishing Up", below), you should be able to see and activate WiFi connections by clicking on the 'network' icon in the top bar (or, by clicking on the 'spanner and screwdriver' icon from the drop-down menu under the rightmost ('power') icon on the top bar).

Bluetooth

Like many modern notebooks, the CF-AX3 has an integrated Bluetooth modem. To see information about your system's Bluetooth hardware, issue in the second terminal (the one not displaying the menuconfig interface):

koneko ~ #hwinfo --bluetooth

To enable it on the CF-AX3, set the following options (this will work for many other machines too):

KERNEL Configuration options for Bluetooth on the CF-AX3
-*- Networking support  --->
 <M>   Bluetooth subsystem support  --->
  Bluetooth device drivers  --->
   <M>   HCI USB driver
Note
There is no need to emerge sys-firmware/bluez-firmware for this PC.
Note
When you later restart under your new kernel and log in again to GNOME (see "Finishing Up", below), you should be able to see and activate Bluetooth devices (e.g., wireless mice) using the Bluetooth control panel. Find this by pressing Windows Key and then typing 'Bluetooth' (or, by clicking on the 'spanner and screwdriver' icon from the drop-down menu under the rightmost ('power') icon on the top bar).

You must now ensure that the Bluetooth service will start on boot. To do so, issue:

koneko ~ #rc-update add bluetooth default

Touchscreen

As is increasingly common, the CF-AX3 has a touchscreen (an eGalaxTouch device in this case). You can generally find out more information about your touchscreen (and touchpad, if present, although this is likely already supported at this point in the install), by issuing in the second terminal (the one not displaying the menuconfig interface):

koneko ~ #hwinfo --mouse

To enable the eGalaxTouch device (this will also work for many other touchscreen panels), set the following options:

KERNEL Configuration options for touchscreen on the CF-AX3
Device Drivers  --->
 HID support  ---> 
  Special HID drivers  --->
   <M>   HID Multitouch panels
Note
When you later restart under your new kernel (see "Finishing Up", below) you should be able to make basic touch and drag actions using the screen. However, gesture support is still (as of the time of writing) unimplemented in GNOME.[2]

Webcam

The CF-AX3 has an integrated webcam (a common feature on many laptops and netbooks). You can find out more information about your machine's webcam by issuing in the second terminal (the one not displaying the menuconfig interface):

koneko ~ #hwinfo --pci --usb | awk '/webcam/' RS="" IGNORECASE=1
Note
The hwinfo command will output blank-line-separated records about each device found on the PCI and USB busses (your webcam will almost certainly be on one of those, most likely USB). Then the awk command prints any of these records that contain the text "webcam" (not case sensitive), using a blank line as a record separator.

To enable the webcam on the CF-AX3 (this will work for many modern machines, as many webcams are UVC devices), set the following options:

KERNEL Configuration options for webcam on the CF-AX3
Device Drivers  --->
 <M> Multimedia support  --->
  [*]   Cameras/video grabbers support
  [*]   Media USB Adapters  --->
   <M>   USB Video Class (UVC)  
   [*]     UVC input events device support (NEW) 
Note
When you later restart under your new kernel and log in again to GNOME (see "Finishing Up", below), you should be able to test your webcam using the Cheese application (which is installed with GNOME by default).
Note
You may wish to physically cover the webcam's lens (and built-in microphone input apertures) when not in use ^-^

Audio

The CF-AX3 has an integrated Intel HD audio device, accessed on the PCI bus. You can find out more information about your machine's soundcard by issuing in the second terminal (the one not displaying the menuconfig interface):

koneko ~ #hwinfo --sound

As configured, sound works 'out of the box' for the CF-AX3, but the pulseaudio sound server complains about lack of high resolution timer support, and insufficiently large buffers. To address these problems on the CF-AX3, set the following options

KERNEL Configuration options for audio on the CF-AX3
General Setup  --->
 Timers subsystem  --->
  [*] High Resolution Timer Support

Device Drivers  --->
 <M> Sound card support  --->
  <M>   Advanced Linux Sound Architecture  --->
   [*]   PCI sound devices  --->
          HD-Audio  --->
     (2048) Pre-allocated buffer size for HD-audio driver
Note
When you later restart under your new kernel and log in again to GNOME (see "Finishing Up", below), audio should still be operational; you probably won't notice any difference after making these changes, other than the fewer warnings when emerging sound-related packages.

Card Reader

The CF-AX3 has an integrated SD/MMC card reader. You can find out more information about your machine's reader by issuing in the second terminal (the one not displaying the menuconfig interface):

koneko ~ #hwinfo --pci --usb | awk '/ sd /' RS="" IGNORECASE=1

Although the necessary kernel options (MMC_SDHCI and MMC_SDHCI_PCI) for this card are modularized in the minimal install kernel, there is a bug impacting the CF-AX3 (and many other machines) which prevents correct initialization when a card is inserted. To fix this, still in the second terminal, issue:[3]

koneko ~ #echo "options sdhci debug_quirks=0x40" > /etc/modprobe.d/sd-card-fix.conf
Note
Note that buildkernel will copy the contents of /etc/modprobe.d into the initramfs for you.
Note
When you later restart under your new kernel and log in again to GNOME (see "Finishing Up", below), you should be able to insert an SD card and have it automatically show up in GNOME).
Note
If you have a Realtek card reader in your machine, you may need to modularize MMC_REALTEK_USB to get it working properly.[4]

Others

There are a couple of other devices on the CF-AX3 which I have not dealt with here:

  • The CF-AX3 has an i7 processor with Intel's Management Engine; if you really want access to this scarily-out-of-band coprocessor, enable the INTEL_MEI setting in the kernel configuration.
    Note
    If you are comfortable working with hardware — in particular BIOS reflashing — and wish to disable the Management Engine on your PC, a mini-guide for this has now been added here.
  • It also has a number of integrated sensors (geomagnetic, gyroscopic, acceleration etc.); however, these are not generally supported by Linux applications at the moment, so I haven't detailed their setup here.

Of course, as mentioned earlier, your particular target platform will have its own set of devices that may well not have been mentioned here (for example, MemoryStick readers, digital TV receivers etc.), and you should obviously adapt your kernel configuration accordingly.

Lastly, if you find that your early boot splash is being interrupted with the error message kvm: already loaded the other module, then you should ensure that only the KVM option (Intel or AMD) appropriate to your processor is set in the configuration. The relevant options are CONFIG_KVM_INTEL and CONFIG_KVM_AMD.

Finishing Up

When satisfied with your configuration, exit menuconfig, saving changes. Once you have done so, buildkernel will automatically create a new kernel with the newly created configuration, sign it, and copy it over to the boot USB key. Wait for the process to complete (you get the message All done!). Then (leaving the boot USB key inserted) restart your target machine (you can do this from within GNOME, by clicking on the 'power' icon (in the top right of the screen), clicking on the 'power' button in the dropdown menu that then appears, and then clicking on the 'Restart' button in the dialog).

The machine should then power cycle (you will be cleanly logged out of GNOME first). When it restarts, as before, you will need to enter your LUKS keyfile gpg passphrase (the one you created earlier), directly at the target machine keyboard to unlock the LUKS partition. You should then be presented with a GNOME login page (as previously). Directly at the target machine, click on your (regular) user name then, when prompted, type in the (regular user) password you set up earlier (ensure you have the correct keyboard settings, if relevant, as discussed above).

You should now be able to use all the features of your machine that you just enabled (such as WiFi etc.).

Note
Of course, it's entirely fine to repeat this buildkernel --menuconfig process a few times, so if there are other features you need to enable, feel free to do so now. If your machine fails to boot with a given configuration, see these earlier instructions for how to fall back to the prior kernel on the boot USB key (buildkernel makes a backup of the previous kernel each time it is run).

LCD Screen Backlight (Addressing the i915 Regression)

One final note. Like most laptops, the CF-AX3 has a dimmable backlight on its LCD screen. With modern kernels (3.17+) and the i915 graphics driver (as used by many Ultrabooks), you may find that you cannot change the display brightness using the standard GNOME controls. This is a regression; if it affects you, first use the process described in "Preliminaries", above to get a root terminal, then issue:

koneko ~ #nano -w /etc/buildkernel.conf

Locate the line specifying ADDITIONALKERNELCMDS. If it is currently commented out (the line starts with a # character), then uncomment and edit that line so it reads:

FILE /etc/buildkernel.confSpecifying additional kernel command line options
ADDITIONALKERNELCMDS="acpi_backlight=video"

Save and exit the nano editor.

Note
If you already have some additional kernel command line options specified using the ADDITIONALKERNELCMDS variable, then simply add the acpi_backlight=video text to the end of the string (in /etc/buildkernel.conf), separating it from the existing text with a space.

Now, ensure that you have the boot USB key inserted, and issue:

koneko ~ #buildkernel

to rebuild the kernel. Wait for the process to finish (you receive the message "All done!"). Then power cycle the machine as described in "Finishing Up", above.

When you log in again to GNOME, you should find that the screen brightness controls now operate correctly.

Reducing the Kernel Image Size (Optional Step)

Note
This is an entirely optional step - if you'd like to skip it, simply continue to the next section now.

As your current Linux kernel is largely derived from the minimal-install image configuration, it contains a lot of modularized and enabled features that are irrelevant to your machine (for example, all the specific x86 platform support drivers for vendors other than yours). While this bloat is mostly harmless, there are a few negative side effects of having features you don't need, for example:

  • the kernel image is larger (which makes boot time slightly longer) — even even where most features are modularized — since all modules are copied into the initramfs, which is then integrated into the kernel itself. This can be an important consideration if you choose to migrate your kernel into the (somewhat cramped) Windows EFI system partition (instructions for which are provided later);
  • more code must be (uselessly) compiled each time you upgrade your kernel, which costs time; and
  • more features = a larger attack surface exposed to malware.

Furthermore, to ensure that all necessary devices can be properly initialized during early boot, by default a complete copy of /lib/firmware is included within the initramfs too (as was discussed earlier). This directory is ~300MiB uncompressed at the time of writing, and while the vast majority of its contents will have no relevance to your target machine's hardware, they certainly will swell the resulting kernel image significantly — so much so, in fact, that it becomes impossible to fit it inside a typical existing Windows EFI system partition (100MB).

Accordingly, you may wish to take steps to pare down the number of unnecessary modules and/or unnecessary firmware files contained within the bootable kernel image created by buildkernel. If so, instructions for these (optional) steps are provided in the subsections immediately following.

Note
Other than a slight impact on load time, the final size of the kernel image is not particularly relevant if you intend — as many users of this guide will — to continue to boot from USB stick (and so not migrate the kernel onto a pre-existing existing EFI system partition, as described later). A big initramfs does not mean that the kernel of the booted system will consume a large amount of system memory, for example (since the initramfs is discarded by the initial startup script, shortly after the main root filesystem is brought live).
For that reason, the instructions in this section are optional: if you wish, simply click here to skip them.
Important
Always proceed cautiously, when removing firmware — or disabling kernel configuration items — that do not appear to be relevant to you, and ensure (as detailed below) that you have a 'known good' backup kernel to fall back to in case of problems.
Important
Remember that if you change any important hardware components on your PC (switching the graphics card, for example), you should revisit this section, to ensure that the modules and boot-time firmware are appropriately tailored to your new reality.

Removing Unnecessary Kernel Modules from the initramfs

The safest way to remove unneeded modules from your kernel configuration is as follows:

  1. as root, run buildkernel --menuconfig (ensuring your boot usb key is inserted first); then
  2. manually deselect those features which appear to have no local relevance (working on a small section at a time for manageability);
  3. reboot (once the new kernel has been built); then
  4. test for regression (reverting or rebuilding the kernel if necessary); and
  5. repeat steps 1 through 4, until an acceptably small configuration is obtained.

Unfortunately, such a process can easily take a day (or more) to complete fully.

Fortunately, however, there is a quicker, automatic method to remove unnecessary modules: namely, the make localmodconfig tool, which is standard utility shipped with the kernel source code.[5][6][7][8] To be fair, this is a little riskier than doing things by hand (since the utility causes any modules not currently loaded by the kernel to be purged from the configuration, which can in turn cause some (wanted) filesystem drivers, crypto modules, codepages etc. to be dropped. Moreover, it tends to retain rather a lot of 'false positive' modules as well (e.g. ATA drivers), so it certainly isn't perfect. Nevertheless, it is convenient and 'one-shot' in nature, so, if you do wish to try out localmodconfig for yourself, proceed as follows.

First, if you don't have a root terminal open already in GNOME, do so now: press the Windows Key, and type 'terminal', then press Enter. A standard-issue terminal window should open. Become root:

sakaki@koneko ~ $su --login root
Password: <enter root password>

The password required here is the one you set up earlier in the tutorial (and have used when ssh-ing in).

Then in this terminal, issue:

koneko ~ #buildkernel --snapshot-backup

to create a 'last known good' timestamped backup of the current kernel (and configuration) on the USB boot key (this ensures that there's no risk we lose our 'safe' version, which might otherwise happen were we to run buildkernel twice in a row between test reboots).

Ensure you plug in any important devices at this point, so their driver modules will be loaded (incidentally, it's generally fine to unplug them again almost immediately, as any relevant modules will generally remain loaded in such an event). Then, when ready, switch to the kernel directory, and ask localmodconfig to do its magic then return:

koneko ~ #pushd /usr/src/linux && make localmodconfig && popd

Once this has completed, ensure you have the boot USB key inserted, and create a new kernel based on the stripped-down configuration:

koneko ~ #buildkernel --menuconfig

This will allow you to review the proposed configuration for sanity in the make menuconfig tool, and make any necessary changes.

Note
You can find a short overview of make menuconfig in an earlier troubleshooting section of this tutorial.

When satisfied with your final configuration, exit menuconfig, saving any changes. Once you have done so, buildkernel will automatically create a new kernel with the newly created configuration, sign it, and copy it over to the boot USB key, as before. Once the process completes (you get the message All done!), you can check the new size of your kernel image, by issuing:

koneko ~ #ls -lht /boot/vmlinuz*-gentoo | head -n 1
-rw-r--r-- 1 root root 130M Oct 26 12:18 /boot/vmlinuz-4.14.65-gentoo

Obviously, your output will differ, depending upon your kernel version, the number of modules removed etc.

Note
Yes, the size is still large, and that's due to the included firmware files, an issue we will address shortly.
Note
If you chose earlier to deblob your kernel, use /boot/vmlinuz*-ck in place of /boot/vmlinuz*-gentoo in the above. For avoidance of doubt, this will not apply to most users.

Then — leaving the USB key inserted — reboot, and login again, in the normal manner.

If you find, when rebooted, that some previously working facilities of your target machine have regressed, simply run (as root) buildkernel --menuconfig again, restore any necessary features, and reboot once buildkernel has completed building the new kernel, repeating as necessary until your system is fully functional once more.

Note
If your machine fails to boot with your new configuration, see these earlier instructions for how to fall back to the prior (or snapshotted last-known-good) kernel on the boot USB key, so you can get back in to fix things up.

Removing Unnecessary Firmware from the initramfs

With the module set reduced, we can now turn our attention to the major driver of kernel image size — the default inclusion of a complete copy of /lib/firmware/<...> in its integral initramfs.

Note
Obviously, this subsection does not apply to those who chose earlier to deblob their kernel, and such users should click here to skip to the next section now (for avoidance of doubt though, most users of this guide will not be deblobbing, and so should continue reading ^-^).

Fortunately, we can easily pare down what is included here, through use of the user_modify_initramfs() function in /etc/buildkernel.conf. Recall that when buildkernel runs, it creates an uncompressed staging copy of the initramfs filestructure at /boot/initramfs, then calls user_modify_initramfs() (if defined), then repacks the (possibly modified) initramfs filestructure again for inclusion into the final kernel image.

As such, there are two basic approaches we can take using this function:

  1. remove everything from the initramfs' /lib/firmware directory, reboot, and then retain only those firmware files which the kernel complains about being unable to find; or
  2. start with a full set of firmware, then cautiously remove some (hopefully!) irrelevant content from the initramfs' filestructure, reboot to test, and repeat as necessary.

The first approach is preferred, since it will result in the smallest possible initramfs, and requires generally just one or two reboot iterations to converge on the final result. As such, in what follows we'll try that avenue of attack initially, falling back to option 2 only in case your target system won't boot at all without initramfs firmware, even to a command line interface — a rare situation for most PCs.

Option 1: Retaining only what is Required

To begin, open (as before) a root terminal, and issue:

koneko ~ #nano -w /etc/buildkernel.conf

and then uncomment the lines specifying user_modify_initramfs(), and modify the function body, so it now reads:

FILE /etc/buildkernel.confExample of purging all firmware from initramfs via hook function
user_modify_initramfs() {
    show "Removing all firmware from initramfs..."
    local FD="${INITRAMFSDIR}/lib/firmware"
    # remove all firmware files (and symbolic links) that we
    # don't explicitly retain
    find "${FD}" \
        \( -type f -o -type l \) -exec rm -f {} +
    # remove all empty directory trees
    find "${FD}" -type d -empty -delete
}

Leave the rest of the file as-is. Save, and exit nano.

Note
The first find command in the above searches for all files or symbolic links recursively within the ${FD} (i.e., /boot/initramfs/lib/firmware) directory. It builds up a list of all such paths (the {} +), and then executes a forced rm (delete) on the resulting set. Once this has been done, the second find command then locates any empty directories within ${FD}, and deletes those too (for clarity when reviewing the initramfs image — they don't take up much space).
Yes, this is a rather complex way to (sort-of!) write rm -rf "${FD}"/*, but it will make more sense shortly, when we start excluding paths we want to keep.
Tip
We use the case-insensitive -ipath here, since vendors sometimes change the capitalization of provided firmware files.
Note
Upon entry to the user_modify_initramfs() hook function, the INITRAMFSDIR variable is set to /boot/initramfs: as in the above, it should be used in preference to hard-coding (in case this path changes in a later release of buildkernel).
Incidentally, show is an function used like echo within buildkernel; its use here is, obviously, optional.
Note
If you have already uncommented the user_modify_initramfs() function (which, for avoidance of doubt, most users will not by this stage in the tutorial), then simply add the new lines to the end of the existing body, before the trailing }.

Now, ensure the boot usb key is inserted, and rebuild the kernel. Issue:

koneko ~ #buildkernel
... additional output suppressed ...
* Copying static gpg program into initramfs...
* Copying contents of /etc/modprobe.d directory into initramfs...
* Calling user_modify_initramfs function...
* Removing all firmware from initramfs...
* Deleting old initramfs cpio archive, and repacking...

... additional output suppressed ...

* All done!
Tip
The /boot/initramfs directory is left around (for convenience) when buildkernel exits, so you can easily check to see that your user_modify_initramfs() function had the desired effect.

Assuming this completed successfully (you get the output All done!), then leave the boot USB key inserted, and reboot the system, entering your gpg passphrase in the normal manner.

Now, if (and only if) your machine fails to come back up correctly (an unlikely eventuality for most PCs, but possible), see these earlier instructions for how to fall back to the prior (or snapshotted last-known-good) kernel on the boot USB key. Once you have done this and restarted under the old kernel, click here to jump to option 2 instead — unfortunately, the 'option 1' approach will not work for your system.

Assuming, however, that your machine did start up fine (the more common case), then login as your regular user, in the normal manner.

Note
You may well find you have lost WiFi functionality etc. in the absence of boot-time firmware. That is quite usual, and will be rectified by the steps which follow.

Next, open a terminal, become root, and check which firmware files the kernel complained about being unable to find. Issue:

koneko ~ #dmesg | grep --ignore-case 'firmware' | grep --ignore-case --extended-regexp 'err|fail'
[    4.394776] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[    4.400051] iwlwifi <addr>: Direct firmware load for iwlwifi-7260-17.ucode failed with error -2
[    5.695475] brcmfmac <addr>: Direct firmware load for brcm/brcmfmac4356-sdio.bin failed with error -2

This will display any firmware load errors reported in the kernel's message buffer. Obviously, what you see will depend upon your particular system: the above is output obtained by following this route on a CF-AX3 (with an additional Broadcom 4356 WiFi adaptor on the PCI bus), and so you must adapt what follows accordingly.

Note
If nothing is printed out, and further testing shows your system is running normally, congratulations — it appears your system (unusually) can run without any uploaded boot-time firmware at all (or, on subsequent iterations of this process, with just the firmware you have elected to retain in the initramfs). In such a case, click here to jump forward to the next section now (leaving /etc/buildkernel.conf as-is).

Proceeding with the CF-AX3 example, we can see that two (top-level) firmware files, regulatory.db and iwlwifi-7260-17.ucode failed to load, and one firmware file in the brcm/ (Broadcom) subdirectory also failed to load (brcm/brcmfmac4356-sdio.bin).

Rather than just exclude these particular files from deletion though, we need to take a look at the context first, since there may be other, related files present, or the file in question may be versioned (and so may have a different name in a future release of sys-kernel/linux-firmware), etc.

Issue (again, remember we are just working through the output on a CF-AX3 for concreteness here; adapt for your own system dmesg results):

koneko ~ #ls /lib/firmware/regulatory*
/lib/firmware/regulatory.db  /lib/firmware/regulatory.db.p7s
koneko ~ #ls /lib/firmware/iwlwifi-7260-*
/lib/firmware/iwlwifi-7260-10.ucode  /lib/firmware/iwlwifi-7260-17.ucode
/lib/firmware/iwlwifi-7260-12.ucode  /lib/firmware/iwlwifi-7260-7.ucode
/lib/firmware/iwlwifi-7260-13.ucode  /lib/firmware/iwlwifi-7260-8.ucode
/lib/firmware/iwlwifi-7260-16.ucode  /lib/firmware/iwlwifi-7260-9.ucode
koneko ~ #ls /lib/firmware/brcm/brcmfmac4356-*
/lib/firmware/brcm/brcmfmac4356-pcie.bin
/lib/firmware/brcm/brcmfmac4356-pcie.txt
/lib/firmware/brcm/brcmfmac4356-sdio.bin

Your queries and results will most likely differ from those shown.

Note
We're searching in the 'real' /lib/firmware directory here, as it hasn't been emptied (unlike the current /boot/initramfs/lib/firmware variant).

From the above output, we can see that:

  • the regulatory.db firmware (database) has a partner file, regulatory.db.p7s, that may also be relevant;
  • the iwlwifi-7260-17.ucode firmware has companion versions (and so may itself be superseded, in time); and
  • the bcrm/brcmfmac4356-sdio.bin firmware has companion files that look relevant.

With that information in hand, we can modify the first find command in user_modify_initramfs() accordingly, adding (on a wildcard basis) appropriate paths to be excluded from deletion.

Note
The worst that can happen with wildcards used in this manner is that you end up retaining slightly more than you need — for example, earlier firmware versions — but on the other hand, it is an easy approach to grasp, and relatively robust. While more sophisticated techniques are possible, wildcards strike a good cost-benefit balance.

Issue:

koneko ~ #nano -w /etc/buildkernel.conf

and then modify the body of the user_modify_initramfs() function, so it reads (note the modified show and added -ipath <...> lines):

FILE /etc/buildkernel.confExample of purging unneeded firmware from initramfs via hook function
user_modify_initramfs() {
    show "Removing unnecessary firmware from initramfs..."
    local FD="${INITRAMFSDIR}/lib/firmware"
    # remove all firmware files (and symbolic links) that we
    # don't explicitly retain
    find "${FD}" \
        -ipath "${FD}/brcm/brcmfmac4356-*" -prune -o \
        -ipath "${FD}/iwlwifi-7260-*" -prune -o \
        -ipath "${FD}/regulatory.*" -prune -o \
        \( -type f -o -type l \) -exec rm -f {} +
    # remove all empty directory trees
    find "${FD}" -type d -empty -delete
}

As before, modify these to suit your own target system's requirements. Leave the rest of the file as-is. Save, and exit nano.

Note
The -ipath test checks, in a case-insensitive manner, each path that find locates against the pattern following it — which in the above includes wildcards — for a match. Note that the paths need to be fully qualified (hence the use of the ${FD} prefix). Matches are then subjected to the given action, which in this case is -prune: this drops the path (and any subpaths, if a directory) from subsequent consideration. Paths that don't match are passed on to the next clause via -o (short-circuit OR).
This idiom allows us to retain key files, with the remainder eventually falling through to the trailing test (which then deletes any of them that are files or symbolic links, just as before).

Now we have our exclusions in place, the second find command makes more sense — any subdirectory that (transitively) contains leaf files (such as bcrm/ here) will be preserved (as not -empty), which is what we want.

With user_modify_initramfs() thus modified, run buildkernel again to take up the changes. Ensure the boot usb key is still inserted, then issue:

koneko ~ #buildkernel
... additional output suppressed ...
* Copying static gpg program into initramfs...
* Copying contents of /etc/modprobe.d directory into initramfs...
* Calling user_modify_initramfs function...
* Removing unnecessary firmware from initramfs...
* Deleting old initramfs cpio archive, and repacking...

... additional output suppressed ...

* All done!

Once the process completes (you get the message All done!), you can check the new size of your kernel image, by issuing:

koneko ~ #ls -lht /boot/vmlinuz*-gentoo | head -n 1
-rw-r--r-- 1 root root  23M Oct 28 14:32 /boot/vmlinuz-4.14.65-gentoo

Obviously, your output will differ, depending upon your kernel version, the amount of firmware retained etc. However, you should see a significant reduction in size compared with the prior version (in the case of this example, 130MiB has been reduced to 23MiB — comfortably small enough to fit within the Windows system partition should we wish to do that (as described later)).

Next, leaving the boot USB key inserted, reboot your system again, enter your gpg passphrase in the normal manner, and log back in as the regular user.

Then, repeat the process from the dmesg check above, iterating until no missing firmware files are reported (note that it isn't unusual to see different firmware files being complained about in dmesg at this point, since the underlying drivers will presumably have been able to proceed further through their bring-up than last time). Once none are, congratulations: you have successfully slimmed down your kernel image, in a manner that should continue to apply even in the face of future upgrades, so click here to jump down to the next section now.

Note
If however, after several iterations of the process, there remain some stubborn firmware load errors you can't seem to clear, remember that not all hardware is supported by the files in /lib/firmware provided by sys-kernel/linux-firmware, and that even such hardware that is supported may require additional files to function correctly. A good sanity check is to look at the dmesg output of an unslimmed kernel — if the error shows up there as well, you'll need to do an internet search for further information.

Option 2: Incrementally Paring Back

Note
The following option 2 approach should only be attempted if option 1, above, didn't work for your target PC. So, if option 1 did work, click here to jump to the next section now.

The alternative (slower, option 2) way to reduce the firmware included in your kernel's integral initramfs, is to start from a full copy of /lib/firmware, and then use the user_modify_initramfs() function to delete only those files and directories therein that you believe to be irrelevant to your target PC, reboot to check you didn't break anything, and then iterate until a sufficiently small kernel image is obtained.

To begin, open (as before) a root terminal, and then issue:

koneko ~ #nano -w /etc/buildkernel.conf

Modify the body of the user_modify_initramfs() function you set up previously, so it now reads:

FILE /etc/buildkernel.confA null hook function, to keep all firmware in initramfs
user_modify_initramfs() {
    show "Retaining all firmware in initramfs..."
    local FD="${INITRAMFSDIR}/lib/firmware"
}

Leave the rest of the file as-is. Save, and exit nano. Now rebuild the kernel, to return temporarily to the "full-fat" initramfs firmware payload. Ensure the boot usb key is inserted, and issue:

koneko ~ #buildkernel
... additional output suppressed ...
* Copying static gpg program into initramfs...
* Copying contents of /etc/modprobe.d directory into initramfs...
* Calling user_modify_initramfs function...
* Retaining all firmware in initramfs...
* Deleting old initramfs cpio archive, and repacking...

... additional output suppressed ...

* All done!

Once the process completes (you get the message All done!), reboot, enter your gpg passphrase, and log in as the regular user again.

Next, open a terminal, become root, and then list the largest 10 files or directories in /boot/initramfs/lib/firmware. Issue:

koneko ~ #du -hsx /boot/initramfs/lib/firmware/* | sort -rh | head -n 10
29M	/boot/initramfs/lib/firmware/netronome
25M	/boot/initramfs/lib/firmware/liquidio
19M	/boot/initramfs/lib/firmware/amdgpu
16M	/boot/initramfs/lib/firmware/qed
16M	/boot/initramfs/lib/firmware/intel
16M	/boot/initramfs/lib/firmware/brcm
8.7M	/boot/initramfs/lib/firmware/ti-connectivity
8.6M	/boot/initramfs/lib/firmware/bnx2x
8.4M	/boot/initramfs/lib/firmware/mrvl
7.6M	/boot/initramfs/lib/firmware/ath10k

Your results will most likely differ, depending on the version of sys-kernel/linux-firmware installed on your target system.

Note
This determines the sum size (using du) of the top-level files and subdirectories within /boot/initramfs/lib/firmware/, in human-readable form (staying on a single filesystem, the -x), then reverse sorts these, taking into account their human-readable units, and finally prints out only the top 10 entries (using head).

Have a look through the output list, and make a note of any that are irrelevant to your system. For example, a little checking with hwinfo (and dmesg | grep --ignore-case <name>), shows that the CF-AX3 has no peripherals from netronome, liquidio, AMD or qed (inter alia), so we obviously don't need any of those vendors' firmware to be able to boot (remember, all firmware will still be present on your root directory, under /lib/firmware, once the boot has completed — we are only working on the initramfs here).

So, let's modify user_modify_initramfs() to purge these top-level directories from the initramfs. Issue:

koneko ~ #nano -w /etc/buildkernel.conf

and then modify the function body of user_modify_initramfs(), so it now reads:

FILE /etc/buildkernel.confExample of purging unneeded firmware from initramfs via hook function
user_modify_initramfs() {
    show "Removing unnecessary firmware from initramfs..."
    local FD="${INITRAMFSDIR}/lib/firmware"
    rm -rf "${FD}"/{netronome,liquidio,amdgpu,qed}
}

Leave the rest of the file as-is. Save, and exit nano.

Important
Obviously, do not simply copy the above rm -rf <...> line verbatim — only delete those firmware files or directories which are irrelevant on your target machine.
Note
The rm utility deletes files and/or directories — in the above we ask it to delete recursively, and the -f option makes it work silently, and not complain if a specified entity is absent (this makes it more robust against possible reorganization of /lib/firmware, if say one of the cited top-level directories were to be dropped, or renamed).

Now, leaving the boot usb key inserted, build the kernel, and reboot to test it. Issue:

koneko ~ #buildkernel
... additional output suppressed ...
* Copying static gpg program into initramfs...
* Copying contents of /etc/modprobe.d directory into initramfs...
* Calling user_modify_initramfs function...
* Removing unnecessary firmware from initramfs...
* Deleting old initramfs cpio archive, and repacking...

... additional output suppressed ...

* All done!

Assuming this completed successfully (you get the output All done!), then leave the boot USB key inserted, and reboot the system.

When it restarts, enter the gpg passphrase and then log in (as the regular user) in the usual manner. Open a terminal, become root, and issue:

koneko ~ #dmesg | grep --ignore-case 'firmware' | grep --ignore-case --extended-regexp 'err|fail'

to check that there are no firmware load errors reported in the kernel's message buffer (if there are, you have probably been a bit over-aggressive with the firmware you have removed (but clearly not so aggressive that it prevented you from booting): in such a case, you can simply tweak your user_modify_initramfs() and try again).

Note
If your machine fails to boot with your new configuration, see these earlier instructions for how to fall back to the prior (or snapshotted last-known-good) kernel on the boot USB key, so you can get back in to fix things up.

Assuming everything still appears to be functioning OK (and the dmesg test you just ran returned no output), you can then, as before, check the new size of your kernel image, by using:

koneko ~ #ls -lht /boot/vmlinuz*-gentoo | head -n 1
-rw-r--r-- 1 root root  94M Oct 26 17:55 /boot/vmlinuz-4.14.65-gentoo

Obviously, your output will differ, depending upon your kernel version, the amount of pruning you have done etc. In the above example, you can see that a reasonable start has been made, with the kernel size having fallen from its original 130MiB to 94MiB.

Now, repeat the process (starting again from here), continuing to remove files or directories deemed unnecessary for booting from the initramfs, until an acceptable final kernel size has been reached (with only a little effort, it should be possible to get down to around 30-40MiB using this approach — as with many things, a Pareto principle applies ^-^).

Once you have obtained a sufficiently small kernel image, congratulations: you can now click here to jump down and continue reading the next section of this guide.

Tip
If you need only a particular driver from a given vendor's subdirectory, you can use find within the user_modify_initramfs() function to selectively remove the other contents.
For example, suppose your system had a Broadcom/Cypress 4356 WiFi adaptor, as shown by e.g. hwinfo --wlan. You obviously shouldn't then delete the whole ${INITRAMFSDIR}/lib/firmware/brcm subdirectory — but you don't have to keep its contents wholesale either. Instead, you can modify /etc/buildkernel.conf to selectively purge the subdirectory, as follows (remember to leave the rest of the file as-is):
FILE /etc/buildkernel.confExample of retaining only specific firmware for a vendor
user_modify_initramfs() {
    show "Removing unnecessary firmware from initramfs..."
    local FD="${INITRAMFSDIR}/lib/firmware"
    rm -rf "${FD}"/{netronome,liquidio,amdgpu,qed}
    ... etc ...
    find "${FD}/brcm" -type f -not -name "brcmfmac4356-*" -delete
}

This will keep any file (or files) in the /boot/initramfs/lib/firmware/brcm subdirectory whose base) filename starts with brcmfmac4356- deleting all other files (in the that subdirectory, recursively). It's a useful idiom to be aware of.

Remember — this is only an example — you need to check what is installed on your own target system, and adapt these instructions accordingly.

Remember, slimming your kernel image is very much an optional task, so feel free to postpone it for a rainy day (or forever if you like ^-^ !).

Note
However, to reiterate, if you would like to migrate your kernel to the Windows EFI partition on the hard drive (instructions for which are provided later), then you will have to slim it down somewhat to fit: standard Windows installations (like the CF-AX3) have a 100MB EFI system partition, of which about 20% is used for Windows files: as such, an 'unslimmed' kernel will (emphatically) not fit.

Suspend and Hibernate

At this point, let's take the time to properly configure power management (suspend and hibernate), as this is a useful feature to have operational on your machine.

The default sys-power/pm-utils power management works well for many systems out of the box. This provides the power-management functions invoked when certain buttons are pressed on the machine. Specifically, the 'suspend' key (FnF7 on the CF-AX3) invokes the 'suspend' action (aka 'sleep'), and and the 'hibernate' key (FnF10 on the CF-AX3) invokes the 'hibernate' action (aka 'suspend to disk').[9]

Note
Your machine may use different buttons for suspend and resume. If it does not have any, unfortunately at the present time you cannot also add suspend and resume actions to the power menu in GNOME via the "Hibernate Status Button" shell extension, as this requires systemd to operate. However, you can use the "Power" control panel in GNOME to make your PC's main power button trigger hibernation if you like (the default binding is "Suspend").

For the CF-AX3, the 'stock' configuration works perfectly for suspend (simply press FnF7 and the machine will enter sleep state, with its power button light flashing slowly; slide the power button, and it will resume). However, hibernate requires a little further tweaking (it does work, but the system doesn't fully shutdown after the memory image is written to disk). To get around this, we need to request that pm-utils writes the string shutdown into /sys/power/disk, rather than platform (this may be the case on your system too, but try to see if it works without making any changes first).[10][11]

To achieve this, we need to add the file /etc/pm/config.d/00-use-shutdown-on-suspend (which does not exist by default).[12] If you don't have a root terminal open already in GNOME, do so now: press the Windows Key, and type 'terminal', then press Enter. A standard-issue terminal window should open. Become root:

sakaki@koneko ~ $su --login root
Password: <enter root password>

The password required here is the one you set up earlier in the tutorial (and have used when ssh-ing in).

Then in this terminal, issue:

koneko ~ #nano -w /etc/pm/config.d/00-use-shutdown-on-suspend

Put the following text in the file:

FILE /etc/pm/config.d/00-use-shutdown-on-suspendAsking pm-utils to write shutdown to /sys/power/disk on hibernate
# use shutdown instead of platform, so machine switches off fully on hibernate
HIBERNATE_MODE=shutdown

Save and exit the nano editor (you can also close out the terminal if you have no further use for it).

After this, hibernate should work properly (on the CF-AX3). Press FnF10 and the machine will write its memory to the LVM swap partition on the LUKS encrypted volume (buildkernel conforms the kernel command line to specify this, as noted earlier), and then automatically power off. To resume, ensure that the boot USB key is inserted, and slide the power key. Enter your LUKS password when prompted, log in to GNOME, and you should find your desktop just as you left it. As this feature uses encrypted swap, it is relatively safe to travel with the laptop hibernated in this fashion (you should unplug and carry the boot USB key separately, of course).

Setting the System Default python Interpreter

This is a bit of an odd one, but it does seem to catch people out. Python is a widely used dynamic language. There are two major versions (2.x and 3.x),[13] and a lot of python scripts that you find on the web use the older version. The problem is that these scripts also often start with a versionless shebang like:

#!/usr/bin/env python

On Gentoo, this will end up invoking Python 3.x (not 2.x),[14] thereby (often) causing the script to break.

It's generally safe to set the default /usr/bin/python to refer to version 2.7 instead (since scripts that require version 3 will explicitly call it).

To do so, open a root terminal in GNOME (if you don't already have one open): press the Windows Key, and type 'terminal', then press Enter. A standard-issue terminal window should open. Become root:

sakaki@koneko ~ $su --login root
Password: <enter root password>

The password required here is the one you set up earlier in the tutorial (and have used when ssh-ing in).

Then in this terminal, issue:

koneko ~ #eselect python list
Available Python interpreters, in order of preference:
  [1]   python3.6
  [2]   python2.7 (fallback)

Your output may very somewhat from the above, but if the top line is not the '2.7' version (it is [2] in the above), set it as the default:

koneko ~ #eselect python set 2
Note
Substitute the correct index for python 2.7 (in the list returned on your system) for 2 in the above command.

That's it!

Disabling sshd

Up until now, you've been running sshd (the secure shell daemon) on your target machine, to allow for simpler configuration via a helper PC. This is no longer required, and running such a service can present security risks. Unless you have good reason to keep it, stop sshd now (and ensure it does not restart again on boot).

To do so, open a root terminal in GNOME (if you don't already have one open): press the Windows Key, and type 'terminal', then press Enter. A standard-issue terminal window should open. Become root:

sakaki@koneko ~ $su --login root
Password: <enter root password>

The password required here is the one you set up earlier in the tutorial (and have used when ssh-ing in).

Then in this terminal, issue:

koneko ~ #rc-update del sshd default
koneko ~ #/etc/init.d/sshd stop
Note
If you do wish to retain sshd, you should at least disable the ability to log-in directly as root (by editing /etc/ssh/sshd_config), change to password-less login, and possibly emerge and configure denyhosts (app-admin/denyhosts), or some similar service.[15]

Next Steps

Once you have worked through the above points to your satisfaction, congratulations - you now have a fully functioning dual-boot machine! We'll now cover a few quick points about day-to-day maintenance, cleanup, and other software you might like to install. Click here to go to the next (and final) chapter, "Using Your New Gentoo System under OpenRC".

Notes

< Previous Home Next >