如何在Ubuntu 24.04 LTS上启用休眠模式?
Hey there! I totally get how frustrating it is when suspend doesn't cut it and hibernation feels out of reach—especially on a Lenovo ThinkBook. Let's walk through step-by-step fixes to get it working for you.
第一步:检查并配置足够的Swap空间
Hibernation saves your entire RAM content to swap, so you need swap space that's at least as large as your total RAM (or slightly bigger for safety). Here's how to check and adjust it:
- Run
free -hin the terminal to see your total RAM size (look at theMem: totalvalue). - Next, check your current swap with
swapon --show. If the swap size is smaller than your RAM, we'll need to resize or create a swap file:- Turn off existing swap:
sudo swapoff /swapfile - Delete the old swap file (if it exists):
sudo rm /swapfile - Create a new swap file matching your RAM size (replace
16Gwith your actual RAM size):sudo fallocate -l 16G /swapfile - Set proper permissions for security:
sudo chmod 600 /swapfile - Format the file as swap:
sudo mkswap /swapfile - Enable the new swap:
sudo swapon /swapfile - Make swap permanent by adding this line to
/etc/fstab(usesudo nano /etc/fstabto edit):/swapfile none swap sw 0 0
- Turn off existing swap:
第二步:配置Grub以支持休眠
We need to tell the kernel where to find the swap space when resuming from hibernation:
- Get your swap partition's UUID by running
blkid | grep swap. You'll see output like/dev/nvme0n1p3: UUID="abc123xyz..." TYPE="swap"—copy that UUID string. - Edit the Grub config with
sudo nano /etc/default/grub. Find the line starting withGRUB_CMDLINE_LINUX_DEFAULTand addresume=UUID=abc123xyz...(replace with your actual UUID) inside the quotes. For example:GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=abc123xyz..." - Update Grub to apply changes:
sudo update-grub
第三步:检查BIOS/UEFI设置
Lenovo laptops often have specific power settings that block hibernation. Reboot your laptop and enter BIOS (usually by pressing F2 or Fn+F2 during startup):
- Look for Secure Boot and disable it (this can interfere with hibernation on some systems).
- Find power-related options like Resume from Hibernation or Suspend to Disk and make sure they're enabled.
- Save changes and reboot into Ubuntu.
第四步:测试休眠功能
Now let's test if hibernation works:
- Run
sudo systemctl hibernatein the terminal. Your laptop should shut down completely. - Turn it back on—it should resume exactly where you left off.
If that doesn't work, try installing pm-utils (a power management tool) with sudo apt install pm-utils, then run sudo pm-hibernate to test again.
额外:让合盖触发休眠
If you want your laptop to hibernate when you close the lid:
- Edit
/etc/systemd/logind.confwithsudo nano /etc/systemd/logind.conf. - Find the line
#HandleLidSwitch=suspend, remove the#and change it toHandleLidSwitch=hibernate. - Restart the logind service to apply changes:
sudo systemctl restart systemd-logind
Hopefully these steps get hibernation working on your ThinkBook! If you hit any snags, let me know which step failed and we can troubleshoot further.
备注:内容来源于stack exchange,提问作者D'Hyena

