Adding swap /hibernation after install

I did a fresh install again on a new laptop dual boot Windows. I created a partition for linux and used replace partition in the installer. Ive been messing with this trying to figure out the best setup. I want the system when i close the lid to hibernate. Right now it is set to suspend but i see i don’t have swap or hibernate so I’m not sure it’s doing that or just shutting down the display. I left it overnight and battery was dead already. My fstab is them following.

# <file system>             <mount point>  <type>  <options>  <dump>  <pass>
UUID=F23A-62B4                            /boot/efi      vfat    umask=0077 0 2
UUID=1b3dcd7d-b403-4b62-975f-ebbb0c435982 /              ext4    defaults,noatime 0 1
[ricklinux@eos-xfce ~]$ 

Can i add hibernation after the fact? I need swap file to do that and add info to my fstab?
If i do this I’m looking to have the laptop shutdown on hibernation. Is that the way it hibernates?

1 Like

Yes, you need swap{partition,file} to hibernate.

Also yes, hibernate actually fully powers off the machine after saving your current state into your swap and setting it to resume from swap. However, I will say, if you have an SSD, hibernation doesn’t get you much. Resuming from hibernate vs. power off/on when system is on an SSD is pretty much the same speed (possible 1-3 seconds slower w/ power on, but very similar).

Yes, you can definitely add hibernate after the fact, but there’s a LITTLE more to setting up hibernate from a swapfile than from a swap partition.

I just might wipe this off again and install it with hibernation and try it first. Then i will add Windows maybe? Everything seems to work including backlighting. I’ve been experimenting with it. It’s not that I mind Windows it’s the 3rd party crapware and Microsoft’s own crap it installs. I usually take everything out except for Windows 10 and then i add what i want with software. Not Windows store apps.

Always install Windows first. Windows does not play well with being installed after other OS’s.

2 Likes

swapfile should do the job, as it does not need to change partitions

doens forget the resume= otherwise is useless that swapfile :slight_smile:

1 Like

Can you explain how i do this before i end up doing another bare metal install? First make a swap file. Then i have to add stuff to fstab? Plus i have to edit grub?

You need a swap partition and resume=swap_device kernel parameter to hibernate your system state, although this works a bit differently if encryption is involved.

https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#Hibernation

Better to test install your setup on a VM first, rather than bare metal, particularly if not 100% sure of how it all works.

I’d recommend not just simpy re-installing, this could be a good learning process for you, just make any mistakes in a VM first.

I just made a swap file but it doesn’t show anything in fstab? I guess that is only if you create a swap partition?

[ricklinux@eos-xfce ~]$ free
              total        used        free      shared  buff/cache   available
Mem:        7554380     1236852      138024      149352     6179504     5865508
Swap:       8191996           0     8191996
[ricklinux@eos-xfce ~]$ 

Edit: Can i just hibernate to this swap file? Do i need to do anything else?

You need to add a swap file entry manually, simply creating a file doesn’t create the fstab entry automatically.

/swapfile  none swap defaults 0 0

Take your time. Read the Arch Wiki and understand what you are doing instead of just shooting from from the hip.

I wouldn’t recommend using a swap file for hibernation either.

https://wiki.archlinux.org/index.php/Swap#Swap_partition

sudo dd if=/dev/zero of=/swapfile bs=1M count=512 status=progress
512 must be changed to the size you want (size of your RAM alike)

sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Finally, edit the fstab configuration to add an entry for the swap file:

sudo nano /etc/fstab


/swapfile none swap defaults 0 0

simple as this… to get it working for hibernation/suspend:

Add the resume option to grub kernel line
to the the UUID of the partition containing your /swapfile:

sudo findmnt -no UUID -T /swapfile

sudo nano /etc/default/grub

# GRUB boot loader configuration

GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="EndeavourOS"
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 resume=UUID=**put the uuid here** nowatchdog"

regenerating grub.cfg :vulcan_salute:
sudo grub-mkconfig -o /boot/grub/grub.cfg

https://discovery.endeavouros.com/storage-and-partitions/adding-swap-after-installation/2021/03/

2 Likes

I have 8G ram. I used 8000 which gave me 7.8G swap file should i go bigger?

should be fine

I actually use fallocate for creating mine, so that I can specify the size in GiB (Gibibytes), so that it’s truly 8. Easier than doing the maths for dd. :smiley:

fallocate -l 8Gib /swapfile

2 Likes

Besides the resume=UUID= a resume_offset value needs also to be added to the boot parameters when hibernating into a swapfile:

https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#Hibernation

1 Like

Okay i left it at 7.8G. I’m going to try it this way. Thanks!

be aware of files with holes :nerd_face:
https://jlk.fjfi.cvut.cz/arch/manpages/man/swapon.8#Files_with_holes

As if i don’t have enough to hurt my little brain! :rofl:

Edit: I think it’s beware of holes in your head?

Eh, it’s not hard. Do it a couple times in a VM and it’ll be simple as anything. Yeah, a few extra commands, but still easy. Just…not worth it to me since I moved to SSD’s.

IDK, simply giving a list of commands to blindly copy and paste doesn’t really help
Rick understand, which IMHO doesn’t really help him in the long run.

I understand EndeavourOS is not Arch, but a certain degree of encouragement to learn should be given for such a simple task.

1 . Create swap partition.
2 . Set resume kernel parameter to swap partition UUID.

IDK.