Quick checklist

Here is the install checklist for those who don't want to read the entire article:

Detailed guide to installing Gentoo Linux on a ThinkPad T460

Preparing the install media and the BIOS

Let's start with preparing the install medium - I personally recommend the Gentoo LiveDVD for this, not the minimal install ISO. The reason for this is that the Gentoo minimal install medium does not support booting in UEFI mode - because of this, you will not be able to install a UEFI bootable system, as the EFIvar file system will not get mounted.

Writing the ISO to an install media is easy:

root@kingfisher ~ # dd if=livedvd-amd64-multilib-20160704.iso of=/dev/sdb bs=4M status=progress

You (obviously) need to substitute your install media's device in place of sdb and use the ISO's actual filename. After dd is done writing the data to the device, I recommend issuing a sync command as well, to make sure all data has finished writing to the install media.

If you were to boot from the install media right after this, you would find yourself without the EFIvar file system mounted - I found out this the hard way. The T460 defaults to legacy boot (BIOS) first, then UEFI, and because the LiveDVD is capable of both, this can lead to some confusion.

Boot up your laptop and start pressing the F1 key. After getting into the BIOS, disable Secure Boot (General->Secure Boot), enable VT-x and VT-d if you have a capable processor - the i5-6300U and i7-6600 specifically - (General->Virtualization, why are they off in the first place?) and then set the boot to UEFI-only (Boot Order->Boot Order, or UEFI-first, if that's your thing). Without disabling Secure Boot, you will be unable to boot into the installer.

Installing the Gentoo base system with UEFI

For most parts, this guide will follow the Gentoo Handbook.

First, ensure you have Internet connection, this is left as an exercise to the Reader. After that's done, partition your drive(s). I used parted for this task, as it has better support for GPT (which is required for UEFI) than fdisk.

livecd / # parted -a optimal /dev/sda
(parted) mklabel gpt
(parted) unit mib
(parted) mkpart primary 1 3
(parted) name 1 grub
(parted) set 1 bios_grub on
(parted) mkpart primary 3 131
(parted) name 2 boot
(parted) set 2 boot on
(parted) mkpart primary 131 -1
(parted) name 3 root
(parted) quit

Attentive readers will notice that swap was not created. My view (and opinion) is that in the days of 16GB of RAM becoming a common sight to see even in laptops, swap is completely redundant for desktops and laptops. If you require a swap partition, I suggest you create it as the third partition. Following this, we will create a FAT32 file system on the boot partition. This is to accommodate for UEFI's shitty choice in file systems.

livecd / # mkfs.fat -F 32 /dev/sda2

When that's done, create the root file system. ext4 is a great all-around choice, I can also recommend XFS for general usage. ZFS if you like pretending your laptop is a file server. If you have nothing to lose, you can use Btrfs as well (you do backup regularly, right, friend-o?). Here is an example for creating an ext4 file system on /dev/sda3.

livecd / # mkfs.ext4 /dev/sda3

If you did everything correctly, you should see the following in parted:

(parted) print
Partition table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
1       1049kB  3146kB  2097kB               grub  bios_grub
2       3146kB  137MB   134MB   fat32        boot  boot, esp
3       137MB   256GB   256GB   ext4         root

Following this, mount the root file system at /mnt/gentoo.

Follow the Handbook's directions up to the point where it asks you to set the CFLAGS. Use the bog-standard march=native CFLAGS:

CFLAGS="-O2 -pipe -march=native"

and we will set the CPU flags as well:

CPU_FLAGS_X86="aes avx avx2 avx512 fma3 mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3"

The gcc compiler that comes with the stage3 tarball does not contain information regarding the Skylake architecture yet (only up to Broadwell), but we are going to change this right now, don't worry!

Upgrading GCC

I recommend you upgrade gcc the first thing you do, to save you from lengthy rebuilds.

As I am writing this article, the current stable gcc version in Gentoo is 5.4.0. That's a bit old, but we don't want to risk "cutting" ourselves on the bleeding-edge gcc versions. 6.3.0 offers a good compromise, it is currently marked as testing (~) in the official Gentoo ebuild repository. In case of gcc, I like to keep up with the latest testing versions.

I use ACCEPT_KEYWORDS for this purpose. Unmasking the latest testing version is quite simple:

echo "sys-devel/gcc" >> /etc/portage/package.accept_keywords

Following this, upgrading gcc is just one emerge away:

emerge --quiet --ask --verbose sys-devel/gcc

Don't make the same mistake I made: don't forget to set the gcc version!

Use gcc-config -l to list available gcc versions, and issue gcc-config # where # is the desired gcc version.

You will most likely need to rebuild libtool as well, as it depends on internal hard-coded paths to gcc.

emerge --quiet --ask --verbose --oneshot sys-devel/libtool

No further rebuilds should be necessary, as there is no general ABI breakage upgrading from 5.4.0 to 6.3.0. Continue following the Handbook's guidance.

Small detour: rebuilding / re-emerging EVERYTHING

As I neglected to set the gcc version before upgrading everything, I ended up needing to re-emerge everything. For future reference to myself and other poor souls:

emerge -qve1 @world

Have FUN!!! /s

Kernel fun

When you get to installing and configuring the kernel, the real time-stealing (((fun))) begins.

First, the current LTS kernel, 4.9.6 (as of time of writing), does not contain every fix and feature required to run a Skylake system. We will need to get the latest kernel marked as testing (4.11.7 as of time of writing). I generally use the latest testing kernel, unmasking it can be done similarly to gcc:

echo "sys-kernel/gentoo-sources" >> /etc/portage/package.accept_keywords

I will try to only list required changes in the kernel config. The reader may autism over the other settings as they see fit.