Ubuntu will by default go sleep when your laptop battery is running into critical low. For those who want to apply anther action, here’s how to do the trick in Ubuntu with the default GNOME desktop.
NOTE: This tutorial is tested and works in Ubuntu 22.04 with default GNOME. It may also works in current other Ubuntu releases.
1. First, open terminal either by searching from ‘Activities’ overview or by pressing Ctrl+Alt+T on keyboard.
2. When terminal opens, run command to edit the upower config file:
sudo gedit /etc/UPower/UPower.conf
For Ubuntu 22.10+, replace
gedit in command with
gnome-text-editor, or use
nano instead for other Linux.
3. Once file opens, scroll down and find out the line CriticalPowerAction=HybridSleep (the last line in my case). As the description says, you can change the value into:
- Hibernate – need to enable hibernate function first.
(Optional) 4. For choice, you may also edit the value of following lines:
- PercentageLow=20 – battery low when percentage 20% left.
- PercentageCritical=5 – battery critical when percentage 5% left.
- PercentageAction=2 – perform the action you set in step 3 when battery 2% left.
In case you want to use time remaining instead, find out and change UsePercentageForPolicy=false. So, following values will be in active:
- TimeLow=1200 – battery low when 1200 seconds left.
- TimeCritical=300 – battery critical when 300 seconds left.
- TimeAction=120 – perform action (step 3) when 120 seconds left.
5. Once you saved the file (for
nano text editor, press Ctrl+X, type y and hit Enter), run the command to restart upower service to apply changes:
sudo systemctl restart upower.service
That’s all. Enjoy!