Sunday, March 19, 2017

Slackware with Kaby Lake Hardware

Last week, i just bought a new laptop equipped with the latest Intel processor i5 7200U 7th Gen aka Kaby Lake. It's quite a nice laptop. I added 256 GB SSD and 16 GB of RAM (total 20 GB) on top of 4 GB RAM, 1 TB of HDD and GeForce 940 MX. This is my first experience with SSD and also UEFI-based system.

First thing i did was checking the BIOS setting whether it has secure boot feature or not. Turns out it has and it was enabled by default. Since i didn't know how to disable it at that moment, i installed Windows 10 with secure boot turned on (my first mistake). Turns out, you can easily disable secure boot by setting administrator's password. Secure boot can be disabled and you can turn off the administrator's password once again if you don't need it. Most Linux will not work with Secure Boot enabled. Make sure to disable Secure Boot before installing any Linux OS.

During Windows installation, i pick the default UEFI layout (my second mistake). Although UEFI offers many advantages over legacy, it requires more efforts to set up. However, Windows 8 and newer will gain more benefit by using UEFI. Nevertheless, i continue the installation and set up my Windows system normally. No problems at this point. I set up all applications i need, migrate all data, emails, etc into the new laptop and in no time, everything is settled.

Next thing was to install Slackware onto this laptop. I choose to use USB-based installation. I copied the Slackware-Current image into a flash drive and boot with it. Installation worked just fine. It detect Window's EFI partition automatically and so on and installation finished in less than 15 minutes. Troubles comes when i rebooted. No ELILO or any other boot loader showed up and it directly goes into Windows 10. I tried to reinstall Slackware Current again but i got the same problem. I was able to login to my Slackware using my flash drive, but that's not the ideal condition. I need a way to get the boot loader working normally.

Finally i decided to try grub2. After mounting Slackware's root partition and chrooting, i set up grub2 (grub-mkconfig -o /boot/grub/grub.cfg), install it to correct partition (grub-install /dev/sdb), rebooted but problem persists. It still directly boot into Windows 10. Next I tried to use EasyUEFI in Windows but it only worked when i added grub and set it to boot once. After i rebooted, the Windows Boot Loader took place and Grub no longer first choice and back to square one. I thought it was Linux's fault, but turns out it's a known issue with Windows 10. Easy solution is to run this command on Window's command prompt (administrator mode): bcdedit /set {bootmgr} path \EFI\grub\grubx64.efi. After running this command, grub2 showed up and i can select which operating system i wanted to boot. First problem solved. Just in case, i made a backup using EasyUEFI.

Slackware booted nicely and very fast due to SSD. Second problem arose when i tried to run startx on my user after installing NVidia driver. It showed an error message "No screens found". I tried to run X -configure to generate xorg.conf, but still no luck. Turns out my laptop has an Optimus-based technology, meaning it has a Hybrid GPU (Intel/NVidia).

My previous laptop also has a hybrid GPU and i can easily disabled my discrete GPU (nvidia) to preserve battery life. I did the same on my new laptop. I also tried to install Bumlebee project (i forked the project and update it as well to the latest version), but the problem persists.

On Saturday, i spent few hours on my laptop to find the solutions. While i may be out of X, but i was still able to connect to my house's access point using wpa_supplicant and command line interface (that's one advantage of knowing some command lines). My first thought was about Kaby Lake support that wasn't available on Linux Kernel 4.4.x. So i decided to compile my own Linux Kernel based on Slackware's config. I grab 4.10.3's source and build it using Slackware's huge config. It took a while to answer all the new options for building new kernel. Once it's done, it started to compile. While compiling, i Googled (using links) and found a discussion about creating a new configuration for both Intel and Nvidia device. I added the configuration. 

Here's the xorg.conf configuration i used on my laptop:

Section "ServerLayout"
    Identifier "layout"
    Screen 0 "intel"
    Inactive "nvidia"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1:0:0"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
    Option "AllowEmptyInitialConfiguration" "Yes"
EndSection

Section "Device"
    Identifier "intel"
    Driver "modesetting"
    BusID "PCI:0:2:0"
    Option "AccelMethod"  "sna"
EndSection

Section "Screen"
    Identifier "intel"
    Device "intel"
EndSection


I also removed all Bumblebee installation and any settings i made so it goes back to the original state. Next i edited my grub.cfg to point to the new kernel and rebooted with the new kernel. I logged in to my user account and i ran startx, voila, and now it boots into X and MATE 1.18 loaded (i built it during compiling the Linux Kernel). So the culprit was lack of support from Linux Kernel for my Intel GPU which was loaded by Xorg. Kaby Lake support was added in 4.8, but 4.10 will give you better results in terms of power management. Second problem solved.

At this moment, most of the applications i used regularly has been installed on that machine. Most of the data has also been migrated, but i still need to work on few things, mostly dealing with virtual machines. At least all of the problem has been solved for now. Slackware-Current is working nicely on my new laptop here. I might play some experiments with my NVidia in the future so that i can use this powerful GPU.

Some tips: If you have new hardware and had a problem like i did, it's better to try using the latest Linux Kernel to make sure your hardware is properly supported. I also hope that Patrick will include new kernel (along with kernel-firmware) soon in -current (at least the configs or in testing/) so that users can built their own kernel or test the new kernel with the new hardware.