Thanks to: https://github.com/nazar256/publications/blob/main/guides/steam-deck-hibernation.md
# create file
sudo swapoff -a # release swapfile
sudo rm /home/swapfile
sudo dd if=/dev/zero of=/home/swapfile bs=1G count=20 # overwrite swapfile with empty file of 20GiB
sudo mkswap /home/swapfile # reformat swap again
sudo chmod 600 /home/swapfile
sudo e4defrag /home/swapfile
sudo swapon /home/swapfile # activate it back# get ID
sudo filefrag -v /home/swapfile | awk '$1=="0:" {print substr($4, 1, length($4)-2)}'
# 62105600
sudo findmnt -no UUID -T /home/swapfile
# cbf1bbb0-a1eb-43eb-9801-ab9666fc9946
sudo vim /etc/default/grub
## GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet splash plymouth.ignore-serial-consoles resume=/dev/disk/by-uuid/cbf1bbb0-a1eb-43eb-9801-ab9666fc9946 resume_offset=62105600"
sudo update-grub
echo '[Sleep]
AllowSuspend=yes
AllowHibernation=yes
AllowSuspendThenHibernate=yes
HibernateDelaySec=120min
' | sudo tee /etc/systemd/sleep.conf
sudo systemctl daemon-reload sudo systemctl edit systemd-logind.service
# add:
# [Service]
# Environment=SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1echo '#!/bin/bash
PATH=/sbin:/usr/sbin:/bin:/usr/bin
is_bluetooth_ok() {
echo "Checking Bluetooth status..."
bluetoothctl discoverable on
if [ $? -ne 0 ]; then
echo "Bluetooth is misbehaving."
return 1 # Bluetooth needs fixing
else
echo "Bluetooth is working fine."
return 0 # Bluetooth is OK
fi
}
sleep 2 # make sure system woke up completely
if ! is_bluetooth_ok; then
# if bluetooth problem detected, reinitialize the driver
(echo serial0-0 > /sys/bus/serial/drivers/hci_uart_qca/unbind ; sleep 1 && echo serial0-0 > /sys/bus/serial/drivers/hci_uart_qca/bind)
fi
' | sudo tee /home/deck/.local/bin/fix-bluetooth.sh
echo '[Unit]
Description=Fix Bluetooth after resume
After=hibernate.target hybrid-sleep.target suspend-then-hibernate.target bluetooth.service
[Service]
Type=oneshot
ExecStart=/home/deck/.local/bin/fix-bluetooth.sh
[Install]
WantedBy=hibernate.target hybrid-sleep.target suspend-then-hibernate.target
' | sudo tee /etc/systemd/system/fix-bluetooth-resume.service
sudo systemctl enable fix-bluetooth-resume.service
sudo ln -s /usr/lib/systemd/system/systemd-suspend-then-hibernate.service /etc/systemd/system/systemd-suspend.service