Skip to content

Instantly share code, notes, and snippets.

@Lahorde
Last active September 4, 2018 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lahorde/d459695668ed299beec5af20dd34f0f4 to your computer and use it in GitHub Desktop.
Save Lahorde/d459695668ed299beec5af20dd34f0f4 to your computer and use it in GitHub Desktop.
Raspberry partitioning scheme

Raspberry Read Only File System

Description

This gist provides a partitioing scheme and some tips to have a RO protected filesystem on your favorite distribution. It is well suited for Raspberry filesystem as it is stored on an SDCard.

Raspberry case

On several Raspberries I got some failing filesystems after some months of use. Some of it were occasionally rebooted and often rebooted cleanly. Lot of writes to SD were done as it stored some databases. But from what I've read, most of sd card failure causes are :

overclocking

now out of date on recent Raspberry firmware - it was solved in end of 2013

under / over voltage

A

###sudden power loss

maximum number of write limit per sector reached - endurance

There is no read limit. For write limit it is ~100k.

For instance, it would take over 10 years to wear out an area on the SD Card on which a file of any size (from 512 bytes to maximum capacity) was rewritten 3 times per hour, 8 hours a day, 365 days per year. With typical applications, the endurance limit is not of any practical concern to the vast major

In an extreme use, with our previous file rewritten all minutes, 24 hours a day it would take less than 2.5 months to reach this limit.

More info can be found in Sandisk SD Card Prod Manual

https://cdn-shop.adafruit.com/datasheets/TS16GUSDHC6.pdf

number of write /block on SSD /SD

check errors on journalctl and move needed folders to ...

persistent logs when shutting down, unmounting /var/log won't be successful => it's not an issue as discussed here : https://bbs.archlinux.org/viewtopic.php?pid=1204644#p1204644

non persistent logs cf journalf.conf, si message d'erreur lorsque commane journalctl --boot=-1 bien vérifier que /var/log/journal existe

disable man-db service

sudo systemctl maks man-db.timer
# no need to disable man-db unit, it is just linked to man-db.timer that starts it periodically

man-db update must be done manually (it also must be updated on pacman pkg install)

sudo systemctl start man-db

disable logrotate service

issues : umount /var/log

sudo systemctl mask logrotate.timer
# no need to disable logrotate unit, it is just linked to man-db.timer that starts it periodically

logrotate must be done manually (it also must be updated on pacman pkg install)

sudo systemctl start logrotate

openhab2

Unable to update instance pid: /usr/share/openhab2/runtime/instances/instance.properties (Read-only file system)

Solution :

sudo mkdir -p /others_rw_flash/usr/share/openhab2/runtime/instances/
fs_rw /
sudo mv  /usr/share/openhab2/runtime/instances/instance.properties /others_rw_flash/usr/share/openhab2/runtime/instances/
sudo ln -s /others_rw_flash/usr/share/openhab2/runtime/instances/instance.properties /usr/share/openhab2/runtime/instances/

In some cases it is not possible to remount system as read only

systemd timesyncd et systemcd 234 235, without timesync all ssl verification will fail because your clock will be in the past.

systemd

problem on ro fs, systemd needs rw permission on `/var/lib`

solution

use chronyd
do not forget to trim clock on chrony startup
initstepslew 30 server ntp-serv.inrialpes.fr server 0.arch.pool.ntp.org
https://chrony.tuxfamily.org/manual.html

# enable it on netctl connection
cat /etc/netctl/hooks/chrony-service-dispatcher 
#!/bin/sh

# Hooks to toggle chrony online state
ExecUpPost="systemctl restart chronyd"
ExecDownPre="systemctl stop chronyd"

https://raspberrypi.stackexchange.com/questions/26800/how-can-a-read-only-sd-card-get-corrupted-repeatedly [Sandisk SD Card Prod Manual]: http://www.convict.lu/pdf/ProdManualSDCardv1.9.pdf

#
# /etc/fstab: static file system information
#
# <file system> <dir> <type> <options> <dump> <pass>
/dev/mmcblk0p1 /boot vfat defaults,ro,errors=remount-ro 0 0
/dev/mmcblk0p6 /home ext4 defaults,ro,errors=remount-ro 0 0
# Keep pacman package cache in a separate partition
/dev/mmcblk0p7 /var/cache/pacman/pkg ext4 defaults,noatime 0 0
# Persistent logs
/dev/mmcblk0p5 /var/log ext4 defaults,noatime 0 0
# Non persistent logs
#tmpfs /var/log tmpfs defaults,size=32M 0 0
# In this partition are stored all rw files that cannot be in RAM
/dev/mmcblk0p8 /others_rw_flash ext4 defaults,noatime 0 0
tmpfs /var/tmp tmpfs nodev,nosuid 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment