Adding a swapfile to my too small swap partition results in impossibility to hibernate

Dear manjaro-users,

since my installation of Manjaro, it seems that I have done a bad manual partition since I cannot hibernate my computer (hibernating my computer is something important and useful for me). Indeed I have created a swap partition with only 4GB of swap, which is less than my ca. 8 GB of ram... If it is possible, I would like to have the possibility to hibernate whenever I want. i.e. without clothing any opened application. Since I have no non attributed space on my two hard disk drives (SSD and HDD), I thought that the easiest way would be to create a swapfile. It is then what I have done by following these listed steps on the Manjaro wiki. Now, I have rebooted and I see that I cannot hibernate any more, just after the boot or when a few application are opened, which was possible before adding this swap file. Does anyone have an idea how to solve it? I do not know if it is linked with the fact that my swap partition is to be found on the HDD disk whereas the swap file is maybe (since I created it as /swapfile) on the SSD disk... Since my swap partition is on the HDD disk, should I necessarily create a swap file on the HDD disk too? It would be more convenient to have it on the SSD one, since there is more empty space.
Thanks a lot in advance!!
Here you can find some more information:

inxi -Fxzc0 --no-host
  Kernel: 4.19.121-1-MANJARO x86_64 bits: 64 compiler: gcc v: 9.3.0 
  Desktop: Xfce 4.14.2 Distro: Manjaro Linux 
  Type: Laptop System: Notebook product: N650DU v: N/A serial: <filter> 
  Mobo: Notebook model: N650DU serial: <filter> UEFI: American Megatrends 
  v: 5.12 date: 02/26/2018 
  ID-1: BAT0 charge: 49.3 Wh condition: 49.3/62.2 Wh (79%) 
  model: Notebook BAT status: Full 
  Topology: Quad Core model: Intel Core i5-7500T bits: 64 type: MCP 
  arch: Kaby Lake rev: 9 L2 cache: 6144 KiB 
  flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx 
  bogomips: 21696 
  Speed: 1600 MHz min/max: 800/3300 MHz Core speeds (MHz): 1: 1600 2: 1601 
  3: 1600 4: 1600 
  Device-1: Intel HD Graphics 630 vendor: CLEVO/KAPOK driver: i915 v: kernel 
  bus ID: 00:02.0 
  Display: x11 server: 1.20.8 driver: intel unloaded: modesetting 
  resolution: <xdpyinfo missing> 
  OpenGL: renderer: Mesa Intel HD Graphics 630 (KBL GT2) v: 4.6 Mesa 20.0.6 
  direct render: Yes 
  Device-1: Intel 100 Series/C230 Series Family HD Audio vendor: CLEVO/KAPOK 
  driver: snd_hda_intel v: kernel bus ID: 00:1f.3 
  Sound Server: ALSA v: k4.19.121-1-MANJARO 
  Device-1: Intel Wireless 8265 / 8275 driver: iwlwifi v: kernel port: f040 
  bus ID: 01:00.0 
  IF: wlp1s0 state: up mac: <filter> 
  Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet 
  vendor: CLEVO/KAPOK driver: r8168 v: 8.048.02-NAPI port: e000 
  bus ID: 05:00.0 
  IF: enp5s0 state: down mac: <filter> 
  Local Storage: total: 1.14 TiB used: 549.24 GiB (47.2%) 
  ID-1: /dev/nvme0n1 vendor: Samsung model: SSD 960 EVO 250GB 
  size: 232.89 GiB 
  ID-2: /dev/sda vendor: Seagate model: ST1000LM048-2E7172 size: 931.51 GiB 
  ID-1: / size: 227.24 GiB used: 29.53 GiB (13.0%) fs: ext4 
  dev: /dev/nvme0n1p2 
  ID-2: /home size: 911.95 GiB used: 519.70 GiB (57.0%) fs: ext4 
  dev: /dev/sda2 
  ID-3: swap-1 size: 4.00 GiB used: 0 KiB (0.0%) fs: swap dev: /dev/sda1 
  System Temperatures: cpu: 63.5 C mobo: N/A 
  Fan Speeds (RPM): N/A 
  Processes: 178 Uptime: 10m Memory: 7.71 GiB used: 2.33 GiB (30.3%) 
  Init: systemd Compilers: gcc: 9.3.0 Shell: bash v: 5.0.16 inxi: 3.0.37
inxi -m
  RAM: total: 7.71 GiB used: 2.77 GiB (35.9%) 
free -h
              total        used        free      shared  buff/cache   available
