- Shell 100%
| .gitattributes | ||
| LICENSE | ||
| README.md | ||
| upgrade.sh | ||
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/bootto 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/repositoriesto upgrade allhttp://links tohttps://, and seamlessly updates specific version tags (likev3.18) tolatest-stablewhile safely leavingedgerepositories 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
- Checks the current kernel to determine if the Pi requires
aarch64,armv7, orarmhf. - Locates the active Raspberry Pi boot partition.
- Checks the Alpine CDN for the latest targeted architecture tarball.
- Remounts the boot partition as read-write and creates a staging directory directly on the disk.
- Downloads, extracts, and organizes the new boot files without exhausting system RAM.
- Intelligently updates
/etc/apk/repositoriestohttps://andlatest-stable. - Generates the post-upgrade OpenRC script and enables the
localservice. - Installs the cron job if the
-aflag was provided. - Commits the current state using
lbu commit -dand reboots. - 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.