1. Disable Suspend and Hibernation in Linux

To prevent your Linux system from suspending or going into hibernation, you need to disable the following systemd targets:

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

$ sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
[sudo] password for alexlai: 
○ sleep.target - Sleep
     Loaded: loaded (/usr/lib/systemd/system/sleep.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

○ suspend.target - Suspend
     Loaded: loaded (/usr/lib/systemd/system/suspend.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

○ hibernate.target - System Hibernation
     Loaded: loaded (/usr/lib/systemd/system/hibernate.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

○ hybrid-sleep.target - Hybrid Suspend+Hibernate
     Loaded: loaded (/usr/lib/systemd/system/hybrid-sleep.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)
   alexlai@hc4Gnome    sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Created symlink /etc/systemd/system/sleep.target → /dev/null.
Created symlink /etc/systemd/system/suspend.target → /dev/null.
Created symlink /etc/systemd/system/hibernate.target → /dev/null.
Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.
 
    sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
○ sleep.target
     Loaded: masked (Reason: Unit sleep.target is masked.)
     Active: inactive (dead)

○ suspend.target
     Loaded: masked (Reason: Unit suspend.target is masked.)
     Active: inactive (dead)

○ hibernate.target
     Loaded: masked (Reason: Unit hibernate.target is masked.)
     Active: inactive (dead)

○ hybrid-sleep.target
     Loaded: masked (Reason: Unit hybrid-sleep.target is masked.)
     Active: inactive (dead)
  1. Enable Suspend and Hibernation in Linux

To re-enable the suspend and hibernation modes, run the command:

$ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

  1. Open the GNOME Settings app and navigate to the "Privacy" section.
journalctl -b
  1. If all else fails, you can try disabling suspend mode and power management altogether by adding the following kernel boot parameter:
noacpi
sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash noacpi" or "acpi=off apm=off"
# my orangepi5
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet acpi=off apm=off"
sudo update-grub
git clone https://aur.archlinux.org/update-grub.git
cd update-grub
makepkg -si
$ sudo mkdir /boot/grub
[alexlai@orangepi5 update-grub]$ sudo update-grub
Generating grub configuration file ...
Found linux image: /boot/Image
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done
  1. Not Nwcessary --->To prevent the system from going into suspend state upon closing the lid, edit the /etc/systemd/logind.conf file.

$ sudo vim /etc/systemd/logind.conf

Append the following lines to the file.

[Login] 
HandleLidSwitch=ignore 
HandleLidSwitchDocked=ignore