Mem:          7,7Gi       2,8Gi       2,5Gi       316Mi       2,5Gi       4,4Gi
Swap:         8,0Gi          0B       8,0Gi
/swapfile file        4G   0B   -2
/dev/sda1 partition   4G   0B   -3
1 Like

I doubt if hibernation is possible using a combined swap partition and swapfile. I have never come across such a case. Since you say that you can't assign more space to your swap partition, I would suggest to expand your swapfile a bit more and delete your current swap partition. You've got a lot of space in your / :

ID-1: / size: 227.24 GiB used: 29.53 GiB (13.0%)

On the other hand, from what I understand the content of RAM will be compressed before written to the "resume" device so you might still hibernate successfully with a resume device which is smaller than your RAM.



Thanks a lot for your answer @Marte!

Could someone please confirm this doubt?

Reading about swap, it seems to me better to have a swap partition than a swap file. As you say, I have a lot of space available on my root partition. Removing 8 Go from the root partition, in order to create a swap partition would be too dangerous, wouldn't it?

I am not sure to have understood what you have meant and what I can read in the Arch wiki but before adding this swap file, I was able to hibernate after clothing some applications in order to have less than 4 Go used by my RAM.
Thanks again!

If it were me I would eliminate the swap partition, grow the resultant freespace in '/' and then add a swap file of 8 gigs.

1 Like

Thanks for your advice!

No, not really.

Since you cannot expand your currently existent swap partition, you could opt for either of the following options:

  1. expand your swapfile, run the relevant commands to enable hibernation from swapfile (see Manjaro and/or Arch wiki); Delete youe swap partition.

  2. From a live usb, shrink your / partition with 8 GB (the size of your RAM). Create a new swap partition. Make the necessary adjustment to fstab. Boot back to your installed system and make the relevant modifications to enable hibernation fro swap partition.

1 Like

For partition manipulation, you can Gparted:

No need actually as Gparted is part of the live iso. For KDE it is KDE partition Manager.

Thanks again for your nice answer!
Reading your answer, @c00ter's one and some more documentation (i.a. Destination Linux #172 about swap), I am inclined to chose this first solution.
Since I am not an expert at all, I would launch the following command lines:

sudo swapoff /swapfile
rm /swapfile
sudo !!
sudo sudo fallocate -l 12G /swapfile
sudo mkswap /swapfile
sudo chmod 600 /swapfile
sudo swapon /swapfile

Since I have already launched sudo bash -c "echo /swapfile none swap defaults 0 0 >> /etc/fstab" for my actual swapfile, it seems unnecessary to launch it again, if I can still find this information in /etc/fstab.

The Arch wiki documentation regarding hibernation is quite hard to follow and to understand... You spoke about the Manjaro English wiki but I can just find a page relating to the swap but nothing relating to the enabling hibernation from a swapfile. On the French Manjaro wiki, I can find a page updated in 2013 relating to this topic (so I am not sure that it is still relevant...), but it deals with swap partition and hibernation and not with swap file and hibernation.

Following this Ubuntu documentation, it seems that 12 GB of RAM would be better to hibernate my 8 GB computer. Do you agree with that?

Sorry for my beginner's questions and fears!

Thanks again!

My opinion: swap is hardly used during regular work. If your laptop starts swapping while you are working it will become very, very slow. The main purpose of swap these days is hibernation. And for that it doesnt matter if it is a swap file or a swap partition. I personally only use swapfiles on my laptops because they are a lot more flexible.

Therefor I second @Marte's suggestion: remove your swap partition and go for a bigger swap file.

1 Like

You do not need 12 GB swap if you have 8 GB RAM. 8 GB is more than sufficient because the RAM is compressed during hibernation.

Once the swap file is created you need to tell the kernel where to look for the hibernation swap. You do this with some grub command line options. You need to add "resume=" and "resume_offset=".


You are of course right. There is apparently no page in Manjaro Wiki that deals with enabling hibernation with swapfile. I was mistaken.

Honestly I think you could hibernate comfortably with a swapfile with the size of your RAM. Here is what Arch Wiki says about the size of swap partition/file:

About swap partition/file size

Even if your swap partition is smaller than RAM, you still have a big chance of hibernating successfully. According to kernel documentation:

/sys/power/image_size controls the size of the image created by the suspend-to-disk mechanism. It can be written a string representing a non-negative integer that will be used as an upper limit of the image size, in bytes. The suspend-to-disk mechanism will do its best to ensure the image size will not exceed that number. However, if this turns out to be impossible, it will try to suspend anyway using the smallest image possible. In particular, if "0" is written to this file, the suspend image will be as small as possible. Reading from this file will display the current image size limit, which is set to 2/5 of available RAM by default.

