Cannot create swap files in Leap 15.5

Hello, I seem to be unable to create swapfiles in Leap 15.5
I need to do this because despite having disabled suspension and hibernation my VM keeps crashing in kernel panic when I leave it idle for too long. (Presumably it’s still suspending somehow, regardless.)
So I asked chatGPT (yes I know) to help me make a swapfile.

I followed the following steps:
1: sudo dd if=/dev/zero of=/swapfile8GB bs=1G count=8
2: sudo chmod 600 /swapfile8GB
3: sudo mkswap /swapfile8GB
4: sudo nano /etc/fstab
5: added the following line to the /etc/fstab file: /swapfile8GB none swap defaults 0 0
6: sudo swapon -a

I got the following output from my command prompt: swapon: /swapfile8GB: swapon failed: Invalid argument

So I tried something else, I added the UUID of the swapfile to the /etc/fstab file instead in the proper format, and did the command again. Got this message: swapon: cannot find the device for UUID=

So I tried something else, I copied the UUID, manually added the UUID to the file and added a label for good measure: mkswap -L swapfile8GB -U . Added this to the fstab file too with the label in tow in the correct way.
The time came for swapon -a, same error as before.

I have tied remaking the swap file, giving it different names, deleting it, doing it again and again and again, nothing worked. I catted out the file /proc/sys/vm/swappiness: “60”
According to chatGPT it should theoretically work. Despite theory, it does not.

I am at a loss, I could not find anything about this online, the only semi similar result I found was that if your Unix kernel has an older version that you can’t add swap files. But as far as I’m aware that’s not the case here.
I don’t know what else to do, chatGPT even said to ask the forums here because it could not help me any further.

I even tried turning it off and turning it back on again.

Hopefully someone in this forum has answers. Reinstalling the VM with a bigger swap partition is not an option, I just got it working in the way I wanted it to with all the software I needed. The thought of having to go through all of that again gives me a massive headache. This petty annoyance has also grown out of proportion, however.

Thanks in advance.

So that is the problem you need to solve, not follow “advice” of some AI. Configure serial console in your VM, capture console output when it crashes, it may give some hint what happens. Start new topic with appropriate subject.

By default openSUSE is using btrfs and there are restrictions on what files can be used as swap on btrfs. I am sure chatGPT should have known it.

I wasn’t following chatGPT’s advice, I only used it to help make the swap file itself. The reason I wanted a bigger swap file in the first place was an idea I got from reading this exact forum.

I won’t start a new topic with another subject because this remains relevant as well, I still cannot create a swap file when all the signs point towards having to be able to.

https://btrfs.readthedocs.io/en/latest/Swapfile.html

Yep:

erlangen:~ # btrfs filesystem mkswapfile --help
usage: btrfs filesystem mkswapfile <file>

    Create a new file that's suitable and formatted as a swapfile.

    Create a new file that's suitable and formatted as a swapfile. Default
    size is 2GiB, minimum size is 40KiB.

    -s|--size SIZE            create file of SIZE (accepting k/m/g/e/p suffix) 
    -U|--uuid UUID            specify UUID to use, or a special value: clear (all zeros), random, time (time-based
                              random) 
    
    Global options:
    -v|--verbose              increase output verbosity 
    -q|--quiet                print only errors 

erlangen:~ # 
***
1 Like

Hey, thanks for the quick reply, when trying the “mkswapfile” command I get this:

The instructions on this page worked! Amazing, thank you so much.

Running the command on infamous host erlangen:

erlangen:~ # btrfs filesystem mkswapfile -s1g /swap
create swapfile /swap size 1.00GiB (1073741824)
erlangen:~ # file /swap
/swap: Linux swap file, 4k page size, little endian, version 1, size 262143 pages, 0 bad pages, no label, UUID=df22dba8-f88d-4dbe-970c-fbc8173da958
erlangen:~ # 

More:

erlangen:~ # swapon /swap
erlangen:~ # free -h
               total        used        free      shared  buff/cache   available
Mem:            30Gi       4.3Gi        24Gi        97Mi       2.8Gi        26Gi
Swap:          1.0Gi          0B       1.0Gi
erlangen:~ # 
1 Like

And, what does chatGPT recommend if, you ask it to explain how to create a Swap File on a Btrfs file-system?

You did say swap file and not swap partition, so here is what I did.

Open YAST Software.
Search: zram
Install the three packages listed.

Open YAST
Open Services Manager
Scroll to the very bottom of the list once it populates
Highlight zramswap
Click Start Mode and change to On Boot
Click Start

I have a working swap file equal to my RAM size. I can see it when I open lsblk