Alpine Linux in Raspberry Pi not activating swap partition on boot

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.

        after clock root
        before localmount
        keyword -docker -jail -lxc -openvz -prefix -systemd-nspawn -vserver

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

        ebegin "Deactivating swap devices"
        case "$RC_UNAME" in
                NetBSD|OpenBSD) swapctl -U -t noblk >/dev/null;;
                *)              swapoff -a >/dev/null;;
        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.

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…

Answered By: Manan Intindinichu
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.