Skip to content

Instantly share code, notes, and snippets.

@fmarcia
Last active January 28, 2017 22:41
Show Gist options
  • Save fmarcia/f96df1a3afadb51637b0 to your computer and use it in GitHub Desktop.
Save fmarcia/f96df1a3afadb51637b0 to your computer and use it in GitHub Desktop.
Read only Archilinux on raspberry pi

Initial system

Once the sdcard is inserted in your linux laptop, prepare partitions:

# create 1 fat32 partition (100MB)
# create 1 linux partition (remaining space)
# see http://archlinuxarm.org/platforms/armv6/raspberry-pi

# prepare mount points
$ cd /tmp
$ mkfs.vfat /dev/mmcblk0p1
$ mkfs.ext4 /dev/mmcblk0p2
$ mkdir boot root
$ mount /dev/mmcblk0p1 boot
$ mount /dev/mmcblk0p2 root

# populate them
$ wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz
$ bsdtar -xpf ArchLinuxARM-rpi-latest.tar.gz -C root
$ mv root/boot/* boot
$ sync

Before starting with the raspberry

Now that the standard installation is over, let's start preparing our system:

$ nano boot/cmdline.txt
# replace "rw" with "ro" after device name

$ echo rpi > root/etc/hostname # choose your own here

$ cat > root/etc/fstab
/dev/mmcblk0p1  /boot           vfat    defaults,ro,noatime,errors=remount-ro,nodev,nosuid,noexec 0  0
/dev/mmcblk0p2  /               ext4    defaults,ro,noatime,errors=remount-ro,data=ordered        0  1
tmpfs           /var/tmp        tmpfs   defaults,mode=1777                                        0  0
tmpfs           /var/log        tmpfs   defaults,mode=1777                                        0  0
tmpfs           /tmp            tmpfs   defaults,mode=1777,nodev,nosuid                           0  0
^D

$ cat > root/usr/bin/rw
#!/bin/bash
mount -o rw,remount /
mount -o rw,remount /boot
^D

$ cat > root/usr/bin/ro
#!/bin/bash
mount -o ro,remount /
mount -o ro,remount /boot
^D

$ chmod +x root/usr/bin/ro root/usr/bin/rw

$ cat >> root/etc/skel/.bashrc
export HISTFILE=/tmp/.$USER-bash_history
^D

$ cat >> root/root/.bashrc
export HISTFILE=/tmp/.root-bash_history
^D

$ cat >> root/home/alarm/.bashrc
export HISTFILE=/tmp/.alarm-bash_history
^D

$ sync
$ umount boot root

Now on the raspberry pi

Insert the sdcard in the raspberry pi.
Boot on the new system.
Log in as root with the password root.

Locale, keymap and localtime

$ rw

$ localectl status

$ localectl list-locales
$ localectl set-locale LANG=fr_FR.UTF-8 # choose your own here

$ localectl list-keymaps
$ localectl set-keymap fr # choose your own here

$ timedatectl
$ timedatectl list-timezones
$ timedatectl set-timezone Europe/Paris # choose your own here

Packages removal

$ pacman -Rns logrotate man-db man-pages jfsutils reiserfsprogs xfsprogs mdadm cryptsetup s-nail lvm2 haveged
$ sync
$ ro

Done

Reboot to apply settings.
The system is ready now.

After booting, / and /boot are read-only.
Run rw to get both / and /boot writable.
Run ro to set them back to read-only.

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