ArchLinux on Arm (Raspberry Pi)

Jarret B

Well-Known Member
Staff member
Joined
May 22, 2017
Messages
377
Reaction score
445
Credits
14,054
ArchLinux was released for ARM processors and supports many chipsets.

The main website for the ARM version is ‘https://archlinuxarm.org’.

If you have an ARM processor in a system, other than the Raspberry Pi, then head to their website to find the proper image file you need. But in this article, I will cover creating a bootable SD card for the Raspberry Pi 3 and 4.

Software Requirement

There is only one app needed, which you use to extract the downloaded compressed file. In a terminal type, ‘bsdtar’. If you get an error that the command does not exist, you need to install it.

To install it on Ubuntu, use the command:

Code:
apt install libarchive-tools -y

Initial SD Setup

To start, the SD card must be able to boot and also contain the files to load ArchLinux.

So, have an SD card ready that is at least 8 GB. The larger SD cards may work better if you plan on installing a lot of programs or storing data. A good Class 10 SD card will provide better performance.

You need to partition and format the SD card properly so it can hold the files. Unfortunately, when you download the image file, it does not include both partitions, but we can put it all together to make it work.

I’m working with an Ubuntu system, but any Linux system will work. The commands are all done in a terminal.

Attach your SD card so we can work with it. If it has a format already, it will most likely auto-mount.

So, we need to unmount the drive. In a terminal, run ‘lsblk’ to see the name of the SD card. On my system, it mounted as ‘/dev/sda’ with one partition as ‘/dev/sda1’. Be sure to get the proper name for your SD card so you do not format a device you do not want to lose the data. I will use the names ‘sda’ or ‘sdaX’ in my examples. Be sure to change these as needed for your device if it is not ‘/dev/sda’.

Start by switching to root privileges with ‘sudo su’. Enter your password to get elevated privileges within the terminal.

The next step is to go into ‘fdisk’ and get the partitions set up as you will need:

Code:
fdisk /dev/sda

You should now be at an ‘fdisk’ prompt that is ‘Command (m for help):’. You need to remove any partitions on the SD card by entering the letter ‘o’.

If the SD card is GPT, you will get a message about it being GPT. Enter ‘w’ to write the changes and then ‘q’ to quit ‘fdisk’, if it doesn’t exit after writing the MBR table, and restart ‘fdisk’ so it can reread the partition table. Now, when you enter ‘o’, it should read that the partition table is now MBR. No partitions should exist.

If you type ‘p’, you’ll see a list of partitions, which it should list none.

We now need to create a new primary partition, so type in ‘n’ for a new partition and then ‘p’ for a Primary partition. We need to create the initial partition that will boot the SD card. The boot partition should be only about 200 MB. Enter ‘1’ for the first Primary partition. It will prompt you for the first sector to use, so press enter to accept the default of ‘2048’. Now it should ask for the last sector to use for the partition, so enter ‘+200M’.

NOTE: For the 64-bit OS, make partition 1 larger than 200 MB. Try 1000 MB, or 1 GB, for more storage when updating the kernel.

It may prompt you that the partition has a signature already and wants to know if you want to remove it. Enter ‘y’ for ‘yes’.

Next, enter ‘t’ to change the Partition Type and then ‘c’ to change the type to W95 FAT32 (LBA).

We now need to create the second primary partition, so type in ‘n’ and then ‘p’. It should ask you for a partition number, so enter ‘2’. It should prompt you for the first sector for the second partition, so press ‘enter’ for the default and press it again to accept the ending sector, which should be the end of the SD card. If it asks you to remove the signature, enter ‘y’ for yes.

You need to write all the changes to the SD card, so enter ‘w’. It should write all the settings and exit you from ‘fdisk’.

Formatting the SD Card

If you perform the command ‘lsblk’, you should now see two partitions on your SD card. In my case, I have ‘sda1’ and ‘sda2’. The first partition, being the boot partition, is the ‘FAT’ format. The second partition is larger and is the ‘ext4’ format.

