Arch Linux ARM
Minimal Image for the RPi2
Create the image file
For creating the image file we can exploit my favourite command
The command below, for example, creates a file of the size of 2GiB:
dd if=/dev/zero of=./image.img bs=2G count=1
Setup a loop device
In this step we create a loopback device so we can format and partition the image disk file like a normal block device file or hard disk. In short, a loopback device allows files to be interpreted as real block devices.
The next command setups the image file
image.img as a loop device:
sudo losetup -f image.img
To list the status of all loop devices and to find out the corresponding loop
device for our image, we can run
losetup with the option
In my case the loop device for my image file is
Partiton the image
Now that we setup a loopback device for the image, we can finally partition it
fdisk like any other hard disk:
At the fdisk prompt, delete old partitions and create a new one:
- Type o. This will clear out any partitions on the drive.
- Type p to list partitions. There should be no partitions left.
- Type n, then p for primary, 1 for the first partition on the drive, press ENTER to accept the default first sector, then type +100M for the last sector.
- Type t, then c to set the first partition to type W95 FAT32 (LBA).
- Type n, then p for primary, 2 for the second partition on the drive, and then press ENTER twice to accept the default first and last sector.
- Write the partition table and exit by typing w.
Once we have partioned the image file, we need to reload the partition table of
the loop device. This can be done using
partprobe which informs the OS of
partition table changes.
sudo partprobe /dev/loop0
Format the partitions
In this step, we format the previously created partitions.
The first partition will contain the bootloader and must be formatted using the FAT filesystem:
sudo mkfs.vfat /dev/loop0p1
The second partiton will contain the root filesystem of the Arch system, which should be formatted using the ext4 filesystem:
sudo mkfs.ext4 /dev/loop0p2
Bootstrap the Arch system
In the following, we bootstrap the Arch system on the image file.
First we must create two empty directories so we can mount the two partitions of the image file:
mkdir boot root
Second, we mount both partitions as shown below:
mount /dev/loop0p1 boot mount /dev/loop0p2 root
Third, we download and extract the Arch root filesystem to the mounted root partition (as root, not via sudo):
su wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz bsdtar -xpf ArchLinuxARM-rpi-2-latest.tar.gz -C root sync
Fourth, we need to move the boot files from the root filesystem to the first partition:
mv root/boot/* boot
Lastly, unmount the two partitions:
umount boot root
Testing the image on a RPi
Flash the image to a sdcard
Now that we have an Arch Linux image file, we can easily flash it to a sdcard.
As before, we can use the handy
dd command. In my case the sdcard is available
/dev/mmcblk0 on my system so the command looks as follows:
sudo dd if=./image.img of=/dev/mmcblk0 bs=4M status=progress && sync
Poweron and Login
Once the RPi is powered on, we can ssh into the Arch system, assuming we know the IP address. The default settings of an Arch Linux ARM are as follows:
- Hostnane: alarmpi
- User: alarm
- Password: alarm
- Root password: root
Resizing the root partition
As final adjustments, it's a good idea to resize the ext4 root partition so we don't run out of disk space. Otherwise, the root partition is limited to 1.9GiB.
Overall, extending a root partition at runtime is possible by simply using
fdisk. So the steps are as follows:
- Delete the root partiton.
- Recreate the root partition.
Afterwards, the system should be rebooted and the root partition be resized using
sudo resize2fs /dev/mmcblk0p2
Useful development tools
In case you intend to compile and develop some Arch Linux ARM packages, you should definitely install the following packges:
pacman -S base-devel pacman -S git vim zsh sudo wget pacman -S python-pip ipython
Changing the hostname is just a matter of editing the files
echo chaotix > /etc/hostname
In case of the
hosts file we should add an extra line like the
one below. For example, I decided to use the hostname
127.0.1.1 chaotix.localdomain chaotix
Custom DNS Nameserver
On ArchLinux|ARM DNS is managed by systemd. This means for setting a custom
DNS nameserver you need to edit the file
Basically, we just need to set a value for the DNS entry as shown below:
[Resolve] DNS=10.0.0.50 10.0.0.1
As one can see, multiple DNS nameservers are separated by a whitespace.
Create a new user
A default user on a new Arch Linux ARM system is the user alarm. If you like to create a new user you can do that as follows:
useradd -m -s /bin/zsh xander passwd xander
As you can see, my new user is called xander and uses the awesome
zsh shell :-).
I often use sudo instead of a root account to administer my Linux systems,
so I added my user account to the group
gpasswd -a xander wheel
To complete the sudo configuration, we must not forget to uncomment
the first line starting with
In other words, remove the Hashbang
Also note that you should use
visudo to edit the
Delete default user
And if you're like me and don't need the existing
you can simply remove the user from the image:
userdel -r alarm
Lastly, we should change the default root password of the Arch Linux ARM image:
In order to make the single board computer discoverable on the home network, we can install avahi and mdns. Overall, the installation procedure is the same as described on the Arch Linux Wiki.
pacman -S avahi nss-mdns
Once installed, we should adapt the
/etc/nsswitch.conf so the hostname
resolution using the
.local naming scheme works:
hosts: ... mdns_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns ...
And finally, to enable the avahi service on every boot, we can run the following
systemctl enable avahi-daemon.service
Install the i2c tools:
pacman -S i2c-tools
Add the line below to
Add the following lines to
To use I2C with python, you need to install the packages
pip install cffi smbus-cffi
- : https://archlinuxarm.org/
- : https://archlinuxarm.org/platforms/armv7/broadcom/raspberry-pi-2
- : https://www.qemu.org/
- : https://wiki.archlinux.org/index.php/QEMU
- : https://en.wikipedia.org/wiki/Chroot
- : https://wiki.archlinux.org/index.php/change_root
- : https://en.wikipedia.org/wiki/Binfmt_misc
- : https://wiki.archlinux.org/index.php/avahi