User:Sakaki/Sakaki's EFI Install Guide/Final Preparations and Reboot into EFI

In this section, we'll be following along with Chapter 8 of the Gentoo handbook. However, we'll defer some of the configuration tasks mentioned there until the next chapter, when you have rebooted (mainly to help out those users who have chosen as their target init, since  configuration is most easily done from within a system actually running ). The steps we'll be undertaking are:
 * 1) Setting up the mountpoint tables  and ;
 * 2) Concluding preparations, viz.:
 * 3) Emerging some necessary packages (which it will be useful to have in place before a reboot);
 * 4) Taking note of networking information;
 * 5) Configuring networking for use post-reboot ( users only)
 * 6) Setting up a root password for the new system; then
 * 7) Cleanly dismounting the, and restarting;
 * 8) Before the OS boots, modifying the BIOS settings so that non-secure UEFI mode is used, then restarting again.

Instructions are also provided at the end of this chapter to recover back to a environment, should things not go as planned.

Please note that at the conclusion of this chapter there is a parting of the ways, depending on your previous choice of init system: The division point is clearly marked.
 * users targeting should continue following the regular guide Chapters 10-14; however
 * users targeting should instead follow the 'alternative track' Chapters 10-14.

So let's get started!

Setting up the Mountpoint Tables
Per the Gentoo handbook, we first need to setup, so that the system knows the location, mount point, filesystem type and mount options for the key system partitions. There are three such partitions (which we created earlier):
 * 1) the root partition, which holds the system software, configuration files, and the superuser's home directory (device file path );
 * 2) the swap partition, which is used to extend the system's available memory, and can also be used for hibernation (device file path ); and
 * 3) the home partition, which holds the home directories of normal users (device file path ).

We need to add entries for each of these to fstab; so issue:

and then edit the file, so that the only uncommented lines (those not starting with a symbol), are as follows:

If you have a cd- or dvd-rom drive on your machine (the Panasonic CF-AX3 does not), you can also add the following additional line:

Save and exit.

In the file:
 * The first field describes the path to the partition's device file (NB - when this file is referenced, the initramfs-based script will already have unlocked the LUKS partition and activated the LVM logical volumes, so we can safely use the device-mapper paths, as above).
 * The second field shows the mount point.
 * The third field shows the filesystem type. I have assumed (per the tutorial instructions) that you have used ext4 for the root and home partitions; if you chose something different, make sure to reflect it here. The use of for the optional cd-rom makes the operating system guess the filesystem type, which is useful with removable media.
 * The fourth field contains the mount options; these choices here are described in more detail below.
 * The fifth field is used by the command to denote which filesystems require dumping. It's generally fine to leave this as '0' (do not dump) in all cases.
 * The sixth field is used by to determine the order filesystems are integrity checked at boot time. A  indicates no check. The root filesystem should have (as here) a  to force it to be checked first, and then all other persistent filesystems can have  specified (so they are checked together, but after the root filesystem).

Here are the specific mount options selected above, and their meaning:

Per the Gentoo wiki article on, the mounted file systems table  must be a symlink to  (this is now also required for  ), so issue:

Some Concluding Preparations
It will be useful to have the DHCP daemon, Wikipedia:Wpa_supplicant and Wikipedia:GNU_Screen software available immediately upon reboot. They're not yet installed on the operating system, only on the 'outer' host, so let's emerge them now. Issue:

Next, take note of your current network interface name - this will be the same after a reboot, and knowing it will be useful during / configuration. Issue:

and look for a record name similar in format to (your system will most likely have a different name - in this particular case it refers to a ethernet card on PCI (p) bus 0, slot 25).

Next, we must set up a root password. Yes, we did indeed set up a root password earlier, but that was for the host operating system on the target machine, and we are about to discard that and boot directly into the new (currently -ed) one. As such, we need to set a fresh root password within the. Issue:

Similarly, we need to ensure that the setup inside the  will allow  to log-in (while we complete our set-up, at any rate). Issue:

