【Hacker News搬运】使用只读根文件系统运行Raspberry Pi
-
Title: Running a Raspberry Pi with a read-only root filesystem
使用只读根文件系统运行Raspberry Pi
Text:
Url: https://www.dzombak.com/blog/2024/03/Running-a-Raspberry-Pi-with-a-read-only-root-filesystem.html
标题:在Raspberry Pi上运行只读根文件系统 内容概要: 本文介绍如何在Raspberry Pi等单板计算机上运行只读根文件系统,以延长SD卡的使用寿命。作者建议,对于不需要在Pi上存储任何状态的应用程序,可以考虑使用只读根文件系统。文章内容包括: 1. 准备SD卡,确保不需要的软件和不需要的服务已被禁用,SD卡没有用作交换空间。 2. 修改引导参数,禁用交换和文件系统检查。 3. 迁移到ntp服务,避免使用systemd-timesyncd。 4. 调整网络相关的文件和设置,以便在只读文件系统上正常工作。 5. 为必要的目录挂载tmpfs,例如/tmp、/var/tmp、/var/log、/var/spool/mail和/var/spool/rsyslog等。 6. 修改/etc/fstab,将SD卡的挂载参数更改为只读模式。 7. 配置系统维护的bash脚本,例如切换只读和读写模式。 8. 重启系统,检查挂载情况和日志,确保没有问题。 注意事项: - 只读根文件系统可能不适合所有应用场景,需要根据具体需求进行调整。 - 某些服务可能在只读文件系统上无法正常工作,需要进行相应的配置或禁用。 - 在只读文件系统上,日志记录可能需要特别处理,以确保日志数据能够被远程收集。 作者建议,在做出更改之前,应该仔细评估系统的需求,并确保有足够的知识来处理可能出现的问题。
Post by: ingve
Comments:
st_goliath: Surprisingly, the article doesn't seem to mention SquashFS[1] or EROFS[2].<p>Both SquashFS and EROFS are filesystem <i>specifically designed</i> for this kind of embedded, read-only use case. The former is optimized for high data density and compression, and already well established. The later is comparatively new and optimized for high read speed.[3] SquashFS as a rootfs can already be found in many embedded applications using flash storage and is typically also combined with tmpfs and persistent storage mount points or overlay mounts.<p>For both those filesystems, one would build a rootfs image offline. In the Debian ecosystem, there already exists a tool that can bootstrap a Debian image into SquashFS[4].<p>[1] <a href="https://en.wikipedia.org/wiki/SquashFS" rel="nofollow">https://en.wikipedia.org/wiki/SquashFS</a><p>[2] <a href="https://en.wikipedia.org/wiki/EROFS" rel="nofollow">https://en.wikipedia.org/wiki/EROFS</a><p>[3] <a href="https://www.sigma-star.at/blog/2022/07/squashfs-erofs/" rel="nofollow">https://www.sigma-star.at/blog/2022/07/squashfs-erofs/</a><p>[4] <a href="https://manpages.debian.org/testing/mmdebstrap/mmdebstrap.1.en.html" rel="nofollow">https://manpages.debian.org/testing/mmdebstrap/mmdebstrap.1....</a>
st_goliath: 令人惊讶的是,这篇文章没有;似乎没有提到SquashFS[1]或EROFS[2]<p> SquashFS和EROFS都是文件系统<i>,专门为这种嵌入式只读用例设计</i>。前者针对高数据密度和压缩进行了优化,并且已经建立起来。后者相对较新,并针对高读取速度进行了优化。[3] 作为rootfs的SquashFS已经在许多使用闪存的嵌入式应用程序中找到,并且通常还与tmpfs和持久存储装载点或覆盖装载相结合<p> 对于这两个文件系统,可以离线构建rootfs映像。在Debian生态系统中,已经存在一种可以将Debian图像引导到SquashFS[4]中的工具<p> [1]<a href=“https://;/;en.wikipedia.org//,wiki/:SquashFS”rel=“nofollow”>https:///;en.wikipedia.org/;wiki/;SquashFS</a><p>[2]<a href=“https://;/;en.wikipedia.org//!wiki/:EROFS”rel=“nofollow”>https:///;en.wikipedia.org/;wiki/;EROFS</a><p>[3]<a href=“https://;/;www.sigma-star。at/:blog/!2022/,07/)squashfs-EROFS/”rel=“nofollow”>https:///;www.sigma-star;博客/;2022;07;压扁erofs/</a> <p>[4]<a href=“https://;/;manpages.debian.org/:测试/!mmdebstrap/…mmdebstrap.1.en.html”rel=“nofollow”>https:///;manpages.debian.org/;测试;mmdebstrap;mmdebstrap.1</a>
floating-io: This problem seems very overblown to me. The simple answer is "don't skimp."<p>- Use a power supply that can deliver enough current<p>- Use good USB cables that can actually <i>carry</i> said current (a lot of people miss this one)<p>- Do not use cheap SD cards<p>- Oversize your card so that the card can properly perform wear-levelling.<p>I have a pair of Raspberry Pi's (2's and/or 3's IIRC) running constantly since 2015. They're running an ancient version of Redsleeve (and are on my list to rebuild but never mind that). DNS, DHCP, and a few other services run on them. They've also survived multiple abrupt powerfail events.<p>They log to the SD card, and yet I've never had a problem. I personally believe that the fact that I'm using oversized cards with gigabytes of free space is the key. Well, perhaps that and the fact that my personal home directory is on NFS.<p>Or maybe I'm just lucky? Who knows...
floating-io: 这个问题对我来说似乎言过其实了;don;不要吝啬"<p> -使用能够提供足够电流的电源<p>-使用真正能够<i>承载</i>所述电流的良好USB电缆(很多人错过了这个)<p>-不要使用廉价的SD卡<p>-过大尺寸的卡,以便卡能够正确地进行磨损平衡<p> 我有一双树莓派;s(2/s和/f或3/s IIRC)自2015年以来持续运行。他们;重新运行一个古老版本的红袖(在我的重建名单上,但没关系)。DNS、DHCP和其他一些服务都在它们上运行。他们;ve还经历了多次突然停电事件<p> 他们登录到SD卡,但我;I’我从来没有遇到过问题。我个人认为,事实上;我使用的超大卡有千兆字节的可用空间,这是关键。好吧,也许还有我的个人主目录在NFS上的事实<p> 或者也许我;我只是运气好?谁知道呢。。。
idatum: These Pi* devices have served well running their Debian version for years.<p>I had a Pi3b run ADS-B (generally RTL-SDR) for many years. Dang though, all with (seemingly) random SD storage failures. Article details seems like it can help.<p>There are more options now though. Aarch64 ones that use eMMC.<p>I replaced the Pi3b with a Pine64 Rock64 running FreeBSD 14 booting from eMMC. Simple and just works with all RTL-SDR needs covered.<p>It's great to have options, both hw and os.
idatum: 这些Pi*设备多年来一直运行良好的Debian版本<p> 我有一个Pi3b运行的ADS-B(通常是RTL-SDR)很多年了。不过危险的是,所有这些都是(看似)随机的SD存储故障。文章细节似乎会有所帮助<p> 不过现在有更多的选择。使用eMMC的Aarch64<p> 我用Pine64 Rock64取代了Pi3b,它运行从eMMC启动的FreeBSD 14。简单且适用于所有RTL-SDR需求<p> 它;有硬件和操作系统两种选择真是太好了。
blackfawn: I like using Alpine for read-only operation on the Pi right out of the box: <a href="https://wiki.alpinelinux.org/wiki/Raspberry_Pi" rel="nofollow">https://wiki.alpinelinux.org/wiki/Raspberry_Pi</a>
blackfawn: 我喜欢使用Alpine在Pi上进行只读操作,这是开箱即用的:<a href=“https://;/;wiki.alpinelinux.org//!wiki/:Raspberry_Pi”rel=“nofollow”>https:///;wiki.alpinelinux.org/x2F;wiki/;树莓_Pi</a>
jasongill: You can skip the ntp/systemd-timesyncd/fake-hwclock stuff if you add a RTC/coin battery to the device. The Raspberry Pi 5 has built-in RTC with support for an official battery which costs about five bucks and works well for this. Older devices have aftermarket RTC's with battery backups as well.
jasongill: 您可以跳过ntp/;systemd时间同步;如果你添加一个RTC/;硬币电池到设备。树莓派5内置RTC,支持官方电池,价格约为5美元,运行良好。较旧的设备具有售后市场RTC;s也有备用电池。