Lenovo ThinkPad X1 Carbon 3rd Gen

This is a guide to setting up Gentoo on a Lenovo X1 Carbon, Gen 3 with a WQHD touchscreen. The guide assumes you are starting from scratch and are prepared to erase the entire SSD. The aim of this installation is to provide you with a desktop environment using stable sources for almost everything (non-stable sources will be used for the Firefox browser). The desktop will have working WiFi and auto-detect USB drives when they are plugged in. During the installation, it can be useful to take snapshots of progress in case you change your mind or want to roll back. This guide recommends the use of "btrfs" for this purpose.

The installation will be described in 2 sections:
 * 1) Self-hosting/booting (roughly 1.5 - 2 hours; 30 mins attended)
 * 2) Setting up the desktop (roughly 4 - 6 hours; 1 hour attended)

It is highly recommended to use a separate computer (aka. "the host PC") with a working desktop so you can SSH into the target X1 Gen3 laptop and cut/paste commands from this wiki page into the target laptop.

Connecting to the Target Laptop
Boot the Live DVD on your target laptop. Once booted, press +++ to get a shell.

Change the root password:

Discover the network address:

Make a note of the IP address (example highlighted in green).

Start the SSHD daemon:

You can get back to the Live DVD GUI if you press +++, but it's not necessary.

Now, close the laptop lid and SSH into the target laptop through your host PC's SSH client. Use the IP address you found earlier.

Identify your CPU flags

Copy the results of this command into a text editor on your host PC; you'll need them for later.

Graphics Capabilities
Visit the Gentoo Intel web page to see what features your CPU supports.

Notes for the X1 Gen3:
 * 1) It has a 5000-series CPU, so it's a Gen 5 (Nehalem).
 * 2) The integrated graphics are "intel i965"
 * 3) It supports OpenGL (opengl), OpenGL ES (gles2) and VAAPI (vaapi)
 * 4) It does not support OpenCL or Vulkan

Remote Control
Start a virtual screen; you can disconnect from it at any time by pressing + then.

If you disconnect, you can re-attach at any time with:

While disconnected, you can close the SSH session or shut down the host PC without cancelling your work in progress. This is handy when you kick off a bulid with lots and lots of dependencies.

Format The Drive
Now, format the HDD and set up partitions. This example shows settings for a 512GB drive, with the intent to mount /opt as a separate partition.

Now, erase the disk and specify units of MB.

(Optional) You can print the resulting partition scheme.

Write the changes to the disk and get back to the command prompt.

Set up File Systems
We are using "btrfs" because it allows us to take snapshots as we progress through the installation.

Install the Stage 3 Tarball
Go to Gentoo's distribution page to find the latest release. This example shows the first Stage3 tarball to contain v17.0 profiles.

The LiveDVD has already inspected your hardware, so take a moment to make a copy of what it found. You can use this as a reference later if you think that you are missing a driver.

Configure the Make system
Copy the block of text below into a text editor and edit the processor flags to match the results we got earlier. You shouldn't need to modify the example if you are using a 3rd Gen X1 Carbon.

Delete everything and paste the contents of the example.

CFLAGS="-march=native -O2 -pipe" CXXFLAGS="${CFLAGS}" MAKEOPTS="-j5"
 * 1) These settings were set for a Lenovo Carbon X1 Gen 3 for a Cinnamon Desktop
 * 2) Please consult /usr/share/portage/config/make.conf.example for a more
 * 3) detailed example.

CHOST="x86_64-pc-linux-gnu"
 * 1) WARNING: Changing your CHOST is not something that should be done lightly.
 * 2) Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.

USE="-bindist" CPU_FLAGS_X86="aes avx avx2 fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" PORTDIR="/usr/portage" DISTDIR="${PORTDIR}/distfiles" PKGDIR="${PORTDIR}/packages" USE_PYTHON="2.7 3.5" PYTHON_TARGETS="python2_7 python3_5 python3_6 pypy pypy3" PYTHON_SINGLE_TARGET="python3_5" LLVM_TARGETS="X86"
 * 1) These are the USE and USE_EXPAND flags that were used for
 * 2) buidling in addition to what is provided by the profile.

GENTOO_MIRRORS="http://ftp.swin.edu.au/gentoo" GRUB_PLATFORMS="efi-64"

LINGUAS="en_AU en_GB en_US en" L10N="en-AU en-GB en-US en"

VIDEO_CARDS="intel i965" INPUT_DEVICES="evdev keyboard mouse synaptics mutouch"

USE="-bindist hardened pie icu mpi"
 * 1) Main global USE flags
 * 2) Notes:
 * 3) The use of "bindist" or "-bindist" is up to you
 * 4)  * "bindist" gives you binary blobs
 * 5)  * "-bindist" compiles from sources, but may infringe patents
 * 6) "hardened" only applies to packages (not the kernel)
 * 7) "icu" is Internationalization Components for Unicode
 * 8) "pie" is Position Independant Executables (a security thing)
 * 9) "mpi" is the Message Passing Interface

