Setup Raspberry Pi with Arch Linux
Setup Raspberry Pi with Arch Linux
- author
-
akeil
- date
-
2013-12-28
- version
-
2
- Updated
-
2014-06-09
Note
2014-06-09: Added instructions on how to Change Partition Size.
This post describes how to install and set up Arch Linux ARM 1 on a Raspberry Pi 2 (a Model B Rev 2.0, precisely). This is done by writing the bootable Arch Linux ARM image onto an SD card, then booting the Raspberry Pi with that card. The Pi needs to be connected to the network only, it does not require a monitor or a keyboard.
Requires a PC with a card reader and internet access plus a SD card with at least 2GB storage and finally router that supports DHCP.
ArchLinux is a Linux distribution aimed at simplicity and flexibility. It has a certain "do-it-yourself-style", meaning that most things are not pre-installed or preconfigured. Luckily the Arch Wiki 3 has excellent documentation on most topics.
Prepare the Image
Download the image from the download URL listed at the Arch Linux ARM for Raspberry Pi 4 page.
After the files have downloaded,
compare the output of md5sum
with the downloaded checksum
to verify the integrity of the file.
If everything is OK, unzip the image.
The ZIP-archive and the md5 checksum are now longer needed and can be deleted.
$ wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.zip $ wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.zip.md5 $ md5sum ArchLinuxARM-rpi-latest.zip $ cat ArchLinuxARM-rpi-latest.zip.md5 $ unzip ArchLinuxARM-rpi-latest.zip $ rm ArchLinuxARM-rpi-latest.zip $ rm ArchLinuxARM-rpi-latest.zip.md5
This should leave a single file named archlinux-hf-YYYY-MM-DD.img
with about 2GB in size. This file goes onto the SD card.
Insert the SD card into the PC's card reader.
After making sure that the device is not mounted, use dd
to write
the image to the SD card (as root):
Warning
dd
will overwrite any content on the SD card.
# dd bs=1M if=/the/image.img of=/dev/sdX # sync
/dev/sdX
is the device name of the card
(for example /dev/sdc
).
The command will not generate any output until it completes,
which may take a while.
The sync
command flushes the file system buffers.
Run it to make sure that the data is completely written
before the SD card is removed.
Change Partition Size
The image comes with a predefined partition size of about 1.7 GB for the main partition. Depending on how many additional packages you are going to install, this can turn out to be a bit low.
Although the partition can be resized while the system is running (see this forum post 8), it is safer to do it right after writing the image onto the SD card and before inserting the card into the Raspberry Pi.
# fdisk /dev/sdX
Press
p
to print the current partition table.-
Press
d
to delete a partition.Delete partition
2
.
-
Press
n
to create a new partitione
to select the "extended" partition type<enter>
to accept the suggested partition number (should be "2").<enter>
to confirm the offset for the first sector<enter>
to confirm the offset last sector
-
Press
n
to create another partitionl
for a "logical" partition (partition number is assigned automatically and should be "5").<enter>
to confirm the offset for the first sector<enter>
to confirm the offset last sector
Press
w
to write the partition table
The complete session will look like this:
Command (m for help): p Disk /dev/sdc: 3965 MB, 3965190144 bytes 122 heads, 62 sectors/track, 1023 cylinders, total 7744512 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 Disk identifier: 0x417ee54b 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 Command (m for help): d Partition number (1-5): 2 Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): e Partition number (1-4, default 2): Using default value 2 First sector (186368-7744511, default 186368): Using default value 186368 Last sector, +sectors or +size{K,M,G} (186368-7744511, default 7744511): Using default value 7744511 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-7744511, default 188416): Using default value 188416 Last sector, +sectors or +size{K,M,G} (188416-7744511, default 7744511): Using default value 7744511 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
Then, resize the partition with:
# e2fsck -f /dev/sdX5 # resize2fs /dev/sdX5
The resized partitions should look like this:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT [...] sdc 8:32 1 3.7G 0 disk ├─sdc1 8:33 1 90M 0 part ├─sdc2 8:34 1 1K 0 part └─sdc5 8:37 1 3.6G 0 part [...]
Install
Insert the SD card and connect the Raspberry Pi via Ethernet to your router and power it up.
See if it boots.
Booting takes some time (LED's blinking).
When complete, all status LED's should be on except the ACT
.
The Raspberry Pi status LED'S:
Label |
Color |
Meaning |
---|---|---|
ACT |
Green |
SD Card Access |
PWR |
Red |
Power |
FDX |
Green |
Full Duplex LAN connected |
LNK |
Green |
Link/Activity (LAN) |
100 |
Yellow |
100Mbit LAN connected |
Luckily, the Arch Linux ARM image for the Raspberry Pi comes preconfigured
to start sshd
on boot and allow root-login via SSH.
It also supports DHCP 5 which means that if your router has DHCP enabled, the Raspberry Pi will automatically obtain an IP address from the router.
To find out which IP was assigned, either ask your router or guess (guessing is actually not that bad - most routers will follow some semi-predictable pattern when handing out IP addresses).
Log in via ssh:
$ ssh root@ip-of-your-pi
The initial password for the root user is "root", without the quotes.
Post Installation
The Arch Linux beginners guide 6 is also applicable to Arch Linux ARM and describes many standard tasks.
Some Small Details
Set the hostname
Although the default alarmpi
is pretty cool,
you can change the hostname to whatever you like:
# echo my-pretty-pi > /etc/hostname
Time Settings
To change or set the local time zone:
# rm /etc/localtime # ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
Run the date
command to print the current local time.
The Raspberry Pi has no Real Time Clock (RTC) which means it will lose its time setting as soon as the power goes off. If it is always (or most of the time) connected to the internet, consider using NTPd 7 to obtain the current time. NTPd is already installed and just needs to be enabled:
# systemctl enable ntpd # systemctl start ntpd
(enable
to always start on boot, start
to start right now)
Passwords and Users
To change the password for the root user, just type:
# passwd
This Will open a prompt where you enter your new root password (2x).
The root user should not be used for non-administrative tasks. So add a user for yourself and give it a password:
# useradd -m -s /bin/bash username # passwd username
The -m option will create a home directory for the new user
in /home/username
.
A group with the same name will also be created
if USERGROUPS_ENAB
is set to "yes" in /etc/login.defs
(which it is).
Configure SSH
If you plan to log in to the Raspberry Pi frequently via SSH, you can make your life easier.
SSHD
Edit /etc/ssh/sshd_config
to contain the following lines:
# /etc/ssh/sshd_config PermitRootLogin no RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile %h/.ssh/authorized_keys AllowUsers your-username
Then restart sshd:
# systemctl restart sshd
You can easily check if everything worked out - if you cannot login via SSH anymore, it didn't.
Also, journalctl --unit sshd
will list log messages related
to SSH - for example denied login attempts.
Authenticate Without a Password
To log yourself in without a password, generate a key for yourself (on your PC, not on the Raspberry Pi):
$ ssh-keygen -t rsa -b 2048 -f ~/.ssh/name-of-keyfile
Will create two files name-of-keyfile
(the Private Key)
and name-of-keyfile.pub
(the Public Key)
in the ~./ssh
directory. The .pub file goes onto the Raspberry Pi.
Configure the SSH client to use your keyfile automatically:
$ touch ~/.ssh/config $ chmod 600 ~/.ssh/config $ nano ~/.ssh/config
Add the following entry to the config file:
Host rpi-address IdentityFile ~/.ssh/name-of-keyfile User username
Where "rpi-address" is the IP address of your Raspberry Pi and username is your remote username (on the Pi).
Transfer the keyfile to the Raspberry Pi:
$ scp ~/.ssh/name-of-keyfile.pub username@rpi-address:~
Switch to the Raspberry Pi to install the key:
# su username $ mkdir ~/.ssh $ touch ~/.ssh/authorized_keys $ chmod 600 ~/.ssh/authorized_keys $ cat ~/name-of-keyfile.pub >> ~/.ssh/authorized_keys $ rm name-of-keyfile.pub $ exit
You should now be able to use type ssh rpi-address
and be logged
in on the Raspberry Pi.