Disable sleep on linux

How to prevent computer from automatically sleeping and/or hibernating?

My question: how to disable the automatic sleep and/or hibernate (and/or anything similar) in Ubuntu 12.04. I don’t care if it’s still possible to sleep/suspend/hibernate/whatever by pushing buttons or running some command or reciting led zeppelin lyrics backwards. I just want my laptop to be ready for work in the morning.

*The laptop is a Dell Latitude something or other. I don’t want to get too specific because I’ve seen a lot of similar questions get closed for being too specific. I think my question is generic enough to stand — it’s a question about the latest, stable version of Ubuntu.

Nothing I’ve tried so far has prevented Ubuntu from sleeping at night, and when it does sleep, nothing I have tried can reliably get it to wake back up. I’ve seen a few posts that say buggy video drivers can cause problems with waking.

Last night, on a hunch, I tried switching to console (ctrl+alt+1) before leaving work, just to see what would happen. This morning when I woke up the computer, it instantly woke up back to the console. I switched over to Gnome (ctrl+alt+7) and although the screen looked frozen, I typed my password, pressed enter, and made some coffee. When I got back a few minutes later, my desktop was ready, just like I left it last night.

I’m going to keep trying this to see if this is a reliable solution.

No dice. Switching to the console after logging out does nothing for me. still have to reboot my computer each morning. It’s driving me nuts. I can’t believe how erratic suspend is on Ubuntu. Or the fact that it can’t simply be disabled.

Источник

How to Disable Suspend and Hibernation Modes In Linux

In this article, we take you through how to disable suspend and hibernation modes on a Linux system. But before we do that, let’s briefly have an overview of these two modes.

When you suspend your Linux system, you basically activate or put it into sleep mode. The screen goes off, even though the computer remains very much powered on. Also, all of your documents and applications remain open.

Suspending your system helps save power when you are not using your system. Getting back to using your system requires a simple mouse-click or a tap on any keyboard button. Sometimes, you may be required to press the power button.

There are 3 suspend modes in Linux:

  • Suspend to RAM (Normal Suspend): This is the mode that most laptops automatically enter incase of inactivity over a certain duration or upon closing the lid when the PC is running on the battery. In this mode, power is reserved for the RAM and is cut from most components.
  • Suspend to Disk (Hibernate): In this mode, the machine state is saved into swap space & the system is completely powered off. However, upon turning it on, everything is restored and you pick up from where you left.
  • Suspend to both (Hybrid suspend): Here, the machine state is saved into swap, but the system does not go off. Instead, the PC is suspended to RAM. The battery is not used and you can safely resume the system from the disk and get ahead with your work. This method is much slower than suspending to RAM.
Читайте также:  Добавление репозитория oracle linux

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

You get the output shown below:

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.

Disable Suspend and Hibernation in Ubuntu

Then reboot the system and log in again.

Verify if the changes have been effected using the command:

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

Verify Suspend and Hibernation in Ubuntu

From the output, we can see that all four states have been disabled.

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

Here’s the output that you will get.

Removed /etc/systemd/system/sleep.target. Removed /etc/systemd/system/suspend.target. Removed /etc/systemd/system/hibernate.target. Removed /etc/systemd/system/hybrid-sleep.target.

Enable Suspend and Hibernation in Ubuntu

To verify this, run the command;

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

Verify Suspend and Hibernation in Ubuntu

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

Save and exit the file. Be sure to reboot in order for the changes to take effect.

This wraps our article on how to disable Suspend and hibernation modes on your Linux system. It’s our hope that you found this guide beneficial. Your feedback is most welcome.

This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I’m not running commands on the terminal, I’m taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Linux IP Address

Upgrading to Debian 12 from Debian 11

Install Google Chrome 46 in Debian Systems

RHEL vs Debian

Debian vs Ubuntu

Host Website Locally in Linux

16 thoughts on “How to Disable Suspend and Hibernation Modes In Linux”

You can also edit /etc/systemd/sleep.conf or do it the drop-in way and put this in /etc/systemd/sleep.conf.d directory. You have to create the file first.

$ sudo touch /etc/systemd/sleep.conf.d/sleep.conf
[Sleep] AllowSuspend=no AllowHibernation=no AllowSuspendThenHibernate=no AllowHybridSleep=no #SuspendMode= #SuspendState=mem standby freeze #HibernateMode=platform shutdown #HibernateState=disk #HybridSleepMode=suspend platform shutdown #HybridSleepState=disk #HibernateDelaySec= #SuspendEstimationSec=60min

I’m using Ubuntu 18.04. I tried as you said, it’s gone, but after a few minutes the pause symbol is showing again on top, whenever I get this symbol my keyboard is not working, and when I try to click with the mouse in the browser it is downloading html file. I’ll be very thankful for any solutions to get rid of this. Reply

Читайте также:  Расширение установочного файла линукс

Hello Good Android Team, I tried to enable suspend and hibernation mode in Linux, but every time I copy and paste the above, command I run into this error message “Command not found” am really worried. Any help would really be of help. Reply

Does this command also disable sleep and hibernate for a USB HDD? If not, how would you go about doing that? Reply

Hi James, thanks for the info but how can I remove being suspended in my own hiber account cause the hiberofficials suspended me i did not even do something wrong please help me James thanks. Reply

