2

Probably this is a really naïve question, but I can’t make this work by trying the methods I’ve found in the existing documentation or in other solutions.

I have Alpine Linux installed on a Raspberry Pi, which SD card is formatted to have the usual boot partition and an ext4 to host /, I added a swap partition since my Pi has not much RAM. The issue is that the swap partition does not activates at boot.

As far as I’m aware, the conventional method to configure a dedicated swap partition, is to declare it on the /etc/fstab file. This does not work, so my other approach was to try making a script in the /etc/init.d folder to force its activation. To my surprise, an init.d file already exists in this build to do exactly that, which is the /etc/init.d/swap, which reads as follows.

depend()
{
        after clock root
        before localmount
        keyword -docker -jail -lxc -openvz -prefix -systemd-nspawn -vserver
}

start()
{
        ebegin "Activating swap devices"
        case "$RC_UNAME" in
                NetBSD|OpenBSD) swapctl -A -t noblk >/dev/null;;
                *)              swapon -a >/dev/null;;
        esac
        eend 0 # If swapon has nothing todo it errors, so always return 0
}

stop()
{
        ebegin "Deactivating swap devices"
        case "$RC_UNAME" in
                NetBSD|OpenBSD) swapctl -U -t noblk >/dev/null;;
                *)              swapoff -a >/dev/null;;
        esac
        eend 0
}

Somehow, this does not run properly, neither the /etc/init.d/swap.apk-new which has the exact same contents as /etc/init.d/swap.

I know that the /etc/fstab is properly configured as running swapon -a >/dev/null activates the swap partition the intended way! Yet Alpine refuses to do this at boot despite being declared already…

Am I missing something? I know I can activate the swap manually each time I turn on the device, but I’m sure the system should do it automatically on boot.

If it serves of any help, the line I added in /etc/fstab reads as follows.

UUID=<my partition UUID number> none swap defaults 0 0

And swapon -a recognizes the partition. This Alpine build was made using the sys install, and its specs are the followings

OS:     Alpine Linux v3.18 aarch64
Host:   Raspberry Pi 3 Model B Rev 1.2
Kernel: 6.1.37-0-rpi

Thanks in advance.

2 Answers 2

3

Doing something completely different I ran into the solution, and it works! I feel extremely silly since it was something as trivial as just declare this in the terminal:

rc-update add swap boot

And now the swap activates as intended!

I’ll just leave this in case anyone runs into a similar issue I guess…

1

swapon needs to be run besides configuration in /etc/fstab. Linux init system like systemd (Debian/Ubuntu/Fedora/RHEL) or OpenRC (Gentoo/Alpine) is responsible for it.

In OpenRC, a script in /etc/init.d/ defines a service, but not necessary loads it at boot.

What you missed is starting the service manually with rc-service swap start or telling OpenRC to start it at boot with rc-update add swap.

Additional notes:

  1. When using rc-update add, you can either add to default runlevel, or boot, which is called by default anyway.
  2. You need the swap line in /etc/fstab so swapon -a in /etc/init.d/swap knows how to mount your swap partition/file.

More information on swap is at Alpine Wiki.

You must log in to answer this question.