USE="${USE} opengl vaapi glamor"
 * 1) Globals for Intel 5000 series integrated graphics
 * 2) Not using "gles2" because it's a subset of OpenGL

USE="${USE} wayland pulseaudio"
 * 1) Globals for desktop systems:

USE="${USE} ldap zeroconf fam acl networkmanager nls"
 * 1) Globals for filesystems and networking:

USE="${USE} truetype type1 cleartype corefonts"
 * 1) Optional extra font handling for desktops

USE="${USE} bluetooth wifi"
 * 1) Globals for Cinnamon


 * 1) Globals for programming Vala (language used in Enlightenment.io)
 * 2) USE="${USE} vala"


 * 1) Uncomment this to get the latest unstable software packages globally
 * 2) ACCEPT_KEYWORDS="~amd64"

Chroot and Sync
Mount the drives that you need.

Now enter your (very minimal) OS.

Now, get the latest version of the portage tree.

Please take the time to read the news; it's there for a reason.

You are now running off the laptop's SSD, but there are a few steps left before we can boot without the USB stick.

Customise Your Environment
Check that you're using GCC v6.x

If you're not running GCC v6.x, you need to run this command:

Choose a profile for the Cinnamon desktop (unless you want Gnome or KDE)

Pick your timezone:

Copy this block of text into the /etc/locale.gen file, adding extra locales as necessary

en_US ISO-8859-1 en_US.UTF-8 UTF-8 en_GB.UTF-8 UTF-8 en_AU.UTF-8 UTF-8

Activate the new language settings and update your prompt string.

Install Sources
Install Gentoo-enhanced Linux Kernel Sources

Save the Defaults
Exit straight away and make a reference so you can write a guide like this ;)

Menuconfig Settings
Now go back and customise the kernel in order to get all device components functional for this laptop.

Make any final tweaks, then:

Check for success; it looks like this: sh ./arch/x86/boot/install.sh 4.12.12-gentoo arch/x86/boot/bzImage \ System.map "/boot"

Set up your fstab
/dev/sda2  /boot        vfat    defaults,noatime     0 2 /dev/sda3  none         swap    sw                   0 0 /dev/sda4  /            btrfs   noatime              0 1

Change the Hostname
my_laptop_name

hosts:      files dns my_laptop_name

127.0.0.1      localhost my_laptop_name ::1            localhost my_laptop_name

Install Core Daemons
GRUB_CMDLINE_LINUX="rootfstype=btrfs"

Allow root Logins for SSHD
Only while we are setting this up; we need to remember to turn this setting off later, for security reasons.

PermitRootLogin yes

Reboot
Your laptop should shutdown and reboot. You can remove the USB stick when you see the screen go black as the system starts up again (before the BIOS logo).

This is everything you need to get Gentoo booting on the X1 Carbon Gen 3. The next step is to re-establish an SSH session and update the software on your new OS.

Compare Your Kernel
How well did our configuration match the LiveCD's hardware probing?

Compare these files with the livecd result using "diff", if you like.

Now lets get a virtual terminal again.

Rebuild Everything
First, take a look at the result from this command:

We have got a circular dependency with mesa, opengl and vaapi. We solve it by temporarily building "mesa" without "vaapi", then adding "vaapi" back to "mesa" and recompiling it.

Check the use flags in red; if they're redundant, consider removing them. Check the flags in blue; if you want any of those features, go back and edit your /etc/portage/make.conf file.

Leave the LLVM_TARGETS flag alone unless you're building on ARM

Modify the use flags, then do the world "emerge" for real.

Go away for a few hours. This is where it can be useful to disconnect from the screen terminal session and switch off the host PC. You can tell when the compiler is finished because the laptop fan stops blowing.

Now we can build "mesa" properly, with "vaapi" this time.

Add More Useful Programs
Uncomment this line to let users in the "wheel" group use the "sudo" command. %wheel ALL=(ALL) ALL

Don't use "etc-update" anymore; use "dispatch-conf" instead (because it is safer).

Make a Snapshot
We have to install the "btrfs" tools before we can make a snapshot, but the tools use an old version of Python. We solve this by setting a specific version flag for the "asciidoc" package which requires it.

Note: This is the syntax for setting special flags for a single package.

Last action: take a "btrfs" snapshot of what you've built so far in case you want to roll back to this point instead of reinstalling everything from scratch again.

If that happened so quickly that you can't believe it has safely made a copy of every system file, you can take a look and see what it did:

Lastly, look for unfinished business or hints/tips that you may have missed during the software installations

You have finished installing the Gentoo base system on your laptop. From here, you should add the Xorg-server, a Display manager, a Desktop and some apps. That will be covered in Part 2.