Using swap files instead of swap partitions, how to create a swapfile?

I have installed opensuse tumbleweed to an external drive attached through the usb port, and yast, as always, was really good at that, no problems. But… what happens if I use a 16GB system to install opensuse to the external drive, but then I want to use that system on a system with less RAM? Then, I can’t use hibernation because the swap partition that opensuse wants to create is not big enough. That’s why there should be a swap file, not a swap partition, and the swap file will be encrypted if it is in an encrypted partition. But now that I couldn’t set up a swap partition, or didn’t set one up, now I want to enable hibernation, but want to use a swap file. I am asking that swap files be the standard way of hibernating, and that it be included in when installing opensuse.

Answering the question in your thread title:
Just create a file of a certain size (without holes). the man page suggests using dd e.g.
dd if=/dev/zero of=/swapfile bs=1024 count=1024
for 1Gb (I hope my calculating is correct, but better check yourself).
And then start using is with
swapon /swapfile

I did not test this, but I hope it is a hint enough to read the man pages and test yourself.

About the more or less hidden last sentence in your post: I am not sure that hibernation is able to use a (swap) file for storage. As far as I understand it, it is configured using the kernel parameter resume = and I doubt that that may point to a file inside a probably not mounted file system of unknown type at that point in the booting sequence.

That “just” will not work on btrfs. Try to google for “btrfs swap file”.

This parameter can point to device + offset, where offset corresponds to the physical location of the swap file. Again, on btrfs there is no public API to get physical location of file, so hibernation on swap file on btrfs is rather nontrivial (albeit possible) to setup.

Just found this: Power management/Suspend and hibernate - ArchWiki

It has some pointers on how to use a swap file for hibernation. E.g. it explains how to tell the kernel where the file starts inside the block device (that contains the file system that contains the swap file).

That’s all great, but maybe you could add something to Settings, or maybe a prompt in YAST to ask me if I want to add a hibernation file or swap file? maybe next time I do a system upgrade/update?

Sorry, but it seems that you do not quite understand this forum. It is a forum of openSUSE users that try to help other openSUSE users. We can not “add something to YaST”.

BTW, IMHO using swap files is only done by a minority of people. Most here will not even be aware that swapping to file is possible, let alone that they want a new confusing feature in the Installer and/or YaST.

Hi,
thanks for your response.

In terms of understanding this forum, I thought that we are required to post first to these forums instead of posting to github. Honestly, I would have gone straight to github every single time, as I am looking for changes to opensuse, including problems and feature requests.

Actually, now, looking at the opensuse repositories, it’s nuts. How many frickin repositories do you need? There are like 600 repositories there. how nuts is that? Honestly, it makes me just want to stick my issues in any old repository and you all can figure out the appropriate place to place the issues.

I just want to say thank you, though, to you and the others who help others. That has been really nice. But I want to post somewhere where my voice is heard. if the developers are not looking through these forums, then I might as well be posting into the air.

@as-muncher you can also fix/implement features yourself? Oh and hibernation is about to stop working anyway…so a moot point.

Hibernation is about to stop working, on purpose? how come?
One reason why I started using opensuse is mostly because of YAST. I love YAST, for the most part. So many other distributions are stupid when it comes to trying to install on an external hard drive.

@as-muncher if you have secure boot enabled, yes for the kernel lock down patches suspend/hibernation will not work.

As a Tumbleweed user you should be following the Factory Mailing List…
https://lists.opensuse.org/archives/list/factory@lists.opensuse.org/thread/APEWGMWSEABQ5ZFGZ2I5M3MWJERZ4K7I/
https://bugzilla.opensuse.org/show_bug.cgi?id=1208766

@as-muncher might want to give MicroOS desktop a whirl? You can zcat the image onto the USB device, run a combustion script to configure and done… oh and no swap file either…

I was using opensuse leap for a while, then figured maybe to start using tumbleweed. If i use YAST, will YAST update my tumbleweed system to MicroOS, saving all my personal files?

I just want to use a system that will work. I would be using linux mint, but mint and ubuntu can’t figure out well how to install to an external hard drive. Yast does it easily. and I love yast for that reason. I’ve been thinking of switching to gentoo, but that means reading the manual, watching a bunch of youtube videos on how to install.

@as-muncher not possible, MicroOS is transaction system… but it does have images to pop onto an external device with xzcat…

xzcat openSUSE-MicroOS.x86_64-SelfInstall.raw.xz | dd bs=4M of=/dev/sdc iflag=fullblock oflag=direct

I used combustion on another USB device to run/configure the system (portable minecraft server).