4

I use a single-board computer with Debian Buster (armhf) installed on an SD card. It has 1 GB of soldered RAM, which can't be increased. I have disabled Linux swap, which generally works fine.

But I have one application where I would like swap to be available. I want to have a swap partition on a USB hard drive, and only plug in the drive when I need to use the swap. This application requires this drive to be present, so adding the swap functionality would be pretty handy.

So far, so good.

But, I would like Debian to automatically detect and use the swap space when available, without user interaction.

Is there a good method to do this without the user calling a script? A reboot is acceptable, but I'd rather not require it. And if I simply put the swap partition in fstab, the boot fails if the drive isn't plugged in when booting.

Finally, I'm not worried about disabling the swap. The system will be shut down after the application is finished.

  • 1
    You should be able to add a udev rule that detects the event and runs a script to enable swap on the device. There are many questions on udev on this site and lots of people who know a lot more about it than I do, so I'll leave it at that. – NickD Jul 3 at 2:35
1

If you want to use an automounted fstab entry, you could add mount option nofail and a systemd timeout x-systemd.device-timeout=XX. This way no errors are reported and booting continues after the specified timeout setting. Otherwise the default timeout is 90s.

Example fstab entry with 3 seconds timeout:

/dev/sdb1   none    swap    nofail,sw,x-systemd.device-timeout=3s   0   0

To mount the swap partition after boot, you would have to create a udev rule or manually run swapon -a or create a script to start your application which checks for the device and runs swapon -a.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.