We also need to make sure that the editor does not accidentally get removed later in the installation (as it is only 'held in place' by a virtual,, at the moment). Issue:

Configure Networking for Post-Reboot Use (OpenRC Users Only)
To make sure you have your network interface available after restart, be sure to add to the default runlevel. Issue:

You should also ensure that the service will automatically start on boot, so you can log in remotely; issue:

Next, if you are performing this install over WiFi, we need to ensure that can be started by  (NB: if using wired Ethernet for the install, you should skip these commands). Issue:

Now, we also need to prepend one line to that configuration file, so that can invoke  directly. Issue:

and prepend the following line to the file:

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

Also, as of version 6.10.0 of, you need to ensure that the appropriate 'hook' script is in place to start and stop on each wireless interface. So, to ensure that you have this file in place, issue:

Assuming you want to use DHCP on your interface (wired or wireless), that's all you need to do: pace the Gentoo Handbook, there's no need to add symbolic links, edit  etc.

However, if you have more complex networking requirements (static IP, proxies etc.) should consult the relevant section of the Handbook. Also, if you have more complex WiFi configuration requirements, you may also find these notes useful.

Cleanly Dismounting the and Restarting
Almost there! Now we have to exit the in both our  virtual consoles, quit both of those consoles (thereby exiting ), unmount the various logical volumes, deactivate the LVM volume group, and close out the LUKS partition. Issue:

then:

The first exits the  in the first  virtual console, the second exits that console itself. Now do the same for the second virtual console (which you'll automatically be dropped out to):

then:

Unmount everything (and turn off swap), deactivate LVM, and close LUKS:

Now we're ready to restart. Ensure your boot USB key is still inserted into the target machine (as well as the minimal install USB key, at this point), and issue:

Your session will exit. Immediately your target machine starts to come back up again, enter the BIOS setup screen.

Selecting UEFI Boot Mode in the BIOS and Restarting!
As mentioned earlier, the exact method of entering the BIOS varies greatly from machine to machine (as does the BIOS user interface itself). On the Panasonic CF-AX3, press during startup (you may need to press it repeatedly, and you do this directly on the target machine's keyboard).

Once the BIOS setup screen comes up, remove the minimal install USB key, so that only the boot USB key (the smaller capacity one) remains inserted. Then, using the same navigation techniques as before, perform the following steps:
 * 1) disable legacy / CSM boot mode;
 * 2) enable EFI boot mode;
 * 3) ensure any 'fast boot' / 'ultra fast boot' options (if present) are disabled (as these may cause USB to be disabled until the operating system comes up);
 * 4) turn off secure boot (our kernel is currently unsigned, and we have not yet updated the machine's key database in any event);
 * 5) select the USB boot key as the highest priority UEFI boot device; and
 * 6) restart your machine (saving changes).

It's impossible to be precise about the GUI actions required to achieve the above, as they will vary from BIOS to BIOS. However, to give you some idea, here's how you go about it on the Panasonic CF-AX3 (which has an AMT BIOS).

Using the arrow keys, navigate across to the 'Boot' tab. Then, navigate down to the 'UEFI Boot' item, and press. In the popup that appears, select 'Enabled' using the arrow keys, and press. This switches the system out of legacy / CSM boot and into standard UEFI mode (steps 1 and 2 in the list above):

Next (step 4), we'll turn off secure boot, since we haven't yet signed our kernel (or installed our own keys into the BIOS). On the CF-AX3, use the arrow keys to select the 'Security' tab, then navigate down to the 'Secure Boot' item, and select it by pressing. This enters a 'Security' sub-page; navigate to the 'Secure Boot control' item, and press. In the popup that appears, select 'Disabled' using the arrow keys, and press :

Next, on the CF-AX3, it is necessary to restart the machine at this point (as it will not pick up valid UEFI boot devices immediately upon switching into UEFI boot mode). Press to restart, and confirm if prompted.

