Debian disable sleep and gnome

1. Disable All Suspend, Sleep, and Hibernate 

These commands globally block the system from entering power-saving states. 

Mask Sleep Targets: Prevents the system from reaching any sleep state by linking targets to /dev/null.

bash

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

Modify Sleep Config (Optional): Explicitly disable modes in the configuration file.

bash

echo -e "[Sleep]\nAllowSuspend=no\nAllowHibernation=no\nAllowSuspendThenHibernate=no\nAllowHybridSleep=no" | sudo tee /etc/systemd/sleep.conf.d/nosuspend.conf


Ignore Lid Actions: Prevents laptops from sleeping when the lid is closed.

Edit /etc/systemd/logind.conf and set HandleLidSwitch=ignore.

Apply with sudo systemctl restart systemd-logind.service. 

2. Disable / Re-enable GNOME (GDM3) 

For a headless server, you can stop the GUI to save resources or re-enable it for occasional maintenance. 

Action Command Description

Disable GUI (Boot) sudo systemctl set-default multi-user.target Sets the system to boot into text mode only.

Enable GUI (Boot) sudo systemctl set-default graphical.target Sets the system to boot into the GNOME login screen.

Stop GUI Now sudo systemctl isolate multi-user.target Immediately stops GNOME and switches to terminal mode.

Start GUI Now sudo systemctl isolate graphical.target Immediately starts the GNOME desktop environment.

Hard Disable sudo systemctl mask gdm3 Completely blocks GDM3 from starting, even as a dependency.

Undo Hard Disable sudo systemctl unmask gdm3 Allows GDM3 to be started again.

3. Disable GNOME Idle/Login Timers

GNOME often has its own timers that operate independently of the system-level ones. 

User Session: gsettings set org.gnome.desktop.session idle-delay 0.

Login Screen (GDM): Edit /etc/gdm3/greeter.dconf-defaults and ensure sleep-inactive-ac-timeout=0 and sleep-inactive-ac-type='nothing' are set to prevent the login screen from triggering a suspend. 

--------- Shorter version of same

1. The "Never Sleep" Commands
Run this to ensure the kernel and systemd never trigger a power-down state:
bash
# Block all sleep/hibernate states
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

# Ensure laptop lids (if applicable) don't trigger sleep
sudo sed -i 's/#HandleLidSwitch=suspend/HandleLidSwitch=ignore/' /etc/systemd/logind.conf
sudo systemctl restart systemd-logind
Use code with caution.

2. Disabling the GUI (GNOME)
This stops the overhead of the desktop environment while keeping it installed for later use:
bash
# Set system to boot into text mode (Multi-User)
sudo systemctl set-default multi-user.target

# Stop the current GNOME session immediately
sudo systemctl isolate multi-user.target

# Hard-lock GDM to prevent it from ever starting
sudo systemctl mask gdm3
Use code with caution.

3. Re-enabling the GUI (GNOME)
If you ever need to log in locally or via a physical monitor:
bash
# Unlock the service
sudo systemctl unmask gdm3

# Set system to boot into the desktop (Graphical)
sudo systemctl set-default graphical.target

# Start GNOME immediately
sudo systemctl isolate graphical.target
Use code with caution.

4. Verification Commands
Use these to confirm your server is in the correct state:
Check boot mode: systemctl get-default (should be multi-user.target)
Check sleep blocks: systemctl status sleep.target (should be masked)
Check memory usage: free -h (to see the RAM saved by killing GNOME)

Popular posts from this blog

Dearpygui resizable table

Fixing DNS Resolution problems with Linux Mint 19