Fedora 30 with Linux Surface Kernel

Junhai Yang
May 2 · 5 min read

So, with everything changed around Fedora 30, getting Surface device to work got somewhat easier and harder at the same time.

My laptop is the Surface Book 2 15", so it’s the run of the mill Surface Book 2, nothing special.

Fedora 30 now has Deepin Packed in!

Credit:

  1. I followed most of the steps here: https://medium.com/@zax_myth/installing-fedora-27-linux-on-surface-pro-4-5d5c84f86a15
  2. This is where all the magic happens: (aka the author of the kernel patches) https://github.com/jakeday/linux-surface
  3. In case, some instructions given in linux-surface is not going to work, reference: https://github.com/dmhacker/arch-linux-surface
  4. Arch Wiki : (Yes, Fedora and Arch is compatible, don’t look for Ubuntu wiki) https://wiki.archlinux.org/index.php/Microsoft_Surface_Book_2

What works out of the box?

  • Keyboard (and backlight)
  • Touchpad
  • WiFi
  • Bluetooth
  • Speakers
  • Power Button
  • Volume Buttons
  • SD Card Reader
  • Suspend (Hibernate is a bit sketchy), but S-1 always work
  • Sensors (accelerometer, gyroscope, ambient light sensor)
  • USB-C (including for HDMI Out)
  • UEFI , Secure Boot (Look at that beautiful f30 plymouth)

What will work after installing the kernel?

  • Keyboard (and backlight)
  • Touchpad
  • 2D/3D Acceleration
  • Touchscreen
  • Pen
  • WiFi
  • Bluetooth
  • Speakers
  • Power Button
  • Volume Buttons
  • SD Card Reader
  • Hibernate (need more testing, works for S-1 and S-2)
  • Sensors (accelerometer, gyroscope, ambient light sensor)
  • Battery Readings
  • Docking/Undocking Tablet and Keyboard
  • USB-C (including for HDMI Out)
  • Dedicated Nvidia GPU (recognized, no error, but just doesn’t load…)

What’s changed in Fedora 30?

Well, grub is very different now (I will say good different?), you cannot just manipulate grub the good old way any more. Grubby has became a really good friend recently.

Surface Book 2 is bearable in F28 and F29 without the surface-linux kernel; but in F30, computer will run into full power mode soon, and you will realize that trying to shutting it down takes a while. watchdog is the main culprit here.

Also, to make your life easier, when you install Fedora, please allocate a swap partition of at least 4 GB.

Steps and all

0. Make DNF fast:

gedit admin:///etc/dnf/dnf.conf
# then add this line:
fastestmirror=true
  1. Update your system to the latest, so :
sudo dnf update -y

2. Install Compilation Tools (elfutils is the new kid here)

sudo dnf groupinstall "Development Tools" 
sudo dnf groupinstall "C Development Tools and Libraries"
sudo dnf install openssl-devel perl-devel perl-generators pesign ncurses-devel elfutils-libelf-devel

Let us also create a new folder in home directory for all kernel related files , e.g. your kernel signing keys, kernels, patches etc.

3. Setup Kernel Signing

So, secure boot is still very nice, and it would be nice to keep that. So , simple steps:

Setup MOK, Kindly visit : https://github.com/jakeday/linux-surface/blob/master/SIGNING.md , and follow step 1 -4

  • Reboot and select the last entry (system firmware or something like that)
  • Go to security -> secure boot , change the option to Microsoft And 3rd party
  • Reboot again, and now you should be greeted with a blue screen (of death), which is MOK Manager, so that will be step 5
  • Back to fedora, verify that MOK is setup nice
sudo mokutil --list-enrolled

4. Kernel Patch Time

So, this is pretty much the same as mentioned in Credit Number 1, the very first thing to do is :

mkdir ~/kernel-sources
cd ~
git clone https://github.com/jakeday/linux-surface.git
cd linux-surface

Then , run

chmod a+x setup.sh && sudo sh setup.sh 

Here, when setup.sh ask you about libwacom, kindly reject his offer. And, skip the last two steps ( setting your clock and download kernel)

Then, we are ready to clone Fedora Linux Kernel, (replace && with ; in fish)

cd ~/kernel-sources &&
git clone  git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git &&
cd fedora &&
git checkout f30

