Wie erstelle ich ein /swap subvolume nachträglich in Btrfs?

Ich habe vor, auf einem Rechner, der mit Btrfs läuft, nachträglich eine swapfile zu erstellen.
Ich verwende also die mir bisher bekannten Befehle dafür:

sudo dd if=/dev/zero of=/swap/swapfile bs=1M count=8196 status=progress
sudo chmod 600 /swap/swapfile
sudo mkswap /swap/swapfile
sudo swapon /swap/swapfile

Eintrag in die fstab:

/swap/swapfile none swap defaults 0 0

Wie mache ich das, wenn ich swap als subvolume haben möchte?

“Contradictio in adjecto”?

swapfile versus subvolume?

Ich weiß es nicht… :v:

Hm, Widerspruch … immerhin wird bei der automatischen Installation mit Btrfs und swapfile selbige als Subvolume erstellt. Musss also einen Sinn haben (weniger Fragmentierung?). Da ich aber das bestehende manulle Partitionsschema nicht verändern will, fällt die automatische Installation aus.

Verstehe jetzt. :wink:

Du solltest @joekamprad, oder @dalto fragen, die wissen das bestimmt. :v:

1 Like

Na vllt. verirrt sich ja einer von beiden hierher … :wink:

:vulcan_salute:

2 Likes

Bestimmt. :wink:

If you are using btrfs, it is /swap that should be a subvolume. You then put the swapfile inside that subvolume.

If /swap isn’t already a subvolume, you should create one there first.

The reason you use a separate subvolume for swap is that you cannot activate a swapfile on a subvolume that has snapshots. That is why you use a separate subvolume.

As a side note, you no longer need to follow all the above steps. If /swap is a subvolume, you can do this instead:

sudo btrfs filesystem mkswapfile --size 8G /swap/swapfile
sudo swapon swapfile
2 Likes

Thanks dalto, but what do I enter in the fstab then?

The same thing as you have in your first post. That command just creates the file for you in one step.

Of course, if you don’t have a swap subvolume, you will need to deal with that as well.

This entry is not for a subvolume, something is missing, isn’t it?

/swap/swapfile none swap defaults 0 0

It depends how you create the subvolume at at /swap.

If you use a nested subvolume, no entry in /etc/fstab is needed.

If you create a flat subvolume, you would need to add an entry like you do with all your other subvolumes.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.