Enabling a maximum battery charge amount (charge threshold) on Lenovo X1 in Ubuntu

Most of the time when using my laptop I am plugged into it’s AC charger. But, I don’t want my lithium-ion battery charged to 100% all of the time, as that is unhealthy for the battery and will lead to it prematurely losing capacity.

My Lenovo X1 Carbon allows you to set a value less than 100 in the:
field and will stop charging your battery if it goes above that amount.

So you can issue a command like the following to prevent your laptop from charging your battery above 80%:

echo "80" | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

(and if you wanted to get fancy, you could tell it to not start charging the battery until it fell below 70% with a command like the following)

echo "70" | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold

Then, you would have to unplug the laptop to discharge the battery below 80, and it would just stay there.   If you were planning on taking your laptop somewhere without a power cord, you would want to reset this to 100 and fully charge it before you left.

On the X1 carbon with Ubuntu 21.04, I got some “/sys/class/power_supply/BAT0/charge_control_end_threshold: Invalid argument” type errors when trying to set the end amount to a value lower than the current start amount (or the start amount to a value higher than the current end amount). So if you are messing with one, you should probably set the other appropriately before-hand. For example, I use the following commands, in this specific order to limit to 80 (start charging below 70):

echo "70" | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold
echo "80" | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold


And then to reset to 100 (start charging below 99 or less) I use the commands in this order:

echo "100" | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold
echo "99" | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold


Using this ordering prevents the Invalid argument errors for me.

The above commands reset the default values, and will not survive a reboot. So if you want them to always be active, you can set up a system service which will fire every time your computer reboots by creating a file in /etc/systemd/system/   called charge-threshold.service that looks like the following:

Description=Set the battery charge threshold

ExecStart=/bin/bash -c 'echo 70 | tee /sys/class/power_supply/BAT0/charge_control_start_threshold; echo 80 | tee /sys/class/power_supply/BAT0/charge_control_end_threshold'


Then enable the service with the following:

X1:/etc/systemd/system$ sudo systemctl enable charge-threshold.service
X1:/etc/systemd/system$ sudo systemctl start charge-threshold.service

Installing Ubuntu 20.04 on Lenovo X1 Carbon (6th gen) with UEFI Secure Boot

Installing Ubuntu 20.04 on a Lenovo X1 Carbon (6th gen) with UEFI Secure boot can be a relatively painless process (If you are using one of the default install options).

When the Ubuntu 20.04 install DVD ISO image detects that your computer booted using UEFI (Secure Boot) it will ask you to provide a password that you can use to install the Ubuntu signed secure boot version of the grub bootloader and authorize it to your BIOS.

After the first reboot, the X1 BIOS brings up a window where instead of booting, you need to move down one menu option and view the new certificate, and then accept/install it. At this point it will ask you to type the password you earlier provided to Ubuntu, and if you are able to do so, it will accept the Ubuntu installed grub bootloader as valid and boot with it.   [If you DON’T do this, but try and just boot immediately, it obviously won’t work, and the easiest thing to do is re-do the entire install process, although I’m sure there is some magic you can type with efi tools to give yourself another chance….]

Full Disk Encryption

Continue reading

Installing an Encrypted Partition with LVM dual boot on Ubuntu 16.04

The Ubuntu 16.04 installer has the option to install full disk encryption using LVM if you are erasing everything on the hard drive. However, if you want to dual boot (use some of the hard drive for Windows, and the rest for Linux) the automated installer won’t allow you to automagically use full disk encryption.

You can still make it work, but have to do a lot of manual work using a terminal from the Live CD environment.   Here is a log of what I had to do to get it working for me.

Continue reading

HOWTO: Full Disk encryption on Ubuntu 10.04

How to set up an entirely encrypted disk using Ubuntu 10.04 (LTS):

    Use the Alternative installer (text based) ISO image so that you have access to the LVM and Encrypted Disk options.
    Assuming you want to keep a windows partition or some other pre-existing partitions intact, you will have to manually partition things instead of using the guided partitioner, so select “manual”.

Continue reading

IBM Think pad X31 Radeon M6 – Suspend Screen Fix

My Thinkpad X31 laptop with a Radeon M6 graphics chip had a problem with ACPI Suspend/Resume. About every five resumes, the graphics card would get messed up, making the screen unusable.
The computer would suspend/resume fine otherwise, but I’d be forced to reboot just to get X working again. (Just shutting down X and re-starting it wasn’t enough.)

The easy solution is to pass a “nomodeset” option to the kernal upon boot, but to do this on different versions of Ubuntu you need to do modify files in different places.

9.04: Edit the /boot/grub/menu.lst file, and look for the defoptions= line. Add nomodeset to the end. Run sudo update-grub afterwards to save your changes.

9.10: Edit the /etc/grub.d/10_linux file to add a line such as:
or just add “nomodeset” to the end of a previous GRUB_CMDLINE_EXTRA entry. After this, run sudo update-grub.

10.04: Edit the /etc/defaults/grub file and change GRUB_CMDLINE_LINUX="" to
(You may have to run sudo update-grub again, or it may be taken care of for you)

