Raspberry Pi - Arch Linux Install Notes
Image SD Card
Download and image your SD Card with the image located at Arch Linux ARM.
Linux
dd bs=1M if=/path/to/archlinux-hf-2013-07-22.img of=/dev/sdX
Windows
Download and install Win32DiskImager.
Initial Boot & Configuration
Go ahead and plug the SD Card back into the Raspberry Pi (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. Before you do anything it would be a good idea to change the root password.
passwd
System Update
First we need to update the system to make sure everything is current. Before you do so it would be a good idea to edit the /etc/pacman.d/mirrorlist in order to select a mirror that is closest to your location. I have found that the default auto-selection mirror doesn't work that well. Un-comment the mirror that best suits your location.
vi /etc/pacman.d/mirrorlist
#Server = http://mirror.archlinuxarm.org/armv6h/$repo ... Server = http://ca.us.mirror.archlinuxarm.org/armv6h/$repo |
You can also take this time to enable the Color option in the /etc/pacman.conf if you like.
vi /etc/pacman.conf
# Misc options #UseSyslog Color #TotalDownload CheckSpace #VerbostPkgLists |
Run pacman to update the system. After this it is safe to reboot to enact the changes.
pacman -Syu
systemctl reboot
Now that the system is up to date we can 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.
pacman -S packer arm-mem-git linux-headers-raspberrypi-latest linux-raspberrypi-latest vim
systemctl reboot
Configuration
Upon login you should be able to see that you are now running the latest available kernel version. I now take the time to setup the actual system itself as if you just rebooted into a fresh Arch Linux installation.
Hostname
Begin by setting the hostname. I will be using the hostname archey.kyau.net.
hostnamectl set-hostname archey.kyau.net
Timezone
Set the timezone. For me this is US/Pacific.
timedatectl set-timezone US/Pacific
Locale
Setup the appropriate locale. First edit the /etc/locale.gen file and un-comment the lines that correspond to your language selection. Generate the needed locales, set you keymap and finally set the with the system.
vim /etc/locale.gen
en_US ISO-8859-1 en_US.UTF-8 |
locale-gen
localectl set-keymap us
localectl set-locale LANG="en_US.UTF-8"
Time/Date Syncing
Finally we can install and enable ntp. This is not required but as the RPi does not have a hardware clock it is useful to use a time syncing service.
pacman -S ntp
systemctl enable ntpd
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 log off the root account. I will be using the username kyau for the extent of this write-up. Finally we can also change the root password.
useradd -m -g users -s /bin/bash kyau
passwd kyau
pacman -S sudo
visudo
kyau ALL=(ALL) NOPASSWD: ALL |
passwd
At this point you can again safely shutdown the RPi. Once you see only the red LED lit you can safely pull the power.
systemctl poweroff
Parition Management
Next you will need to decide what you will be using as the main drive. If all you have is an SD Card use the second option. However if you plan on experimenting with overclocking or you happen to have an external USB hard drive or USB flash drive that is of adequate size it will be better in the long run to use this as your main drive instead. No matter which method you use you will always need an SD Card for at bare minimum the /boot partition.
Main Drive: USB Drive (OC-Friendly)
If you are going to be using a USB hard drive you should really consider moving the Arch install to the USB hard drive. This will increase overall speed of the RPi and give you the option of overclocking as you will no longer be limited by SD corruption. Start by plugging your SD Card and USB hard drive into a separate Linux machine.
Partitioning
Pull up a list of all partition table information and locate the USB hard drive.
fdisk -l
Then launch fdisk on the USB hard drive. In my case this happens to be /dev/sdb.
fdisk /dev/sdb
Start by refreshing the drive to a DOS partition table, then create three partitions: a 15GB root partition, a 1GB swap partition, and finally the rest of the drive for the media partition.
Welcome to fdisk (util-linux 2.23.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 Building a new DOS disklabel with disk identifier 0x2c00a6a4. 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 (256-976754644, default 256): Using default value 256 Last sector, +sectors or +size{K,M,G} (256-976754644, default 976754644): +15G Partition 1 of type Linux and of size 15 GiB is set Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (3932416-976754644, default 3932416): Using default value 3932416 Last sector, +sectors or +size{K,M,G} (3932416-976754644, default 976754644): +1G Partition 2 of type Linux and of size 1 GiB is set Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (3,4, default 3): First sector (4194560-976754644, default 4194560): Using default value 4194560 Last sector, +sectors or +size{K,M,G} (4194560-976754644, default 976754644): Using default value 976754644 Partition 3 of type Linux and of size 3.6 TiB is set |
Next change the partition type of the swap partition.
Command (m for help): t Partition number (1-3, default 3): 2 Hex code (type L to list all codes): 82 Changed type of partition 'Linux' to 'Linux swap / Solaris' |
Finally write the changes to the drive and format the partitions.
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. |
mkfs.ext4 /dev/sdb1
mkfs.ext4 /dev/sdb3
mkswap /dev/sdb2
Clone the Current System
Then mount the old and new system partitions and copy over the existing Linux installation.
mount /dev/sdb1 /mnt/usb
mount /dev/sdd5 /mnt/tmp
cd /mnt/tmp && cp -a * /mnt/usb
When finished un-mount both partitions and then mount the /boot partition from the SD Card.
cd && umount /mnt/{usb,tmp}
mount -t vfat -o rw,noauto,async,user,umask=1000 /dev/sdd1 /mnt/tmp
You will need to edit the cmdline.txt file and modify the boot line to boot off of the USB Drive instead of the the SD Card. If the USB Drive is the only external drive plugged into the RPi this will be /dev/sda.
vi /mnt/tmp/cmdline.txt
ipv6.disable=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/sda1 rootfstype=ext4 elevator=noop rootwait |
You can now un-mount the SD Card and re-plug them into your RPi and continue.
cd && umount /mnt/tmp
Finalizing
Note that when booting off of USB there is an initial delay to initialize the USB drive right after you see the RPi logo. After you boot back into your RPi login and edit the /etc/fstab to reflect the new partitions.
sudo vim /etc/fstab
# # /etc/fstab: static file system information # # <file system> <dir> <type> <options> <dump> <pass> /dev/sda1 / ext4 defaults,noatime 0 0 /dev/mmcblk0p1 /boot vfat defaults 0 0 /dev/sda2 none swap defaults 0 0 /dev/sda3 /media ext4 defaults,noatime,nosuid,user 0 0 tmpfs /tmp tmpfs nodev,nosuid,size=2G 0 0 |
Then go ahead and reboot.
sudo systemctl reboot
Main Drive: SD Card
At this point remove the SD Card from your RPi and plug it into another Linux machine. Given that we used a pre-made image to install Arch Linux onto our SD Card, it came with pre-defined partitions that are not sized to your entire SD Card. To fix this we will be making a backup of the install, then resizing the partition and finally re-formatting it with a different filesystem than before for better SD Card performance.
Use the fdisk command to display all of your devices and locate the device node of the newly inserted SD Card (it should look similar to below).
sudo fdisk -l
Device Boot Start End Blocks Id System /dev/sdc1 2048 186367 92160 c W95 FAT32 (LBA) /dev/sdc2 186368 3667967 1740800 5 Extended /dev/sdc5 188416 3667967 1739776 83 Linux |
Backup Current Installation
First mount the SD Card to a temporary directory, then copy over (with permissions) the entire contents of the partition to a temporary folder.
sudo mkdir -p {/mnt/rpi,/mnt/rpi-backup/rpi,/mnt/rpi-backup/boot}
sudo mount /dev/sdc5 /mnt/rpi
cd /mnt/rpi
sudo cp -a * /mnt/rpi-backup/rpi/
When finished un-mount the partition before continuing.
cd && sudo umount /mnt/rpi
Expand the Linux Partition
Remembering the device node from earlier, go ahead and open it up in fdisk.
sudo fdisk /dev/sdc
Remove the Linux and Extended partitions.
Command (m for help): d Partition number (1,2,5, default 5): 5 Partition 5 is deleted Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 is deleted |
Create new partitions using the entirety of the SD Card.
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-61405183, default 186368): Using default value 186368 Last sector, +sectors or +size{K,M,G} (186368-61405183, default 61405183): Using default value 61405183 Partition 2 of type Extended and of size 29.2 GiB is set 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-61405183, default 188416): Using default value 188416 Last sector, +sectors or +size{K,M,G} (188416-61405183, default 61405183): Using default value 61405183 Partition 5 of type Linux and of size 29.2 GiB is set |
Write the changes to the partition table to exit fdisk.
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. |
F2FS
F2FS (Flash-Friendly File System) is a file system created by Samsung intended for NAND-based flash memory. In my experience I have better results using this as apposed to ext3/4. If you are modifying the SD Card from an Arch Linux machine simply install the package for F2FS.
sudo pacman -S f2fs-tools
Format the new Linux partition on the SD Card with F2FS.
sudo mkfs.f2fs /dev/sdc5
Mount the new partition, edit the /etc/fstab in the backup to reflect changing to F2Fs and then copy back the Arch Linux installation.
sudo mount /dev/sdc5 /mnt/rpi
cd /mnt/rpi-backup/rpi
sudo vim etc/fstab
# <file system> <dir> <type> <options> <dump> <pass> /dev/mmcblk0p5 / f2fs defaults,noatime,discard 0 0 /dev/mmcblk0p1 /boot vfat defaults 0 0 |
sudo cp -a * /mnt/rpi/
Un-mount the Linux partition. Mount the FAT32 boot partition.
cd && sudo umount /mnt/rpi
sudo mount -t vfat -o rw,noauto,async,user,umask=1000 /dev/sdc1 /mnt/rpi
Edit the cmdline.txt file to change the filesystem type from ext4 to f2fs. The file should now look something like the following.
... console=tty1 root=/dev/mmcblk0p5 rootfstype=f2fs elevator=noop rootwait |
You can now return the SD Card to the RPi and turn it back on. Your RPi will boot into the new F2FS partition which if you check df you should confirm it has been expanded to accommodate all the space available on the SD Card.
User Setup
Next I download and restore my RPi home directory backup.
wget http://kyau.net/kyau-rpi.tar.bz2
tar zxvf kyau-rpi.tar.bz2
rm kyau-rpi.tar.bz2
Re-login to enact all the changes.
Xorg Install
With the RPi fully configured let's move on to installing Xorg. Before we begin we must install the base development package group in order to build packages on the RPi.
sudo pacman -S base-devel
Then proceed by installing the base for Xorg along with the proper video driver for the RPi.
sudo pacman -S xorg-server xorg-xinit xorg-server-utils mesa xf86-video-fbdev
Next install a window manager and some basic applications, themes and fonts.
sudo packer -S openbox-git
Here you will encounter the first package that refuses to compile, the following message is roughly what you will see.
==> ERROR: docbook-to-man is not available for the 'armv6h' architecture. |
The solution is actually really quite simple, rerun the install command and this time choose to edit the PKGBUILD of that package. Modify the arch line to look like the following.
arch=(i686 x86_64 armv6h) |
The package should now build properly, you will encounter this a couple of times during the following steps use this exact method to remedy the problem every time.
sudo pacman -S lxappearance lxappearance-obconf notify-osd rxvt-unicode stalonetray ttf-liberation
sudo pacman -S gedit mirage thunar tumbler thunar-archive-plugin file-roller unrar zip unzip
sudo packer -S volumeicon-git gtk-engine-mist elementary-icon-theme gtk-theme-elementary-bzr
sudo packer -S terminus-font
Packages that need you to edit the PKGBUILD: docbook-to-man openbox-git volumeicon-git gtk-engine-mist gtk-theme-elementary-bzr
XBMC
Now that the Arch Linux baseline is finished let's get to installing XBMC.
sudo packer -S xbmc-rbp-git
The latest version they forgot to fix some permissions on the RPi with Arch. Let's add these now, create the following file and dump the contents into it.
sudo vim /etc/udev/rules.d/raspberrypi.rules
SUBSYSTEM=="vchiq|input", MODE="0777" KERNEL=="mouse*|mice|event*", MODE="0777" |
Autologin
With XBMC installed we can now configure Arch Linux to autologin to your user account.
sudo mkdir /etc/systemd/system/getty@tty1.service.d
sudo vim /etc/systemd/system/getty\@tty1.service.d/autologin.conf
[Service] ExecStart= ExecStart=-/usr/bin/agetty --autologin kyau --noclear %I 38400 linux Type=simple |
Start X at Login
Finally let's get Xorg starting upon login.
vim ~/.bash_profile
# Start X at Login [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx |