I created a swap-file on my old notebook: but this swapfile is not persistent - it vanished after switching off

I have a pretty old pc that I havent used in a few years. Currently runs windows xp but Ive been thinking of putting linux on it to squeeze more life out of. it is a Thinkpad TT520 that it has 4gb of ram,

hmm all i know untill now - is to go and create a swap-file:

well - Swap files are a form of virtual memory management and serve as a fallback mechanism. The swap space has significantly slower access times than RAM. Heavy reliance on swap files leads to performance losses.

my problem is - that i went through the whole process _ but believe it or not - after switching off and on again - all is lost!??!

question: why does this happen!?

here is what i have done: The free command with the -h tag shows the total, available, and used swap space in a human-readable format. For example:

The /proc/meminfo file shows the total, free, and used swap space in kilobytes:

cat /proc/meminfo | grep Swap

The /proc/swaps file shows active swap devices:

cat /proc/swaps

The swapon command with the --show tag displays swap information:

swapon --show

How to View a Swap File on Linux

To view the contents of a swap file, use the strings command and save the contents to another file. For example:

sudo strings <swap file path> > <output file path>.txt

How can i create a new Swap File on my Linux notebook?

well i think that creating a swap file on Linux is a pretty simple process.

That said i think i have to do like so: to make a new swap file on a Linux system.

1. i have to create some kind of Storage File

therefore i have to make use the dd tool to create a new storage file. For example:

like so:

sudo dd if=/dev/zero of=/swapfile bs=2MB count=1024

The command contains the following parameters:

if=/dev/zero is the input file. The /dev/zero file is a kind of a very special file that returns as many (awful many) null characters as a read operation requests.

of=/swapfile is the output swap storage file. The common practice is to place the file in the root directory.

The bs parameter is the block size.: it is damned important

The count parameter determines how many blocks to copy. I often use this command.

The total data size is bs*count, which in this case is 2GB.

and now its pretty important to set the Swap Permissions; but how!?

can i set the swap file permissions for the swap file to the user root read and write.

well can i do make use the following command:

sudo chmod 600 /swapfile

The command shows - afaik no output. Check the permissions with the following:

ls / | grep swapfile

swap file permissions

how to do this!? well how to changing the permissions to root helps avoid accidental overwriting.

  1. Set Up Swap Area

The swap file requires formatting the reserved file size into a swap area. Use the mkswap command to format the swap file:

sudo mkswap /swapfile

The command formats the swap file into a swap space and outputs the size, label, and UUID.

4. Enable Swap

To enable the swap area for use, run the following command:

sudo swapon /swapfile

Verify the swap is active with the following command:

swapon --show

well - my big big problem is - that this is not pesisten - if i switch off the notebook and on again

all is lost - the swap file is not active any more

Question; why is this so!? this behaviour is crazy

btw: can anybody tell me the difference between the swap-concepts - the swapfile and the ZRAM as SWAP-Device - i never have used it

https://wiki.archlinux.org/title/swap#Swap_file_creation

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

/swapfile none swap defaults 0 0

Use a text editor to add the above line to your /etc/fstab file.

2 Likes

hello dear stagger lee - many thanks i will do so…
awesome - i am happy to be part of this great forum

have a great day

I know you’ve asked a LOT of questions historically. Make sure you add the complete terminal input/output.

Saying: The swapon command with --show tag displays swap information.

You don’t have to tell us that if you just post the output of swapon --show and then output. It’s self-explanitory, AND much more informative since saying you have output and showing us the output are vastly different. And, we still can’t actually verify what/if you have proper swap setup.

It’s much much easier for someone to help you if you give us information.

1 Like

hello and good day dear fbodymechanic

awesme - first of all i want to thank you.

EOS is not only the most impressive distro - in technical sight but also the most impressive - if we look at the commmuity.

in fact: i am really happy to be here.

that said - i now will digg deeper and have a closer look at all these things

i go and create a swapfile - edit the etx config and report all the things and findings here

have a great day

1 Like

as mentioned before - the created swap-file is not “pesistent” in other words
switching of the computer and on - again - and all is vanished

see below how i did it so far - and yes: i guess i have to do changes in the

ext/fstab

[martin@martinkaspar-4243f53 ~]$ free -h
              gesamt       benutzt     frei      gemns.  Puffer/Cache verfĂĽgbar
