Linux on Lenovo Yoga C740

I just bought a Lenovo Yoga C740, the one with an Intel Core i7 with 16GB RAM and 1TB SSD. I like it so far, but it needs to run Linux of course…

So this is what I want to have:

  • Dual-boot Ubuntu & Windows 10
  • Everything working (at least) as smoothly as in Windows

That didn’t go as smooth as hoped though, so this post is a work-in-progress for people who would like to achieve the same thing, and for myself in case I need to redo it later…

TL;DR: the following are working:

  • Touchpad
    • Works like a charm, including two-finger scrolling
  • Touchscreen
    • Works as a mouse in most cases (i.e. selects text instead of scrolling)
    • Does work for scrolling in Firefox
  • Tablet mode (on-screen keyboard, auto-rotate)
    • Not perfect, sometimes screen doesn’t pop up
  • WiFi
    • Works like a charm
  • Bluetooth (mouse)
    • Very laggy in combination with MX Anywhere 2S
  • USB-C (power, display)
    • Works
  • Suspend & Hibernate
    • Works, but hibernate requires disabling UEFI Secure Boot

Things still on the TODO:

  • Make Gnome 3 look more like Unity
    • e.g. remove useless empty lock screen, smaller title bars
  • Dim keyboard backlight when idle (esp when screen itself turns off)
  • Fingerprint reader
    • Driver not supported by fprintd (some kind of Synaptics device)

Please do post any improvements you have found yourself in the comments, below!

Dual-boot Ubuntu / Windows 10

First, I shrunk my C:-drive by 750GB using Windows Storage Manager to leave it at ~250GB.

Warning: the C:-drive is encrypted using BitLocker, and it’s likely that you’ll taint its security check in the process. Make sure you know where to find the BitLocker Recovery Key. Apparently, it’s automatically stored in your Microsoft account, in case you entered that during initial set up.

I created an Ubuntu Live CD (19.04, the current Ubuntu stable), and continuously pressed F12 during boot to boot into that.

That worked, but WiFi, touchpad and touchscreen didn’t work. After a bit of Googling, it appeared that many of the drivers were located in newer kernels, so I opted to go for 19.10 instead (it’s already in feature freeze, so should be fine).

With Ubuntu 19.10, most things started working out-of-the-box. Nice! Wifi, touchpad, touchscreen now all work.

I then set out to install it to my drive. I chose the following:

  • Create 1GB partition for /boot (unencrypted, ext4)
    • Seems modern Grub can also boot from a kernel inside a LUKS volume, but I didn’t know at the time, and don’t bother changing it right now.
  • One big 750GB partition for / and swap (LUKS encrypted, BTRFS)
    • Inside that partition the installer defaults to create just one big partition. I initially tried to remove that, and manually create swap and root partitions, but the installer then crashes later with a message like “cannot mount /target” or something.
    • On the next try, I marked it as one big BTRFS volume.
    • By default, Ubuntu will create BTRFS sub-volumes for /, /swapfile and /home (as I noticed after the installation).

I left UEFI Secure Boot enabled throughout the process. That didn’t go very smooth: both the on-disk installation and live-CD failed to boot afterwards. Probably something to do with enrollment of custom signing keys for third-party kernel drivers (which in the end, I didn’t appear to need so far). I did get into the MOKManager at some point and enrolled a key, but not sure that was actually the right one (given that my install failed a few times at initial attempts).

Temporarily disabling Secure Boot resolved these issues, and I could actually work with Secure Boot enabled for a while (until I wanted to have hibernation working).

Hibernation

I want hibernation to work for the occasional escape to Windows (and back), and in case I run out of battery on the road, but don’t want to shut down completely.

It appears that nowadays, swapfiles are the default, and they are just as efficient as ‘old-school’ swap partitions, due to the kernel just using the raw disk offset / size directly, bypassing any filesystem layers.

Creating a swapfile

  • Create a subvolume for your swapfile: btrfs subvolume create /swap
  • Create a swapfile (20GB in my case: 16GB to store all RAM, 4GB actual swap space):
