🍒Alpine Linux

It’s quite simple!

radxa-e20c:~# uname -a
Linux radxa-e20c 6.1.75-vendor-rk35xx #1 SMP Mon Sep  2 13:12:21 UTC 2024 aarch64 Linux
radxa-e20c:~# cat /etc/motd
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <https://wiki.alpinelinux.org/>.

You can setup the system with the command: setup-alpine

You may change this message by editing /etc/motd.
radxa-e20c:~# pstree
init-+-beszel-agent---6*[{beszel-agent}]
     |-crond
     |-dropbear-+-dropbear
     |          `-dropbear---sh---pstree
     |-3*[getty]
     |-ntpd
     |-syslogd
     `-udhcpc
radxa-e20c:~# free -m
              total        used        free      shared  buff/cache   available
Mem:           3922         100        3752           0          70        3785
Swap:             0           0           0

🤔️Why?

I’m running Armbian for a very long time on SBCs, but what I don’t like is the size of the image, and also it has some dependencies(tools/scripts) I don’t need. I like the os simple as possible. So I’m trying to build a Alpine Linux for radxa e20c.

  • 256M Armbian_community_25.5.0-trunk.4_Radxa-e20c_bookworm_vendor_6.1.99_minimal.img.xz
  • 1.4G Armbian_community_25.5.0-trunk.4_Radxa-e20c_bookworm_vendor_6.1.99_minimal.img

⚙️Specs

  • Rockchip RK3528A, Quad-core Arm Cortex®-A53 @ 2.0GHz
  • 2GB LPDDR4
  • No Onboard eMMC version/1x microSD Card Slot
  • 1x USB Type-C for Debug and Data
  • 2x Gigabit Ethernet Ports

đź’ˇHow

Recipes

  • linux-image-vendor-rk35xx_24.11.3_arm64.deb

    • idbloader.img
    • u-boot.itb
  • linux-image-vendor-rk35xx_24.11.3_arm64.deb

    • kernel
    • kernel modules
  • alpine-minirootfs-3.21.0-aarch64.tar.gz

Build

Sets up GPT partition table with 128MB FAT32 boot partition and remaining space as ext4 root partition.

fallocate -l 512M alpine.img
sudo parted alpine.img mklabel gpt
sudo parted alpine.img mkpart boot fat32 16.8M 144.8M
sudo parted alpine.img set 1 boot on
sudo parted alpine.img mkpart rootfs ext4 144.8M 100%

This writes the U-Boot bootloader components (idbloader and u-boot.itb) to specific locations in the image file. These are necessary for the board to boot.

sudo dd if=linux-u-boot-vendor-radxa-e20c/idbloader.img of=alpine.img bs=512 seek=64 conv=notrunc
sudo dd if=linux-u-boot-vendor-radxa-e20c/u-boot.itb of=alpine.img bs=512 seek=16384 conv=notrunc

Creates FAT32/ext4 filesystems on partitions, disables reserved blocks on rootfs, and mounts partitions for setup.

sudo losetup -f alpine.img
sudo partx -a /dev/loop0

sudo mkfs.vfat /dev/loop0p1
sudo mkfs.ext4 /dev/loop0p2
sudo tune2fs -m0 /dev/loop0p2

mkdir mnt
sudo mount /dev/loop0p2 mnt/
sudo mkdir -p mnt/boot/dtbs mnt/usr
sudo mount /dev/loop0p1 mnt/boot/

Extracts and deploys kernel files, device tree blob, and associated libraries to appropriate locations.

dpkg -x linux-image-vendor-rk35xx_24.11.3_arm64.deb kernel
sudo cp kernel/boot/* mnt/boot

sudo mv mnt/boot/vmlinuz-6.1.84-vendor-rk35xx mnt/boot/vmlinuz-rockchip
sudo mv mnt/boot/config-6.1.84-vendor-rk35xx mnt/boot/config-rockchip
sudo mv mnt/boot/System.map-6.1.84-vendor-rk35xx mnt/boot/System.map-rockchip

sudo cp -a kernel/lib mnt
sudo cp -a kernel/usr/lib mnt/usr
sudo mkdir -p mnt/boot/dtbs/rockchip
sudo cp mnt/usr/lib/linux-image-6.1.84-vendor-rk35xx/rockchip/rk3528-radxa-e20c.dtb mnt/boot/dtbs/rockchip
# sudo cp -r mnt/usr/lib/linux-image-6.1.84-vendor-rk35xx mnt/boot/dtbs

Extracts Alpine Linux root filesystem into the root partition.

sudo tar -C mnt -xf alpine-minirootfs-3.21.0-aarch64.tar.gz

Configures system to load Ethernet and Rockchip OTP memory modules at boot.

echo "r8168" | sudo tee -a mnt/etc/modules
echo "nvmem_rockchip_otp" | sudo tee -a mnt/etc/modules

Installs essential packages, generates initramfs, enables system services, and sets root password.

sudo chroot mnt/ sh -c "apk update ; \
        apk add alpine-base dropbear dropbear-scp mkinitfs e2fsprogs dosfstools --no-cache; \
        mkinitfs -o /boot/initramfs-rockchip 6.1.84-vendor-rk35xx ; \
        rc-update add crond default ; \
        rc-update add dropbear default ; \
        rc-update add ntpd default ; \
        rc-update add bootmisc boot ; \
        rc-update add hostname boot ; \
        rc-update add hwclock boot ; \
        rc-update add modules boot ; \
        rc-update add networking boot ; \
        rc-update add seedrng boot ; \
        rc-update add sysctl boot ; \
        rc-update add syslog boot ; \
        passwd -d root ; \
        echo -en 'root\nroot' | passwd root ; \
        "

Configures FIQ0 serial port for login access and adds to secure terminals list.

echo "#console tty" | sudo tee -a mnt/etc/inittab
echo "ttyFIQ0::respawn:/sbin/getty -L 1500000 ttyFIQ0 vt100" | sudo tee -a mnt/etc/inittab
echo ttyFIQ0 | sudo tee -a mnt/etc/securetty

Defines filesystem mount points and options in /etc/fstab.

echo "/dev/mmcblk0p2  /       ext4    defaults,noatime,commit=600,errors=remount-ro   0 1
/dev/mmcblk0p1  /boot   vfat    defaults,noatime                                0 2
" | sudo tee mnt/etc/fstab >/dev/null

Creates U-Boot boot menu entry specifying kernel, initrd, device tree, and boot parameters.

sudo mkdir mnt/boot/extlinux
echo "label Alpine 3.21
    kernel /vmlinuz-rockchip
    initrd /initramfs-rockchip
    devicetreedir /dtbs
    fdt /dtbs/rockchip/rk3528-radxa-e20c.dtb
    append root=/dev/mmcblk0p2 console=ttyFIQ0,1500000 console=tty1 loglevel=7 mitigations=off rootwait rw init=/sbin/init rootfstype=ext4
    " | sudo tee mnt/boot/extlinux/extlinux.conf >/dev/null

Done🎉.

sudo umount mnt/boot mnt
sudo sync
sudo partx -d /dev/loop0p1 /dev/loop0
sudo partx -d /dev/loop0p2 /dev/loop0

sudo losetup -d /dev/loop0

Here is the Alpine Linux.

main@builder:~/radxa-e20c-alpine$ du -sh alpine-3.21-6.1.75-vendor-rk35xx.img
280M    alpine-3.21-6.1.75-vendor-rk35xx.img

âś…Tips

How to install

Flash the image into SD card and then plug into sbc.

dd if=alpine-3.21-6.1.75-vendor-rk35xx.img of=/dev/sda bs=1M