To format the first partition, we use the command:

Code:
mkfs.vfat /dev/sda1

For the second partition, we use:

Code:
mkfs.ext4 /dev/sda2

Depending on the size of the SD card, formatting the larger partition may take a little time.

Mounting the Partitions

Before continuing, the partitions need to be unmounted so we can remount them where we need them. Both partitions need to be mounted to allow for writing to them from the compressed file.

Switch to the ‘/mnt’ folder with ‘cd /mnt’ and then make the two folders we need to mount the partitions:

Code:
mkdir part1
mkdir part2

To mount Partition 1 into ‘part1’, we use the command:

Code:
mount /dev/sda1 /mnt/part1

And then we can mount Partition 2 to ‘part2’:

Code:
mount /dev/sda2 /mnt/part2

Downloading the Operating System

Things are nearly ready to place the files on the partitions, but we need the Operating System (OS). We need to move to the ‘/mnt’ folder, so when we get the OS, it will be in that folder. So, use the command ‘cd /mnt’.

To get the OS, use the command:

Code:
wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-armv7-latest.tar.gz

NOTE: This is a 32-bit version of the OS. For the 64-bit version, you want the AARCH download at:

Code:
 wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz

Installation Instructions

Now we can extract the image to the second partition for the 32-bit OS:

Code:
bsdtar -xpf ArchLinuxARM-rpi-armv7-latest.tar.gz -C /mnt/part2

And for the 64-bit OS:

Code:
bsdtar -xpf ArchLinuxARM-rpi-aarch64-latest.tar.gz -C /mnt/part2

Before continuing, make sure the files are all complete in writing. You can use the ‘sync’ command to make sure.

All the image is now on partition 2, but we need the boot files on partition 1 so the SD card will be bootable. Use the command to copy the files over:

Code:
mv /mnt/part2/boot/* /mnt/part1

Again, make sure the files are complete in writing to Partition 1 before unmounting the partitions. Use the ‘sync’ command.

If you are using the 64-bit OS, then you need to change the OS configuration. Edit the file using ‘sudo’, at ‘/mnt/part1/etc/fstab’. The entry for ‘/dev/mmcblk0p1’ needs to be ‘/dev/mmcblk1p1’. Save the file.

You can unmount the partitions with:

Code:
umount /dev/sda*

The SD card is now ready to boot the Raspberry Pi, so insert the card into the Pi and connect the Pi to a monitor, keyboard and mouse. Connect a wired ethernet cable and power the Pi on.

OS on the Pi

Once you boot up, you’ll come to a login prompt. If the system stops at one point, just press the ‘enter’ key to get to the prompt.

Login as ‘root’ and use the password ‘root’. At the prompt, you need to set up the key-ring for using certificates, keys and other security related items. Use the following two commands:

Code:
pacman-key --init
pacman-key --populate archlinuxarm

Now that we’ve enabled the key security, we can perform an update:

Code:
pacman -Syu

Answer ‘Y’ to any prompt or press ‘enter’.

After the update has completed, you need to install the ‘sudo’ app with the command:

Code:
pacman -S sudo

We need to add the ‘alarm’ user to the ‘sudo’ and ‘wheel’ group:

Code:
usermod -aG root,wheel alarm

NOTE: You can add a different user, but ‘alarm’ already exists.

We can now add the user ‘alarm’ to the ‘sudoers’ file, so edit ‘/etc/sudoers’ and add the line:

[code]alarm ALL=(ALL:ALL) ALL

Save the file and you can reboot the system.

At the login prompt, you can login as the user ‘alarm’ with a password ‘alarm’.

Conclusion

This should get you started with ArchLinux on ARM.

If needed, backup the SD Card to another system to restore if the OS gets corrupted and you need to start over.

Have fun!
 

Members online


Top