truncate -s 0 /swap/swapfile
chattr +C /swap/swapfile
fallocate -l 20G /swap/swapfile
chmod 0600 /swap/swapfile
mkswap /swap/swapfile
swapon /swap/swapfile
btrfs property set /swap/swapfile compression ""
  • Change the existing /swap entry in /etc/fstab to:
    /swap/swapfile none swap sw 0 0
  • Remove the ubuntu-default swap: rm /swapfile (wasn’t actually used in my case somehow, otherwise, do a swapoff /swap first)

If you take a look at e.g. top, you should now see your swap being in-use.

Hibernate to swapfile

We’ll need to tell the kernel where to resume from, in this case our swapfile. It lives inside our encrypted volume, and starts at a certain offset within that. Run blkid /swap/swapfile to obtain the UUID, and filefrag -v /swap/swapfile to obtain the offset. (Note: for some people, filefrag apparently returns the wrong offset. It was already correct in my case, though.) For example:

root@yoga:/# blkid /swap/swapfile 
/swap/swapfile: UUID="bd84f05a-45e9-42af-a7a1-fbc89fdeb117" TYPE="swap"
root@yoga:/# filefrag -v /swap/swapfile 
Filesystem type is: 9123683e
File size of /swap/swapfile is 21474836480 (5242880 blocks of 4096 bytes)
 ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        0..       0:    2364672..   2364672:      1:            
   1:        1.. 5242879:    2364673..   7607551: 5242879:             last,unwritten,eof
/swap/swapfile: 1 extent found

Make note of the UUID and the first physical_offset. Then, edit /etc/default/grub, and change the GRUB_CMDLINE_LINUX_DEFAULT variable to include resume and resume_offset, like so (don’t forget the UUID=):

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=bae3e4da-c406-49f0-bb23-3bdea0e50a87 resume_offset=2364672"

Run update-grub.

Some people noted that initramfs also needs to be updated, so I created /etc/initramfs-tools/conf.d/resume to look like this:

root@yoga:/# cat /etc/initramfs-tools/conf.d/resume 
RESUME=UUID=bae3e4da-c406-49f0-bb23-3bdea0e50a87

Run update-initramfs -u to rebuild, and reboot your system.

At this stage, I needed to turn off Secure Boot, because newer kernels don’t allow booting from a hibernate image, as these aren’t signed. Otherwise, suspend to disk is disabled.

To do that, reboot and keep pressing F2 until you enter the BIOS. Disable Secure Boot in the Security menu. Press F10 to Save & Exit, then reboot back to Linux. Check that hibernate should work:

root@yoga:/# cat /sys/power/disk 
[platform] shutdown reboot suspend test_resume

Now, test whether it actually works:

root@yoga:/# echo disk > /sys/power/state

This should hibernate and turn off your PC. When turning on, it should first ask for your passphrase, then show a message that it’s resuming from a hibernated image. Hurray!

Enabling hibernate options in GNOME 3

TODO, didn’t figure this out yet. There are some extensions, but none actually work.

Touch screen (tablet mode)

To get Firefox to scroll instead of selecting text, add the following line to /etc/security/pam_env.conf, then reboot and start Firefox.

MOZ_USE_XINPUT2 DEFAULT=1

Go to https://extensions.gnome.org/ and follow their instructions to enable installing GNOME extensions. Then, enable the following extensions:

  • Right-click For Touch Screen: converts long-press to right-click for touch screens. NOTE: follow the instructions in the comments to make it work with the latest GNOME.
  • Onboard integration: adds a much better on-screen keyboard in tablet-mode

Bluetooth mouse

After connecting my Logitech Anywhere 2S, mouse movements were very laggy (a bit like working across a long-latency remote desktop).

To fix, unpair your mouse, then:

echo 6 > /sys/kernel/debug/bluetooth/hci0/conn_min_interval

Then pair again et voilà.

