How can I force a system shutdown with systemctl hibernate

my inxi dump is below. the system does not shutdown (cpu is alive and fan spinning) when I issue

sudo systemctl hibernate

are there any logs that would show what is going on? I think this may be a conflict between desktop managers.
Thanks everybody.

[email protected]:~$ inxi -Fxxxz
System:
  Kernel: 5.13.0-30-generic x86_64 bits: 64 compiler: N/A 
  Desktop: MATE 1.24.0 info: mate-panel wm: marco 1.24.0 dm: LightDM 1.30.0 
  Distro: Ubuntu 20.04.3 LTS (Focal Fossa) 
Machine:
  Type: Laptop System: ASUSTeK product: VivoBook 15_ASUS Laptop X540BA 
  v: 1.0 serial: <filter> 
  Mobo: ASUSTeK model: X540BA v: 1.0 serial: <filter> 
  UEFI: American Megatrends v: X540BA.303 date: 07/04/2019 
Battery:
  ID-1: BAT0 charge: 28.4 Wh condition: 28.4/33.2 Wh (86%) volts: 10.8/10.8 
  model: ASUSTeK ASUS Battery type: Li-ion serial: <filter> 
  status: Not charging cycles: 183 
CPU:
  Topology: Dual Core model: AMD A9-9425 RADEON R5 5 COMPUTE CORES 2C+3G 
  bits: 64 type: MCP arch: Excavator L2 cache: 1024 KiB 
  flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm 
  bogomips: 12377 
  Speed: 1397 MHz min/max: 1400/3100 MHz boost: enabled Core speeds (MHz): 
  1: 1397 2: 1626 
Graphics:
  Device-1: AMD Stoney [Radeon R2/R3/R4/R5 Graphics] vendor: ASUSTeK 
  driver: amdgpu v: kernel bus ID: 00:01.0 chip ID: 1002:98e4 
  Display: x11 server: X.Org 1.20.13 driver: amdgpu,ati 
  unloaded: fbdev,modesetting,vesa compositor: marco v: 1.24.0 
  resolution: 1366x768~60Hz 
  OpenGL: renderer: AMD STONEY (DRM 3.41.0 5.13.0-30-generic LLVM 12.0.0) 
  v: 4.5 Mesa 21.2.6 direct render: Yes 
Audio:
  Device-1: AMD vendor: ASUSTeK driver: snd_hda_intel v: kernel 
  bus ID: 00:01.1 chip ID: 1002:15b3 
  Device-2: AMD Family 15h Audio vendor: ASUSTeK driver: snd_hda_intel 
  v: kernel bus ID: 00:09.2 chip ID: 1022:157a 
  Sound Server: ALSA v: k5.13.0-30-generic 
Network:
  Device-1: Realtek RTL8821CE 802.11ac PCIe Wireless Network Adapter 
  vendor: AzureWave driver: rtl8821ce v: v5.5.2.1_35598.20191029 port: e000 
  bus ID: 01:00.0 chip ID: 10ec:c821 
  IF: wlp1s0 state: up mac: <filter> 
Drives:
  Local Storage: total: 223.57 GiB used: 11.36 GiB (5.1%) 
  ID-1: /dev/sda vendor: Kingston model: SA400S37240G size: 223.57 GiB 
  speed: 6.0 Gb/s serial: <filter> rev: 62C3 temp: 24 C scheme: GPT 
Partition:
  ID-1: / size: 56.12 GiB used: 11.28 GiB (20.1%) fs: ext4 dev: /dev/sda5 
Sensors:
  System Temperatures: cpu: 40.0 C mobo: N/A gpu: amdgpu temp: 36 C 
  Fan Speeds (RPM): cpu: 1900 
Info:
  Processes: 220 Uptime: 23h 24m Memory: 7.22 GiB used: 2.71 GiB (37.5%) 
  Init: systemd v: 245 runlevel: 5 Compilers: gcc: 9.3.0 alt: 9 Shell: bash 
  v: 5.0.17 running in: mate-terminal inxi: 3.0.38 

https://www.cyberciti.biz/faq/linux-command-to-suspend-hibernate-laptop-netbook-pc/
see option 2

maybe you need the command pm-hibernate

pm-hibernate does the same thing: I get a black screen and the CPU and fan does not stop. Do you know what to look for in the logs?

