Installing Ubuntu 18.04 on a Thinkpad X1 Carbon G6
In just over a week, I'll be starting a new job - and they asked me during the onboarding process what kind of laptop I wanted. Did I want a Mac or a Thinkpad? This seemingly innocent question stumped me, mostly because I was hearing the following questions:
Do I want everything to just work out of the box, or do I want hours of configuration to get GNU/Linux running the way I want it?
Do I want to have a laptop that feels like an extension of my fingers and mind, or do I want a machine where someone else has decided what's best for me?
Do I want to be oblivious of everything under the hood, or do I want to see how much I had forgotten over the last ten years?
Ultimately, it was the last question which really got to me. Ten years ago, I was on top of what was being developed in the kernel, I knew off by heart what parts of the system did what during boot, runtime, and shutdown. That was my job - and it was my passion.
But as it happens, I became interested in how teams work, how organisations grow and change, and what makes a good leader. And off I went down that path, branching away from engineering and into management. Not that I regret that choice in any way - growing these soft skills is fun, and there's so much to learn.
But still. When asked about what laptop I wanted, I found myself looking back at that branch in the road almost a decade ago, thinking - Even if I wanted to install some Linux distro on the laptop, was I capable of it? What if it goes wrong? And what if I don't have the time and/or energy to maintain it afterwards?
As the day approached when I would have to give an answer, I knew that I just had to try it. If I could get the laptop a few weeks in advance, I could install and re-install the machine a few times, learning from my failures and getting things right.
I planned to go with a simple Linux distro, with lots of community support. One where I don't need to compile stuff from scratch, and where I don't need to understand everything, but just enough. Also, a distro which is known for its stability and one which I had used at some point in the past. So I went for Ubuntu, which is close enough to Debian. I decided that if it went well and I liked the experience, I could go with Gentoo or even LFS on another partition.
Below, I'll write out what I did, where I messed up, and how it all turned out.
I went for the latest LTS release of Ubuntu, which turned out to be version 18.04. I did some googling on if there were any particular problems installing Ubuntu on this particular Thinkpad, and didn't find many people complaining about blockers (aside from the normal gang of newbies, and very specific things which I decided to ignore).
After creating the Ubuntu installer liveUSB, I booted up and started installing. One of the guides I used was this one by ThorneLabs, where I found the tips on how to set up BIOS really useful.
I was initially intending to set up the partitions old-school, with a separate root, /boot, /var, /usr/local and /home. But when it struck me that I needed to encrypt the entire disk, I decided to just go with what the installer recommended - which was one EFI, one /boot, and one huge crypto_LUKS partition, which in turn would be divided into two: a swap partition and the entire filesystem in the other.
The article also claimed that hibernation worked out of the box, which was nice since I like to save power when not using the machine.
It almost worked. Almost.
Most everything worked quite nicely, but there were two things which didn't quite work.
This was most urgent to fix, since I won't always have a mouse with me. And since I normally set up X so that focus follows mouse, I use the trackpoint to nudge the pointer to the window I want to focus on.
The problem was that when I touched the trackpad or trackpoint, the mouse pointer would move a bit, then freeze. dmesg told me the following:
psmouse serio1: TouchPad at isa0060/serio1/input0 lost sync at byte 1
I found some nice tips here, which worked for me:
# # Comment out 'blacklist i2c_i801 # perl -p -i -e 's/^blacklist i2c_i801/#blacklist i2c_i801/' /etc/modprobe.d/blacklist.conf` # update-initramfs -u # # # Add kernel param psmouse.synaptics_intertouch=1 # # to grub config # perl -p -i -e 's/GRUB_CMDLINE_LINUX_DEFAULT="(.*?)"/GRUB_CMDLINE_LINUX_DEFAULT="$1 psmouse.synaptics_intertouch=1"/' /etc/default/grub # update-grub
Reboot, and the trackpoint and trackpad worked nicely!
This was a little more difficult to diagnose. Looking around the internet didn't help so much, since it was peppered with many many people with similar but actually different problems. I must have read through at least 20 sites, many of them forums with post after post of people moaning about the problem and false leads.
So I instead did what I should have done from the beginning, which was to gather data.
# # Look at legal disk states # cat /sys/power/disk [disabled] # # # Look at available powersaving modes # cat /sys/power/state freeze mem
So it looked like the kernel didn't support hibernation at all. If it had, /sys/power/disk wouldn't say [disabled], and /sys/power/state would have the string disk in it somewhere.
After many more false trails (among others, one where I upgraded my LTS up to 19.04) I happened to notice a string in dmesg:
# $ dmesg | grep -i acpi:.*supports [ 0.423376] ACPI: (supports S0 S3 S4 S5)
Aha! The kernel does support deep sleep. S4, for example, means putting the system into low-power state. It was mentioned in dmesg - which in turn should have meant that /sys/power/disk should have the string platform in it. Which it didn't. Anyway, it struck me that I could grep for 'hibernation' in the output of dmesg. And there's where I saw it:
[ 1.855894] Lockdown: Hibernation is restricted; see man kernel_lockdown.7
Now this I could work with. The kernel supports hibernation, but refuses to activate it. From this point it was easy to hunt down the problem - it was the whole 'Secure boot' thing, which many people recommended turning off in BIOS. I hadn't done it, since that article by Thornelabs (sic) said it wasn't necessary anymore. So I booted into BIOS and disabled Secure boot.
# cat /sys/power/disk /sys/power/state [platform] shutdown reboot suspend test_resume freeze mem disk
So now my kernel supports hibernation and wasn't locked down! I was super happy with myself, until I realised...
Remember how I let the Ubuntu installer fix the partitions for me? Well, I didn't think about it at the time, but it apparently only set aside 1G for the swap partition. I knew I had to resize it up if I wanted to dump mem into it when suspending-to-disk, and I also knew that disks and partitions were a bit more complicated nowadays, what with LVM and UUIDs for disks. Gone are the days of simple /dev/hda1. Also, I needed to understand at least a little of how the partition was encrypted...
Now I wasn't completely innocent when it came to LVM, since it was something we used back when I was an SRE at Spotify. But it was years and years ago. And to be honest, I never really became good friends with commands like pvdisplay and vgscan. Not like me and good old fdisk or fsck. Ah, those wonderful days where commands were short and man pages obfuscated...
After looking through different walk-throughs, I decided to give this one a shot - it had details at the command-line level, but also explained what was happening. It even had an overview, which I liked.
I didn't need to follow all the instructions - after all, both swap and my root partition lived on the same physical volume in two different logical volumes. So I didn't need to follow the instructions which explained how to resize the PVs.
All I wanted to do was to reduce the root filesystem by 15G, and expand swap by 15G. To do this, I need to:
reduce the root filesystem
reduce the logical volume for the root fs
expand the logical volume for swap
re-create swap to fill the whole logical volume
This is what I did in more detail:
Boot into the liveUSB I used to install Ubuntu.
Load the cryptsetup module
# sudo cryptsetup luksOpen /dev/nvme0n1p3 crypt1
# sudo vgscan --mknodes # vgchange -ay
# sudo e2fsck -f /dev/mapper/ubuntu--vg-root
Shrink the root filesystem by 15G (from 474.75G).
# sudo resize2fs -p /dev/mapper/ubuntu--vg-root 459G
Check the filesystem again to make sure nothing borked up when resizing.
# sudo e2fsck -f /dev/mapper/ubuntu--vg-root
Take a look at the logical volumes on your system. There should be two - one for rootfs and one for swap.
Reduce the logical volume for rootfs, then look at the volume afterward to see the changes.
# sudo lvreduce -L 459G /dev/ubuntu--vg/root # sudo lvdisplay
Now I have space for swap to expand into. Let's expand the swap logical volume. Oh and btw, you might have noticed that I actually shrank the root logical volume by a bit more than 15G. It was 15.75G actually. This is probably unnecessary, but I wanted to make sure that there definitely was enough room to write my mem to swap when hibernating. Also, I found it curious that the lvreduce command was used to expand the LV. Slightly confusing, but heartwarming to see that there are still idiosyncracies around to boggle us :).
# sudo lvreduce -L +15.75 /dev/ubuntu--vg/swap_1 # sudo lvdisplay
Create a new swap, using the entire space
# sudo mkswap -c /dev/mapper/ubuntu--vg-swap_1
After all this, I rebooted, and the command sudo systemctl hibernate worked like a charm. Pressing the power button brought me to the disk decrypt password prompt, and after a short pause I was shown the screen I had in front of me when I ran the hibernate command.
Well, I now have a functioning Thinkpad X1 Carbon G6, and it's working nicely. I haven't bothered with the fingerprint reader or the SIM card reader, I suppose I might try to get them to work at some point.
Looking back at this process, I gotta say that it was about as complicated as I remember it to be. Lots of small hurdles to get over, but that's not really new when installing Free Software onto computers, especially laptops.
I had expected more problems with graphics, sound, the wifi unit (is broadcom still making life difficult for people?) etc. But that just worked out of the box.
I suspect that I'll find maintaining this system a bit of a pain in the future, and to be honest I haven't tested everything yet. I'm not sure how to activate IEEE802.1X which I'm guessing we have at the office, and I'm guessing that printing is still a major PITA. I'm already prepared to have to struggle with PulseAudio. And I haven't wrestled with xrandr to get my secondary monitor working, something I'm sure I'll need to do.
But all in all it was a very satisfying experience, and call me a masochist - but I'm looking forward to getting all that to work.
We'll see what I think in half a year :).
Edit:2019/09/03 I noticed that sometimes after suspend/hibernation my trackpoint stopped working. Very strange. Did a little digging and figured out that the psmouse module was loaded after rmi_smbus. So I changed the order here:
# # change order of loading modules # cat > /etc/initramfs-tools/modules rmi_smbus psmouse EOF # update-initramfs -u
Then rebooting. This seemed to fix the problem.