A script to automatically upgrade alpine linux to the latest stable version, including kernel, on diskless setups on raspberry pis.
Find a file
2026-06-19 13:31:32 +01:00
.gitattributes Initial commit 2026-06-11 01:31:34 -04:00
LICENSE Initial commit 2026-06-11 01:31:34 -04:00
README.md Fiddle the readme 2026-06-17 10:02:11 +01:00
upgrade.sh Remove early out 2026-06-19 13:31:32 +01:00

Alpine Linux Raspberry Pi Upgrade

A robust, multi-architecture, and fully automated script to upgrade an Alpine Linux "diskless" installation on a Raspberry Pi to the latest stable release.

Acknowledgement

This is based on work by gpocali at [https://github.com/gpocali/alpine-linux-pi-upgrade]. My goal was to reduce the scope of the script, and to have it more closely follow the instructions/recommendations of the wiki, which assert to run apk upgrade before the kernel upgrade. It probably doesn't matter

Overview

This repository provides a highly optimized upgrade.sh script designed to handle the complexities of upgrading a diskless Alpine Linux environment. It dynamically detects your Raspberry Pi hardware to fetch the correct architecture (aarch64, armv7, or armhf), locates your boot media, safely extracts updates without exhausting system memory, intelligently updates repository URLs, ensures network connectivity upon reboot, reinstalls your configured packages, and can even install itself as a monthly automated cron job.

Features

  • Multi-Architecture Support: Takes the architecture from the currently running kernel
  • Low-Memory Optimization: Bypasses RAM (tmpfs) limitations entirely by creating a staging directory directly on the physical boot media. This prevents Out-Of-Memory (OOM) crashes on older hardware or heavily loaded systems during the extraction phase.
  • Dynamic Media Detection: Automatically scans /media/* and /boot to identify the correct boot partition (SD card, USB drive, or NVMe) by verifying the presence of essential Pi bootloader files (config.txt, cmdline.txt).
  • Smart Repository Updates: Parses /etc/apk/repositories to upgrade all http:// links to https://, and seamlessly updates specific version tags (like v3.18) to latest-stable while safely leaving edge repositories intact.
  • Stateful Package Reinstallation: Rather than just updating the base system, it reads your explicitly installed package list (/etc/apk/world) and forces a clean reinstallation. This ensures all your custom binaries are perfectly matched to the newly installed kernel and libraries.

Quick Start

You can execute this script directly from the repository using wget piped into sh.

Note: This script must be run as root.

Run the script manually without installing any scheduled tasks:

curl https://forgejo.gwairfelin.com/max/alpine-rpi-upgrade/raw/branch/main/upgrade.sh | sh

What the Script Does

  1. Checks the current kernel to determine if the Pi requires aarch64, armv7, or armhf.
  2. Locates the active Raspberry Pi boot partition.
  3. Checks the Alpine CDN for the latest targeted architecture tarball.
  4. Remounts the boot partition as read-write and creates a staging directory directly on the disk.
  5. Downloads, extracts, and organizes the new boot files without exhausting system RAM.
  6. Intelligently updates /etc/apk/repositories to https:// and latest-stable.
  7. Generates the post-upgrade OpenRC script and enables the local service.
  8. Installs the cron job if the -a flag was provided.
  9. Commits the current state using lbu commit -d and reboots.
  10. Upgrades all apk packages

Prerequisites

  • A Raspberry Pi running Alpine Linux in "diskless" mode.
  • An active internet connection.
  • Root privileges.

Disclaimer

Always ensure you have a backup of your config.txt, cmdline.txt, and .apkovl files before performing major version upgrades. Use at your own risk.