Sample Header Ad - 728x90

Alpine Linux in Raspberry Pi not activating swap partition on boot

2 votes
2 answers
1142 views
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.
lang-sh
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.
lang-sh
UUID= 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.
Asked by user578535
Jul 8, 2023, 06:59 PM
Last activity: Jan 26, 2025, 04:42 AM