Raspberry Pi: Arch Linux Installation

From Wiki³
IconUNDER CONSTRUCTION: The document is currently being modified!

The following tutorial is a collection of notes on how to install the Arch Linux distribution on the Raspberry Pi hobbyist device. This tutorial is essentially a replica of my normal Arch Linux: System Installation guide with RPi (Raspberry Pi) specific notes included. As always we will follow the Arch Linux philosophy, meaning these tutorials are geared at being simple and efficient.

Image SD Card

For use in the creation of this tutorial I used the following environment:

Icon Raspberry Pi Model B
Icon ArchLinuxARM-2014-06-rpi.img

Download and image your SD Card with the image located at Arch Linux ARM.

Linux

If you are using a Linux machine you can simply search for the device node of the SD card you have inserted with the fdisk -l command. Then you can format your SD card with the image using the following command, filling in the path of the downloaded image and replacing the device node with the device node you found with fdisk (e.g. /dev/sdd).

# dd bs=1M if=/path/to/ArchLinuxARM-2014-06-rpi.img of=<device node>

Windows

Download and install Win32DiskImager. Then proceed to use it to format your SD card with the image you downloaded. Be sure to specify the correct device before hitting the Write button.

Initial Boot & Configuration

Go ahead and plug the SD Card back into the RPi and boot it up. You will eventually be greeted with the Arch Linux login prompt. Login to the system using the root account with the default password of root.

System Update

First, run pacman(8) to update the system. After this it is safe to reboot to enact the changes.

[root@alarmpi ~]$ pacman -Syu

...

[root@alarmpi ~]$ systemctl reboot

With the system is up to date, edit the /etc/pacman.d/mirrorlist in order to select an Arch Linux ARM (ALARM) download mirror that is closest to your location. I have found that the default auto-selection based off geo-IP data doesn't work all that well. Uncomment the mirror that best suits your location.

[root@alarmpi ~]$ vi /etc/pacman.d/mirrorlist
———
# Server = http://mirror.archlinuxarm.org/$arch/$repo

...

Server = http://wa.us.mirror.archlinuxarm.org/$arch/$repo
———

You can also take this time to enable the Color option in the /etc/pacman.conf if you like.

[root@alarmpi ~]$ vi /etc/pacman.conf
———
# Misc options
#UseSyslog
Color
#TotalDownload
CheckSpace
#VerbostPkgLists
———

Next, install packer and update the RPi firmware/kernel to the latest version. In addition to this we will be installing arm-mem which are ARM-accelerated versions of selected functions from string.h. Then again reboot the machine to enact the changes.

[root@alarmpi ~]$ pacman -S packer arm-mem-git linux-raspberrypi-latest linux-raspberrypi-latest-headers vim

...

[root@alarmpi ~]$ systemctl reboot

Configuration

With the system updated to the latest kernel it is now time to configure the system for our needs. We can first start with the network.

Network

After you have the RPi running the Linux kernel 3.x you will now have 8188eu wireless support built into the kernel. You can use an 8188eu USB NIC or the built-in wired NIC that comes with the RPi.

Wired

For a wired network card first copy a template and then edit the template to modify your IP address and your chosen DNS server.

[root@alarmpi ~]$ cd /etc/netctl
[root@alarmpi ~]$ cp examples/ethernet-static eth0
[root@alarmpi ~]$ vim eth0
———
IP=static
Address=('192.168.1.30/24')
Gateway='192.168.1.1'
DNS=('4.2.2.1' '4.2.2.2')
ExecUpPost='/usr/bin/ntpd -gq || true'
———

Wireless

If you wish to use wireless instead it is pretty much the same process except we use a different template. The only difference is to make sure you secure the file if it contains your wireless password.

[root@alarmpi ~]$ cd /etc/netctl
[root@alarmpi ~]$ cp examples/wireless-wpa eth0
[root@alarmpi ~]$ vim eth0
———
IP=static
Address=('192.168.1.30/24')
Gateway='192.168.1.1'
DNS=('4.2.2.1' '4.2.2.2')
ESSID='MyWirelessNetworkSSID'
Key='MyWirelessPassword'
#Hidden=yes
ExecUpPost='/usr/bin/ntpd -gq || true'
———
[root@alarmpi ~]$ chmod 640 eth0

