Swapping DietPi for Alpine on a NanoPi NEO2
One microSD card, no serial console, and a boot chain I couldn't afford to break.
I have a NanoPi NEO2 on a shelf: Allwinner H5, four Cortex-A53 cores, 512MB of DDR3, one USB port and a microSD slot. I flashed DietPi on it first, to get a working boot chain, then decided I wanted Alpine on it instead.
The conditions I gave myself were the hard part. One card, no serial adapter, no second storage medium, and no HDMI either, so a failed boot means pulling the card and putting it in the laptop. If the filesystem is bad, that is a reflash of 730MB.
So I did not touch anything that makes it boot.
Preserving the boot chain
An Allwinner board boots in stages. The first 4MiB of the card holds the SPL and U-Boot. After that there is a single ext4 partition. On this board root= on the kernel command line is a UUID, not a device name, so the kernel finds its root filesystem by filesystem ID.
So the partition can be emptied and repopulated in place, and the kernel still finds it. Back up the first 4MiB first in case U-Boot gets damaged.
sudo dd if=/dev/sda bs=1M count=4 of=~/uboot-region.bin status=progress
Before deleting anything I copied two things off the card: /boot and /lib/modules/6.18.54-current-sunxi64. That covers the kernel, its initramfs, the device tree, boot.scr, and the driver modules. DietPi’s U-Boot reads boot.scr, which reads dietpiEnv.txt and assembles the command line. All of it has to survive, because Alpine’s userland is not going to boot on its own here.
Then: mount the partition, remove everything, untar the Alpine minirootfs, put /boot and /lib/modules back.
/lib/modules is the one directory worth checking twice. Without the modules there is no ethernet driver, and a board with no network is a board I cannot reach. I checked it three times.
Installing arm64 packages from an x86 laptop
apk is a static binary, and Alpine ships an x86_64 build of it. So you can point it at the mounted card and have it resolve and install aarch64 packages from your laptop, no emulation involved.
It needs --root to target the card, --arch aarch64, and --no-scripts, because the post-install hooks are aarch64 binaries and will not run.
--no-scripts skips the post-install triggers, so these have to be written by hand:
/etc/fstab/etc/network/interfaces- the OpenRC runlevel symlinks for
networkingandsshd - SSH host keys
- the root password hash
PermitRootLogin yes, since OpenSSH defaults to refusing password logins for root
None of that needs a running arm64 machine. openssl passwd -6 on the laptop produces the hash and you paste it into /etc/shadow. ssh-keygen on the laptop writes host keys that are identical to what the board would have made.
What went wrong on first boot
It came up. Debian’s initramfs mounted the root by UUID, busybox handed over to OpenRC, networking brought up eth0, and DHCP gave it an address. SSH answered.
The clock was at 1970. This board has no RTC battery, so every cold boot starts at the epoch. apk cannot validate any TLS certificate, and it reports that as “server certificate not trusted” rather than as a clock problem. Setting the date by hand fixes the immediate issue.
The second one is in the same direction: ca-certificates was never installed, because the bootstrap ran with --no-scripts. A missing CA bundle and a 1970 clock produce the same error. I spent twenty minutes on the clock before checking for the bundle. I copied the bundle from the laptop over SSH, then installed the package properly so it owns the file. Then chronyd, so the clock stays right afterwards.
The link came up at 100Mb/s on a gigabit board. ethtool was clear about why. The board was advertising 1000baseT/Full and the link partner was advertising 10/100 only. That field is the other end’s autonegotiation, so the router port was the limit.
The kernel swap I abandoned
Alpine ships its own kernel, so I tried it. It does not boot.
vmlinuz-lts in the aarch64 release is not a raw kernel image. It is an EFI zboot image: a PE/COFF executable, MZ at offset 0, wrapping a gzipped arm64 Image. U-Boot’s booti wants a raw Image, which is the magic ARMd at offset 56. Point extlinux.conf at the file as shipped and U-Boot fails to load it, then falls back to boot.scr. Nothing breaks, nothing changes.
You can unwrap it. Find the gzip frame, run gzip -t on it to confirm it is intact, decompress it, check for ARMd at offset 56. U-Boot will load the result.
Then it hangs. Dim red LED, no network. On this board a bright LED means the SoC is running and a dim one means it has halted, so I knew it was a panic and not a power problem, but not much beyond that.
Recovery was: pull the card, delete extlinux.conf, boot again.
Two things came out of that:
- A U-Boot fallback only covers load failures. A kernel that loads and then panics has nothing behind it. Falling back to
boot.scrhad saved me from a bad file; it could do nothing once U-Boot jumped into a panicking kernel. mkinitfswith no argument builds for the kernel that is currently running. If you are targeting a different one you have to name it, or you get an initramfs for the wrong kernel and never find out.
I also wanted to test the new kernel in RAM instead of committing to a reboot. kexec is not available: Armbian builds without CONFIG_KEXEC, so kexec_load returns ENOSYS.
That is where I stopped. The board runs Armbian’s kernel, which carries Allwinner-specific tuning like coherent_pool=2M, with an Alpine userland on top. That pairing is common on small SBCs.
One thing to fix before attempting any kernel swap on this board: Alpine’s default initramfs features build a 161MB initramfs, and it unpacks into RAM. There is 512MB in total. Slim the feature list to base ext4 mmc first and you get about 7MB.
Buy the serial adapter
Buy the 3.3V USB-TTL adapter. It costs less than the board does. Without it, both failures that evening were silent: I had an LED colour and a network that did or did not respond. With a console I would have seen the panic and known in seconds.
I would keep the single card, though. The in-place swap worked, it kept the UUID, and there is no reason to stage through a second medium on a board with one slot.
What it is for
It is about an eighth of my laptop, but it draws around 2W and it is never off, which is what matters for something answering DNS all day. AdGuard Home fits it better than anything else I could put there. tailscaled would give me a stable way into the LAN from outside. ntfy, if I want my own notification hub.
512MB of RAM, a 100Mb/s link, and microSD with a finite number of writes. That is enough for DNS and not much more.