Upgrading Alpine - v1.9.x

From Alpine Linux

This document covers upgrading from a previous version of Alpine 1.9 (or 1.10) to newer versions of 1.9 (or 1.10). Thanks to many improvements in Alpine 1.9, it is possible to easily upgrade in most scenarios.

All examples/instructions/actions mentioned in this document should be executed on the box that you are planning to upgrade (unless you are instructed otherwise).

Upgrading an Alpine Linux Hard-disk installation

When Alpine is installed to hard drive, upgrading the installation is simple.


Update Repositories File

The Repositories file /etc/apk/repositories can be updated using one of the following methods.

Using setup-apkrepos script

Launch the setup-apkrepos script:

# setup-apkrepos

Pressing e will open the file to edit using vi editor. Edit the repository lines to reflect the new version number.

Using sed command

Use a one-line command to edit all version numbers in the file "in place". Here's how you'd change 3.21 to 3.22:

# sed -i -e 's/v3.21/v3.22/g' /etc/apk/repositories

Manual editing of /etc/apk/repositories

Edit the /etc/apk/repositories file using any editor of your choice (nano for instance).

Contents of /etc/apk/repositories

http://dl-3.alpinelinux.org/alpine/v3.21/main http://dl-3.alpinelinux.org/alpine/v3.21/community

In the above file, to upgrade Alpine Linux from version 3.21 to 3.22, simply replace the number 3.21 by 3.22 in all the places:

Contents of /etc/apk/repositories

http://dl-3.alpinelinux.org/alpine/v3.22/main http://dl-3.alpinelinux.org/alpine/v3.22/community

Using latest-stable instead of version number

Manual changes of the version numbers may be avoided for future release upgrades by having the repository lines refer to "latest-stable" instead of an absolute value in the repositories file.

Warning: Changing the repositories to latest-stable may initiate unexpected release upgrades. Beware of the consequences.


The /etc/apk/repositories file should appear as follows:

Contents of /etc/apk/repositories

http://dl-3.alpinelinux.org/alpine/latest-stable/main http://dl-3.alpinelinux.org/alpine/latest-stable/community

Updating package lists

With the correct repositories file in place, the latest index list of available packages can be obtained with:

# apk update

Tip: Adding the --update-cache or -U to another apk command, as in apk add -U ... or apk upgrade -U, has the same effect as always running apk update immediately before the other apk command. Instead of auto-update it only if the index has not been updated recently.

Upgrading packages

At times it is required to first upgrade just the Alpine Linux Package Manager itself to the latest available version, before upgrading any other package. This was the case, for example, when upgrading from a version of Alpine before 2.3.0_rc1. But simply always doing so shouldn't hurt, either:

# apk add --upgrade apk-tools

Next, to upgrade all installed packages:

# apk upgrade --available

The --available switch is used to force all packages to be upgraded, even if they have the same version numbers. Sometimes changes in musl require doing this.

Note: All services that have been upgraded need to be restarted, to begin using the upgraded version. If the kernel is upgraded, it's required to reboot to begin using the upgraded version:

sync reboot

Ensure you have the latest available version of the Alpine Package Manager first before upgrading anything else:

apk add -u apk-tools

Finally, upgrade all remaining packages, including the kernel if applicable:

apk upgrade

Upgrading Separate Boot Media

You may have an installation where the boot media being used (such as a CD, for example) is separate from the media used to store the configuration information. In this case, simply download the latest ISO, and replace the boot media contents with the contents of the latest ISO. If you are booting from a CD, this would simply mean replacing the CD with a CD made from the new image and rebooting the Alpine box.

Upgrading Alpine on CF/USB

Your installation may consist of Alpine running on Compact Flash or USB media. In most cases, it should be sufficient to upgrade most packages using the Alpine Hard-disk Installation upgrade procedures described above. However, for new packages to survive after a reboot, you should enable APK caching.

Warning: As the newer version of alpine may include kernel upgrades, simply pointing the Alpine Package Manager to an Internet-based repository and running apk upgrade will not be enough, as kernel components are not upgraded when Alpine is run from memory.


Setup environment variables

To make the documentation a bit more "generic" we start by setting some environment variables.

vi /etc/lbu/lbu.conf

Make sure that the variable LBU_MEDIA is not commented (by removing the leading '#').

You also need to set a appropriate value for your LBU_MEDIA. The media you choose will be the media where you store your settings/configuration.

Note: Even if you have you alpine installed on CF, HD or USB you can still choose to save your config on some other media that suits your needs. But remember that both the media where you have your Alpine system AND the media where you have your config need to be in your box when booting it.

Examples:

LBU_MEDIA=usb

or:

LBU_MEDIA=sda1

Now that you have your /etc/lbu/lbu.conf configured for your needs, we will set the environment variables (note the leading .).

. /etc/lbu/lbu.conf

You can test if your environment variable was set:

echo $LBU_MEDIA

It should output something like usb, sda1, or whatever you just configured.

Back up your config

Before starting to upgrade, it's wise to save your configuration.

lbu ci

Upgrade Step-by-Step

Start by checking that you have enough space on your media.
You need at least 400MB available space.

df -h | grep "Filesystem\|$LBU_MEDIA"

Download and verify new release

Start downloading a new '.iso' and a '.sha1' file

cd /media/$LBU_MEDIA
wget -c Template:Latest 1.10 alpine iso-mirrorTemplate:Latest 1.10 alpine iso-filename
wget http://dev.alpinelinux.org/alpine/v1.10/releases/Template:Latest 1.10 alpine iso-filename.sha1

Check integrity of the downloaded files (it might take some time)

sha1sum -c Template:Latest 1.10 alpine iso-filename.sha1

The output of the above command should say 'OK'.
If says 'FAILED', delete the iso file and download it again.

Copy the new release

Mount the ISO.

mount -t iso9660 Template:Latest 1.10 alpine iso-filename /mnt

Back up files that you have modified. For example, you might have modified syslinux.cfg to show console output on a serial port.

cp /media/$LBU_MEDIA/syslinux.cfg /media/$LBU_MEDIA/syslinux.cfg.my

Install the rsync package if necessary, and copy the files:

cd /mnt
apk add rsync
rsync --delete -rltv .alpine-release * /media/$LBU_MEDIA/ 

Restore your backed up files (in case you had any)

mv -f /media/$LBU_MEDIA/syslinux.cfg.my /media/$LBU_MEDIA/syslinux.cfg

Make sure that all files are permanently saved in right place

sync

Clean up

Clean up the downloaded/unpacked files

cd ..
umount /mnt
rm /media/$LBU_MEDIA/Template:Latest 1.10 alpine iso-filename
rm /media/$LBU_MEDIA/Template:Latest 1.10 alpine iso-filename.sha1

Save changes

Now that all upgrades are done, we should save our settings to our media (which you hopefully have backed up prior to doing this upgrade).

lbu ci

Load new kernel

In most cases you will need to reboot Alpine (especially if there are changes in the kernel):

reboot
Note: If you know what you are doing, you might not need to reboot. But make sure that all services affected by the upgrade are restarted.

Update remaining packages from Web repository

  • Check that /etc/apk/repositories reflects the current version, for example, for 1.10 it could say:
http://dl-3.alpinelinux.org/alpine/v1.10/packages/main
  • Upgrade packages from Web.
apk update
apk add -u apk-tools
apk upgrade -U