Hi James, Great tutorial, thanks! The other day I installed a music server on an old notebook running Ubuntu Server 20.04.1. Whenever I closed the lid it went to sleep (or hibernation?). The command sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target , and editing the file edit the /etc/systemd/logind.conf file, solves the issue indeed. However, with a side effect: the process /lib/systemd/systemd-logind starts eating up most of the CPU power, going up to 80% and remaining there. When I open the lid it slowly decreases; I close the lid, and up goes the CPU load again:

Last login: Fri Jan 1 14:12:51 2021 from 192.168.1.110 [email protected]:~$ ps -aux | grep systemd-logind root 634 77.0 0.2 17208 8232 ? Rs 14:41 1:20 /lib/systemd/systemd-logind mark 1113 0.0 0.0 9032 740 pts/0 S+ 14:43 0:00 grep --color=auto systemd-logind [email protected]:~$ ps -aux | grep systemd-logind root 634 78.8 0.2 17208 8232 ? Rs 14:41 2:16 /lib/systemd/systemd-logind mark 1117 0.0 0.0 9032 736 pts/0 S+ 14:44 0:00 grep --color=auto systemd-logind

Checking /var/log/auth.log shows it starts being filled up with this when I close the lid, and until opening again:

Jan 1 13:38:53 X201 systemd-logind[2542]: Lid closed. Jan 1 13:38:53 X201 systemd-logind[2542]: Suspending. Jan 1 13:38:53 X201 systemd-logind[2542]: Unit suspend.target is masked, refusing operation. Jan 1 13:38:53 X201 systemd-logind[2542]: Failed to execute suspend operation: Permission denied Jan 1 13:38:53 X201 systemd-logind[2542]: Suspending. Jan 1 13:38:53 X201 systemd-logind[2542]: Unit suspend.target is masked, refusing operation. Jan 1 13:38:53 X201 systemd-logind[2542]: Failed to execute suspend operation: Permission denied Jan 1 13:38:53 X201 systemd-logind[2542]: Suspending. Jan 1 13:38:53 X201 systemd-logind[2542]: Unit suspend.target is masked, refusing operation. Jan 1 13:38:53 X201 systemd-logind[2542]: Failed to execute suspend operation: Permission denied : : :
[email protected]:~$ tail /var/log/auth.log Jan 1 14:45:43 X201 systemd-logind[634]: Suspending. Jan 1 14:45:43 X201 systemd-logind[634]: Unit suspend.target is masked, refusing operation. Jan 1 14:45:43 X201 systemd-logind[634]: Failed to execute suspend operation: Permission denied Jan 1 14:45:43 X201 systemd-logind[634]: Suspending. Jan 1 14:45:43 X201 systemd-logind[634]: Unit suspend.target is masked, refusing operation. Jan 1 14:45:43 X201 systemd-logind[634]: Failed to execute suspend operation: Permission denied Jan 1 14:45:43 X201 systemd-logind[634]: Suspending. Jan 1 14:45:43 X201 systemd-logind[634]: Unit suspend.target is masked, refusing operation. Jan 1 14:45:43 X201 systemd-logind[634]: Failed to execute suspend operation: Permission denied Jan 1 14:45:43 X201 systemd-logind[634]: Lid opened. [email protected]:~$

With some more searching I found this page:
https://serverfault.com/questions/1045949/how-to-disable-suspend-on-ubuntu-20-04-systemd-via-cli In my case unfortunately updating /etc/systemd/logind.conf & reboot does not help. Continuing my googling … Thanks & best regards
Mark Reply

LidSwitchIgnoreInhibited=no

The title should be “How to disable suspend and hibernate in SYSTEMD”. To claim that this is universal across all of Linux is just plain wrong. The steps outlined in the article do not work on many distros. Ubuntu is NOT the be-all and end-all of Linux. Reply

Читайте также:  Tracker extract linux что это

Hi Dragonmouth, I totally agree with you that Systemd, while frequently used with Linux, is not the same thing as Linux. It’s too bad the misleading headline pulled you in and annoyed you. It would be better if the title was: “How to disable suspend and hibernate using Systemd on Linux”. On the other hand, I have to admit that the tips worked for me as I haven’t used a non-systemd box in a long time. I miss those times. Even all these years since it took over, the systemd still feels like a foreign invader, forcing me to speak its stilted dialect and learn new, tortuous ways of doing things I used to be able to do simply. I still haven’t figured out how to do some things: like if a particular process is hanging at boot time, being able to hit ^C to just cancel it and go on booting was super handy. Is there even a systemd equivalent? I don’t think so. There was a time when it wasn’t completely ludicrous for someone to say, “This is a UNIX system. I know this!” Now, UNIX is just vestigial trappings, a quisling prince kept as a figurehead for appearances, but powerless. Systemd is the true power. But don’t blame the “everything is Ubuntu” mentality. Systemd is a much wider scourge having taken over Debian and its derivatives. Ultimately, Systemd was created by RedHat, so I blame them, even if it is
Linus Torvald’s distribution of choice. Reply

“Linux is Ubuntu and Ubuntu is Linux” viewpoint predates systemd by a few years. However, because of being almost universally pushed, *buntus have done their part in the spread of the systemd pandemic. Systemd is an init that aspires to be a distro. Luckily there still are some very good distros that have not been infected. Reply

By the way, if you don’t use systemd, it looks like you can just write to certain files in /sys/power/. I don’t know how to make that setting stick, though. Reply

Источник

Оцените статью
Adblock
detector