5

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
  • 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. Commented Jul 3, 2019 at 2:35

1 Answer 1

4

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.