The first configuration step is to edit the Makefile and set EXTRAVERSION to something like -sp4 or -surface. The value of EXTRAVERSION will be appended to the end of your kernel name. Having something easily recognizable will be helpful later in this process.

$ gedit Makefile

Next, copy the config file from your system to the kernel source directory. This will ensure you’re building with options that are most relevant to the way the Fedora team builds the packaged kernels.

$ cp /boot/config-`uname -r` .config

In the Fedora Repository (which means that stay in fedora folder), we are going to apply patches:

for i in ~/linux-surface/patches/5.0/*; do patch -p1 < $i; done

(fish version)

for i in ~/linux-surface/patches/5.0/*                           
        patch -p1 < $i
    end

Then we can build our configs, by issuing:

make oldconfig

It is going to ask a lot of questions, I always answer m when m is available, else I answer y. Never say no to Linux Kernel.

5. Kernel Compilation and Installation

This is going to the step, where you wanna plugin your computer, close all other programs. It will take about half an hour, make sure that your computer does not doze off during this time. (move your cursor a bit, type press some random keys)

make -j `getconf _NPROCESSORS_ONLN` bzImage && make -j `getconf _NPROCESSORS_ONLN` modules

(fish version)

make -j (getconf _NPROCESSORS_ONLN) bzImage ; make -j (getconf _NPROCESSORS_ONLN) modules

Wait for about half an hour, once it is done, install by doing:

sudo make -j `getconf _NPROCESSORS_ONLN` modules_install && sudo make -j `getconf _NPROCESSORS_ONLN` install

(fish version)

sudo make -j (getconf _NPROCESSORS_ONLN) modules_install; sudo make -j (getconf _NPROCESSORS_ONLN) install

6. Sign yo kernel

Warning: the following step only work for Fedora 30

Navigate to your MOK private key folder, and run:

Note: [KERNEL-VERSION] right now is 5.0.9 , but that obviously changes

if you did not set your extra version, then it will just be 5.0.9+

sudo sbsign --key MOK.priv --cert MOK.pem /boot/vmlinuz-[KERNEL-VERSION]-[EXTRAVERSION] --output /boot/vmlinuz-[KERNEL-VERSION]-[EXTRAVERSION]signed

e.g. I did not set [EXTRAVERSION] , so my kernel file is : (and please write down the whole path somewhere)

/boot/vmlinuz-5.0.9+

Now, find the boot entry for your kernel:

sudo grubby --info=ALL

You should see the kernel that was just compiled, mine look like this:

index=1
kernel="/boot/boot/vmlinuz-5.0.9+"
args="ro resume=UUID=a4d58548-ae9b-4bc8-8ba2-e9d6067b8d46 rhgb quiet rd.driver.blacklist=nouveau"
root="UUID=2cde08bc-8d82-4af9-9a16-f0990ab10a68"
initrd="/boot/boot/initramfs-5.0.9+.img"
title="Fedora (5.0.9+) 30 (Surface Edition)"
id="ca2853ab6d1b4441bad49f4a6742bf65-5.0.9+"

Remember the id, now let’s take that id, and go to

sudo su # sudo fish, if you use fish
cd /boot/loader/entries

You should see a conf file with aforementioned id, let’s edit it!

gedit admin:///boot/loader/entries/[id].conf

The file should look somewhat like this:

title Fedora (5.0.9+) 30 (Surface Edition)
version 5.0.9+
linux /boot/vmlinuz-5.0.9+
initrd /boot/initramfs-5.0.9+.img
options $kernelopts
id fedora-20190502010556-5.0.9+
grub_users $grub_users
grub_arg --unrestricted
grub_class kernel-

You want to change the line that starts with linux, with your signed kernel , so in my case , I change it to:

linux /boot/vmlinuz-5.0.9+signed

And change the title for something fancier, like Linux Skynet Edition or Microsoft Linux … whatever fancies you.

Yes, no more grub-XYZ commands here, this is the one file you need to change, and that is the one file that will stick forever.

Now, you reboot, you should be seeing a Fedora, with touch support, working hibernation, battery indication etc.

If everything works after reboot, set your kernel to default entry:

sudo grubby --set-default /boot/vmlinuz-5.0.9+signed 

P.S. Will update my journey with Nvidia as I go along.