Skip to content
  • Blog
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Community Forum

  1. Home
  2. Categories
  3. Blog articles comments
  4. Protect your Raspberry PI SD card, use Read-Only filesystem

Protect your Raspberry PI SD card, use Read-Only filesystem

Scheduled Pinned Locked Moved Blog articles comments
lifefilesystemcardlogend
69 Posts 42 Posters 64.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CharlesC Offline
    CharlesC Offline
    Charles
    wrote on last edited by
    #36

    @rln-nard
    very interesting, thanks for sharing it 😉

    1 Reply Last reply
    • B Offline
      B Offline
      Bcow7
      wrote on last edited by
      #37

      Hi,
      Thank you very much for this tutorial. It helped me a lot! I have one issue that I can't solve by myself! I followed this tutorial step by step on my Raspian Jessie Lite system and it works perfectly...but when I put SD Card into another Raspberry Pi (same model RPi B+), it always boot with the IP (through Ethernet) 169.254.xxx.xxx. To fix it, I have to boot (only one time) without ",ro" in /etc/fstab for the disk "/". Then I can put back ",ro"! Do you think that I have some missing symlinks??
      Thanks

      1 Reply Last reply
      • CharlesC Offline
        CharlesC Offline
        Charles
        wrote on last edited by
        #38

        @Bcow7
        That's interesting, may be network config has MAC address hard coded and then it can't write the new. Did you tried to switch the SD and the Wifi Dongle at the same time ? (if you're not using eth0 of course) ?

        1 Reply Last reply
        • B Offline
          B Offline
          Bcow7
          wrote on last edited by
          #39

          @Charles
          Hi, I'm using eth0 and I don't have any Dongle or shield. I tried to list all modified files modified after I reboot in Read-Write, but I didn't find anything related to the MAC address... :-S

          1 Reply Last reply
          • M Offline
            M Offline
            MarkDurbin
            wrote on last edited by
            #40

            I've made a couple of scripts for this as I keep needing it for various projects.
            These work with the standard desktop and with the chrome browser as I use it for kiosk mode.
            The main problem I had was making the file system RO only to realize I needed to install/update something so I've included a script to re-enable RW mode.
            Nothing complicated, but they seem to work reliably.
            One caviat, if you riu the makerw script when the file system is already RW you'll screw up your OS, I should add a check at the start of the script really...
            https://github.com/MarkDurbin104/rPi-ReadOnly

            1 Reply Last reply
            • G Offline
              G Offline
              Gregor Ratajc
              wrote on last edited by Gregor Ratajc
              #41

              Hi,

              great tutorial, helped me a lot! Hopefully this will end my SD card corruption problems. One thing I noticed is that there is a constant error in syslog: frequency file /var/lib/ntp/ntp.drift.TEMP: Read-only file system - ntp wants to write driftfile but is unable to. I fixed that so that driftfile command in /etc/ntp.conf points to /tmp/ntp.drift.

              # /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
              
              driftfile /tmp/ntp.drift
              

              Another thing - I added loggly integration so I'm able to debug my Pi after reboots when syslogs are gone. I kept rsyslog and followed this guide (besides Python specific logging it also adds adds syslogs).

              Some info about driftfile: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-Understanding_the_Drift_File.html

              1 Reply Last reply
              • CharlesC Offline
                CharlesC Offline
                Charles
                wrote on last edited by
                #42

                @Gregor-Ratajc
                Thanks for the tip, I updated the tuturial according driftfile 😉

                1 Reply Last reply
                • CharlesC Offline
                  CharlesC Offline
                  Charles
                  wrote on last edited by
                  #43

                  I also updated to avoid the random-seed file problem

                  1 Reply Last reply
                  • B Offline
                    B Offline
                    Bruce Aldridge
                    wrote on last edited by
                    #44

                    I've used this multiple times, great resource.
                    One thing that could be made clearer is the tmpfs additions to fstab, I missed them and couldn't ssh in

                    1 Reply Last reply
                    • C Offline
                      C Offline
                      Christian Ferbar
                      wrote on last edited by
                      #45

                      Thanks a lot for this tutorial!
                      On debian jessie /usr/lib/tmpfiles.d/var.conf chmods /var/spool to 0755. This means that /tmp is changed to 0755 as well because we changed /var/spool to point to /tmp. So the /var/spool line in /usr/lib/tmpfiles.d/var.conf has to be commented out.
                      /run and /run/lock are tmpfs already, maybe they are better softlink targets than /tmp.

                      1 Reply Last reply
                      • X Offline
                        X Offline
                        xproto
                        wrote on last edited by
                        #46

                        @Bruce Aldridge
                        I cannot SSH too, to my RPi. What I did is I created a symlink for sshd

                        ln -s /tmp /var/run/sshd

                        Great article btw Charles! :). Thanks!

                        1 Reply Last reply
                        • X Offline
                          X Offline
                          xproto
                          wrote on last edited by
                          #47

                          Update: My mistake I missed the sysmlink for /var/run.

                          No need for my first comment.

                          v
                          v
                          v

                          1 Reply Last reply
                          • J Offline
                            J Offline
                            Joo
                            wrote on last edited by
                            #48

                            Hello,
                            There is a (rather new) Olimex single board card with onboard 4GB eMMC MLC/SLC Flash
                            Do you think this could be an answer to the corruption of data for an always on card ?
                            (with regular backup...of cours...) or the problem is not related to SD card ???
                            thx.

                            1 Reply Last reply
                            • N Offline
                              N Offline
                              notmichael
                              wrote on last edited by
                              #49

                              I tried this tutorial twice and both times couldn't SSH in after the final reboot. I found this tutorial a little more helpful - http://petr.io/en/blog/2015/11/09/read-only-raspberry-pi-with-jessie/. I susptec the difference was the part they mentione specifically enables SSH after changing these settings. That tutorial also makes it a little more clear that you have to add three lines in /etc/fstab, not just add ro twice.

                              1 Reply Last reply
                              • I Offline
                                I Offline
                                Ing.Fernando
                                wrote on last edited by
                                #50

                                Hi I successfully made my Pi Zero v 1.3 Read Mode, but a problem came up when I was trying to connect to internet with a 3g usb dongle.

                                First, the modem get connected to internet, but after a minute or less, it losed the connection, and then it reconnects, and the same story was looping forever.

                                After thinking, the problem was the DNS, because when the modem connects to internet, it changes the default DNS and tried to write the new DNS to the default file, here is the problem, the modem didn't notice that he cant write to the SD!

                                I took the solution from here: https://github.com/emoncms/emoncms/blob/master/docs/RaspberryPi/read-only.md

                                touch /tmp/resolv.conf
                                sudo rm /etc/resolv.conf
                                sudo ln -s /tmp/resolv.conf /etc/resolv.conf

                                touch /tmp/resolv.conf.dhclient-new
                                sudo chmod 777 /tmp/resolv.conf.dhclient-new
                                sudo rm /etc/resolv.conf.dhclient-new
                                sudo ln -s /tmp/resolv.conf.dhclient-new /etc/resolv.conf.dhclient-new

                                sudo mv /sbin/dhclient-script /sbin/dhclient-script_original
                                sudo ln -s /home/pi/emonpi/dhclient-script_raspbian_jessielite /sbin/dhclient-script

                                Then rebooted and all worked fine, the 3g modem connected to the internet and never disconnected, then I successfully SSH with weaved.com service.

                                After that another problem came up, my system is a GPS tracker for public transport, so there is a GPS module in my system, and the GPS was not working for the same reason as the 3g modem.

                                I'm using a "Ublox Neo 6m GPS" and GPSD to get the required information.

                                When GPSD run at boot it tryes to write a configuration file to open the stream, but it cant because the Pi is in read mode, so we need to put in that file what GPSD write at boot.

                                To solve this, just edit this file: /etc/default/gpsd

                                Then edit as this:

                                START_DAEMON="true"
                                GPSD_OPTIONS="-n"
                                DEVICES="/dev/ttyAMA0" #My GPS is connected via UART, change if yours is via USB or whatelse
                                USBAUTO="true"
                                GPSD_SOCKET="/var/run/gpsd.sock"

                                Finally reboot and all will work fine.

                                So, if you are having a problem with a sensor or what else, first verify if the program who communicates with it needs to write sometime to the SD.

                                Thank you and greetings from Mexico!!!

                                1 Reply Last reply
                                • F Offline
                                  F Offline
                                  FBorges
                                  wrote on last edited by
                                  #51

                                  Hi !

                                  I've tried to complete tour tutorial but when I do the step "Move some system files to temp filesystem", I've detected that it result on a dbus problem that when the Raspberry is rebooted It can resolve the dhcp and hostname service.

                                  Can anyone help me please?

                                  1 Reply Last reply
                                  • C Offline
                                    C Offline
                                    cfreund
                                    wrote on last edited by
                                    #52

                                    need to change UPEX4C_autoconfigfil in /usr/sbin/update-exim4.conf

                                    1 Reply Last reply
                                    • W Offline
                                      W Offline
                                      willn
                                      wrote on last edited by
                                      #53

                                      Will brick your Pi if you're running the new PIXEL distro. Any idea what's causing this?

                                      1 Reply Last reply
                                      • D Offline
                                        D Offline
                                        dgatwood
                                        wrote on last edited by
                                        #54

                                        You should really add some commentary about the tmpfs lines in /etc/fstab before the code listing. When I got to that step, I read that we were ready to set the volume to read-only, and thought, "I know how to do that," and stopped reading at that point, resulting in an unbootable system. I'd imagine many other folks with sysadmin experience will do the same. Actually, you should probably add the tmpfs lines first before you start making changes that depend on them, then make the changes, then change fstab a second time to make it read-only. Also, for Jessie, the systemd changes are unnecessary, because /run is already a tmpfs volume. And it might be worth redirecting things from /var/run to /run just for simplicity (on Jessie).

                                        1 Reply Last reply
                                        • B Offline
                                          B Offline
                                          Bruno Duarte
                                          wrote on last edited by
                                          #55

                                          How to fix this ?

                                          pi@raspberrypi(ro):~$ reboot
                                          Failed to execute operation: The name org.freedesktop.PolicyKit1 was not provided by any .service files
                                          Must be root.

                                          1 Reply Last reply

                                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                          With your input, this post could be even better 💗

                                          Register Login
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          4

                                          Online

                                          5.8k

                                          Users

                                          565

                                          Topics

                                          5.3k

                                          Posts

                                          Top Topics

                                          Popular Tags

                                          teleinfo
                                          25 topics
                                          arduino
                                          19 topics
                                          remora
                                          16 topics
                                          esp8266
                                          10 topics
                                          arduipi
                                          10 topics
                                          raspberry
                                          8 topics
                                          wifinfo
                                          7 topics
                                          broadcast
                                          7 topics
                                          Copyright © 2022 Charles-Henri Hallard | Return to blog page | Powered by NodeBB
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Blog
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups