How To: Disable Sleep And Hibernation on Ubuntu Server

For some reason, Ubuntu Server comes with ‘power management’ enabled. This is an article that tells you how to disable sleep and hibernation in Ubuntu Server. It’ll work just fine for non-server installs, but this is aimed specifically at the Ubuntu Server release.

I recently was working on my own router. For this, I used Ubuntu Server as the base operating system. For some reason, it was shutting itself down after periods of inactivity. This isn’t acceptable behavior for a device that’s meant to be running all the time.

I checked in my logs and I found entries like this one:

Apr 3 12:18:27 server systemd[1]: Reached target Sleep.

That was entirely unacceptable. I do not know why power management was installed, nor do I know why it was active by default. I merely know that it was and that I couldn’t have that behavior with a server, a device meant to be always powered on.

So, I did what anyone would do in my shoes. I disabled sleep and hibernation entirely. It’s quick and easy – and effective! I’ll show you how!

Disable Sleep/Hiberation:

Like most articles, you’re gonna need a terminal. If it’s actually a server, you’re likely already able to connect with SSH. So, add the step of connecting to the server if you’re doing this remotely. If not, just proceed.

Once you have your terminal open, you’re to kill everything that has to do with suspend, sleep, or hybrid-sleep. It’s actually pretty easy. Start by opening said terminal, by pressing CTRL + ALT + T and then enter the following commands:

First, you mask ‘sleep.target‘:

Then mask ‘suspend.target‘:

And mask ‘hibernate.target‘:

Finally, mask ‘hybrid-sleep.target‘:

Later, should you change your mind, you can unmask them and that’ll enable them again. Just change ‘mask’ to ‘unmask’ and run the commands again. See? Pretty easy!

If you want, you can verify the efficacy. Simply use the following:

(You can change ‘sleep.target’ to one of the above services and check them individually.) 

Closure:

That’s it! I told you that it’d be pretty easy. It’s not only easy, it’s easy to undo this should you change your mind. Again, I do not know why power management is enabled by default in a server release. Nobody asked me! So, that’s how you disable sleep and hibernation with Ubuntu. (It’ll surely work with other distros.)

Thanks for reading! If you want to help, you can donate, write an article, vote for articles you like, share this article on social media, buy cheap hosting, register to help, etc… Nobody ever reads the last paragraph anyhow. Still, you can help if you want!

Update 01.27.2020 Per comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.