1

I was told in response to my question that the kernel uses files without the help of the filesystem - once a file is located the kernel just uses its location on the disk.

The example was an empty mountpoint (directory) where a file is located which the kernel uses as swap. After some time an external HDD gets mounted into this mountpoint. On this external HDD there is also a swapfile in the root directory. So, both files have the same path /mountpoint/swapfile.

My question is how to swapoff /file the first file. To be clear again: swapoff /mountpoint/swapfile will not work since this is the second file (after mount) which is not used by the kernel at that moment. At least I would suspect this.

I want to swapoff a file that is not visible in my filesystem.

(Yes, there are probably other solutions but I am curious about this.)

bomben
  • 272

1 Answers1

1

you can identify the swap device/file you want to disable by its swap area UUID.

First list UUIDs of all swap areas:

$sudo swapon --show=SIZE,NAME,UUID -v
 SIZE NAME          UUID
1023M /dev/sda5     af72b528-c4fe-4dfe-8a1b-82e4d2d46d2a
1020K /tmp/testswap 32149ab7-bc18-4aef-872c-7b70ce144572

Then find the file you are after (testswap in my case) and disable it as follows:

$sudo swapoff UUID=32149ab7-bc18-4aef-872c-7b70ce144572

Verify that it is no longer active:

$ sudo swapon --show=SIZE,NAME,UUID -v
 SIZE NAME      UUID
1023M /dev/sda5 af72b528-c4fe-4dfe-8a1b-82e4d2d46d2a
Eradian
  • 86