However, now suspend to RAM is broken, apparently due to a recent bug. I temporarily worked around it by running tail /sys/bus/usb/devices/*/power/wakeup, and then echo disabled > /sys/bus/usb/devices/1-10/power/wakeup (where 1-10 is the device ID that showed “enabled” in the previous tail command). This is not remembered across reboots, so if I get annoyed by this, I’ll fix it properly some way.

Other tweaks

Go to https://extensions.gnome.org/ and follow their instructions to enable installing GNOME extensions. Then, enable the following extensions:

  • Unite: makes your top bar look more like Unity: removes title bar on maximized windows, rearranges icons in the top bar, moves the date/time to the right. Very nice!
  • CpuFreq: adds CPU speed indicator to your panel, and a way to change the CPU profile (powersave / balance / performance)

Conclusion

I’m quite happy with the system so far, but there’s quite a bit to tweak. I’ll update this post as I make further improvements.

Please post your tips, tricks or a simple thank-you in the comments below!

26 Comments

  1. I’m sorry but where did you found Ubuntu 19.10 for Intel architecture?

    I also recently bought C740 same as yours, just with a 500 GB hard disc. Not one unix release I’ve tried so far worked. Well, they work, except WiFi and touchpad, wich makes C740 laptop with unix OS unusable for everyday work. I’ve struggled to instal WiFi drivers on it but it seems to be more of the mission impossible without ethernet connection.

    Reply
    • Sorry for the late response…

      I simply downloaded it from http://releases.ubuntu.com/19.10/ and used the standard installation instructions to ‘burn’ it to an SD card, which I then mounted using a USB-SD-reader.

      Reply
  2. Have any of these issues been resolved?

    I’d like to switch but not unless everything works. I really need it to work in tablet mode for note taking. One of the reasons I bought it.

    Reply
    • Well, as a ‘normal’ laptop it works fine now, but the tablet mode still is far from ideal.

      Though it’s trivial to just flash Ubuntu on a USB stick and boot it, if you want to try it out for yourself.

      Reply
  3. I am unable to make 19.04 release recognize the internal microphone. Were you able to make it work?

    Reply
    • As mentioned, I had to use 19.10 to make most of the other stuff work (wifi, mouse, etc.).
      But I didn’t actually have a need for the microphone yet, so don’t know whether it worked.

      Right now, I’m in the process of Arch Linux, because I really didn’t like the instability and inflexibility of the Ubuntu / GNOME system so far. So can’t test the microphone on that either right now, sorry…

      Reply
  4. Hi, were you able to get fingerprint reader working? Also, do your fn+F11/F12 (brightness) work? I made custom shortcut Ctrl+F11/F12 with xbacklight, but after using xbacklight GUI glitches. If somebody is reading this and looking for distro that works (almost perfectly) out of the box, you should try Pop OS!.

    Reply
    • Hey, didn’t get the fingerprint reader to work no, and I highly doubt it will ever work, given the lack of activity on GitHub threads for that driver.

      I think the backlight keys worked at some point, but not 100% sure. I’m still trying Arch for now (first i3, but don’t like it for a widescreen, e.g. no option to limit maximum window size, now running Cinnamon). Didn’t get to configure the laptop brightness, yet, but according to Arch wiki should be trivial.

      Pop!_OS looks interesting indeed, thanks for the tip! If Arch doesn’t work out in the end, I’ll try it 🙂

      Reply
  5. Linux 5.5 supports Sound Open Firmware which is needed to get many audio chipsets running since Skylake, including the Realtek AC285 in the Yoga C740 [1]. This is also needed to get the digital microphones to work.

    In Arch Linux, first, install Linux 5.5 (i.e. linux-mainline in the AUR), then install sof-firmware, then reboot. If you happen to have low volume on your speakers even if you set it to 100%, install alsa-utils, start alsamixer, select the correct sound card and raise the master volume (which does not seem to be the same as in PulseAudio). In alsamixer, you’ve got both microphones. DMIC0 is the 48kHz one and DMIC1 is the 16kHz. In VLC they identify as hw0,6 and hw0,7 respectively, and work flawlessly. The sof driver does complain about protocol issues with the sof firmware, but at least until now, that has not been an issue.

    Fingerprint reader still does not work but I read somewhere [2] that Lenovo and Synaptics would be working on a Linux driver. Let’s see.

    [1] https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1856392/comments/2
    [2] https://forums.lenovo.com/t5/Other-Linux-Discussions/Linux-on-T495/m-p/4474320/highlight/true#M13440

    Reply
  6. I have the same Yoga c740. Just got it yesterday. When I booted Ubuntu 19.10 (5.3 Kernel) off of the USB it had no problem finding the wifi during the live boot. I did a full install with the 3rd party download option checked. However when I booted off the hard drive after the install, the wifi won’t work. I have a USB C hub with an eth adapter on it and that works w/out a problem. I’m really not sure what to do with the WiFi problem. The wifi isn’t showing up in the settings either. I’ve tried everything that I could find on Google.

    Reply
  7. Hi Martin et al.,

    I just installed the freshly released Ubuntu 20.04 LTS on my C740, along with all currently available updates.

    Working: Wifi, sound (speaker and microphone), touchpad, touchscreen, webcam.
    Hotkeys for volume, mute, all working except for brightness (can set via menu though).
    Not working: fingerprint (not detected).
    Untested: suspend

    Reply
    • I can confirm this. I would like to add that the sound from the speakers has become a lot louder than it previously was on 19.10. It seems they got the other speakers working.

      Reply
      • Curious if other folks are experiencing odd fan behaviour when screen turns off?

        Fan seems reasonable otherwise:
        – loud whine and lots of warm air when CPU is working hard (make -j8)
        – fan is silent when machine is idle

        But after 5 minutes idle, screen turns off, and then the fan cycles on/off at low speed every 5 to 15 seconds. Happens regardless if running on battery or AC.

        I worked around it by turning off the screen blanking (“none” instead of 5 mins).

        Reply
        • Haven’t experienced that, no. Fan seems to work as expected here.

          Perhaps log in through ssh while it’s happening to see what causes the load?

          Reply
          • Tried that, but there no visible processes or kernel threads with any sort of CPU load. In fact the load average reports as 0.0/0.0/0.0. I left “top” running and “journalctrl -f” and neither gave any clue.

        • Yes, I have experienced the same thing and I have also turned off the screen blanking because of it. I believe that this has happened in Windows too, though.
          What I find much more annoying is that this fan thing also frequently happens when I shut the lid and the system is supposed to go to sleep. It apparently does go to sleep as I can see the power light on the right flashing slowly but very often the fan will go really nuts and continue to spin for hours even though the system is in sleep mode. Once I put the laptop into my bag and when I took it out later the fan was still spinning wildly and the battery was almost dead.

          Reply
  8. Hi Martin!
    Thank you for your writeup on your experience setting up Ubuntu on your Yoga C740.
    Did you have any issues getting your hotkeys to work?
    Specifically, I’m not seeing any scancode output from the display brightness adjustment keys (F11/F12). Wondering if you had a fix for this, or it was a non-issue.

    Reply
  9. I installed Linux Mint 20 using itsfoss.com How to install dual boot (beginners guide). I got Mint 20 installed. All hardware works. The pen does not want to calibrate. The onscreen keyboard icon works but when I swing the screen to tablet configuration, I can’t get the icon to bring up the screen.
    The bigger issue: now the system will not boot into Windows 10, says the files are damaged. I think I have to start over; re-load Windows from the recovery disk, then re-install Mint 20 and see if it works on a second try. I may have made a mistake but I think not, fearing I will be doing the same thing a 2nd time and expecting different results.
    Ideas?

    Reply
  10. I too am trying to make the fingerprint reader work in Ubuntu 20.04 LTS without success. It’s that or change my login to 1234. Jk! Any news from anyone on this yet?
    Rod in Canada

    Reply

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.