Migrating Alpine Linux LXC from x86_64 to aarch64 is surprisingly easy. You first have to transfer the files to your ARM server, setup a mountpoint of the root dataset in a functioning arm64 Alpine LXC, and use its Alpine Package Keeper (apk) to reinstall all of the packages using the aarch64 versions. Make sure that the work LXC has the same privileges as the LXC to migrate. A few steps need to be performed before asking apk to do this. So, after mounting the root dataset in your work Alpine LXC (ideally of the same version of the LXC to be migrated), you perform the following steps:
- Assuming you mounted the root dataset under
/mntand as root in LXC work environment, install the Alpine keys foraarch64repos. Make sure to get the version for the environment you are trying to migrate
wget https://dl-cdn.alpinelinux.org/alpine/latest-stable/main/aarch64/alpine-keys-2.5-r0.apk
apk -p /mnt add --allow-untrusted ./alpine-keys-2.5-r0.apk
- Change arch of the environment to migrate by modifying
/mnt/etc/apk/archtoaarch64 - Upgrade the environment using
apk:
apk -p /mnt upgrade -a
- Reinstall all packages in case some post-upgrade scripts were broken at reinstallation:
apk -p /mnt info | xargs apk -p /mnt fix
If you encounter errors like APK unavailable, skipping, it means that there is a package in /etc/apk/world keeping the environment from fully upgrading. This can occur when a package does not exist anymore, in which case it is stuck with an old version. Try removing some risky packages until apk -p /mnt upgrade -a yields a good result.