Speicher:      3,7Gi       2,7Gi       655Mi       243Mi       797Mi       991Mi
Swap:             0B          0B          0B
[martin@martinkaspar-4243f53 ~]$ cat /proc/meminfo | grep Swap
SwapCached:            0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
[martin@martinkaspar-4243f53 ~]$ 
cat /proc/swaps
Filename                                Type            Size            Used            Priority
[martin@martinkaspar-4243f53 ~]$ swapon --show
[martin@martinkaspar-4243f53 ~]$ sudo dd if=/dev/zero of=/swapfile bs=2MB count=1024
[sudo] Passwort fĂĽr martin: 
sudo dd if=/dev/zero of=/swapfile bs=2MB count=1024



1024+0 Datensätze ein           
1024+0 Datensätze aus
2048000000 Bytes (2,0 GB, 1,9 GiB) kopiert, 32,7138 s, 62,6 MB/s
[martin@martinkaspar-4243f53 ~]$ sudo chmod 600 /swapfile
[martin@martinkaspar-4243f53 ~]$ ls / | grep-swapfile
bash: grep-swapfile: Kommando nicht gefunden.
[martin@martinkaspar-4243f53 ~]$ sudo mkswap /swapfile
Auslagerungsbereich Version 1 wird angelegt, Größe = 1,9 GiB (2047995904 Bytes)
keine Bezeichnung, UUID=986259ba-e4a1-421f-9916-cbf03cffbf46
[martin@martinkaspar-4243f53 ~]$ sudo swapon /swapfile
[martin@martinkaspar-4243f53 ~]$ swapon --show
NAME      TYPE SIZE USED PRIO
/swapfile file 1,9G   0B   -2
[martin@martinkaspar-4243f53 ~]$

see above how i did it so far - and yes: i guess i have to do changes in the

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

/swapfile none swap defaults 0 0

as you adviced me: i will do so

Use a text editor to add the above line to your /etc/fstab file.

will do so now

many thanks

good day -

wekk tried to find /etc/fstab but there is no such folder and file

nhmmm

see the actual - status in contant:


[martin@martinkaspar-4243f53 ~]$ free -h
              gesamt       benutzt     frei      gemns.  Puffer/Cache verfĂĽgbar
Speicher:      3,7Gi       2,7Gi       655Mi       243Mi       797Mi       991Mi
Swap:             0B          0B          0B
[martin@martinkaspar-4243f53 ~]$ cat /proc/meminfo | grep Swap
SwapCached:            0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
[martin@martinkaspar-4243f53 ~]$ 
cat /proc/swaps
Filename                                Type            Size            Used            Priority
[martin@martinkaspar-4243f53 ~]$ swapon --show
[martin@martinkaspar-4243f53 ~]$ sudo dd if=/dev/zero of=/swapfile bs=2MB count=1024
[sudo] Passwort fĂĽr martin: 
sudo dd if=/dev/zero of=/swapfile bs=2MB count=1024



1024+0 Datensätze ein           
1024+0 Datensätze aus
2048000000 Bytes (2,0 GB, 1,9 GiB) kopiert, 32,7138 s, 62,6 MB/s
[martin@martinkaspar-4243f53 ~]$ sudo chmod 600 /swapfile
[martin@martinkaspar-4243f53 ~]$ ls / | grep-swapfile
bash: grep-swapfile: Kommando nicht gefunden.
[martin@martinkaspar-4243f53 ~]$ sudo mkswap /swapfile
Auslagerungsbereich Version 1 wird angelegt, Größe = 1,9 GiB (2047995904 Bytes)
keine Bezeichnung, UUID=986259ba-e4a1-421f-9916-cbf03cffbf46
[martin@martinkaspar-4243f53 ~]$ sudo swapon /swapfile
[martin@martinkaspar-4243f53 ~]$ swapon --show
NAME      TYPE SIZE USED PRIO
/swapfile file 1,9G   0B   -2
[martin@martinkaspar-4243f53 ~]$ swapon --show
NAME      TYPE SIZE USED PRIO
/swapfile file 1,9G 435M   -2
[martin@martinkaspar-4243f53 ~]$ ^C
[martin@martinkaspar-4243f53 ~]$ swapon --show

what to do now… - i need to do this.

entry for the swap file:

/swapfile none swap defaults 0 0

as you adviced me: i will do so

Use a text editor to add the above line to your /etc/fstab file.

look forward to hear from you

see how i have added this line in the nano editor

additional: - how i did it so far:

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

https://wiki.archlinux.org/title/Fstab#Usage

Well open the file in a text editor? Or better use a terminal editor like nano/vim etc:

sudo nano /etc/fstab

well - whats the easiest way to edit the fstab-file accordingly!?

Use whatever editor you want.

The easiest editor is one that you’re familiar with.

Why did you put a “u” at the beginning of the line?

If editing a file is too difficult for you, just paste this command in a terminal:

echo '/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstab

2 Likes