Category: Blog

Ubuntu on the Legion 5 Pro (2021)

Heads up: I’m not a gamer. A combination of specs, pricing, availability and urgency led me to purchase this laptop for productivity reasons. My run-through may not cover all aspects needed for gaming.

If the RGB show on the keyboard annoys you, use Fn+SPACE to select a less annoying mode for now. Also: Fn+L to toggle the Legion logo, Fn+Q to toggle thermal profile. These shortcuts work on both Windows and Linux.


As my work depends on this laptop, I did purchase the additional on-site support. And as I expect support to want to deal with Windows only, I left Windows installed.

Even if you decide to remove Windows, I recommend you set it up first and use it to apply any BIOS or firmware updates prior to installing Ubuntu. (As it turns out, my laptop already shipped with the latest BIOS version.)

The factory Windows install uses about 60GB, so I shrunk the Windows-SSD down to 75GB. You can use the Disk Management tool to do so.


Shutdown the laptop and restart it while pressing F2. This gets you into the BIOS. I made the following changes:

  • Graphic Device: Dynamic Graphics (you will need to use nomodeset in GRUB if you don’t do this)
  • Boot > PXE Boot to LAN: Disabled

That’s it. I left Secure Boot enabled. Ubuntu and Ubuntu based Linux distributions have no problem with it.

Install Ubuntu

How to install Ubuntu has been well documented, I won’t repeat it here. Recommended:

My notes when following that how-to:

  • Start the laptop while pressing F2 so you can boot from the Ubuntu USB stick.
  • Optional: I chose to manually partition the drive and create an encrypted BTRFS volume voor my root.

Just works

A lot of things actually just work. Nice!

  • Wi-Fi
  • Bluetooth
  • Internal Audio (incl. volume control)
  • Ethernet
  • Clickpad
  • Keyboard
  • USB-C PD power

Brightness Control

You’ll notice that while the brightness function keys appear to work they do not actually change the brightness. You can fix this by editing /etc/default/grub and adding the amdgpu.backlight parameter:


Run update-grub, reboot, and things will work. (This assumes you use Ubuntu 21.04 or later. Earlier version will need an updated kernel from the mainline ppa.)


This one is personal, but I think things are too small at the default 100% scaling, and too large at 200%. Using Fractional Scaling at 150% suits me much better. Gnome warns of a performance impact, but this seem negligible for my uses.

Power Saving

I’m running TLP with the default settings for now. Will update this section if/when I make adjustments. With current settings I get about 5 and a half hours of batter time.

sudo apt install tlp smartmontools

My adjustments to tlp.conf so far:

Battery Conservation

Battery conservation mode prevents your laptop battery from charging fully and keeps it around 60% instead. This should aid the longevitity of the battery.

To enable battery conservation:

echo 1 > "/sys/devices/pci0000:00/0000:00:14.3/PNP0C09:00/VPC2004:00/conservation_mode"

To disable battery conservation:

echo 0 > "/sys/devices/pci0000:00/0000:00:14.3/PNP0C09:00/VPC2004:00/conservation_mode"

For convenience I created a systemd unit called /etc/systemd/system/battery-conservation-mode.service with the following content:

Description=Battery Conservation Mode

ExecStart=/usr/bin/bash -c 'echo 1 > "/sys/devices/pci0000:00/0000:00:14.3/PNP0C09:00/VPC2004:00/conservation_mode"'
ExecStop=/usr/bin/bash -c 'echo 0 > "/sys/devices/pci0000:00/0000:00:14.3/PNP0C09:00/VPC2004:00/conservation_mode"'


Which you can then start, stop, or have executed automatically upon start-up:

systemctl daemon-reload
systemctl start battery-conservation-mode
systemctl stop battery-conservation-mode
systemctl enable battery-conservation-mode

Function Lock

Maybe you never use the F1, F2,.. keys and just want them to function them as permanent media keys (for volume control, etc.) instead. You can do this by enabling the Fn Lock:

echo 1 > "/sys/devices/pci0000:00/0000:00:14.3/PNP0C09:00/VPC2004:00/fn_lock"

Just like the battery conservation mode, you can put this in a systemd unit to enable it automatically at start-up.

File System

Ubuntu comes with periodic SSD trimming out of the box. No need to enable that yourself. If you use encrypted partitions like I do, Ubuntu also enabled discard in crypttab automatically.

Some changes I made to fstab:

  • Added the ssd option for my btrfs file systems.
  • Added the noatime option to both btrfs and ext4 file systems.

Snap apps with Wayland and Zsh

There’s are two longstanding issues using snap apps in Ubuntu. Two issues that still exist in Ubuntu 20.04 beta.

  • Snap apps don’t show up in Gnome’s Activities view when using Wayland instead of Xorg.
  • Snap apps cannot be started from the command-line when using zsh instead of bash.

Looking into this, I ran into numerous discussions on both topics. Most notably:


The zsh work-around mentioned in these and other discussions works very well. Just add the following line to your .zshrc. (Adding it to /etc/zsh/zshrc should work as well.)

emulate sh -c 'source /etc/profile.d/'

When using bash the scripts in /etc/profile.d/ are sourced automatically. Zsh does not bother with them, unless we instruct it to.


Unfortunately the work-arounds for Wayland did not work for me. They failed to convince Wayland and Gnome to look in snap’s applications folder.

The following line links snap’s applications folder into the Ubuntu’s main applications folder.

sudo ln -s /var/lib/snapd/desktop/applications/ /usr/share/applications/snap

Unlike all the other work-arounds out there, there’s no need to logout and log back in. This works instantly.

Cleaner Theme

Changed to a nice clean WordPress theme that uses Tailwind CSS. Based on the wp-tailwind starter theme by freeshifter. (Thank you!)

Will share my changes on Github shortly.

Pretty Code

Tried a number of WordPress plugins while looking for a syntax highlighter that supports the regular Gutenberg code block and does not come with a ton of unnecessary bloat.

I think I found it. You’re looking at Code Syntax Block by¬†Marcus Kazmierczak. What do you think?

 * Retrieves the cron lock.
 * Returns the uncached `doing_cron` transient.
 * @ignore
 * @since 3.3.0
 * @global wpdb $wpdb WordPress database abstraction object.
 * @return string|false Value of the `doing_cron` transient, 0|false otherwise.
function _get_cron_lock() {
        global $wpdb;

        $value = 0;
        if ( wp_using_ext_object_cache() ) {
                 * Skip local cache and force re-fetch of doing_cron transient
                 * in case another process updated the cache.
                $value = wp_cache_get( 'doing_cron', 'transient', true );
        } else {
                $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) );
                if ( is_object( $row ) ) {
                        $value = $row->option_value;

        return $value;

First Post!

First post on the new domain. I’m expecting many more to follow.