Community Forum
    • Blog
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

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

    Scheduled Pinned Locked Moved Blog articles comments
    lifefilesystemcardlogend
    69 Posts 42 Posters 48.4k Views
    Loading More Posts
    • 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.
    • J Offline
      Joo
      last edited by

      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 Reply Quote
      • N Offline
        notmichael
        last edited by

        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 Reply Quote
        • I Offline
          Ing.Fernando
          last edited by

          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 Reply Quote
          • F Offline
            FBorges
            last edited by

            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 Reply Quote
            • C Offline
              cfreund
              last edited by

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

              1 Reply Last reply Reply Quote
              • W Offline
                willn
                last edited by

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

                1 Reply Last reply Reply Quote
                • D Offline
                  dgatwood
                  last edited by

                  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 Reply Quote
                  • B Offline
                    Bruno Duarte
                    last edited by

                    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 Reply Quote
                    • M Offline
                      mjeanne
                      last edited by

                      you need to be root..
                      use 'sudo'

                      1 Reply Last reply Reply Quote
                      • M Offline
                        mocart2
                        last edited by

                        Hello! Can anybody help me with user crontab file? I have problem: i installed raspbian in Read-only mode, i have some scripts, (cron jobs) that works every 5 minutes, 10 etc. I set it by crontab -e command, but after reboot, system is clean it, i think, because i moved /var/spool dir to tmpfs (like howto), and user cronjob file stored at /var/spool/cron/crontabs dir. How i can fix it for not clearing after system reboot? Thanks!

                        1 Reply Last reply Reply Quote
                        • C Offline
                          Cavallonzio
                          last edited by

                          Did anyone figured out how to use crontab? it is wiped after reboot and i really need it 😞

                          1 Reply Last reply Reply Quote
                          • CharlesC Offline
                            Charles
                            last edited by

                            We need to put the system into Read Write Mode before changing the crontab
                            If you followed this tuto should be something like that

                            sudo mount -o remount,rw /
                            

                            Then edit your crontab

                            sudo crontab -e
                            

                            put pack in Read Only or reboot

                            sudo mount -o remount,ro /
                            
                            1 Reply Last reply Reply Quote
                            • Damian MacD Offline
                              Damian Mac
                              last edited by

                              Charles you are going wrong. crontab -e give us file on /tmp which has been deleted on boot. We need to go this way:
                              rw
                              sudo su
                              nano /etc/crontab (dont forget to add user) example below:

                                      • root /usr/bin/vpncheck.sh > /dev/null 2>&1
                              1 Reply Last reply Reply Quote
                              • N Offline
                                Neoromantic
                                last edited by

                                Hello Charles,
                                I was wondering if I don't have entry about /tmp being a mount entry point for tmpfs neither in fstab nor mtab, what would be the point in moving things there? Am I missing something or?
                                I am playing with Raspberry PI-2 and Raspbian Jessie.

                                1 Reply Last reply Reply Quote
                                • R Offline
                                  ricky
                                  last edited by

                                  This post is deleted!
                                  1 Reply Last reply Reply Quote
                                  • Rok JarcR Offline
                                    Rok Jarc
                                    last edited by

                                    Great article, thanx! To be able to use sudo i did have to add this line to /etc/fstab as well:

                                    tmpfs /var/lib/sudo/ts tmpfs nosuid,nodev 0 0

                                    1 Reply Last reply Reply Quote
                                    • D Offline
                                      dev
                                      last edited by

                                      Has this tutorial worked for anyone? The 1st error is saw was under Move files to temp filesystem after running:

                                      touch /tmp/dhcpcd.resolv.conf; ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf

                                      Failed to create symbolic link ‘etc/resolv.conf’ file exists. Next after reboot see errors regarding “a start job is running for dhcpd on all interfaces..." The raspi fails to boot and see pi@raspberrypi: prompt. Thanks in advance for any insights!

                                      1 Reply Last reply Reply Quote
                                      • A Offline
                                        Antoine Megens
                                        last edited by

                                        I don't seem to be able to copy/paste from your crayon syntax highlighter widgets? The copy button doesn't work, nor does the button to expand the code.

                                        1 Reply Last reply Reply Quote
                                        • P Offline
                                          Piotr Mackowiak
                                          last edited by

                                          OK, nice tutorial. But where (I mean about file) I have to place:

                                          rm -rf /var/lib/dhcp/ /var/lib/dhcpcd5 /var/run /var/spool /var/lock /etc/resolv.conf
                                          ln -s /tmp /var/lib/dhcp
                                          ln -s /tmp /var/lib/dhcpcd5
                                          ln -s /tmp /var/run
                                          ln -s /tmp /var/spool
                                          ln -s /tmp /var/lock
                                          touch /tmp/dhcpcd.resolv.conf; ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf

                                          1 Reply Last reply Reply Quote
                                          • E Offline
                                            Elliott Balsley
                                            last edited by

                                            Nice guide. I used it on Stretch.

                                            • I had to symlink /var/lib/sudo/ts to /tmp because it gives an error every time running sudo, then I made a systemd service to make that folder
                                            • The /tmp/random-seed file does not get created at startup, even though I added the ExecStartPre line. It says success, but I can't figure out why that file isn't being created:
                                              Process: 97 ExecStartPre=/bin/echo a > /tmp/random-seed (code=exited, status=0/SUCCESS)
                                            • Stretch uses systemd-timesyncd, so there's no need for ntp and it would conflict.
                                            • I like the bash_logout idea to mount ro, but it fails because mount: only root can use "--options" option
                                            • Fail2ban isn't working. Anybody know if it's possible to configure that to monitor the busybox ring buffer?
                                            1 Reply Last reply Reply Quote
                                            • First post
                                              Last post

                                            3

                                            Online

                                            5.7k

                                            Users

                                            534

                                            Topics

                                            5.0k

                                            Posts

                                            Top Topics

                                            • Denky 4 - Domoticz - Triphasé -
                                              Nicolas BernaertsN
                                              Nicolas Bernaerts
                                              0
                                              7
                                              249

                                            • Denky D4 et Linky Standard TInfo Rx Non Configuré
                                              CharlesC
                                              Charles
                                              0
                                              5
                                              282

                                            • CC1101
                                              CharlesC
                                              Charles
                                              0
                                              2
                                              117

                                            Popular Tags

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