Skip to content

Instantly share code, notes, and snippets.

@sclaret
Last active October 22, 2021 20:45
Show Gist options
  • Save sclaret/08e7601720725e9ac987dc694e688d10 to your computer and use it in GitHub Desktop.
Save sclaret/08e7601720725e9ac987dc694e688d10 to your computer and use it in GitHub Desktop.
Arch Linux Raspberry Pi 3 B+

Arch linux

https://archlinux.org

https://archlinux.org/packages/

https://aur.archlinux.org

https://wiki.archlinux.org

https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-3

Prepare Files

mkdir arch
cd arch
wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz
md5sum *.tar.gz
wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz.md5

apt install dosfstools btrfs-progs 

mkdir root
tar -xpf ArchLinuxARM-rpi-aarch64-latest.tar.gz -C root/.

cd root/
nvim etc/hostname
pi3
nvim etc/ssh/sshd_config
PermitRootLogin prohibit-password
mkdir root/.ssh
cp ~/.ssh/authorized_keys root/.ssh/authorized_keys

Initialize SD Card

fdisk /dev/sdc
o
n
+1G
t
c
n
+2G
n
+32G
n
w

d=sdc
mkfs.vfat /dev/${d}1
mkfs.ext4 -F /dev/${d}2
mkdir /mnt/${d}{1,2,3}
mount /dev/${d}1 /mnt/${d}1
mount /dev/${d}2 /mnt/${d}2
df -h
cd ~/arch/root/
cp -aR boot/* /mnt/${d}1/.
cp -aR * /mnt/${d}2/.
rm -rf /mnt/${d}2/boot/*

blkid /dev/${d}1
nvim /mnt/${d}2/etc/fstab
UUID="B977-208D" /boot   vfat    defaults        0       0
reboot
snapshot: arch

ssh root@pi3
blkdiscard -f /dev/mmcblk0p3
blkdiscard -f /dev/mmcblk0p4

Add swap device

https://wiki.archlinux.org/title/Swap

mkswap /dev/sda3
blkid /dev/sda3
vim /etc/fstab
UUID="df5f5176-19e3-442d-8fa7-e729a568c520" swap swap defaults 0 0
reboot

swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/sda3 partition  10G   0B   -2

free -h
               total        used        free      shared  buff/cache   available
Mem:           895Mi       268Mi       231Mi       0.0Ki       396Mi       611Mi
Swap:            9Gi          0B         9Gi

sysctl vm.swappiness
vm.swappiness = 60

htop

Convert Root Partition to BTRFS

Note: PARTUUID seems to change when you copy a partition from one device to another

https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)

https://wiki.archlinux.org/title/Solid_state_drive#Periodic_TRIM

ssh root@pi3

userdel -r alarm
pacman-key --init 
pacman-key --populate archlinuxarm
pacman -Syu
pacman -Sy nvim
pacman -Sy uboot-tools btrfs-progs 

systemctl enable fstrim.timer
Created symlink /etc/systemd/system/timers.target.wants/fstrim.timer -> /usr/lib/systemd/system/fstrim.timer.

nvim /etc/mkinitcpio.conf
MODULES=(btrfs)
mkinitcpio -P

cd /boot
nvim boot.txt
part uuid ${devtype} ${devnum}:3 uuid
./mkscr

mkfs.btrfs -f /dev/mmcblk0p3
UUID:               c8908ca0-0815-4a29-ba97-bb6552b05c34
mkdir /mnt/snap
nvim /etc/fstab
UUID="c8908ca0-0815-4a29-ba97-bb6552b05c34" /mnt/snap btrfs defaults,subvolid=5 0 0
mount -a

cd /mnt/snap
mkdir root
cd root
btrfs subvolume create 10-empty
btrfs subvolume snapshot 10-empty 20-initial
btrfs subvolume get-default .
btrfs subvolume set-default 20-initial
btrfs subvolume get-default .
systemctl poweroff

d=sdc
mount /dev/${d}2 /mnt/${d}2
mount -o subvolid=5 /dev/${d}3 /mnt/${d}3
cp -a /mnt/${d}2/* /mnt/${d}3/root/20-initial/.
systemctl poweroff

[root@pi ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       4.0G  1.4G  2.3G  39% /
/dev/sda1      1022M  100M  923M  10% /boot
/dev/sda3       4.0G  1.4G  2.3G  39% /mnt/snap

btrfs subvolume show /
root/20-initial

cd /mnt/snap/root
btrfs subvolume snapshot 20-initial 30-apps
btrfs subvolume set-default 30-apps
btrfs subvolume get-default .
reboot
btrfs subvolume show /
btrfs subvolume list -tqu /

Update & Install Apps

May interfere with boot when upgraded:
pacman -Ql raspberrypi-bootloader
pacman -Ql mkinitcpio

pacman -Syu

pacman -Sy --noconfirm git neovim emacs-nox
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
emacs
pacman -Sy --noconfirm mlocate man-pages man-db tldr
pacman -Sy --noconfirm htop sysstat tmux
pacman -Sy mosquitto docker 
updatedb

/bin/bash <(curl -fsSL "https://raw.githubusercontent.com/sclaret/dotfiles/master/bootstrap/dotfiles?$(date +%s)")

cd /mnt/snap/root
btrfs subvolume snapshot 30-apps 40-mos
btrfs subvolume set-default 40-mos
btrfs subvolume get-default .
reboot

Upgrade

pacman -Syu
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment