I bought a raspberry 4b (4g mem) to use as a low-power home server and emulator console (libretro). By far it’s quite satisfactory.
This is a memo about my settings and tunings.
- Prepare SD card
- Customization and hardening
- Tuneables to minimize SD card IO
- Mount remote disk via iSCSI
- Gaming stuff: libretro and joystick
Prepare SD card
I started from the build at ArchLinuxARM but used a btrfs root instead of ext4.
The original instructions used ext4 should definitely work. It’s just I prefer to use a btrfs subvolume as root for a few reasons:
- transparent compression (makes the SD card less of a bottleneck)
- subvolume snapshots (enables convenient transfer with
btrfs send/receive, and backup like btrbk)
The following snippet assumes SD card is at
/dev/sdX. You need to use actual path in commands.
Partition the card
fdisk or other tools you like:
sdX1, a 100MB FAT partition, and set partition type to
W95 FAT32 (LBA). This becomes
sdX2with rest of the disk, and set partition type to
Linux. This becomes parent of other subvolumes including
- If swap space is required (think twice, it’s SD card after all), shrink
sdX2and create a swap partition now, because swap file is not supported in btrfs.
Refer to original instructions if you are uncertain about
mkfs and extract image
# cd /media # mkfs.vfat /dev/sdX1 # mkfs.btrfs /dev/sdX2 # mkdir -pv sdcard # mount /dev/sdX2 sdcard -o ssd,discard,compress=lzo # btrfs subvolume create sdcard/root-current # This subvolume becomes / at run time. It can be snapshot-ed separately. # mkdir sdcard/root-current/boot # mount /dev/sdX1 sdcard/root-current/boot # bsdtar -xpf ArchLinuxARM-rpi-4-latest.tar.gz -C sdcard/root-current
rootflags part to mount the subvolume at
-root=/dev/mmcblk0p2 rw rootwait console=ttyAMA0,115200 ... +root=/dev/mmcblk0p2 rootflags=subvol=/root-current rw rootwait console=ttyAMA0,115200 ...
sdcard/root-current/etc/fstab, add our mount options (it boots without these lines, but new created files won’t get compressed):
+/dev/mmcblk0p2 / btrfs defaults,compress=lzo,subvol=/root-current 0 0 +/dev/mmcblk0p2 /media/sdcard btrfs defaults,compress=lzo,subvol=/,noauto 0 0
/media/sdcard mount is not necessary for everyday use. It can be used to manage subvolumes / snapshots.
Customization and hardening
After successfully booting from SD card:
locale-gen(It’s strange that the
locale.gendoes not come with any locale.)
- Recommended: harden sshd and other security config
Tuneables to minimize SD card IO
After the following attempts, I’m already OK with the performance. Stopping here until I need to squeeze more out of it.
- vfat partition:
- btrfs partition:
Stop journald from persisting logs
# /etc/systemd/journald.conf [Journal] -Storage=auto +Storage=volatile
Mount remote disk via iSCSI
This is my first journey about iSCSI but it’s smoother than I thought.
Server aka “iSCSI target”
Client aka “iSCSI Initiator”
Gaming stuff: libretro and joystick
The CPU is ARMv8-capable but I don’t see any ARMv8 builds published. Guess I have to check the following links later: