Setting up a Swap File

I am trying to set up a swap file (instead of a partition) for hibernation.

I created a file at /mnt/swapfile. My /etc/default/grub contains the following:

GRUB_DEFAULT=saved
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="Manjaro"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash apparmor=1 security=apparmor udev.log_priority=3"
GRUB_CMDLINE_LINUX="resume=/mnt/swapfile"

and my /etc/fstab has this line

/mnt/swapfile none swap defaults 0 0

However, when I try to hibernate, it does the same as shutting off. Running journalctl -b | grep hibernate gives the following:

sep 04 14:32:45 <my-name> gsd-media-keys[1258]: Failed to grab accelerator for keybinding settings:hibernate

Any ideas on what’s wrong?

1 Like

You need to set the UUID of the swapfile and the offset. Take a look here: Power management/Suspend and hibernate - ArchWiki

1 Like

Why not just do it like all the guides tell you:
put the swap file directly below /
instead of below /mnt

Is there a reason for why you want it under /mnt ?

upon resume, /mnt (the contents of it) might not be there - so the swap file can’t be located

… and what @megavolt said: the UUID of the device and the offset to find the start of it in the file system is needed

You can place a swap file anywhere and it will work - but resuming from it might prove difficult if you put it anywhere else than below /

1 Like

Thanks for your suggestions!

I moved my swap file to /swapfile, our of /mnt. Also, I updated my grub file:

GRUB_DEFAULT=saved
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="Manjaro"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash apparmor=1 security=apparmor udev.log_priority=3"
GRUB_CMDLINE_LINUX="resume=6b3152a0-facd-49ee-89da-cff1aa9eb423 resume_offset=6115328"

This line is in my fstab

/swapfile none swap defaults 0 0

However, still when I try to do systemctl hibernate, it just goes back to lock screen after a few seconds. This is the output of journalctl -b | grep hibernate:

sep 04 23:12:33 <my-name> systemd-logind[631]: The system will hibernate now!
sep 04 23:12:37 <my-name> systemd-sleep[4554]: Entering sleep state 'hibernate'...
sep 04 23:12:39 <my-name> systemd[1]: systemd-hibernate.service: Main process exited, code=exited, status=1/FAILURE
sep 04 23:12:39 <my-name> systemd[1]: systemd-hibernate.service: Failed with result 'exit-code'.
sep 04 23:12:39 <my-name> systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
sep 04 23:12:39 <my-name> systemd[1]: systemd-hibernate.service: Consumed 1.701s CPU time.

I think you need to add resume=UUID=....

And which filesystem is your mint partition?

3 Likes

resume=UUID=...
and:
you did regenerate the initrd and rebooted?

I moved my swap file to /swapfile

Why move it?
Simply recreate it, make a new one (dd and then mkswap)
Copying that file might be problematic.

2 Likes

Here

https://wiki.archlinux.org/title/Swap#Swap_file

…is real, proper, complete instructions. Might be worth looking into.

Hope it helps!

2 Likes

I once wrote this

Click on the flag to have it in english

1 Like

Adding

resume=UUID=...

fixed it. Thanks all!

My problem was that I tried to use ChatGPT to set this up, turns out it gave me a bunch of nonsense for the most part. Then I had to go around fixing all the individual things it screwed up. Don’t trust that thing.

The Arch Wiki should always be the first place to go to, directly.
And perhaps the Manjaro Wiki as well in some cases, where the differences between the two might matter.
Other distributions Wikis as well as a next step.
ChatGPT as an intermediate which compiles … whatever information by whatever algorithm and passes it of as reliable information should come last.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.