This is a guide to setup a Raspberry Pi as a webserver running Arch Linux ARM.
Some important links:
- http://archlinuxarm.org/platforms/armv7/broadcom/raspberry-pi-2
- https://wiki.archlinux.org/index.php/Raspberry_Pi
Raspberry Pi 2 B: much more powerfull than previous models, has 1GB RAM and a 900MHz CPU, very capable as a home server.
Make sure to get a high quality SD card (at least 8GB). SD cards easily corrupt and are often slow. Get a class 10 card from a well known brand.
A good power supply is also necessary. Phone chargers can work, but it should supply at least 1A, more if you want to power USB devices.
A heat sink is not necessary, but can be nice if you plan to overclock.
See http://archlinuxarm.org/platforms/armv7/broadcom/raspberry-pi-2 for more details.
wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
Insert the SD card into the reader on your computer and make sure that it is not mounted automatically. You need to make two partitions: /boot
(must be FAT32) and /
(ext4 recomended). You can do this with any partiton manager you like (gparted, parted, fdisk).
# The following must be done as root
su
# After filesystems are created mount the SD card
mkdir root
mount /dev/xxxx1 root
mkdir boot
mount /dev/xxxx2 boot
# Extract archive
bsdtar -xpf ArchLinuxARM-rpi-2-latest.tar.gz -C root
sync
# Move boot files
mv root/boot/* boot
# Unmount
umount boot root
Insert the SD card and turn on the power!
SSH is enabled by default, so connect ethernet and login from another computer. First you need to find the IP address of the Raspberry Pi (look in router settings or use Fing (an android app)). Default user is alarm with password alarm.
ssh alarm@<ip-address>
# Set a secure password
passwd
You can either do the same for the root account, or just lock it (you really should never login as root). The default password for root is root.
su
usermod -L root
pacman -Syu base base-devel vim archlinuxarm-keyring
pacman-key --init
pacman-key --populate archlinuxarm
Edit /etc/pacman.conf
:
...
Color
TotalDownload
ILoveCandy
...
SigLevel = Optional TrustAll
Run visudo. Add:
Defaults insults
Defaults editor=/usr/bin/rvim, !env_editor
%wheel ALL = (ALL) ALL
The Raspberry Pi does not have a realtime clock, so the time should be updated over the internet on each boot.
sudo timedatectl set-timezone America/New_York
sudo timedatectl set-ntp true
sudo hostnamectl set-hostname name
sudo fallocate -l 1024 /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Avoid using swap
sudo echo "vm.swappiness=5" > /etc/sysctl.d/fs.conf
Add the following line to /etc/fstab
swap /swapfile defaults 0 0
In /etc/fstab
add noatime,discard
to the mount options for /
.
Write journal to volatile storage: in /etc/systemd/journald.conf
add Storage=volatile
. Also add your user to the systemd-journald group to be able to view all of the journal gpasswd -a alarm systemd-journald
.
Do not store core dumps: in /etc/systemd/coredump.conf
add Storage=none
.
Install iotop to view disk I/O activity by process.
Since the Raspberry Pi is going to be running as a headless server, we can allocate more memory towards the CPU, instead of the GPU. In /boot/config.txt
add gpu_mem=16
. This is also where you can overclock the Pi if you want. For more information about all of the options see http://elinux.org/RPiconfig.
We are going to use nginx, since it is a lightweight, but high performance server.
pacman -S nginx