Introduction
In this first part of the multi-part tutorial I will be walking you through some of the issues you might face while installing ubuntu 22.04 on Lenovo Thinkbook 16g2 and ways to solve common issues. The tutorials are heavily focused on issues around installing technical/simulation software and its intended audience is an advanced beginner using Ubuntu/Linux for doing scientific/technical work in linux. This also is part of my effort to document for myself the issues and solutions to installation woes and the tricks to solve it. I will provide useful references and links that i found spending hours searching for solutions to problems. Hopefully even if your laptop/desktop does not match my particular laptop specifications you will still be able to get some pointers to solving these common problems which to my experience is not quite properly documented.
My laptop has an AMD 5800H, 8 core APU processor along with Nvidia RTX 3060 GPU. Installing Ubuntu is fairly straight forward and there are several step-by-step tutorials1 that you can use if you are unfamiliar with the install process.
Motivation
So I recently came to own a Thinkbook 16p G2 ACH2 laptop which was a great upgrade over my older dell Inspiron 15 gaming laptop3. I needed to run some open source codes such as ElmerFEM4 which were developed in Linux. I had always wondered how Linux will fare for my technical workflow but I never got the opportunity to tinker and try, mainly because most of the technical software need software licences which you cant get when doing just hobby projects. So I decided it will be a good experiment to try linux for work and evaluating for myself if its fit for purpose for use for work as opposed to my normal use case which is for hobby coding projects. Which meant I also got to evaluate other commercial software which I normally run on windows to see how it performs in linux. So this includes the Ansys Suite and Matlab.
So, with that in mind I Downloaded the Ubuntu 22.04 LTS ISO, fired up Rufus5 to burn the ISO to a usb stick and off I went. I had originally estimated that it will probably take me 3-4 days to get everything sorted, but it took me about 2.5 weeks to get everything in a workable state. By this i mean that actually the installation of ubuntu was fairly quick and pain free but getting the scientific/technical softwares to run properly took a lot of time to figure out the right way to make it work.
AMD APU drivers
Since my Laptop has an AMD processor with integrated GPU it is wise to install the APU drivers first and then install the GPU drivers. This is because if the Nvidia driver detects another GPU it will have options to dynamically switch which GPU to use, something call a prime profile.
However it’s quite confusing to figure out which .deb file to download and install as per the AMD gpu help page. Searching for drivers on the AMD GPU drivers web-site leads to no joy since I could not find the processor in the list. So, instead I navigated to the AMD driver Repository and navigated to the particular version of Ubuntu that I had jammy Jellyfish. So, interestingly at the time of my install and indeed the publication of the post here, there was some issue in the latest version of AMD drivers and the driver file version that shows up is amdgpu-install_5.4.50400-1_all.deb. However, I found out while searching on this issue that AMD has the wrong version of driver in the latest folder. Haha, go figure. So instead we have to go to the main folder in the AMD repo and select the highest version number of driver available which at the time of publication was 22.20.4 released on 10-Nov-2022. Other versions will appear as they are made so do double check the version number you are getting because the driver under latest folder does not seem to have the right version number currently. To install use the following commands as a guide. Also do read this document from AMD on the linux installation process.
1
2
3
4
5
6
7
8
9
10
11
12
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get -y install build-essential
sudo apt-get -y install dkms
cd ~Downloads/
wget https://repo.radeon.com/amdgpu-install/22.20.5/ubuntu/jammy/amdgpu-install_22.20.50205-1_all.deb
sudo dpkg -i amdgpu-install_22.20.50205-1_all.deb
sudo amdgpu-install --usecase=graphics,opencl --vulkan=amdvlk,pro
To check if the install has gone swimmingly, check the install using the following commands.
1
2
3
4
5
6
7
8
9
10
11
12
$ glxinfo | grep -iE 'vendor:|device:|version:'
Vendor: AMD Radeon Software
Device: Mesa DRI Radeon RX 570 (0x166)
Version: 21.1.5
$ modinfo amdgpu
filename: /lib/modules/5.15.0-56-generic/updates/dkms/amdgpu.ko
version: 5.16.9.22.20
license: GPL and additional rights
description: AMD GPU
author: AMD linux driver team
If you have discrete graphics card from AMD use a similar process but use the amdgpu-pro installer and perhaps an instruction page from Dell can help you.
Nvidia Drivers
Off-the-shelf Ubuntu detects the GPU but installs only the Nvidia Nouveau driver6. This is ok if you are just using the laptop for productivity work but if you are interested in machine learning or GPU based compute then installing the correct proprietary Nvidia Driver is a must. Fortunately Nvidia provides a step-by-step tutorial on how to install. What I found about the instructions are that they are too detailed and give too many options that can easily confuse a reader who is trying to quickly install the drivers. So, I have listed the steps I did so that you can use that as a guide. Please use the actual instructions on the Nvidia page as they get updated regularly, and use my instructions only to navigate through the install process.
What I found was the easiest way to install the Nvidia drivers on Ubuntu is to follow the package manager installation guide within the overall install guide. There are other options to install the drivers namely using the runfile method but I found this to be easier and hassle-free.
The first thing to do is to double check that you have nvidia GPU installed and the system pre-requisites are met and you know the distribution and release number of your linux kernel.
1
2
3
lspci | grep -i nvidia
uname -m && cat /etc/*release
You can then follow the rest of the steps in the nvidia ubuntu installation using the package manager guidelines as shown below. Change the distro and arch to reflect the particulars of your system config found using the above steps. After that we use the apt command to install the cuda package (which installs the nvidia drivers as well) and the gds package.
1
2
3
4
5
6
7
8
9
sudo apt-key del 7fa2af80
export distro=ubuntu2204
export arch=x86_64
wget https://developer.download.nvidia.com/compute/cuda/repos/$distro/$arch/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get install cuda
sudo apt-get install nvidia-gds
if you are using python to do machine learning and accessing the cuda toolbox follow the steps in this link to pip install the necessary packages.
Once done we have to make sure the cuda installed location is available on path by following the post installation steps.
1
2
# add to .bashrc
export PATH=/usr/local/cuda-12.0/bin${PATH:+:${PATH}}
Reboot your system and see if the desktop launches. Check you nvidia driver install by running the following command and observing a similar response as seen below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ nvidia-smi
Tue Jan 10 01:04:39 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.60.13 Driver Version: 525.60.13 CUDA Version: 12.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... On | 00000000:01:00.0 Off | N/A |
| N/A 43C P8 9W / N/A | 6MiB / 6144MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 3089 G /usr/lib/xorg/Xorg 4MiB |
+-----------------------------------------------------------------------------+
If you have problems after install and you want to revert to the original nouveau drivers using the following commands to purge the system of the proprietary nvidia drivers.
1
2
3
4
sudo apt-get --purge remove "*cuda*" "*cublas*" "*cufft*" "*cufile*" "*curand*" "*cusolver*" "*cusparse*" "*gds-tools*" "*npp*" "*nvjpeg*" "nsight*" "*nvvm*"
sudo apt-get --purge remove "*nvidia*" "libxnvctrl*"
sudo apt-get autoremove
sudo apt autoremove
Nvidia Brightness Bug - Attempt 1
After installation of the nvidia drivers everything worked well except for the brightness control using the keyboard function key. The display was frozen to max. brightness78910. Initially I was very disappointed as the screen was burning my retinas so I hit stack-overflow and came up with a dirty hacky way to reduced back-light running the command line. Note that if you have lcd or equivalent screens the reducing the back-light intensity reduces the brightness using the backlight brightness below using the echo to set the brightness number. If however you have oled screens you have the change the brightness by changing the contrast using the xrandr command below. To use the xrandr command you have to first determine the current screen you are using. For my laptop it was using the eDP for the laptop screen.
1
2
3
4
5
6
7
8
9
10
11
12
13
# for LCD etc
echo 40 | sudo tee /sys/class/backlight/amdgpu_bl0/brightness
# find out actual brightness setting
cat /sys/class/backlight/amdgpu_bl0/actual_brightness
# find out max brightness supported by the display
cat /sys/class/backlight/amdgpu_bl0/max_brightness
# for OLEDs
xrandr --current --verbose
xrandr --output eDP --brightness 0.5
Nvidia Brightness Bug - Attempt 2
Using the instruction originally the changes proposed to grub did not work for me. So I did a bit of hit-and-trial to get the final configuration when re-enabled the back-light control on my laptop.
1
2
3
4
5
6
7
8
sudo vim /etc/default/grub
# edit the following line in grub file and save using <esc>:wq to write the modified file
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amdgpu.backlight=0 nvidia.NVreg_RegistryDwords=EnableBrightnessControl=1 acpi_backlight=video"
sudo update-grub
sudo reboot
After reboot check again whether the brightness control is working either through the keyboard shortcut or through the ubuntu display settings.
Check Nvidia Install
Ok, so now you are happy that the computer isn’t doing something funny, we should cross-check that the nvidia driver has actually been successfully installed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# after reboot install mesa-utils to run glxgears program
sudo apt install mesa-utils
# check which gpu in control
$ prime-select --help
Usage: /usr/bin/prime-select nvidia|intel|on-demand|query
$ prime-select query
on-demand
# test graphics performance by running a simple opengl gears program
glxgears -info
sudo apt-get install clinfo
nvidia-smi
glxinfo | grep "OpenGL renderer"
glxinfo | grep -iE 'vendor:|device:|version:'
lspci | grep -i nvidia
lsmod | grep nvidia
sudo lshw -c video
lspci -nnk | egrep -i --color 'vga|3d|2d' -A3 | grep 'in use'
Check GPU Switching
As the system has 2 GPUs one on the Ryzen 7 APU and the other the discrete Nvidia graphics card, we need to check that we can select or rather force-select which GPU to use. Use the following lines to select and then check if the driver has taken control of the display. Its to be noted that in the prime-select option, to select the Ryzen APU as the GPU you actually have to use prime-select intel and not prime-select amd. The authors of prime-select i guess couldn’t be bothered to change the vendor name to AMD. Regardless, choosing intel means choosing the cpu integrated GPU for graphics rendering and prime-select nvidia selects the discrete GPU.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# test by switching gpu to amd
sudo prime-select intel
sudo reboot
# check to see the AMD graphics in charge
glxinfo |grep vendor
# change to Nvidia and check again.
sudo prime-select nvidia
sudo reboot
# check to see the Nvidia graphics in charge
glxinfo |grep vendor
Other Unsorted References
- https://docs.nvidia.com/deploy/cuda-compatibility/index.html
- https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ubuntu
- https://www.omgubuntu.co.uk/2022/06/fix-apt-key-deprecation-error-on-ubuntu
- https://askubuntu.com/questions/1406420/cant-change-brightness-on-version-22-04
- https://askubuntu.com/questions/23238/how-can-i-find-what-video-driver-is-in-use-on-my-system
- https://www.reddit.com/r/Ubuntu/comments/ttwm5y/install_specific_cuda_version_112_ubuntu_24044_lts/
- https://gist.github.com/Mahedi-61/2a2f1579d4271717d421065168ce6a73
- https://linuxconfig.org/how-to-check-cuda-version-on-ubuntu-20-04-focal-fossa-linux
- https://askubuntu.com/questions/1417418/unmet-dependencies-ubuntu-22-04-amdgpu-hip-support
- https://community.amd.com/t5/drivers-software/cannot-run-amdgpu-install-on-ubuntu-22-04-1/td-p/561053
- https://askubuntu.com/questions/1417418/unmet-dependencies-ubuntu-22-04-amdgpu-hip-support
- https://repo.radeon.com/amdgpu/
- https://wiki.gentoo.org/wiki/AMDGPU#Hardware_detection
- https://wiki.archlinux.org/title/PRIME
- https://askubuntu.com/questions/40779/how-do-i-install-a-deb-file-via-the-command-line
- https://linuxhint.com/ubuntu_dpkg_installation/
- https://linuxconfig.org/amd-radeon-ubuntu-20-04-driver-installation
- https://www.amd.com/en/support/kb/faq/amdgpu-installation
- https://github.com/nvidia/cuda-samples
- https://forum.manjaro.org/t/brightness-control-and-165hz-monitor-not-working-on-lenovo-legion-5-pro/61314
- https://gist.github.com/wangruohui/df039f0dc434d6486f5d4d098aa52d07
- https://installati.one/install-dkms-ubuntu-22-04/
- https://askubuntu.com/questions/1329928/legion-5-pro-brightness-control-doesnt-work-on-ubuntu-20-04-with-nvidia-driver
- https://github.com/systemd/systemd/issues/24223
- https://gitlab.freedesktop.org/drm/amd/-/issues/1671
- https://patchwork.kernel.org/project/platform-driver-x86/patch/20220316012516.2233984-1-ddadap@nvidia.com/
- https://unix.stackexchange.com/questions/691614/changing-brightness-only-works-after-system-resumes-from-sleep
- https://www.linuxcapable.com/how-to-install-linux-mainline-kernel-on-ubuntu-22-04-lts/
- https://www.addictivetips.com/ubuntu-linux-tips/downgrade-ubuntu-kernel/
- https://forums.developer.nvidia.com/t/brightness-not-working-after-upgrading-to-ubuntu-22-04/224227
- https://www.amd.com/en/support/kb/release-notes/rn-amdgpu-unified-linux-20-20
- https://amdgpu-install.readthedocs.io/en/latest/install-installing.html
https://askubuntu.com/questions/1124253/missing-firmware-for-amdgpu
- https://www.amd.com/en/support/kb/release-notes/rn-amdgpu-unified-linux-22-40
- https://community.amd.com/t5/drivers-software/ubuntu-20-04-4-driver-21-50-installation-fails/m-p/513502#M153242
- https://repo.radeon.com/amdgpu-install/22.20.5/ubuntu/focal/