When the machine restarts, hit again, to re-enter BIOS setup. Now we can select a boot device (step 5). Using the arrow keys, navigate to the 'Boot' tab, and then down to the 'UEFI Priorities' item. Press, and a sub-page is displayed. Ensure the item 'UEFI Boot from USB' is enabled (if it isn't, enable it now, and then press to restart (confirming if prompted), and come back to this point). Navigate down to 'Boot Option #1' and press. In the pop-up menu that appears, select your (boot) USB key, and press to select it:

That's it! Now press to restart (step 6), and confirm if prompted.

If all that worked, your target system should restart, and boot the UEFI stub kernel off the boot USB key. After some initialization, you should be prompted for a passphrase to unlock the keyfile for your LUKS partition (this is the passphrase you set up earlier). Type this in (directly at the target machine keyboard), and press. Shortly after, assuming that your passphrase is correct, you'll be presented with a login prompt. Enter 'root' as the user (again, directly at the keyboard, without quotes), and then type the root password you set up above.

If all goes well, you should now be logged in! If this is the case, congratulations, you have a encrypted system which boots from UEFI and uses (depending on your choice earlier) or. You can now click here to complete the configuration of your init system (and other) settings.

If however, for some reason you weren't able to boot, then read on.

<span id="if_things_go_wrong">How to Recover if Things Go Wrong
The following are short-form instructions to get you back into a environment again, so that you can attempt to fix whatever problem prevented you from booting under UEFI. I have included backlinks throughout, so you can hop up to where these steps were first taken, and read in more detail about what is involved - the style of what follows is rather telegraphic.

First, re-insert your minimal install USB key into the target machine (leaving the boot USB key inserted as well, since we'll need it to unlock the LUKS partition), and restart the system. As the machine comes up, re-enter the BIOS and re-activate legacy / CSM booting, and set (if it is not already) the USB key to be the top boot priority device (original instructions here). Save the BIOS settings and exit, thereby rebooting into the Gentoo minimal install system (original instructions here). As before, hit when it beeps at you, remember to select the correct keymap etc. Then, since the boot image itself has no persistence, issue (directly on the target machine's keyboard):

Remember (original instructions here), you are setting up a password for the 'outer', host system here - root's password inside the will be retained (and different), but we haven't remounted the  yet.

Next, ensure that your networking is up. Follow the appropriate instructions below.

If installing over wired Ethernet, simply wait for a little while (if necessary for address allocation to complete), and then note your IP address, using (original instructions here):

Then click here to skip to the next step. If, instead, you are installing over WiFi, you need to re-create your configuration file (original instructions here). Issue:

Lock down the file's access permissions (to root only) and check that its contents look sane. Issue:

Assuming that looks OK, we can connect. Issue:

Then note your IP address:

<span id="restart_sshd">Now start (original instructions here):

This will generate a new set of keys, so take a note of the RSA and ED25519 fingerprints for the host key, as shown with:

Now switch to your helper PC. Note that, if the target PC's IP address is the same as it was originally (quite likely, even with DHCP), then the helper will already have a note of its previous fingerprint, and will refuse to connect via (since a mismatched fingerprint might suggest a man-in-the-middle attack). Therefore, we need to remove the old fingerprint record for the IP from. Issue:

and issue (original instructions here):

Check the key fingerprint and then, if it matches, continue as below:

Once you are connected, we need to get running. Via the connection on the helper PC (which is how you should enter all subsequent commands, unless otherwise specified), issue (original instructions here):

Next, we must mount the USB boot key's EFI system partition, so that we can use the keyfile on it to unlock the LUKS partition. Find out the device file name for the EFI partition on the USB boot key, by issuing (original instructions here):

We will refer to this as in what follows, but of course on your machine it will be something like  or  (note that the initial  prefix is not shown in the  output).

Next, create a temporary mountpoint, and mount it. Issue (original instructions here):

Now, we can open the LUKS volume. You'll need the passphrase (for the keyfile) you set up earlier to do this:

Now we can bring up the LVM logical volumes, and mount them. Issue (original instructions here):

Next, unmount the USB boot key; issue (original instructions here):

Ensure the date and time is set correctly; issue (original instructions here):

Next, make sure that the DNS information will still be valid after we. Issue (original instructions here):

Now, ensure that the various special files in, and  are available after a. Issue (original instructions here):

Now we can actually enter the. Issue (original instructions here):

Remember to source our profile correctly and set a prompt hint. Issue (original instructions here):

Finally, we can setup a second virtual console inside (just as we did before), which will be useful to e.g., monitor the status of long s. Press  then  to start a new console. Then in that new console (which is back outside the, to begin with) enter:

followed by

Now hit then  to get back to the original console.

That's it! You can now proceed to edit your -ed system (and hopefully, to fix it). It is impossible to be specific as to what may have caused a problem, but some likely candidates include:
 * Incorrect kernel configuration. In this case, run, enter the graphical kernel configuration editor when prompted, change the appropriate kernel settings, and then save and exit the editor. The build will continue with your modified configuration. (A problem of this sort is most likely to occur if you have already started to dabble with the configuration, since the standard flow in this tutorial assumes you have used the config from the running minimal install system kernel - which is therefore to some extent 'known good' - as a basis).
 * Buggy version of . Please note that version 1.0.24 has a bug that affects booting and should not be used (earlier and later versions are not affected). Issue  to check, and if you do have the affected 1.0.24 version installed, update it (using ), then rebuild your kernel and reboot.
 * Missing packages. For example, you may have forgotten to install e.g., prior to reboot, preventing you from accessing the network properly. If this is the case, simply  the required software within the chroot, and then try again. There is no need to re-run  in this case.
 * Password not set for root. If for any reason you forgot to set a root password for the new system (as instructed above, when you were -ed in originally), then your attempt to log in will have been rejected. This is easily fixed by using.
 * Wrong keymapping causing mangled passwords. If the system would not accept your keyfile passphrase on reboot, but you were able to successfully unlock it when re-entering the  above, or, if the system would not accept your root password after a restart, then you may have not setup the  variable in  correctly. See this earlier discussion for further details. (These issues can also generally be ameliorated (for most locales) through the use of only standard English letters in your passphrases, as mentioned previously.) Review, and if necessary, change your boot-time keymap by using, and then re-run.
 * Problems with UUIDs. The script tries to ensure that the UUIDs you have passed it (in  above) are valid, but it is still possible to make a mistake (e.g. if you have more than one LUKS partition on your system, for example). Double check these values, and, if necessary, change them (by using ) and then re-run.
 * BIOS configuration problems. A total failure of your new system to even try to start (or if you get Windows instead!) is likely to indicate some issue with your BIOS settings. Are you sure your USB boot key is at the top of the UEFI boot order? And that secure boot is disabled at this point? Run through the steps in the "Selecting UEFI Boot Mode in the BIOS and Restarting!" section once more, then try again. (You should also double-check that the first (and only) partition on your USB boot key is marked as an EFI system partition and is formatted ; see this discussion.) A very few EFI systems also do not look for a boot executable under the standard path, but instead will use . If that's the case for your target machine, change the EFI boot file path using, then re-run.

Once you have made your changes and are ready to have another go at rebooting, simply proceed from the section "Cleanly Dismounting the and Restarting" in the main text. Good luck!

<span id="next_steps">Next Steps (and Fork in the Road)
Now that you have successfully booted into Gentoo from UEFI, we can proceed to configure your system. At this point, you need to follow one of two tracks for the final set of chapters (10-14), depending on your earlier choice of init system:
 * users targeting  (the default) should click here to go to the next chapter on the regular track, "Configuring and Installing Necessary Tools"; whereas
 * users targeting  should instead click here to go to the next chapter on the alternative track, "Completing Configuration and Installing Necessary Tools".