Hibernate and resume from a swap file The 2019 Stack Overflow Developer Survey Results Are InHow do I add more swap easily so that I can hibernate my laptop?Resuming Hibernate from a SwapfileHow to move hibernarnation file, separating it from swap partition/file?Does a swap partition cause hardware degradation? Swap FILE for hibernation?Ubuntu 18.04 can't resume after hibernateHow large of a swap partition is needed to hibernate?Cannot hibernate Ubuntu Budgie 17.04Without having swap partition how to hibernate using only “SWAP FILE”How do I hibernate with swap file without swapping?Hibernation to a swap file 12.04, fragfile outputHow do I add more swap easily so that I can hibernate my laptop?Lenovo S12 fails to hibernate, won't turn off and won't restore session, what to do?Change Swap Amount to Hibernate in WUBIWithout having swap partition how to hibernate using only “SWAP FILE”How do I hibernate with swap file without swapping?Enable hibernate, enlarge swapswap partition vs swap fileCannot hibernate Ubuntu Budgie 17.04Linux swap file and Hibernation partitionUnable to Hibernate: Swap header not found
Is there any way to tell whether the shot is going to hit you or not?
Can you compress metal and what would be the consequences?
Do these rules for Critical Successes and Critical Failures seem Fair?
Why was M87 targetted for the Event Horizon Telescope instead of Sagittarius A*?
Time travel alters history but people keep saying nothing's changed
Lightning Grid - Columns and Rows?
Why do we hear so much about the Trump administration deciding to impose and then remove tariffs?
How to save as into a customized destination on macOS?
FPGA - DIY Programming
Button changing it's text & action. Good or terrible?
Does the shape of a die affect the probability of a number being rolled?
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Why do UK politicians seemingly ignore opinion polls on Brexit?
How to type this arrow in math mode?
Right tool to dig six foot holes?
Falsification in Math vs Science
How to support a colleague who finds meetings extremely tiring?
Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?
What does Linus Torvalds mean when he says that Git "never ever" tracks a file?
Is "plugging out" electronic devices an American expression?
Are there any other methods to apply to solving simultaneous equations?
Can a flute soloist sit?
Origin of "cooter" meaning "vagina"
Why hard-Brexiteers don't insist on a hard border to prevent illegal immigration after Brexit?
Hibernate and resume from a swap file
The 2019 Stack Overflow Developer Survey Results Are InHow do I add more swap easily so that I can hibernate my laptop?Resuming Hibernate from a SwapfileHow to move hibernarnation file, separating it from swap partition/file?Does a swap partition cause hardware degradation? Swap FILE for hibernation?Ubuntu 18.04 can't resume after hibernateHow large of a swap partition is needed to hibernate?Cannot hibernate Ubuntu Budgie 17.04Without having swap partition how to hibernate using only “SWAP FILE”How do I hibernate with swap file without swapping?Hibernation to a swap file 12.04, fragfile outputHow do I add more swap easily so that I can hibernate my laptop?Lenovo S12 fails to hibernate, won't turn off and won't restore session, what to do?Change Swap Amount to Hibernate in WUBIWithout having swap partition how to hibernate using only “SWAP FILE”How do I hibernate with swap file without swapping?Enable hibernate, enlarge swapswap partition vs swap fileCannot hibernate Ubuntu Budgie 17.04Linux swap file and Hibernation partitionUnable to Hibernate: Swap header not found
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have configured a new Ubuntu installation in a Notebook to use a swap file, instead of using a swap partition.
By default is not possible to get Ubuntu to hibernate using a swap file, so I tried this tutorial, but it is specific to grub1, and Ubuntu now uses grub2.
Does anybody know how to do this?
swap hibernate
add a comment |
I have configured a new Ubuntu installation in a Notebook to use a swap file, instead of using a swap partition.
By default is not possible to get Ubuntu to hibernate using a swap file, so I tried this tutorial, but it is specific to grub1, and Ubuntu now uses grub2.
Does anybody know how to do this?
swap hibernate
add a comment |
I have configured a new Ubuntu installation in a Notebook to use a swap file, instead of using a swap partition.
By default is not possible to get Ubuntu to hibernate using a swap file, so I tried this tutorial, but it is specific to grub1, and Ubuntu now uses grub2.
Does anybody know how to do this?
swap hibernate
I have configured a new Ubuntu installation in a Notebook to use a swap file, instead of using a swap partition.
By default is not possible to get Ubuntu to hibernate using a swap file, so I tried this tutorial, but it is specific to grub1, and Ubuntu now uses grub2.
Does anybody know how to do this?
swap hibernate
swap hibernate
edited Mar 13 '17 at 5:31
muru
1
1
asked Oct 13 '10 at 11:58
tfmoraestfmoraes
114116
114116
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Hibernate with Swap file using uswusp
Although it is possible to hibernate to swap file and it supposedly works with systemd hibernate by setting kernel parameters. However, I couldn't get it to resume so instead switched to using uswsusp (userspace software suspend). Here are the steps I used on Ubuntu 17.04/17.10.
Create the Swap File
The commands to create a formatted 4GiB swap file, mounted and added to /etc/fstab:
sudo fallocate -l 4g /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
Verify Swap File Partition
sudo findmnt -no SOURCE,UUID -T /mnt/4GiB.swap
> /dev/sda1 11cc33ee-1234-abcd-1234-ddeeff112233
Install Userspace Software Suspend (uswsusp)
sudo apt install uswsusp
Configure uswsusp
To create /etc/uswsusp.conf and recreate initramfs:
sudo dpkg-reconfigure -pmedium uswsusp
Yesto 'Continue without a valid swap space?' (Wizard not set swap file yet.)- Select the partition that the swap-file resides on, cross-reference with details from
findmntabove. (Note:not the swap-file itself)
Note: Any changes manually made to /etc/uswsusp.conf will require recreating initramfs afterwards with this command:
sudo update-initramfs -u
Test uswusp hibernate
sudo s2disk
There should be snapshot messages on the screen on hibernate and resume.
Use s2disk with systemd hibernate
By default systemd will use it's own hibernate commands so replace them with the uswusp commands by overriding the systemd-hibernate.service:
sudo systemctl edit systemd-hibernate.service
In the text editor that opens put the following text (the blank ExecStart is required). Then save and exit:
[Service]
ExecStart=
ExecStart=/usr/sbin/s2disk
ExecStartPost=/bin/run-parts -a post /lib/systemd/system-sleep
This will create /etc/systemd/system/systemd-hibernate.service.d/override.conf file with override details.
Test systemd hibernate :
systemctl hibernate
Note: To check that the systemd override.conf has been created, loaded and no errors, run:
systemctl status systemd-hibernate.service
References:
- Debian Wiki - Hibernate_Without_Swap_Partition
- Arch Wiki - Uswsusp
This instructions seems to work but the systemd hibernation is not working for me. Have you tested this your own? Should thisExceStart=run-parts -a post /lib/systemd/system-sleepbeExceStartPost=run-parts -a post /lib/systemd/system-sleep
– Joaquín Aramendía
Oct 2 '17 at 14:51
It was tested and working but perhaps that addition is needed. I have updated my answer.
– Cas
Oct 2 '17 at 15:33
This doesn't look quite right. Theenableoption ofsystemctlsymlinks from/etc/systemd/system/to/lib/systemd/system/. You should never be copying directly into/etc/systemd/system/
– Auspex
Oct 29 '17 at 19:46
Yes you should put put service files in/etc/systemd/system, especially if you are overriding existing services: wiki.archlinux.org/index.php/systemd#Writing_unit_files
– Cas
Oct 29 '17 at 22:46
1
I didn't manage to make this work 😞. I set up swapfile, installed and configured uswsusp, butsudo s2diskonly logsSaving snapshot, than turns off the display, hangs for ~5 min and then it shuts down the computer. However after I turn it on, it boots normally like there's been no hibernation.
– m93a
Aug 20 '18 at 7:42
|
show 4 more comments
I've given a quick read to the tutorial and, if I have understood correctly, you just need to specify the resume options to the Linux command line. With Grub2 is really simple, and your changes will be always preserved. You need to edit the /etc/default/grub file, specifically this line:
GRUB_CMDLINE_LINUX="resume=... resume_offset=..."
After that, run sudo update-grub for the changes to take effect.
Changing GRUB_CMDLINE_LINUX won't affect other Linux installations you have (because /etc/grub.d/30_os-prober does not use this variable).
About the problem you're having: is the partition of the swapfile encrypted? If so, hibernation won't work. If not, then the output of filefrag -v /swapfile may be helpful.
Thanks! I will try. But I think it config all linux entries in grub with this line.
– tfmoraes
Oct 13 '10 at 16:26
Don't forget: after changing/etc/default/grubyou need to runupdate-grub.
– JanC
Oct 13 '10 at 16:44
@tfmoraes: why wouldn't you want this added to all linux entries?
– JanC
Oct 13 '10 at 16:45
@JanC: Because I may have other Linux distributions installed.
– tfmoraes
Oct 13 '10 at 17:21
1
@didi_X8 that comment was written 8 years ago. It's possible that things have changed since then. Thanks for sharing.
– Andrea Corbellini
Jul 9 '18 at 16:04
|
show 6 more comments
Here is what I did to make it work with Ubuntu 18.04.
Make your
/swapfilehave at least the size of your RAMsudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrun
sudo mkswap /swapfile
sudo swapon /swapfileNote the UUID of the partition containing your
/swapfile:$ sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0Reconfigure the package
uswsuspin order to correctly use the swapfile:sudo dpkg-reconfigure -pmedium uswsusp
# Answer "Yes" to continue without swap space
# Select "/dev/disk/by-uuid/20562a02-cfa6-42e0-bb9f-5e936ea763d0" replace the UUID with the result from the previous findmnt command
# Encrypt: "No"Edit the SystemD hibernate service using
sudo systemctl edit systemd-hibernate.serviceand fill it with the following content:[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /usr/lib/systemd/system-sleep
ExecStart=/usr/sbin/s2disk
ExecStartPost=-/bin/run-parts -v --reverse -a post /usr/lib/systemd/system-sleepNote the resume offset of your
/swapfile:$ sudo swap-offset /swapfile
resume offset = 34818Configure Grub to resume from the swapfile by editing
/etc/default/gruband modify the following line:GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34818 quiet splash"Update Grub:
sudo update-grubCreate the following
/etc/initramfs-tools/conf.d/resume:RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfileUpdate initramfs:
sudo update-initramfs -u -k all
Now you can hibernate with sudo systemctl hibernate.
One can also create those scripts:
sudo tee /usr/local/bin/gotosleep <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo /usr/sbin/s2both
EOF
sudo chmod +x /usr/local/bin/gotosleep
sudo tee /usr/local/bin/gotohibernation <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo systemctl hibernate
EOF
sudo chmod +x /usr/local/bin/gotohibernation
So you can sleep with gotosleep or hibernate with gotohibernation.
You must be able to execute sudo s2both, sudo s2ram and sudo systemctl hibernatewithout having to enter your password for the previous scripts to work.
You could do that for example by creating a powerdev group, add your current user to it, and configure the following sudoers config (edit it with sudo visudo -f /etc/sudoers.d/powerdev):
%powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram, /bin/systemctl hibernate
Documentation used:
- Cas' answer
- Debian "Hibernate without swap partition"
- Configuring Lubuntu 18.04 to enable hibernation using a swap file
- So question "s2disk works, but hibernation from menu gets stuck afer login"
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f6769%2fhibernate-and-resume-from-a-swap-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Hibernate with Swap file using uswusp
Although it is possible to hibernate to swap file and it supposedly works with systemd hibernate by setting kernel parameters. However, I couldn't get it to resume so instead switched to using uswsusp (userspace software suspend). Here are the steps I used on Ubuntu 17.04/17.10.
Create the Swap File
The commands to create a formatted 4GiB swap file, mounted and added to /etc/fstab:
sudo fallocate -l 4g /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
Verify Swap File Partition
sudo findmnt -no SOURCE,UUID -T /mnt/4GiB.swap
> /dev/sda1 11cc33ee-1234-abcd-1234-ddeeff112233
Install Userspace Software Suspend (uswsusp)
sudo apt install uswsusp
Configure uswsusp
To create /etc/uswsusp.conf and recreate initramfs:
sudo dpkg-reconfigure -pmedium uswsusp
Yesto 'Continue without a valid swap space?' (Wizard not set swap file yet.)- Select the partition that the swap-file resides on, cross-reference with details from
findmntabove. (Note:not the swap-file itself)
Note: Any changes manually made to /etc/uswsusp.conf will require recreating initramfs afterwards with this command:
sudo update-initramfs -u
Test uswusp hibernate
sudo s2disk
There should be snapshot messages on the screen on hibernate and resume.
Use s2disk with systemd hibernate
By default systemd will use it's own hibernate commands so replace them with the uswusp commands by overriding the systemd-hibernate.service:
sudo systemctl edit systemd-hibernate.service
In the text editor that opens put the following text (the blank ExecStart is required). Then save and exit:
[Service]
ExecStart=
ExecStart=/usr/sbin/s2disk
ExecStartPost=/bin/run-parts -a post /lib/systemd/system-sleep
This will create /etc/systemd/system/systemd-hibernate.service.d/override.conf file with override details.
Test systemd hibernate :
systemctl hibernate
Note: To check that the systemd override.conf has been created, loaded and no errors, run:
systemctl status systemd-hibernate.service
References:
- Debian Wiki - Hibernate_Without_Swap_Partition
- Arch Wiki - Uswsusp
This instructions seems to work but the systemd hibernation is not working for me. Have you tested this your own? Should thisExceStart=run-parts -a post /lib/systemd/system-sleepbeExceStartPost=run-parts -a post /lib/systemd/system-sleep
– Joaquín Aramendía
Oct 2 '17 at 14:51
It was tested and working but perhaps that addition is needed. I have updated my answer.
– Cas
Oct 2 '17 at 15:33
This doesn't look quite right. Theenableoption ofsystemctlsymlinks from/etc/systemd/system/to/lib/systemd/system/. You should never be copying directly into/etc/systemd/system/
– Auspex
Oct 29 '17 at 19:46
Yes you should put put service files in/etc/systemd/system, especially if you are overriding existing services: wiki.archlinux.org/index.php/systemd#Writing_unit_files
– Cas
Oct 29 '17 at 22:46
1
I didn't manage to make this work 😞. I set up swapfile, installed and configured uswsusp, butsudo s2diskonly logsSaving snapshot, than turns off the display, hangs for ~5 min and then it shuts down the computer. However after I turn it on, it boots normally like there's been no hibernation.
– m93a
Aug 20 '18 at 7:42
|
show 4 more comments
Hibernate with Swap file using uswusp
Although it is possible to hibernate to swap file and it supposedly works with systemd hibernate by setting kernel parameters. However, I couldn't get it to resume so instead switched to using uswsusp (userspace software suspend). Here are the steps I used on Ubuntu 17.04/17.10.
Create the Swap File
The commands to create a formatted 4GiB swap file, mounted and added to /etc/fstab:
sudo fallocate -l 4g /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
Verify Swap File Partition
sudo findmnt -no SOURCE,UUID -T /mnt/4GiB.swap
> /dev/sda1 11cc33ee-1234-abcd-1234-ddeeff112233
Install Userspace Software Suspend (uswsusp)
sudo apt install uswsusp
Configure uswsusp
To create /etc/uswsusp.conf and recreate initramfs:
sudo dpkg-reconfigure -pmedium uswsusp
Yesto 'Continue without a valid swap space?' (Wizard not set swap file yet.)- Select the partition that the swap-file resides on, cross-reference with details from
findmntabove. (Note:not the swap-file itself)
Note: Any changes manually made to /etc/uswsusp.conf will require recreating initramfs afterwards with this command:
sudo update-initramfs -u
Test uswusp hibernate
sudo s2disk
There should be snapshot messages on the screen on hibernate and resume.
Use s2disk with systemd hibernate
By default systemd will use it's own hibernate commands so replace them with the uswusp commands by overriding the systemd-hibernate.service:
sudo systemctl edit systemd-hibernate.service
In the text editor that opens put the following text (the blank ExecStart is required). Then save and exit:
[Service]
ExecStart=
ExecStart=/usr/sbin/s2disk
ExecStartPost=/bin/run-parts -a post /lib/systemd/system-sleep
This will create /etc/systemd/system/systemd-hibernate.service.d/override.conf file with override details.
Test systemd hibernate :
systemctl hibernate
Note: To check that the systemd override.conf has been created, loaded and no errors, run:
systemctl status systemd-hibernate.service
References:
- Debian Wiki - Hibernate_Without_Swap_Partition
- Arch Wiki - Uswsusp
This instructions seems to work but the systemd hibernation is not working for me. Have you tested this your own? Should thisExceStart=run-parts -a post /lib/systemd/system-sleepbeExceStartPost=run-parts -a post /lib/systemd/system-sleep
– Joaquín Aramendía
Oct 2 '17 at 14:51
It was tested and working but perhaps that addition is needed. I have updated my answer.
– Cas
Oct 2 '17 at 15:33
This doesn't look quite right. Theenableoption ofsystemctlsymlinks from/etc/systemd/system/to/lib/systemd/system/. You should never be copying directly into/etc/systemd/system/
– Auspex
Oct 29 '17 at 19:46
Yes you should put put service files in/etc/systemd/system, especially if you are overriding existing services: wiki.archlinux.org/index.php/systemd#Writing_unit_files
– Cas
Oct 29 '17 at 22:46
1
I didn't manage to make this work 😞. I set up swapfile, installed and configured uswsusp, butsudo s2diskonly logsSaving snapshot, than turns off the display, hangs for ~5 min and then it shuts down the computer. However after I turn it on, it boots normally like there's been no hibernation.
– m93a
Aug 20 '18 at 7:42
|
show 4 more comments
Hibernate with Swap file using uswusp
Although it is possible to hibernate to swap file and it supposedly works with systemd hibernate by setting kernel parameters. However, I couldn't get it to resume so instead switched to using uswsusp (userspace software suspend). Here are the steps I used on Ubuntu 17.04/17.10.
Create the Swap File
The commands to create a formatted 4GiB swap file, mounted and added to /etc/fstab:
sudo fallocate -l 4g /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
Verify Swap File Partition
sudo findmnt -no SOURCE,UUID -T /mnt/4GiB.swap
> /dev/sda1 11cc33ee-1234-abcd-1234-ddeeff112233
Install Userspace Software Suspend (uswsusp)
sudo apt install uswsusp
Configure uswsusp
To create /etc/uswsusp.conf and recreate initramfs:
sudo dpkg-reconfigure -pmedium uswsusp
Yesto 'Continue without a valid swap space?' (Wizard not set swap file yet.)- Select the partition that the swap-file resides on, cross-reference with details from
findmntabove. (Note:not the swap-file itself)
Note: Any changes manually made to /etc/uswsusp.conf will require recreating initramfs afterwards with this command:
sudo update-initramfs -u
Test uswusp hibernate
sudo s2disk
There should be snapshot messages on the screen on hibernate and resume.
Use s2disk with systemd hibernate
By default systemd will use it's own hibernate commands so replace them with the uswusp commands by overriding the systemd-hibernate.service:
sudo systemctl edit systemd-hibernate.service
In the text editor that opens put the following text (the blank ExecStart is required). Then save and exit:
[Service]
ExecStart=
ExecStart=/usr/sbin/s2disk
ExecStartPost=/bin/run-parts -a post /lib/systemd/system-sleep
This will create /etc/systemd/system/systemd-hibernate.service.d/override.conf file with override details.
Test systemd hibernate :
systemctl hibernate
Note: To check that the systemd override.conf has been created, loaded and no errors, run:
systemctl status systemd-hibernate.service
References:
- Debian Wiki - Hibernate_Without_Swap_Partition
- Arch Wiki - Uswsusp
Hibernate with Swap file using uswusp
Although it is possible to hibernate to swap file and it supposedly works with systemd hibernate by setting kernel parameters. However, I couldn't get it to resume so instead switched to using uswsusp (userspace software suspend). Here are the steps I used on Ubuntu 17.04/17.10.
Create the Swap File
The commands to create a formatted 4GiB swap file, mounted and added to /etc/fstab:
sudo fallocate -l 4g /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
Verify Swap File Partition
sudo findmnt -no SOURCE,UUID -T /mnt/4GiB.swap
> /dev/sda1 11cc33ee-1234-abcd-1234-ddeeff112233
Install Userspace Software Suspend (uswsusp)
sudo apt install uswsusp
Configure uswsusp
To create /etc/uswsusp.conf and recreate initramfs:
sudo dpkg-reconfigure -pmedium uswsusp
Yesto 'Continue without a valid swap space?' (Wizard not set swap file yet.)- Select the partition that the swap-file resides on, cross-reference with details from
findmntabove. (Note:not the swap-file itself)
Note: Any changes manually made to /etc/uswsusp.conf will require recreating initramfs afterwards with this command:
sudo update-initramfs -u
Test uswusp hibernate
sudo s2disk
There should be snapshot messages on the screen on hibernate and resume.
Use s2disk with systemd hibernate
By default systemd will use it's own hibernate commands so replace them with the uswusp commands by overriding the systemd-hibernate.service:
sudo systemctl edit systemd-hibernate.service
In the text editor that opens put the following text (the blank ExecStart is required). Then save and exit:
[Service]
ExecStart=
ExecStart=/usr/sbin/s2disk
ExecStartPost=/bin/run-parts -a post /lib/systemd/system-sleep
This will create /etc/systemd/system/systemd-hibernate.service.d/override.conf file with override details.
Test systemd hibernate :
systemctl hibernate
Note: To check that the systemd override.conf has been created, loaded and no errors, run:
systemctl status systemd-hibernate.service
References:
- Debian Wiki - Hibernate_Without_Swap_Partition
- Arch Wiki - Uswsusp
edited Dec 21 '17 at 19:48
MM.
1032
1032
answered Mar 12 '17 at 22:50
CasCas
5,38735296
5,38735296
This instructions seems to work but the systemd hibernation is not working for me. Have you tested this your own? Should thisExceStart=run-parts -a post /lib/systemd/system-sleepbeExceStartPost=run-parts -a post /lib/systemd/system-sleep
– Joaquín Aramendía
Oct 2 '17 at 14:51
It was tested and working but perhaps that addition is needed. I have updated my answer.
– Cas
Oct 2 '17 at 15:33
This doesn't look quite right. Theenableoption ofsystemctlsymlinks from/etc/systemd/system/to/lib/systemd/system/. You should never be copying directly into/etc/systemd/system/
– Auspex
Oct 29 '17 at 19:46
Yes you should put put service files in/etc/systemd/system, especially if you are overriding existing services: wiki.archlinux.org/index.php/systemd#Writing_unit_files
– Cas
Oct 29 '17 at 22:46
1
I didn't manage to make this work 😞. I set up swapfile, installed and configured uswsusp, butsudo s2diskonly logsSaving snapshot, than turns off the display, hangs for ~5 min and then it shuts down the computer. However after I turn it on, it boots normally like there's been no hibernation.
– m93a
Aug 20 '18 at 7:42
|
show 4 more comments
This instructions seems to work but the systemd hibernation is not working for me. Have you tested this your own? Should thisExceStart=run-parts -a post /lib/systemd/system-sleepbeExceStartPost=run-parts -a post /lib/systemd/system-sleep
– Joaquín Aramendía
Oct 2 '17 at 14:51
It was tested and working but perhaps that addition is needed. I have updated my answer.
– Cas
Oct 2 '17 at 15:33
This doesn't look quite right. Theenableoption ofsystemctlsymlinks from/etc/systemd/system/to/lib/systemd/system/. You should never be copying directly into/etc/systemd/system/
– Auspex
Oct 29 '17 at 19:46
Yes you should put put service files in/etc/systemd/system, especially if you are overriding existing services: wiki.archlinux.org/index.php/systemd#Writing_unit_files
– Cas
Oct 29 '17 at 22:46
1
I didn't manage to make this work 😞. I set up swapfile, installed and configured uswsusp, butsudo s2diskonly logsSaving snapshot, than turns off the display, hangs for ~5 min and then it shuts down the computer. However after I turn it on, it boots normally like there's been no hibernation.
– m93a
Aug 20 '18 at 7:42
This instructions seems to work but the systemd hibernation is not working for me. Have you tested this your own? Should this
ExceStart=run-parts -a post /lib/systemd/system-sleep be ExceStartPost=run-parts -a post /lib/systemd/system-sleep– Joaquín Aramendía
Oct 2 '17 at 14:51
This instructions seems to work but the systemd hibernation is not working for me. Have you tested this your own? Should this
ExceStart=run-parts -a post /lib/systemd/system-sleep be ExceStartPost=run-parts -a post /lib/systemd/system-sleep– Joaquín Aramendía
Oct 2 '17 at 14:51
It was tested and working but perhaps that addition is needed. I have updated my answer.
– Cas
Oct 2 '17 at 15:33
It was tested and working but perhaps that addition is needed. I have updated my answer.
– Cas
Oct 2 '17 at 15:33
This doesn't look quite right. The
enable option of systemctl symlinks from /etc/systemd/system/ to /lib/systemd/system/. You should never be copying directly into /etc/systemd/system/– Auspex
Oct 29 '17 at 19:46
This doesn't look quite right. The
enable option of systemctl symlinks from /etc/systemd/system/ to /lib/systemd/system/. You should never be copying directly into /etc/systemd/system/– Auspex
Oct 29 '17 at 19:46
Yes you should put put service files in
/etc/systemd/system, especially if you are overriding existing services: wiki.archlinux.org/index.php/systemd#Writing_unit_files– Cas
Oct 29 '17 at 22:46
Yes you should put put service files in
/etc/systemd/system, especially if you are overriding existing services: wiki.archlinux.org/index.php/systemd#Writing_unit_files– Cas
Oct 29 '17 at 22:46
1
1
I didn't manage to make this work 😞. I set up swapfile, installed and configured uswsusp, but
sudo s2disk only logs Saving snapshot, than turns off the display, hangs for ~5 min and then it shuts down the computer. However after I turn it on, it boots normally like there's been no hibernation.– m93a
Aug 20 '18 at 7:42
I didn't manage to make this work 😞. I set up swapfile, installed and configured uswsusp, but
sudo s2disk only logs Saving snapshot, than turns off the display, hangs for ~5 min and then it shuts down the computer. However after I turn it on, it boots normally like there's been no hibernation.– m93a
Aug 20 '18 at 7:42
|
show 4 more comments
I've given a quick read to the tutorial and, if I have understood correctly, you just need to specify the resume options to the Linux command line. With Grub2 is really simple, and your changes will be always preserved. You need to edit the /etc/default/grub file, specifically this line:
GRUB_CMDLINE_LINUX="resume=... resume_offset=..."
After that, run sudo update-grub for the changes to take effect.
Changing GRUB_CMDLINE_LINUX won't affect other Linux installations you have (because /etc/grub.d/30_os-prober does not use this variable).
About the problem you're having: is the partition of the swapfile encrypted? If so, hibernation won't work. If not, then the output of filefrag -v /swapfile may be helpful.
Thanks! I will try. But I think it config all linux entries in grub with this line.
– tfmoraes
Oct 13 '10 at 16:26
Don't forget: after changing/etc/default/grubyou need to runupdate-grub.
– JanC
Oct 13 '10 at 16:44
@tfmoraes: why wouldn't you want this added to all linux entries?
– JanC
Oct 13 '10 at 16:45
@JanC: Because I may have other Linux distributions installed.
– tfmoraes
Oct 13 '10 at 17:21
1
@didi_X8 that comment was written 8 years ago. It's possible that things have changed since then. Thanks for sharing.
– Andrea Corbellini
Jul 9 '18 at 16:04
|
show 6 more comments
I've given a quick read to the tutorial and, if I have understood correctly, you just need to specify the resume options to the Linux command line. With Grub2 is really simple, and your changes will be always preserved. You need to edit the /etc/default/grub file, specifically this line:
GRUB_CMDLINE_LINUX="resume=... resume_offset=..."
After that, run sudo update-grub for the changes to take effect.
Changing GRUB_CMDLINE_LINUX won't affect other Linux installations you have (because /etc/grub.d/30_os-prober does not use this variable).
About the problem you're having: is the partition of the swapfile encrypted? If so, hibernation won't work. If not, then the output of filefrag -v /swapfile may be helpful.
Thanks! I will try. But I think it config all linux entries in grub with this line.
– tfmoraes
Oct 13 '10 at 16:26
Don't forget: after changing/etc/default/grubyou need to runupdate-grub.
– JanC
Oct 13 '10 at 16:44
@tfmoraes: why wouldn't you want this added to all linux entries?
– JanC
Oct 13 '10 at 16:45
@JanC: Because I may have other Linux distributions installed.
– tfmoraes
Oct 13 '10 at 17:21
1
@didi_X8 that comment was written 8 years ago. It's possible that things have changed since then. Thanks for sharing.
– Andrea Corbellini
Jul 9 '18 at 16:04
|
show 6 more comments
I've given a quick read to the tutorial and, if I have understood correctly, you just need to specify the resume options to the Linux command line. With Grub2 is really simple, and your changes will be always preserved. You need to edit the /etc/default/grub file, specifically this line:
GRUB_CMDLINE_LINUX="resume=... resume_offset=..."
After that, run sudo update-grub for the changes to take effect.
Changing GRUB_CMDLINE_LINUX won't affect other Linux installations you have (because /etc/grub.d/30_os-prober does not use this variable).
About the problem you're having: is the partition of the swapfile encrypted? If so, hibernation won't work. If not, then the output of filefrag -v /swapfile may be helpful.
I've given a quick read to the tutorial and, if I have understood correctly, you just need to specify the resume options to the Linux command line. With Grub2 is really simple, and your changes will be always preserved. You need to edit the /etc/default/grub file, specifically this line:
GRUB_CMDLINE_LINUX="resume=... resume_offset=..."
After that, run sudo update-grub for the changes to take effect.
Changing GRUB_CMDLINE_LINUX won't affect other Linux installations you have (because /etc/grub.d/30_os-prober does not use this variable).
About the problem you're having: is the partition of the swapfile encrypted? If so, hibernation won't work. If not, then the output of filefrag -v /swapfile may be helpful.
edited Oct 14 '10 at 14:01
answered Oct 13 '10 at 15:46
Andrea CorbelliniAndrea Corbellini
12.4k24566
12.4k24566
Thanks! I will try. But I think it config all linux entries in grub with this line.
– tfmoraes
Oct 13 '10 at 16:26
Don't forget: after changing/etc/default/grubyou need to runupdate-grub.
– JanC
Oct 13 '10 at 16:44
@tfmoraes: why wouldn't you want this added to all linux entries?
– JanC
Oct 13 '10 at 16:45
@JanC: Because I may have other Linux distributions installed.
– tfmoraes
Oct 13 '10 at 17:21
1
@didi_X8 that comment was written 8 years ago. It's possible that things have changed since then. Thanks for sharing.
– Andrea Corbellini
Jul 9 '18 at 16:04
|
show 6 more comments
Thanks! I will try. But I think it config all linux entries in grub with this line.
– tfmoraes
Oct 13 '10 at 16:26
Don't forget: after changing/etc/default/grubyou need to runupdate-grub.
– JanC
Oct 13 '10 at 16:44
@tfmoraes: why wouldn't you want this added to all linux entries?
– JanC
Oct 13 '10 at 16:45
@JanC: Because I may have other Linux distributions installed.
– tfmoraes
Oct 13 '10 at 17:21
1
@didi_X8 that comment was written 8 years ago. It's possible that things have changed since then. Thanks for sharing.
– Andrea Corbellini
Jul 9 '18 at 16:04
Thanks! I will try. But I think it config all linux entries in grub with this line.
– tfmoraes
Oct 13 '10 at 16:26
Thanks! I will try. But I think it config all linux entries in grub with this line.
– tfmoraes
Oct 13 '10 at 16:26
Don't forget: after changing
/etc/default/grub you need to run update-grub.– JanC
Oct 13 '10 at 16:44
Don't forget: after changing
/etc/default/grub you need to run update-grub.– JanC
Oct 13 '10 at 16:44
@tfmoraes: why wouldn't you want this added to all linux entries?
– JanC
Oct 13 '10 at 16:45
@tfmoraes: why wouldn't you want this added to all linux entries?
– JanC
Oct 13 '10 at 16:45
@JanC: Because I may have other Linux distributions installed.
– tfmoraes
Oct 13 '10 at 17:21
@JanC: Because I may have other Linux distributions installed.
– tfmoraes
Oct 13 '10 at 17:21
1
1
@didi_X8 that comment was written 8 years ago. It's possible that things have changed since then. Thanks for sharing.
– Andrea Corbellini
Jul 9 '18 at 16:04
@didi_X8 that comment was written 8 years ago. It's possible that things have changed since then. Thanks for sharing.
– Andrea Corbellini
Jul 9 '18 at 16:04
|
show 6 more comments
Here is what I did to make it work with Ubuntu 18.04.
Make your
/swapfilehave at least the size of your RAMsudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrun
sudo mkswap /swapfile
sudo swapon /swapfileNote the UUID of the partition containing your
/swapfile:$ sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0Reconfigure the package
uswsuspin order to correctly use the swapfile:sudo dpkg-reconfigure -pmedium uswsusp
# Answer "Yes" to continue without swap space
# Select "/dev/disk/by-uuid/20562a02-cfa6-42e0-bb9f-5e936ea763d0" replace the UUID with the result from the previous findmnt command
# Encrypt: "No"Edit the SystemD hibernate service using
sudo systemctl edit systemd-hibernate.serviceand fill it with the following content:[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /usr/lib/systemd/system-sleep
ExecStart=/usr/sbin/s2disk
ExecStartPost=-/bin/run-parts -v --reverse -a post /usr/lib/systemd/system-sleepNote the resume offset of your
/swapfile:$ sudo swap-offset /swapfile
resume offset = 34818Configure Grub to resume from the swapfile by editing
/etc/default/gruband modify the following line:GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34818 quiet splash"Update Grub:
sudo update-grubCreate the following
/etc/initramfs-tools/conf.d/resume:RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfileUpdate initramfs:
sudo update-initramfs -u -k all
Now you can hibernate with sudo systemctl hibernate.
One can also create those scripts:
sudo tee /usr/local/bin/gotosleep <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo /usr/sbin/s2both
EOF
sudo chmod +x /usr/local/bin/gotosleep
sudo tee /usr/local/bin/gotohibernation <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo systemctl hibernate
EOF
sudo chmod +x /usr/local/bin/gotohibernation
So you can sleep with gotosleep or hibernate with gotohibernation.
You must be able to execute sudo s2both, sudo s2ram and sudo systemctl hibernatewithout having to enter your password for the previous scripts to work.
You could do that for example by creating a powerdev group, add your current user to it, and configure the following sudoers config (edit it with sudo visudo -f /etc/sudoers.d/powerdev):
%powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram, /bin/systemctl hibernate
Documentation used:
- Cas' answer
- Debian "Hibernate without swap partition"
- Configuring Lubuntu 18.04 to enable hibernation using a swap file
- So question "s2disk works, but hibernation from menu gets stuck afer login"
add a comment |
Here is what I did to make it work with Ubuntu 18.04.
Make your
/swapfilehave at least the size of your RAMsudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrun
sudo mkswap /swapfile
sudo swapon /swapfileNote the UUID of the partition containing your
/swapfile:$ sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0Reconfigure the package
uswsuspin order to correctly use the swapfile:sudo dpkg-reconfigure -pmedium uswsusp
# Answer "Yes" to continue without swap space
# Select "/dev/disk/by-uuid/20562a02-cfa6-42e0-bb9f-5e936ea763d0" replace the UUID with the result from the previous findmnt command
# Encrypt: "No"Edit the SystemD hibernate service using
sudo systemctl edit systemd-hibernate.serviceand fill it with the following content:[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /usr/lib/systemd/system-sleep
ExecStart=/usr/sbin/s2disk
ExecStartPost=-/bin/run-parts -v --reverse -a post /usr/lib/systemd/system-sleepNote the resume offset of your
/swapfile:$ sudo swap-offset /swapfile
resume offset = 34818Configure Grub to resume from the swapfile by editing
/etc/default/gruband modify the following line:GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34818 quiet splash"Update Grub:
sudo update-grubCreate the following
/etc/initramfs-tools/conf.d/resume:RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfileUpdate initramfs:
sudo update-initramfs -u -k all
Now you can hibernate with sudo systemctl hibernate.
One can also create those scripts:
sudo tee /usr/local/bin/gotosleep <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo /usr/sbin/s2both
EOF
sudo chmod +x /usr/local/bin/gotosleep
sudo tee /usr/local/bin/gotohibernation <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo systemctl hibernate
EOF
sudo chmod +x /usr/local/bin/gotohibernation
So you can sleep with gotosleep or hibernate with gotohibernation.
You must be able to execute sudo s2both, sudo s2ram and sudo systemctl hibernatewithout having to enter your password for the previous scripts to work.
You could do that for example by creating a powerdev group, add your current user to it, and configure the following sudoers config (edit it with sudo visudo -f /etc/sudoers.d/powerdev):
%powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram, /bin/systemctl hibernate
Documentation used:
- Cas' answer
- Debian "Hibernate without swap partition"
- Configuring Lubuntu 18.04 to enable hibernation using a swap file
- So question "s2disk works, but hibernation from menu gets stuck afer login"
add a comment |
Here is what I did to make it work with Ubuntu 18.04.
Make your
/swapfilehave at least the size of your RAMsudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrun
sudo mkswap /swapfile
sudo swapon /swapfileNote the UUID of the partition containing your
/swapfile:$ sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0Reconfigure the package
uswsuspin order to correctly use the swapfile:sudo dpkg-reconfigure -pmedium uswsusp
# Answer "Yes" to continue without swap space
# Select "/dev/disk/by-uuid/20562a02-cfa6-42e0-bb9f-5e936ea763d0" replace the UUID with the result from the previous findmnt command
# Encrypt: "No"Edit the SystemD hibernate service using
sudo systemctl edit systemd-hibernate.serviceand fill it with the following content:[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /usr/lib/systemd/system-sleep
ExecStart=/usr/sbin/s2disk
ExecStartPost=-/bin/run-parts -v --reverse -a post /usr/lib/systemd/system-sleepNote the resume offset of your
/swapfile:$ sudo swap-offset /swapfile
resume offset = 34818Configure Grub to resume from the swapfile by editing
/etc/default/gruband modify the following line:GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34818 quiet splash"Update Grub:
sudo update-grubCreate the following
/etc/initramfs-tools/conf.d/resume:RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfileUpdate initramfs:
sudo update-initramfs -u -k all
Now you can hibernate with sudo systemctl hibernate.
One can also create those scripts:
sudo tee /usr/local/bin/gotosleep <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo /usr/sbin/s2both
EOF
sudo chmod +x /usr/local/bin/gotosleep
sudo tee /usr/local/bin/gotohibernation <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo systemctl hibernate
EOF
sudo chmod +x /usr/local/bin/gotohibernation
So you can sleep with gotosleep or hibernate with gotohibernation.
You must be able to execute sudo s2both, sudo s2ram and sudo systemctl hibernatewithout having to enter your password for the previous scripts to work.
You could do that for example by creating a powerdev group, add your current user to it, and configure the following sudoers config (edit it with sudo visudo -f /etc/sudoers.d/powerdev):
%powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram, /bin/systemctl hibernate
Documentation used:
- Cas' answer
- Debian "Hibernate without swap partition"
- Configuring Lubuntu 18.04 to enable hibernation using a swap file
- So question "s2disk works, but hibernation from menu gets stuck afer login"
Here is what I did to make it work with Ubuntu 18.04.
Make your
/swapfilehave at least the size of your RAMsudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrun
sudo mkswap /swapfile
sudo swapon /swapfileNote the UUID of the partition containing your
/swapfile:$ sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0Reconfigure the package
uswsuspin order to correctly use the swapfile:sudo dpkg-reconfigure -pmedium uswsusp
# Answer "Yes" to continue without swap space
# Select "/dev/disk/by-uuid/20562a02-cfa6-42e0-bb9f-5e936ea763d0" replace the UUID with the result from the previous findmnt command
# Encrypt: "No"Edit the SystemD hibernate service using
sudo systemctl edit systemd-hibernate.serviceand fill it with the following content:[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /usr/lib/systemd/system-sleep
ExecStart=/usr/sbin/s2disk
ExecStartPost=-/bin/run-parts -v --reverse -a post /usr/lib/systemd/system-sleepNote the resume offset of your
/swapfile:$ sudo swap-offset /swapfile
resume offset = 34818Configure Grub to resume from the swapfile by editing
/etc/default/gruband modify the following line:GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34818 quiet splash"Update Grub:
sudo update-grubCreate the following
/etc/initramfs-tools/conf.d/resume:RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfileUpdate initramfs:
sudo update-initramfs -u -k all
Now you can hibernate with sudo systemctl hibernate.
One can also create those scripts:
sudo tee /usr/local/bin/gotosleep <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo /usr/sbin/s2both
EOF
sudo chmod +x /usr/local/bin/gotosleep
sudo tee /usr/local/bin/gotohibernation <<EOF
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
sleep 2
sudo systemctl hibernate
EOF
sudo chmod +x /usr/local/bin/gotohibernation
So you can sleep with gotosleep or hibernate with gotohibernation.
You must be able to execute sudo s2both, sudo s2ram and sudo systemctl hibernatewithout having to enter your password for the previous scripts to work.
You could do that for example by creating a powerdev group, add your current user to it, and configure the following sudoers config (edit it with sudo visudo -f /etc/sudoers.d/powerdev):
%powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram, /bin/systemctl hibernate
Documentation used:
- Cas' answer
- Debian "Hibernate without swap partition"
- Configuring Lubuntu 18.04 to enable hibernation using a swap file
- So question "s2disk works, but hibernation from menu gets stuck afer login"
answered 2 days ago
Anthony O.Anthony O.
6392715
6392715
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f6769%2fhibernate-and-resume-from-a-swap-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown