I recently installed Fedora 27 on my Surface Pro 4. I ran into a few challenges along the way so I thought I’d document the steps I took in case others find it helpful.
First of all, I was able to install Fedora 27 via a USB thumb-drive on my Surface Pro 4 with no problems. My instructions assume you know how to and are able to install Fedora 27. If you have problems installing Fedora 27 from USB (I’ve read that some people have) take a look at this. If you don’t know how to install Fedora, I recommend you visit the Fedora site where you’ll find lots of resources to get you started. This is not a “how to install linux” guide.
I’m working on a Surface Pro 4, Core i5, 8gb RAM, 256gb HD. If you have a different configuration or different Surface product, your mileage may vary, but hopefully this proves to be at least a helpful resource.
This guide is for configuring Fedora 27. It may be a useful resource for other distributions or other versions of Fedora. If you’re using Ubuntu, try following Jake Day’s instructions in their entirety.
Most of the features which are important to me seemed to work more or less right away after installing and updating Fedora 27. This included the type cover, speakers, and wi-fi (although wi-fi had a few issues dropping connections or service crashes in the my first few sessions.) There were just a few things I needed which would require installing some new firmware, building a new kernel, and making some configuration changes.
- Stable wi-fi — it would be a deal breaker if I couldn’t get this to work
- Hibernation — not having a way to conveniently save working state would be a deal breaker to me. (The Surface uses “Connected Standby” for Suspend/Sleep which is not supported so hibernation is the best you can get.)
- Touch-screen —This wasn’t critical to me, but it is a nice-to-have feature. I’m used to occasionally interacting with the Surface via touch.
I was able to get all these features working. I have not tested all of the Surface features (and won’t) but here is a list of things that I was able to get working:
- Microsoft Type Cover works great. This includes the keyboard, back-lighting, touch-pad, back light brightness keys, mute, volume up/down, home/end, pgup/pgdn keys.
- Wi-fi appears stable. After a few days of use, I have had no issues.
- Bluetooth — I have successfully connected a Microsoft Arc Mouse and it works great. (The touch-pad also works great — the mouse is just because I like it)
- The Volume Up/Down buttons on the side of the Surface as well as the Power button.
- Speakers — the sounds I expect come out of them.
- Battery levels — I’m a bit skeptical of the accuracy but it appears to at least show some sort of level.
- Touch-screen — It works reasonably well. I mostly just scroll web pages and open or close applications and that’s good enough for me.
- Surface Pen — I tried the pen and it seemed to work to some degree. It isn’t important to me so I haven’t tested it beyond basic poking around.
- Hibernation — this took the most figuring out but has worked flawlessly once I got it configured correctly.
With those features, the Surface Pro 4 seems to be a great little Linux device that I’m looking forward to using. Read on if you’re interested in configuring your Surface Pro 4 to run Fedora 27!
Running Fedora 27 on your Surface Pro 4
We’ll follow these three steps to get Fedora 27 working on the Surface Pro 4:
- Configure Surface & Install Fedora 27
- Build & Install the Kernel from Source
- Configure Hibernation
- Configure the Surface & Install Fedora 27
- Disable Secure Boot — you’ll need to do this to boot from the unsigned kernel you’ll build. You can find instructions to disable secure boot here.
- Install Fedora 27. You can download the ISO here and if you need installation instructions, you can find them here.
- Update Fedora 27 — After installing Fedora 27, login and update to the latest packages. You’ll need to be connected to a network to do this and a large number of packages will be downloaded and installed.
$ sudo dnf update
$ sudo shutdown -r now
At this point, you should be running an updated copy of Fedora 27. Most things should be working reasonably well. However, as I mentioned before, a few important features were not working for me — installing some firmware, building a custom kernel, and making some configurations resolved them.
2. Build & Install the Kernel from Source
Before we can build and install the kernel, we need to clone some source code from git repositories. You don’t have to know much about git but if you get stuck you may find this intro helpful.
Clone Kernel Source Repositories
First, let’s create a directory to clone the kernel sources into. This will keep things organized:
$ cd ~
$ mkdir kernel-sources
$ cd kernel-sources
Clone linux-surface source
$ git clone https://github.com/jakeday/linux-surface.git
$ cd linux-surface
(HEAD at the time I wrote this: 07df5e3a3)
Next, I recommend you follow steps 1–4, 6 & 7 of Jake Day’s Instructions. These instructions make some system configurations and install some important firmware. You can skip Step 5 as that is Ubuntu specific and you’ll need to build your own kernel so steps 8 and 9 aren’t relevant.
Clone Linux kernel source
Jake Day suggests cloning linux-stable from kernel.org but I ran into some issues building both the 4.16 and 4.15 branches so I used the Fedora repository instead and that seemed to work well. This repository will have all of the Fedora 27 patches applied.
$ cd ~/kernel-sources
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git
$ cd fedora
Because Fedora 27 is built on the 4.15 kernel, I opted to use 4.15 sources. Feel free to try 4.16 and just replace f27 with f28 and 4.15 with 4.16 in commands below.
$ git checkout f27
(HEAD at the time I wrote this was: 74f90c5d93c8)
Before we can build the kernel from source, you’ll need to install some dependencies. These may not all be strictly required but will make sure you have what you need to build the kernel in various ways.
$ sudo dnf groupinstall "Development Tools"
$ sudo dnf groupinstall "C Development Tools and Libraries"
$ sudo dnf install elfutils-devel
$ sudo dnf install openssl-devel
$ sudo dnf install perl-devel perl-generators
$ sudo dnf install pesign
$ sudo dnf install ncurses-devel
Configure the kernel build
Jake Day has instructions for compiling the kernel from source which were really helpful to reference. I made enough small changes to his process that I’ve written my own steps out below which I think should work well for Fedora users.
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.
$ $EDITOR 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
We need to update the kernel build config to incorporate new changes in the latest kernel code. You can just hit return to accept the defaults for all the NEW config options.
$ make oldconfig
Before we start building the kernel, you’ll need to make one small edit to the .config file to enable IPTS support. The IPTS module enables touch-screen support. Edit the .config file and make sure to set CONFIG_INTEL_IPTS=m
$ $EDITOR .config
Patch the Kernel
Apply the patches from linux-surface.
$ for i in ../linux-surface/patches/4.15/*; do patch -p1 < $i; done
(NOTE: The Linux kernel source code and linux-surface code will undoubtedly change before many of you read this. This may introduce changes that break this guide. If you run into problems applying the patches above, it may be a result of some of those changes. I mentioned the specific HEAD versions above that I used for both Linux kernel code (from the Fedora repo) as well as linux-surface code— this worked for at least those specific versions. You may want to try them if you get stuck. If you don’t understand git commits take a look at this.)
Build & Install the new kernel
At this point you’ve installed and updated Fedora 27, cloned the source code, made some system configuration changes, installed some firmware, installed the build dependencies, configured the kernel build, and applied some patches! You’re now ready to build the kernel. This will take a while! I didn’t time this but I think bzImage took at least 20 minutes and bzImage took around 45-ish?
$ make -j `getconf _NPROCESSORS_ONLN` bzImage
$ make -j `getconf _NPROCESSORS_ONLN` modules
Install the newly built kernel:
$ sudo make -j `getconf _NPROCESSORS_ONLN` modules_install
$ sudo make -j `getconf _NPROCESSORS_ONLN` install
You should have a new kernel built and installed and ready to use!
Reboot and select your new kernel from the boot loader. You’ll be able to tell which one it is because of the EXTRAVERSION string you added to the Makefile which was appended to the end (something like -sp4 or -surface, etc).
After it boots up, make sure that everything still works as you expect and that touch-screen and pen support are now working and that you’re able to connect and stay connected to wi-fi networks. If there are other features you hope work — other than hibernation — now would be a good time to try them.
3. Configure Hibernation
We’re finally ready to configure hibernation! Fedora doesn’t enable hibernation by default and as mentioned before, suspend is not supported on the Surface. If you followed the the Jake Day instructions (especially step 6), you are ready to use the hibernate scripts but you’ll need to configure Grub to actually restore hibernated images. These next steps assume you have a default Fedora 27 swap configuration. (If you’ve configured your partitions and specifically your swap partition differently, the partition name may be different for you.) If you’re not sure what your swap partition is, run the following command:
$ sudo blkid |grep swap
By default, it should be: /dev/mapper/fedora-swap
Edit your /etc/grub2-efi configuration file. Search for the menuentry that corresponds to your new kernel. An easy way to find it is to search for the string you entered from the EXTRAVERSION in the Makefile (see, I told you it would be helpful!) Find the line in the menuentry section that starts with linuxefi. Append resume=/dev/mapper/fedora-swap to the end of the line:
$ sudo $EDITOR /etc/grub2-efi.cfg
For me, this ends up looking like this. The bold text is what I appended:
linuxefi /vmlinuz-4.15.11sp4+ root=/dev/mapper/fedora-root ro rd.lvm.lv=fedora/root rd.lvm.lv=fedora/swap rhgb quiet resume=/dev/mapper/fedora-swap
Rebuild your grub2 configuration:
$ sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
Reboot your machine and boot back into your new kernel.
At this point, hibernation should be configured. Hibernation looks a lot like a shutdown. Upon initiating hibernate, your screen will immediately go black. However, it will take about another 15-30 seconds for your machine to actually go into a fully hibernated state. If you have back-lighting enabled on your type cover, you will notice that it remains lit after the screen goes black but shortly thereafter, the keyboard back-lighting should go dark at which point your surface should be hibernating.
There are numerous ways to hibernate your computer. Give them all a try:
- Press the power button
- Close the type cover
- sudo systemctl hibernate
(I mostly use the ‘close the type cover’ or ‘power button options’)
To restore your system from hibernation, press the power button to turn on your Surface. You should see the bootloader menu just like when you’re rebooting— select your custom built kernel and Linux will start to boot. If you’ve successfully configured everything, your system should restore back into the state it was in just before you initiated the hibernation — after you enter the password of the user whose session you hibernated, of course!
Hope that helped!
Bonus Feature: If you’re dual-booting Windows (or another OS), you can hibernate your Fedora configuration, boot into Windows, and when you’re ready to go back to your Fedora Linux installation, it will restore your hibernated session. Try it!
One More Thing…
You’ll probably want to keep your Fedora system up to date but you may not want to install new kernel packages that are pushed out. After all, you just spent all this time building and installing a kernel! When you’re ready to update your system you can run:
$ sudo dnf check-update
If you see a kernel package, you may want to ignore it before you update. You can do that with:
$ sudo dnf update -x kernel
You can read more helpful dnf tips here.
If you do install a new kernel — on purpose or by mistake — your old kernel should not have been deleted (unless you deleted it) and you should still be able to boot to it by selecting it in the bootloader menu.