Migrating from Arch Linux ARM to Debian

Guides written by the community, for the community, and only guides!

Migrating from Arch Linux ARM to Debian

Postby fiery » Sun Feb 13, 2022 1:07 pm

Now that ARMv5 and ARMv6 architectures are EOL in Arch Linux ARM (https://archlinuxarm.org/forum/viewtopic.php?f=3&t=15721), I've decided to migrate my NSA325 to Debian.
This is a short guide showing you how to do it with minimal hassle and risk. It's not specific to NSA325 and should work with Arch in general. To minimise the risk of ending up with an unbootable system, I suggest first booting the new system from a USB stick and replacing your existing Arch installation only after you've made sure it works.

Outline

The rough steps to take are:
- preparing the root filesystem with Debian,
- preparing the kernel,
- checking if it all works using a USB stick,
- replacing Arch with Debian on your existing root partition.

Preparing the root filesystem with Debian

Partition your USB stick. To minimize risk, create only one primary partition, 1GB should be enough.

Create a file system. I've tested this on a U-Boot 2016, for older U-Boots, you may need to use ext3/2:

$this->bbcode_second_pass_code('', '
mkfs.ext4 -O ^metadata_csum,^64bit -E lazy_itable_init=0,lazy_journal_init=0 /dev/YOUR_USB_PARTITION_DEVICE_NAME -L rootfs
')

Mount the USB device:

$this->bbcode_second_pass_code('', '
mkdir /debinst
mount /dev/YOUR_USB_PARTITION_DEVICE_NAME /debinst
')

Run debootstrap to create a minimal Debian installation. To do that, follow the guide at https://www.debian.org/releases/stable/armel/apds03.en.html.
Make sure that you've installed ssh/mdamd and set up networking correctly.

Preparing a kernel

Using Arch kernel
I suggest using your current Arch kernel to boot Debian. After all, this is the kernel that's already compatible with your machine and U-Boot. It's also much more recent than what the current Debian offers. To do that, you need to make the following modification to Arch's initrd (the change is compatible with your existing Arch too).
$this->bbcode_second_pass_code('', '
cp /boot/initramfs-linux.img /boot/initramfs-linux.img.orig
sed -i.bak 's@elif \[ ! -x "/new_root${init}" \];@elif ! $(chroot /new_root test -x ${init});@' /usr/lib/initcpio/init
mkinitcpio -P
')

Then, copy the following directories to your Debian rootfs:
$this->bbcode_second_pass_code('', '
cp -ax /boot /debinst/
mv -f /debinst/boot/boot/uEnv.txt /debinst/boot/boot/uEnv.txt-disabled
mv -f /debinst/boot/uEnv.txt /debinst/boot/uEnv.txt-disabled
mkdir -p /debinst/lib/modules/
cp -ax /lib/modules/* /debinst/lib/modules/
')

Arch Linux compresses its kernel modules with zstd, which is a recent addition and Debian userspace doesn't support it (as of bullseye version). You need to unpack the modules:
$this->bbcode_second_pass_code('', '
find /debinst/lib/modules -name '*.ko.zst' |xargs -n 1 zstd -d
')

Using Debian kernel to boot
I suggest doing this only after you've verified that the Arch kernel works.If Debian has a kernel for your device, you can try using it for booting. Install the relevant deb package and make the following changes:

1. Symlink kernel / initrd (using Marvell kernel as an example):

$this->bbcode_second_pass_code('', '
cd /debinst/boot
ln -s initrd.img-5.10.0-11-marvell initramfs-linux.img
ln -s vmlinuz-5.10.0-11-marvell zImage
')

2. copy /boot/dtbs
$this->bbcode_second_pass_code('', '
cp -ax /boot/dtbs /debinst/boot
')

Checking if it all works using a USB stick

At this point, the USB stick should be bootable, so go on and check if it works by rebooting your system.
If it didn't work, double check you did everytihng according to the debootstrap guide and this guide. If you can't find anything wrong, your best chance is using the serial console to find out why the system didn't boot. The good news is that you still haven't altered your original Arch installation so you can just remove the stick and boot back into Arch.

Replacing Arch with Debian on your existing root partition

If your system booted successfully, you can now replace Arch with Debian from your USB stick:
$this->bbcode_second_pass_code('', '
mkdir /tmp/rootfs-arch
mount /dev/YOUR_ARCH_ROOTFS_DEVICE /tmp/rootfs-arch
mkdir /tmp/rootfs-arch/rootfs-arch-backup
mv /tmp/rootfs-arch/* /tmp/rootfs-arch/rootfs-arch-backup
cp -ax /* /tmp/rootfs-arch
mv -f /boot/boot/uEnv.txt-disabled /tmp/rootfs-arch/boot/boot/uEnv.txt
mv -f /boot/uEnv.txt-disabled /tmp/rootfs-arch/boot/uEnv.txt
sync
')

And that's it - power off, remove the stick and boot into your brand new Debian. But before doing that, take a moment to think about all the Arch Linux ARM devs who have been providing you with a bleeding edge distribution for so many years! ;-)
fiery
 
Posts: 1
Joined: Sun Feb 13, 2022 12:37 pm

Return to Community Guides

Who is online

Users browsing this forum: No registered users and 5 guests