Feel free to change either of these to IP=dhcp in order to use DHCP instead of a static address. Also regardless of which you chose you will need to enable the profile with netctl.

[root@alarmpi ~]$ netctl enable eth0

Hostname

Set the hostname for use with networks, I will be using the hostname hex.kyau.net.

[root@alarmpi ~]$ hostnamectl set-hostname hex.kyau.net

Timezone

Set the timezone, for me this is US/Pacific as I am located on the west coast of the United States. Then enable ntpd for internet time syncing capabilities.

[root@alarmpi ~]$ timedatectl set-timezone US/Pacific
[root@alarmpi ~]$ systemctl enable ntpd

Locale

Setup the appropriate locale. First edit /etc/locale.gen and uncomment the lines that correspond to your language selection, generate the needed locales, set your keymap and finally set the language with the system.

[root@alarmpi ~]$ vim /etc/locale.gen
———
en_US ISO-8859-1
en_US.UTF-8
———
[root@alarmpi ~]$ locale-gen
Generating locales...
 en_US.UTF-8
 en_US.ISO-8859-1
Generation complete.
[root@alarmpi ~]$ localectl set-keymap us
[root@alarmpi ~]$ localectl set-locale LANG="en_US.UTF-8"

User Management

With the system configuration out of the way it is time to create a user account, install sudo, give the user full access to sudo and then relog into your new account. I will be using the username kyau for the extent of this tutorial. Finally we can change the default root password.

[root@alarmpi ~]$ useradd -m -g users -s /bin/bash kyau
[root@alarmpi ~]$ passwd kyau
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
[root@alarmpi ~]$ pacman -S sudo

...

[root@alarmpi ~]$ visudo
———
root ALL=(ALL) ALL
kyau ALL=(ALL) ALL
———
[root@alarmpi ~]$ passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
[root@alarmpi ~]$ systemctl reboot

Partition Management

Next you will need to decide what you will be using as the main drive. This choice depends solely on whether or not you want to overclock your RPi or not. If you plan on experimenting with overclocking you will need an external USB hard drive or USB flash drive of adequate size.

USB Drive (Overclock)

Moving the Arch install to a USB drive will increase overall speed of the RPi and give you the option of overclocking as you will no longer be limited by SD card corruption. Start by plugging in your USB drive to the RPi and pulling up a list of all drives on the machine again with the fdisk command.

[kyau@hex ~]$ sudo fdisk -l
...
Device Boot Start End Blocks Id System
/dev/sda1 32 31266815 15633392 c W95 FAT32 (LBA)

Notice the USB drive in the list, execute fdisk on the USB drive. Create two partitions: a 1GB swap partition and then fill the rest of the disk with the root partition.

[kyau@hex ~]$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.24.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x51248fbd.

Command (m for help): n

Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-31266815, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-31266815, default 31266815): +1G

Created a new partition 1 of type 'Linux' and of size 1 GiB.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): n

Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):

Using default response p.
Partition number (2-4, default 2):
First sector (2099200-31266815, default 2099200):
Last sector, +sectors or +size{K,M,G,T,P} (2099200-31266815, default 31266815):

Created a new partition 2 of type 'Linux' and of size 13.9 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Next you need to format and mount the partitions you just created.

[kyau@hex ~]$ sudo mkfs.ext4 /dev/sda2
mke2fs 1.42.10 (18-May-2014)
Creating filesystem with 3645952 4k blocks and 912128 inodes
Filesystem UUID: 3292220f-c043-4ec2-af21-4eb23fea345a
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[kyau@hex ~]$ sudo mkswap /dev/sda1
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=8e1a765b-f4df-4f2d-a799-e0a4d8fc6544

With that finished it is time to clone the current live system. First reboot into rescue mode, then mount the root partitions to temporary directories and then copy over the system.