Commentary: I find it funny that in each of the last three version’s of UBUNTU the name and location of the grub configuration file has changed…

Running Ventrilo under Wine in Ubuntu Linux

Wine will install and run the ventrilo VOIP client very well. To get this working, follow these steps:

apt-get install wine wine-dev msttcorefonts

download ventrilo-3.0.5-Windows-i386.exe

run “wincfg” to prepare things

run “wine ventrilo-3.0.5-Windows-i386.exe”
(go through the install, using all the defaults)

Now, everything works with one quirk.
Push to talk works only when the ventrilo window “has focus”
This is somewhat understandable, but annoying, in that you have
to focus the ventrilo window before you can talk.
The other option is to use voice-detection, but that takes up a bit more cpu-time, and you may accidentally broadcast something you don’t want to.

A program that listens for keypreses and directs them to the ventrilo window fixes this problem:


To compile it, you’ll need xorg headers:
sudo apt-get install xorg-dev

Moving NTFS paritions using Ubuntu (Vista, XP)

This guide gives a good step by step procedure for moving a windows partition from one drive to another:

If you get an “autochk.exe not found” error message just after windows XP boots, it probably means that you have the partition type set incorrectly. Using fdisk under linux just use the “T” option to change the partition type to NTFS (hex 0x07 or number 7 in fdisk).

Ubuntu 8.04 SSH login slow

SSH Login to my Ubuntu 8.04 machine was slow. (It would delay about 5 seconds after I issued the ssh command for the remote machine to request a password.) I believe this is because the remote machine is on my home network, and I have set up it’s hostname using host entries instead of having a true DNS name.
I edited the /etc/init.d/sshd_config file and added the single line:
UseDNS no
which fixed this problem as soon as I restarted the SSH server, with
sudo /etc/init.d/ssh restart

Ubuntu 9.04 (Jaunty Jackalope) Annoyances

I upgraded to Ubuntu 9.04 from 8.10 over the weekend.
The good:
Faster boot up. (worth the upgrade all by itself)
New notification “bubbles” that appear and then disappear again without any fuss.
OpenOffice 3.0 and other software upgrades.

The Bad:
Required tweaks to my pam_mount.conf.xml file to get my encrypted home directory to work. (Not an issue for most users.)

Bluetooth communication ports (serial over bluetooth) started giving errors because standard users no longer had permissions to use them. Adding the following code to an /etc/udev/rules.d/rfcomm.rules file allowed all users in the “dialout” group to access the /dev/rfcommXXX serial over bluetooth ports. (Ubuntu developers know about this problem and it will be fixed eventually.)

KERNEL=="rfcomm*", GROUP="dialout"

Java support for MIDI music failed until I installed timidity again with the following command:
sudo apt-get install timidity pmidi

The Annoying:
The hardware buttons on my thinkpad (brightness, volume, etc) still work, but no longer have an on screen display. I could fix this by installing the tpb (thinkPadButtons) package, but it takes up extra CPU cycles and power. I found that the packagers are actively discussing this issue and have decided to wait until they fix the issue within the default packages.

When running Pidgin (IM client), an “envelope” icon appears inside a “indicator-applet 0.1” to show that it’s running. Of course, Pidgin itself pops up another icon to show that it’s running on my gnome panel at the same time. I’ve thought about removing the indicator-applet from my panel to remove the duplicate items, but worried about what else I may miss if it’s not there to “hold all of the system indicators”. I eventually decided to go into the Pidgin preferences and select “Show System Tray Icon” only “on unread messages” which mostly fixed this annoyance, although now I need two button clicks to bring the IM window to the top instead of just one.

The ATI M6 graphics processor on my IBM X31 laptop was not automatically configured to use hardware acceleration. To use ppracer and other applications that require hardware acelleration to work well (such as the new version of lyx!) I had to edit my xorg.conf file following directions I found here.

Mythtv gotchas when upgrading from Ubuntu 7.04 (Feisty) to 7.10 (Gutsy)

I upgraded my Mythtv server from Feisty to Gutsy for no good reason (other than I like the pain).

Gotchas I ran into when trying to get MythTV working again:

1. The upgrade lost/removed the libqt3-mysql support from my computer. This resulted in the MythTV applications (frontend and backend) giving "unable to connect to database" errors. As the upgrade had also upgraded my MySQL install, I spent a good amount of time checking that the mythtv user still existed and had the proper permissions before I figured out it was a QT database library problem.
  apt-get install libqt3-mt-mysql fixed it.

2. LIRCD stopped receiving commands from my HDHomeRun receiver from SiliconDust. Turns out you have to change the LIRCD_ARGS="-d 5000" line in the /etc/lirc/hardware.conf file to LIRCD_ARGS="-H udp -d 5000".  After this, typing irw showed that LIRCD was now receiving the command codes as it was supposed to.

3. The module name for my D-Link GWL-G122 usb wifi-adaptor have changed, so I had to change entry in the /etc/modprobe.d/blacklist  file to reflect the new name(s) of: rt2x00usb and rt2500usb.