You may either decrease the value of /sys/power/image_size to make the suspend image as small as possible (for small swap partitions), or increase it to possibly speed up the hibernation process. For systems with a large amount of RAM, smaller values may drastically increase the speed of resuming a hibernating system.

At any rate the choice is yours.

Now with all that said, you could follow the steps below:

First we disable all swap spaces:

  • sudo swapoff -a

The we run the following commands:

  • sudo fallocate -l XG /swapfile (replace X with size of your choice, not smaller than 8)

  • sudo chmod 600 /swapfile

  • sudo mkswap /swapfile

  • sudo swapon /swapfile

  • swapon --show

Here we would need to add an entry for the swapfile in the /etc/fstab but you said above that you already have one.

And since you have had a working hibernation, I assume you have already added the resume hook to your /etc/mkinitcpio.config.

Now you would need to edit /etc/default/grub and add two kernel parameters, namely resume=UUID and resume_offset to the GRUB_CMDLINE_LINUX_DEFAULT line.

It should look like:

GRUB_CMDLINE_LINUX_DEFAULT="apparmor=1 security=apparmor resume=UUID=VALUE1 resume_offset=VALUE2 udev.log_priority=3"

Replace VALUE1 with the output of

  • findmnt / -o UUID -n

and VALUE2 with the output of :

  • sudo filefrag -v /swapfile|awk 'NR==4{gsub(/\./,"");print $4;}'

Save the file.


  • sudo update-grub


  • sudo mkinitcpio -P

for rebuilding your initramfs. I guess that is about it.

1 Like

1 Like

Thanks a lot to you all @mbod, @c00ter and above all @Marte ! I have followed your very precise instructions @Marte until editing `/etc/default/grub. Indeed, I wanted to delete using Gparted my swap partition and I see that I can lose data. Since I have "swappoffed" this partition, is there any risk to lose data that are store on the same hard disk, namely from my home repository?

From your inxi:

  ID-1: / size: 227.24 GiB used: 29.53 GiB (13.0%) fs: ext4 
  dev: /dev/nvme0n1p2 
  ID-2: /home size: 911.95 GiB used: 519.70 GiB (57.0%) fs: ext4 
  dev: /dev/sda2 
  ID-3: swap-1 size: 4.00 GiB used: 0 KiB (0.0%) fs: swap dev: /dev/sda1

You can use Gparted to delete the swap partition. Just be careful what partition you choose. Your home won't be touched by this operation.

Could you post an screenshot of the Gparted window showing the disk in question?

Also when you have finished setting up your swapfile and hibernation, please post the output of the following command to double-check:

cat /proc/cmdline

1 Like

Thanks again for your answer, quickly made!!

Here is the screenshot before confirming the deleting of /dev/sda1 where I had partitioned 4 GB swap:

Do you still that is safe deleting this partition?

Many thanks again!

1 Like

That is a generic warning. It looks that it is already deleted since it says "non alloué" . If so just leave it at that.

Sorry, I missed this! Yes, go ahead and click "Appliquer"!

You would need to remove its entry from your/etc/fstab, if you haven't already.

1 Like

Just a word of caution:
I wouldn't bother to expand the home partiton into that un-allocated space. This operation would involve moving a vast amount of data and is potentioally prone to data loss/corruption.

1 Like

Thanks!! I have deleted the swap partition.
I have removed the partition entry in /etc/fstab but I am wondering if it is working when no UUID before the swap file is indicated. The bottom part of the /etc/fstab file appears now like this (with VALUE X Y Z reimplaced by their exacts numbers):

# <file system>             <mount point>  <type>  <options>  <dump>  <pass>
UUID=VALUE_X                            /boot/efi      vfat    defaults,noatime 0 2
UUID=VALUE_Y /              ext4    defaults,noatime 0 1
UUID=VALUE_Z /home          ext4    defaults,noatime 0 2
/swapfile none swap defaults 0 0

Regarding the /etc/default/grub , I had at the beginning of the line GRUB_CMDLINE_LINUX_DEFAULT quiet , which should mean that something is not showed if I remember correctly something that I have read somewhere (but I am not sure). So I have reimplaced the value after resume=UUID= by following your nice command line

and I have let quiet at the beginning of this line and I have added a resume_offset line that was absent when I was using my swap partition. It appears now like this (with VALUE_1 and 2 reimplaced by their respective numbers).
GRUB_CMDLINE_LINUX_DEFAULT="quiet resume=UUID=VALUE_1 resume_offset=VALUE_2 "

Does it seem to you to be ok like this?

Thanks again and thanks for your patience!

Forum kindly sponsored by