[kyau@hex ~]$ sudo systemctl rescue
...
[root@hex ~]$ mkdir /mnt/{blk,sda}
[root@hex ~]$ mount /dev/sda2 /mnt/sda
[root@hex ~]$ mount /dev/mmcblk0p5 /mnt/blk
[root@hex ~]$ cd /mnt/blk
[root@hex ~]$ cp -a * /mnt/sda
systemctl reboot

Once the machine has rebooted it is time to switch over to mounting root off of the USB drive instead of the SD card.

[kyau@hex ~]$ sudo vim /boot/cmdline.txt
———
ipv6.disable=1 avoid_safe_mode=1 selinux=0 plymouth.enable=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=noop rootwait
———
[kyau@hex ~]$ sudo mount /dev/sda2 /mnt
[kyau@hex ~]$ sudo vim /mnt/etc/fstab
———
#
# /etc/fstab: static file system information
#
# <file system> <dir> <type> <options> <dump> <pass>
/dev/sda2 / ext4 defaults,noatime 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 0
/dev/sda1 none swap defaults 0 0
tmpfs /tmp tmpfs nodev,nosuid,size=2G 0 0
———

With all this finished reboot to enact the changes.

[kyau@hex ~]$ sudo systemctl reboot

SD Card

Given that we used a pre-made image to install Arch Linux onto our SD Card, it came with predefined partitions that are not sized to your entire SD Card.

Use the fdisk command to display all of your devices and locate the device node of the SD Card (it should look similar to below).

[kyau@hex ~]$ sudo fdisk -l
[sudo] password for kyau:

Disk /dev/mmcblk0: 14.7 GiB, 15719727104 bytes, 30702592 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x417ee54b

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
/dev/mmcblk0p2 186368 3667967 1740800 5 Extended
/dev/mmcblk0p5 188416 3667967 1739776 83 Linux

Now that we have located the device node as mmcblk0 we can use fdisk to resize the partition. First pull up a list of all of the partitions in the table, then remove and recreate the extended partition.

[kyau@hex ~]$ sudo fdisk /dev/mmbblk0
[sudo] password for kyau:

Welcome to fdisk (util-linux 2.24.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk0: 14.7 GiB, 15719727104 bytes, 30702592 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x417ee54b

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
/dev/mmcblk0p2 186368 3667967 1740800 5 Extended
/dev/mmcblk0p5 188416 3667967 1739776 83 Linux

Command (m for help): d
Partition number (1,2,5, default 5): 2

Partition 2 has been deleted.

Command (m for help): n

Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e
Partition number (2-4, default 2):
First sector (186368-30702591, default 186368):
Last sector, +sectors or +size{K,M,G,T,P} (186368-30702591, default 30702591):

Created a new partition 2 of type 'Extended' and of size 14.6 GiB.

Command (m for help): n

Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l

Adding logical partition 5
First sector (188416-30702591, default 188416):
Last sector, +sectors or +size{K,M,G,T,P} (188416-30702591, default 30702591):

Created a new partition 5 of type 'Linux' and of size 14.6 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

With the partition table updated, reboot the computer to enact the changes.

[kyau@hex ~]$ sudo systemctl reboot

Once the machine reboots log back into the machine and resize the filesystem with the resize2fs command.

[kyau@hex ~]$ sudo resize2fs /dev/mmcblk0p5
[sudo] password for kyau:

resize2fs 1.42.10 (18-May-2014)
Filesystem at /dev/mmcblk0p5 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p5 is now 3814272 blocks long.

Tweaks

None of the following is required and should all be considered optional, as such it is included merely for reference.

Auto Login

To enable automatic login to the console after boot you will need to add a service to systemd. First create the required directories and then the required service unit file.

[kyau@hex ~]$ sudo mkdir -p /etc/systemd/system/getty@tty1.service.d/
[kyau@hex ~]$ sudo vim /etc/systemd/system/getty@tty1.service.d/autologin.conf
———
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin kyau --noclear %I 38400 linux
Type=idle
———