I upgraded my T420 because Ubuntu Mate 19.10 now supports the Nvidia Optimus drivers and includes a utility that lets me switch between Intel and Nvidia graphics cards. However, the upgrade seemed to break the power management on my laptop. When running on the battery, the laptop would suddenly lose power after only 10 minutes, even when the battery still shows ninety percent charge.
I installed Linux Advanced Power Management, TLP. TLP solved my problem. Also, for good measure, I upgraded the BIOS because, while troubleshooting this issue, I discovered is was very out of date.
In his post, I describe how to install and configure TLP and how to upgrade the BIOS on a Lenovo Thinkpad T420.
UPDATE: (March 19, 2020). After writing this post, I decided to delete my disks and re-install Ubuntu Mate. I observed that power management worked properly after re-installing Ubuntu Mate. I did not have to install TLP. If you are installing a fresh instance of Ubuntu Mate, I recommend to just upgrade the BIOS, if needed (I describe that procedure below) and skip installing TLP.
Install TLP
The Mate Power Management utility is part of the Mate desktop environment and provides basic configurations for power management. I don’t know why installing TLP solved my battery problem. I can only suggest that, if you are seeing a similar problem with your battery, try installing TLP before you spend money on a new battery.
TLP is in the Ubuntu repositories. Install TLP using the following command:
$ sudo apt update
$ sudo apt install tlp tlp-rdw
$ sudo tlp start
After restarting my PC and testing it on battery power, I found that simply installing TLP solved my problem. My battery life returned to normal.
Managing TLP
You can view and edit TLP status and settings from the command line.
The tlp-stat
command will show you the TLP configuration and the status of your battery:
$ sudo tlp-stat
You may specify a parameter to display only a specific portion of the tlp-stat
output. The most commonly used would be -c
to see the current configuration and -b
to see the battery status.
$ sudo tlp-stat --help
Usage: tlp-stat [ -b | --battery | -c | --config |
-d | --disk | -e | --pcie |
-g | --graphics | -p | --processor |
-r | --rfkill | -s | --system |
-t | --temp | -u | --usb |
-w | --warn | -v | --verbose |
-P | --pev | | --psup |
-T | --trace ]
TLP is managed by editong a configuration file: /etc/default/tlp. It is a large file with many options. All the default values work well and you probably do not need to change anything. Instead of editing it directly, I installed an optional graphical user interface that helps me to change the TLP configuration.
Optional TLP modules
The TLP utility supports some features specific to Thinkpads, such as the ability to set battery charging thresholds. These are optional and require you install additional kernel modules. Install the additional modules with the following commands:
$ sudo apt-get install acpitool tp-smapi-dkms acpi-call
$ sudo apt-get install smartmontools
TLP Graphical User Interface
The TLP GUI is a set of Python scripts that help users to change TLP configuration files easily. It protects users from setting invalid configurations.
In install TLP GUI, clone the repository to your local drive:
$ git clone https://github.com/d4nj1/TLPUI
To run TLP GUI, navigate to he TLPUI directory and run the Python program:
$ cd TLPUI
$ python3 -m tlpui
The GUI shows you most of the configuration options available for TLP.
The TLP GUI modifies the configuration file when you click the Save button.
Update BIOS
I also decided to upgrade the BIOS on my Thinkpad T420. To check the current vesion of the BIOS, run the following command:
$ sudo dmidecode | grep -A 3 "BIOS Information"
I see I have version 1.37, as shown in the output below:
BIOS Information
Vendor: LENOVO
Version: 83ET67WW (1.37 )
Release Date: 11/28/2011
According to the Lenovo support web site, the latest version is: 1.5227 Jun 2018, so my BIOS is very out of date.
To upgrade the Lenovo Thinkpad T420 BIOS while using Linux, you must download a bootable disk image containing the BIOS upgrade utility from the Lenovo Support site.
NOTE: At the time I wrote this post, the T420 was still supported by Lenovo. However, it looks like it will soon be moved to Lenovo’s unsupported product list. If you do not find the T420 downloads page when you search for T420 on the Lenovo support page, check the Lenovo End of Life product page, instead.
In my case, the file I downloaded was named 83uj33us.iso. After downloading the ISO disk image, convert it into El Torito CDROM format using the following commanda:
$ cd ~/Downloads
$ geteltorito -o bios.img 83uj33us.iso
The command creates a new, converted image named bios.img.
Booting catalog starts at sector: 20
Manufacturer of CD: NERO BURNING ROM
Image architecture: x86
Boot media type is: harddisk
El Torito image starts at sector 27 and has 75776 sector(s) of 512 Bytes
Image has been written to file "bios.img".
Insert a USB stick into the Thinkpad. Find the device name so you can write to it. Be sure to find the correct name or you risk overwiting the wrong disk!
Run the following command:
$ dmesg | tail
In the output, look for something like: Attached SCSI removable disk
[16698.230209] usbcore: registered new interface driver usb-storage
[16698.242852] usbcore: registered new interface driver uas
[16699.245775] scsi 6:0:0:0: Direct-Access Kingston DataTraveler 3.0 PQ: 0 ANSI: 6
[16699.252329] sd 6:0:0:0: Attached scsi generic sg2 type 0
[16699.255635] sd 6:0:0:0: [sdb] 30218842 512-byte logical blocks: (15.5 GB/14.4 GiB)
[16699.256610] sd 6:0:0:0: [sdb] Write Protect is off
[16699.256618] sd 6:0:0:0: [sdb] Mode Sense: 4f 00 00 00
[16699.258499] sd 6:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[16699.265314] sdb: sdb1
[16699.269369] sd 6:0:0:0: [sdb] Attached SCSI removable disk
Here we see the device sdb as recently attached as a removable disk. This is our USB key.
Assuming the USB stick is mounted, you can double-check using the df -lh
command, which will list all filesystems on your local PC. You should see that the device sdb is the same size as your USB key:
$ df -lh
Filesystem Size Used Avail Use% Mounted on
udev 3.8G 0 3.8G 0% /dev
tmpfs 785M 1.5M 783M 1% /run
/dev/sda1 110G 33G 72G 32% /
...
tmpfs 785M 64K 785M 1% /run/user/1000
/dev/sdb1 15G 8.0K 15G 1% /media/brian/xfer
Next, copy the converted disk image, bios.img to the USB stick. The following command will erase the entire stick so, again, be sure you picked the correct device. In this example, it is sdb. In your case, it may be different.
$ sudo dd if=bios.img of=/dev/sdb bs=1M
Now, boot your Thinkpad from the USB stick. Restart the computer and as soon as you see the Thinkpad logo on the screen, press the F12 key to select the boot disk. Choose the USB stick as the boot dosk.
The system should boot into the BIOS update utility. Follow the prompts and choose the Update system program option.
When the utility completes the upgrade, press the Enter key at the information prompt.
The Thinkpad will reboot again. Let it oot into your normal Linux system.
After reboot, open a terminal and run the following command to see BIOS version:
$ sudo dmidecode | grep -A 3 "BIOS Information"
You should see the BIOS has been updated to th latest version which is 1.52, in this case.
BIOS Information
Vendor: LENOVO
Version: 83ET82WW (1.52 )
Release Date: 06/04/2018
It looks like the upgrade was succesful.
Conclusion
Installing TLP solved my battery problem. I did not ned to install any optional modules or upgrade the BIOS to solve the battery issue but I did those things, anyway, and the seemed to cause no other problems.