Current State of Surface-Series Devices
Yes! You can install Linux on the Surface devices and even in the latest surface book 2 with the NVIDIA 1050/1060! This guide will go step by step on how you can install Ubuntu 16.04 with LUKS (encrypted) alongside Windows 10! 🙂
Of course although most of the things work, some features are still under development. The procedure is pretty simple, even if you choose to encrypt the hard disk!
The showcase!
Here is Ubuntu 16.04 running on the new Surface Book 2. Since I use it as a portable workstation, the Surface is running the Yolo classifier (CUDA, cudnn) in ROS – all in a docker container – while playing a 1440p video on youtube! 🙂
Yolo(CUDA)&ROS in docker + 1440p Youtube
Make space for Ubuntu – shrink disk
Go to Disk Manager and right-click on the disk and choose Shrink
Windows 10 Disk Manager
If you don’t have much space, you’ll have to follow these instructions to use some of the swap space.
Prepare Ubuntu Live USB
- To create a Live USB in Windows, follow these instructions.
- For any linux environment just run:
sudo dd bs=4M if=ubuntu-16.04.3-desktop-amd64.iso of=/dev/sdxxx conv=fdatasync
(Optional): Disable Secure Boot and Bitlocker
Well, although you should be fine with the Secure Boot enabled, it saves a lot of headaches if you disable it! Trust me! 🙂
- Here is how to disable Secure Boot. Once here perform also Step 4! Change boot-order to boot from USB.
- Here is how to disable Bitlocker.
Change boot-order to boot from USB
- Make sure the Surface Pro device is turned off.
- Attach a bootable USB storage device.
- Hold the volume-down button.
- Press and release the power button.
- When the Surface logo appears, release the volume-down button.
- Go to “Boot Configuration” and move the USB to the top of the list.
- Reboot
Surface UEFI Configuration Screen
Install Ubuntu on LUKS (using LVM)
Choose “Try Ubuntu”
Just boot into Live Ubuntu.
Create two new partitions
Start “gparted” and create two new partitions:
- The “boot” partition, 1GB and formatted as ext3. In this example: /dev/nvme0n1p5
- The LVM partition, which will host the rest, unformatted. In this example: /dev/nvme0n1p6
Create the LUKS container
Now we are going to encrypt the partition /dev/nvme0n1p6 . Run the following
sudo cryptsetup luksFormat /dev/nvme0n1p6 sudo cryptsetup luksOpen /dev/nvme0n1p6 CryptDisk
Create the LVM physical volume
We are going to a create volume group and three logical volumes. These will serve as root, home and swap. The space you allocate for each logical volume is up to you. Most of the space should go to home and remember that if you want to use hibernation, swap should be at least the amount of physical RAM.
sudo pvcreate /dev/mapper/CryptDisk && \ sudo vgcreate vg /dev/mapper/CryptDisk && \ sudo lvcreate -n root -L 150g vg && \ sudo lvcreate -n home -L 289g vg && \ sudo lvcreate -n swap -L 16g vg
Create the filesystems
sudo mkfs.ext4 /dev/mapper/vg-root && \ sudo mkfs.ext4 /dev/mapper/vg-home && \ sudo mkswap /dev/mapper/vg-swap
Install Ubuntu
No need to reboot or anything, just use the icon on the Ubuntu’s desktop to start the installation.
Installation type: Something else
At this step of the installation procedure you need to select “Something else” such that we can select the appropriate logical volumes.
Map Logical Volumes
Here you need to map vg-root , vg-home and vg-swap and of course /boot. An example of vg-home:
Don’t reboot once finished!
Once the graphical installer is finished, select “continue testing” and open a terminal.
Get the UUID of the LUKS partition
We need to get the UUID of the LUKS partition – /dev/nvme0n1p6 – which are gonna use a lot later. Thus, open a new tab in the terminal and run:
sudo blkid /dev/nvme0n1p6 # which gives: # /dev/nvme0n1p6: UUID="eb7c0bb0-b0f6-4e9a-999c-26ac5bd826d8" [etc]
Chroot into newly installed Ubuntu
Before chroot we need to mount the appropriate devices to the appropriate locations in /mnt:
sudo mount /dev/mapper/vg-root /mnt && \ sudo mount /dev/mapper/vg-home /mnt/home && \ sudo mount /dev/nvme0n1p5 /mnt/boot sudo mount --bind /dev /mnt/dev && \ sudo chroot /mnt # Now inside chroot mount -t proc proc /proc && \ mount -t sysfs sys /sys && \ mount -t devpts devpts /dev/pts
Update Initial Ramdisk
Now use the UUID (switch tab and get it) and create the following two files:
# Create /etc/crypttab echo "CryptDisk UUID=eb7c0bb0-b0f6-4e9a-999c-26ac5bd826d8 none luks,retry=1,lvm=vg" >> /etc/crypttab # Create /etc/initramfs-tools/conf.d/cryptroot echo "CRYPTROOT=target=CryptDisk,source=/dev/disk/by-uuid/eb7c0bb0-b0f6-4e9a-999c-26ac5bd826d8" >> /etc/initramfs-tools/conf.d/cryptroot
and update the initial ramdisk:
update-initramfs -k all -c
You might get some firmware warnings, but that’s OK 🙂
Update GRUB
Next we need to update the default configuration of GRUB (/etc/default/grub):
nano /etc/default/grub # Find GRUB_CMDLINE_LINUX="" and change it with: # GRUB_CMDLINE_LINUX="cryptopts=target=CryptDisk,source=/dev/disk/by-uuid/eb7c0bb0-b0f6-4e9a-999c-26ac5bd826d8,lvm=vg" # and the update grub update-grub
You might get some warnings/errors because of the USB stick (sda) but it is nothing to worry about!
Reboot!
Installation finished! Now reboot to the newly installed Ubuntu! Oh some heads up! There is a high chance that your keyboard will not work. No panic! We will fix that later! However you need to be able to unlock the drive, thus go get an external keyboard – just in case!
Install jakeday kernel
With this patched kernel all your problems (well almost all) will dissapear! Thanks jakeday!! To install the patched-kernel do:
# Let's update first everything and install prerequisites sudo apt update && sudo apt upgrade && \ sudo apt install git curl wget sed # Clone repo git clone https://github.com/jakeday/linux-surface.git ~/linux-surface # Run script - and choose yes for everything. This will install latest kernel cd ~/linux-surface && sudo sh setup.sh
If you want a different kernel version, run the same script but in the end choose “no”. Go to Releases and download the kernel version you want. You need all three .deb files (kernel, headers, libc).
Install NVIDIA Drivers
To install the (latest) nvidia drivers you need to add a new repository and then install the desired version. I am currently using nvidia version 390. I did a lot of stress testing with this version and I didn’t notice any throttling issues. I did also some CUDA (cudnn) tests and those were perfectly fine as well. Version 396 however gave me some laptop freezes so I am not recommending for the book 2.
sudo add-apt-repository ppa:graphics-drivers/ppa && sudo apt-get update sudo apt install nvidia-390 nvidia-modprobe
Custom resolution
By default – at least in my case – there is only the option: to select 4K as your resolution. For me, that was causing at least 2 issues:
- Overheating
- Some Apps were not designed for 4K like MATLAB
So, to fix this, you only need to add a custom resolution – like 1080p – via xrandr in Ubuntu.