How about using systemctl suspend?

This might be of some use for insight and troubleshooting:

It's also important to note that hibernation in Ubuntu is disabled because there are issues with it on some computers, so it might not work for everyone

@stephenbbb you can shutdown a system with sudo poweroff but I guess you don't want to do that. You want your system to hibernate and later wake up.

My suggestion is 1) send a message to syslog that you're going to sleep (logger "Zzzz ... going to sleep now ..."), 2) open syslog (tail -f /var/log/syslog) and look at the messages.

this is the direction I want to go. please, provide more detail. do I send the message and then try to hibernate? or you just want to check if logging works? is there a brief reference to working with the logs?

You could use WOL (wake-on-LAN). You need to enable this in the system's BIOS (in the network settings), then you send a magic packet to wake up the system. It works in a LAN env. To wake up your system from across the Globe is far more complicated. This article may help.
https://www.cyberciti.biz/tips/linux-send-wake-on-lan-wol-magic-packets.html

I can get the log from trying pm-hibernate.
are there people who can debug that? it is quite long.
sudo poweroff works and shuts down, but hibernate goes into black screen without ever shutting down.
I am ready to post the log if there are volunteers.

Muchachos,
I have some bad news to report here. The code for hibernation is not being developed/debugged any more. there was a pm-utils developer group, but the last posts in the newsgroup are from 2017. I found threads with same complaint like mine that did not get resolved. Looks like the Linux kernel can hibernate on some hardware, but not on many. So, I am unlucky with that laptop.

i use this to get hibernation to work:

#!/bin/bash

if [[ $UID != 0 ]]; then
echo "Only tested on Ubuntu MATE 21.10"
echo "Please run this script with sudo or root privileges to enable hibernate"
echo "sudo $0 $*"
exit 1
else

echo "Enable hibernate on system, calculate swap file size"

#Change this value to size the swapfile X times your ram
SWAP_FILE_FACTOR=1.3

#Compute ideal size of swap ( Mem size * 1.5 )
SWAP_FILE_SIZE=$(echo "$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') * $SWAP_FILE_FACTOR" | bc -l | awk '{print int($1)}')
echo "SWAP_FILE_SIZE will be $SWAP_FILE_SIZE bytes"
echo "Creating new swapfile, please wait, this may take a few minutes."
swapoff /swapfile
dd if=/dev/zero of=/swapfile bs="$SWAP_FILE_SIZE" count=1024 conv=notrunc
mkswap /swapfile
swapon /swapfile

# Get UUID & swap_offset

ROOT_UUID=$(findmnt -no SOURCE,UUID -T /swapfile |cut -d\  -f 2)

echo ROOT_UUID = "$ROOT_UUID"

SWAP_FILE_OFFSET=$(filefrag -v /swapfile | awk '{print $4}' | head -4 | tail -1 | cut -d'.' -f1)

echo SWAP_FILE_OFFSET = "$SWAP_FILE_OFFSET"

echo "Modify initramfs"

echo "RESUME=UUID=$ROOT_UUID resume_offset=$SWAP_FILE_OFFSET" | tee /etc/initramfs-tools/conf.d/resume

echo "Update initramfs"

update-initramfs -k all -u

echo "Update Grub config"
#TODO Test if grub was already containing the string
#if [[ grep -q "resume" ]]

GRUB_STRING="resume=UUID=$ROOT_UUID resume_offset=$SWAP_FILE_OFFSET"

sed -i '/^GRUB_CMDLINE_LINUX_DEFAULT=/ s|"\(.*\)"|"\1 '"${GRUB_STRING}"'"|' /etc/default/grub

update-grub

echo "Update MATE policy kit"

tee /etc/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla <<EOF
[Enable hibernate in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Enable hibernate in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes
EOF

echo "Setting hibernate delay after suspend at 1h in /etc/systemd/sleep.conf "

echo "HibernateDelaySec=3600" | tee -a /etc/systemd/sleep.conf


echo "setting sleep-then-hibernate on lid close in /etc/systemd/logind.conf "

echo "HandleSuspendKey=suspend-then-hibernate" | tee -a /etc/systemd/logind.conf
echo "HandleLidSwitch=suspend-then-hibernate" | tee -a /etc/systemd/logind.conf

echo "Hibernate now active, configuration complete"

fi
1 Like