11
submitted 11 months ago* (last edited 11 months ago) by GustavoM@lemmy.world to c/raspberrypi@lemmy.ml

Title. Asides from setting the whole disk to read-only. (It's not an option since apparently docker dislikes that for some reason.). I'm trying to increase my microsd's lifespan.

For instance, here's my current /etc/fstab

tmpfs /tmp tmpfs rw,size=10M,nr_inodes=5k,noexec,nodev,nosuid,uid=gus,gid=notgus,noatime,mode=1700

tmpfs /var/log tmpfs rw,size=10M,nr_inodes=5k,noexec,nodev,nosuid,uid=gus,gid=notgus,noatime,mode=1700

tmpfs /var/tmp tmpfs rw,size=0M,nr_inodes=5k,noexec,nodev,nosuid,uid=gus,gid=notgus,noatime,mode=1700

tmpfs /var/run tmpfs rw,size=0M,nr_inodes=5k,noexec,nodev,nosuid,uid=gus,gid=notgus,noatime,mode=1700

tmpfs /var/spool tmpfs rw,size=0M,nr_inodes=5k,noexec,nodev,nosuid,uid=gus,gid=notgus,noatime,mode=1700

tmpfs /var/lock tmpfs rw,size=0M,nr_inodes=5k,noexec,nodev,nosuid,uid=gus,gid=notgus,noatime,mode=1700

tmpfs /var/cache tmpfs rw,size=0M,nr_inodes=5k,noexec,nodev,nosuid,uid=gus,gid=notgus,noatime,mode=1700

Thanks in advance.

top 4 comments
sorted by: hot top controversial new old
[-] theit8514@lemmy.world 5 points 11 months ago

This is what overlayfs is designed for. You can turn it on in the raspi-config tool under performance. While the overlayfs is on, all writes will just happen in memory. You should also have an update-motd script which will let you know when overlayfs is on.

$ cat /etc/update-motd.d/80-overlay
#!/bin/sh

str=$(mount | grep ' on / ')
if echo $str | grep -q 'overlay'; then
        printf "\n\e[5m\e[1;31m------ INFO: / MOUNTED WITH OVERLAY ------\e[0m\n\n"
elif echo $str | grep -q 'rw'; then
        printf "\n\e[1;32m++++++ INFO: / MOUNTED READ-WRITE ++++++\e[0m\n\n"
else
        printf "\n\e[5m\e[1;31m!!!!!! WARNING: / UNKNOWN STATE !!!!!!\e[0m\n\n"
fi
[-] GustavoM@lemmy.world 1 points 11 months ago* (last edited 11 months ago)

What if my board has barely any available ram for that? (Right now its running sway, docker w/ nextdns and playing a 24/7 livestream through ffplay/yt-dlp and the available ram varies between 90MiB to 300 MiB.)

[-] theit8514@lemmy.world 2 points 11 months ago

It would work like the existing tmpfs that you already have. It overlays the tmpfs over the readonly filesystem mount:

/dev/mmcblk0p2 on /media/root-ro type ext4 (ro,relatime)
tmpfs-root on /media/root-rw type tmpfs (rw,relatime)
overlayroot on / type overlay (rw,relatime,lowerdir=/media/root-ro,upperdir=/media/root-rw/overlay,workdir=/media/root-rw/overlay-workdir/_)

df will tell you how much ram has been reserved for the tmpfs and how much has been "written." On my 4GB Pi that is ~1.5GB. Mine is usually pretty idle and has been up for 40 days, so at 12% used ~1.5GB will last me quite a bit.

$ df /media/root-*
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/mmcblk0p2  59839564 1857276  55517464   4% /media/root-ro
tmpfs-root       1964220  234828   1729392  12% /media/root-rw
[-] i_am_not_a_robot@feddit.uk 1 points 11 months ago

You can use f2fs to increase the lifespan.

this post was submitted on 21 Dec 2023
11 points (100.0% liked)

raspberrypi

3255 readers
1 users here now

Community about the single-board computers, micro-controllers and related projects.

https://www.raspberrypi.com/

Other RaspberryPi communities on Lemmy

founded 4 years ago
MODERATORS