Build Linux Kernel 4.2.0 for Surface Pro 3

Ubuntu got updated to 15.10 and along came an updated kernel
My previous post will not work with the provided patches so I had to apply the code changes by hand and then roll out my own patch.

Assumptions

  • You have followed the instructions on this post replace with version 15.10
  • Installed Ubuntu or Ubuntu Gnome 15.10
  • Will be using an Ubuntu machine to perform the following steps. I recommend a faster machine than the surface but if you must the surface will be enough
  • You are doing all this in your home directory. It simplifies not having to set permissions.

Prerequisites

  • Before getting started run these commands. These are necessary for the build process
    sudo apt-get install kernel-wedge
    sudo apt-get install gawk
    sudo apt-get install git
  • Make sure you have plenty of disk space I think after the build the project ballooned to 11.5 GB. The actual kernel packages are a few MB’s in size.
  • Prepare to wait. Depending on your machine this will take about an hour (i7, 16GB ram, SSD) to a few hours (Surface Pro 3)

Getting the projects

Lets get started by creating a folder for our source files and patches and navigating to it
mkdir ~/source && cd ~/source

Get the kernel. This will create a folder called ubuntu-vivid
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-wily.git

Get the patch. Create a folder called surface-pro-3-linux-kernel-4.2.0-34.40 and get the patch from here
https://raw.githubusercontent.com/CarlosRoque/surface-pro-3-linux-kernel-4.2.0-34.40/master/0001-patched-camera-and-surface-pro3-buttons.patch

so right now you should have the following structure

  • ~/source/
    • ubuntu-wily/
    • surface-pro-3-linux-kernel-4.2.0-34.40/

Adding the patch

Now is when the fun starts. Navigate to the ubuntu-wily folder
cd ubuntu-wily

Apply the patch

patch -p1 --ignore-whitespace -i ../surface-pro-3-linux-kernel-4.2.0-34.40/0001-patched-camera-and-surface-pro3-buttons.patch

Incrementing the version

edit ubuntu-wily/debian.master/changelog and increment the version number by 1
nano debian.master/changelog

example: 4.2.0-34.39 -> 4.2.0-34.40
mine was 4.2.0-34.39 yours might be the different

Build the kernel

Prepare for the build
fakeroot debian/rules clean

Build the new kernel
DEB_BUILD_OPTIONS=parallel=4 AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules binary-generic

You will be prompted about adding a new driver (the ones for the buttons) type yes
Now sit, relax and wait. This part takes a while!
If you run into build errors you will have to google it because I am not an expert on kernel building. I could barely troubleshoot my own problems ๐Ÿ™‚

If your build was successful, there will be 5 .deb files in the ~/source folder you can do the next to double check
cd ..
ls

Installing the kernel

Copy the .deb files

Using a flash drive, network drive etc copy all the .dev files to a folder in your surface home directory.
I recommend saving them under ~/kernel

In the terminal navigate to the new kernel folder
cd ~/kernel

Install the kernel

sudo dpkg -i linux-headers* linux-image*

Update the Grub

sudo grub-install

This is a quote from the author of the article I am referencing

I have found that sometimes after touching grub, the first boot may take a few minutes. DO NOT STOP IT, let the system boot. Afterwards, should be fast again

Recover from grub prompt or UEFI loop

If you have this problem refer to the original article here and read the instructions at the bottom of the page

Final thoughts

For those not interested in rolling out your own kernel you can just clone this repo
git clone git@github.com:CarlosRoque/surface-pro-3-linux-kernel-4.2.0-34.40.git
and follow the steps in Adding the patch

These are the same final thoughts from my previous post

I really enjoyed creating my own kernel and seeing how great it worked in my surface.

Windows is my primary OS on the surface but now I feel confident that I can do some real work in ubuntu and not worry about killing the battery or not being able to video chat or not being able to adjust the volume.
I am very glad that sleep works now… at least it seems to work ๐Ÿ™‚

One thing I hate is that when the SP3 wakes up the touchscreen stops working. To make it work again you can just log out and log back in, no need to restart.
I am glad to inform that the touch screen works all the time!

I have to say that Ubuntu Gnome looks absolutely stunning in the SP3. Way better than regular ubuntu or even windows 8.

The touch screen has some gestures so explore.

One last thing. The other day I lost the sleep ability in windows, to fix this I had to reinstall windows. I chose to wipe the drive and start fresh. This doesn’t touch your Ubuntu partition. This fixed my sleep problem but removed Grub. A nice surprise was that you can boot from window into Ubuntu the same way you would boot to a usb stick, by swiping from the right settings>change pc settings>Update and recovery>recovery>advanced>restart

The next blue screen will give you the option to boot from a usb device clicking that will show Ubuntu
since I use windows primarily, this is perfect for me. If you want grub back. Open the command prompt in windows with administrator rights and run this command bcdedit /set {bootmgr} path \EFI\ubuntu\shimx64.efi
to restore to the windows boot loader run this command bcdedit /set {bootmgr} path \EFI\Microsoft\Boot\bootmgfw.efi

  1. A coworker stored production assets in Dropbox. Chaos ensued.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.