Upgrading Alpine Linux from 3.16 to 3.17

Alpine Linux is a lightweight Linux Operating System and is ideal for fast servers where resources are limited. I run Alpine Linux on a couple of my public-facing servers with my Name Servers coming to mind. Each has only 256 Mb of memory allocated of which they use between 10 – 15 Mb. Upgrading Alpine Linux from 3.16 to 3.17 is incredibly easy and will take you only a few minutes.

You will need root privileges and a text editor such as nano or vi. My personal preference is nano but you can use whatever you’re comfortable with. Obviously you are going to need access to your server by whatever means you normally use.

Make a Backup

hands
Source: Pixabay

Before proceeding it is important you make a complete backup of your server just in case everything turns to custard. While it is unlikely things will go wrong, if it does turn south you will be able to recover.

You can guarantee the 1 in a million chance of a screw up will occur when you didn’t have a valid backup.

Each of my servers have backups made twice a day and I have restored backups previously and know they are reliable.

A common mistake when making backups is not testing the validity of your backup by performing a restore.

Change Repositories

Repositories let Linux know where it should get updates as well as new software packages. So the first thing we need to do is edit ‘/etc/apk/repositories’.

nano /etc/apk/repositories

Change the version number from 3.16 to 3.17 and save your changes. How easy is this so far?

# Old  
# https://dl-cdn.alpinelinux.org/alpine/v3.16/main
# https://dl-cdn.alpinelinux.org/alpine/v3.16/community

# New
https://dl-cdn.alpinelinux.org/alpine/v3.17/main
https://dl-cdn.alpinelinux.org/alpine/v3.17/community

Upgrading Alpine Linux

Run the following three commands;

apk update

apk upgrade --available

sync

If all went well you are now ready to reboot, after which you should check everything is working as expected.

reboot

Because I run a name server on this machine, and nothing else, on this machine I want to verify BIND is working correctly. In my case I have a look at /var/log/messages and scan for errors. Because I’m only interested in BIND I type the following command;

cat /var/log/messages | grep named

Once I’ve confirmed normal operations I test the name server, from outside the network, using the following;

dig @ns1.wozsites.com.au wozsites.com.au

; <<>> DiG 9.18.1-1ubuntu1.3-Ubuntu <<>> @ns1.wozsites.com.au wozsites.com.au
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10955
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 2063c881431dd8a40100000063f805aafb10460dab84501c (good)
;; QUESTION SECTION:
;wozsites.com.au.		IN	A

;; ANSWER SECTION:
wozsites.com.au.	3600	IN	A	49.176.255.229

;; Query time: 4 msec
;; SERVER: 49.176.255.229#53(ns1.wozsites.com.au) (UDP)
;; WHEN: Fri Feb 24 08:32:42 AWST 2023
;; MSG SIZE  rcvd: 88

If you are using DNSSEC, as I am, you can also test it as follows;

dig @ns1.wozsites.com.au wozsites.com.au +dnssec +short

That is all you have to do and your Alpine Linux has been upgraded. Confirmation can be seen by typing;

cat /etc/os-release

NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.17.2
PRETTY_NAME="Alpine Linux v3.17"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"

The entire upgrade takes less time than it does to make a cup of coffee.

You can also read about self hosting at home here.