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.
  • K Offline
    K Offline
    kamikazefish
    wrote on last edited by
    #21

    Thanks for the great tutorial. Works great! If I would make a third partition on the SD card, and put the logs there and a fourth partition for the program data, would this still prevent my raspberry pi from not booting? The system files and programs would be read only. If not, would using an usb stick for the logs and program data be better?

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

      @kamikazefish
      yes have more partition for R/W data could be a great idea and would work. but in this case you won't prevent data corruption on power loss 😉

      1 Reply Last reply
      • K Offline
        K Offline
        kamikazefish
        wrote on last edited by
        #23

        Ok that wouldn't be a big deal with the log files. For the program data I think there are some work arounds. I could implement unionfs with 2 partitions, one with a working state and the other as working dir. Then every x minutes I sync the files from the working dir to the working state. These writes are to an temp file, that are renamed after the write, to prevent corrupting the working state files.

        1 Reply Last reply
        • H Offline
          H Offline
          Harlock
          wrote on last edited by
          #24

          Thank you very much for this!
          Just to add my 2 cents: in Raspbian Jessie (mini) everything was fine except for the DHCP client which after fstab modification it was taking a life to stop waiting for an IP.
          I solved editing /etc/systemd/system/dhcpcd5 this way:

          changed the line

          PIDFile=/run/dhcpcd.pid

          into

          PIDFile=/var/run/dhcpcd.pid

          And now is fine.

          1 Reply Last reply
          • M Offline
            M Offline
            mefi
            wrote on last edited by
            #25

            Thanks for this. It really gives the stability to micro SD card that I need.

            I have one question that may not be really about this topic, but in some way it is. I developed a Qt application which is basically a dummy application. It receives messages and images over UDP sockets, and shows them on the screen. The problem I have is that when I am in read-only mode application just aborts after about half a second or so. When it is run in read-write mode it works great.

            After removing chunks of code and testing it in read-only mode I found out that if application don't process received messages, which i really have to since that's the only functionality application has, it doesn't get aborted. I am not that good with Linux to be honest, but what seems logical to me is that when I read that data in application it needs to be stored somewhere, and that somewhere is in read-only part of memory.

            Does what I wrote make any sense? If yes which parts of file system need to be mounted as tmpfs to fix it? If not what is actually happening and is it possible to fix it somehow?

            By the way I am using Raspbian Jessie Lite if that means something to you.

            Thanks in advance

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

              @Harlock thanks for the headup I will update the doc

              @mefi, I'm not specialist of QT, may be related to QT run time or other lib, that's strange, does the application need to write something somewhere ? may be in your homedir ?

              Would be interesting to know how QT runtime works, I have no idea, sorry.

              1 Reply Last reply
              • M Offline
                M Offline
                mefi
                wrote on last edited by
                #27

                @Charles No, the application doesn't write anything to the file system. It only reads settings. I implemented a logging mechanism which I used while developing but it is disabled now. I've also tried other Qt application and they run well in read-only mode. I hope I find solution soon. I'll leave a comment here when I do so others know what to do in similar situation. Thanks for great article once again.

                1 Reply Last reply
                • M Offline
                  M Offline
                  mefi
                  wrote on last edited by
                  #28

                  @Charles Just to let you and everyone know I fixed the problem. The logger class was trying to open file for writing logs, even when there were no logs, so I added some tests, and now it runs fine. It was my mistake after all..

                  1 Reply Last reply
                  • K Offline
                    K Offline
                    kxb3292
                    wrote on last edited by
                    #29

                    hello,

                    I have a setup of raspberry pi 3 with raspbian jessie installed. On top of it I have installed kodi v16.
                    I have been able to switch read only/read write mode following this tutorial:

                    However, when i put the system in read only mode and try to launch kodi I get the following message:
                    """
                    Could not init logging classes. Permission errors on ~/.kodi (/home/pi/.kodi/temp/)
                    ERROR: Unable to create application. Exiting
                    Couldn't get a file descriptor referring to the console
                    """
                    Is there a way to make kodi write its logs to a different location (like RAM?) or make it stop writing all logs all together?

                    I would really appreciate any help!

                    Thank you so much,

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

                      @kxb3292
                      may be setting kodi temp folder to tmpfs adding this line to /etc/fstab file ?

                      tmpfs  /home/pi/.kodi/temp  tmpfs  nosuid,nodev  0  0
                      

                      Or best change kodi temp folder to point to /tmp/kodi in it's config (I don't know if it's possible)

                      1 Reply Last reply
                      • smartypants_noS Offline
                        smartypants_noS Offline
                        smartypants_no
                        wrote on last edited by
                        #31

                        Trying to make a ro mediaplayer, but when I install omxplayer dbus is a dependency, and dbus do not like a ro filesystem. What are the tricks to make dbus run on a read only filesystem?

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

                          @smartypants_no
                          Not sure it's possible, may be setting up dbus to works on tmpfs Filesystem like I suggested in previous post ?
                          Works is to find out which folder/file need to be on this system.

                          1 Reply Last reply
                          • P Offline
                            P Offline
                            powerpuff
                            wrote on last edited by
                            #33

                            Hello there,
                            Thank you for posting this great tutorial!
                            I tried following your instructions on both Lubuntu 16.04 and on Ubuntu Mate 16.04 but unfortunately my Raspi3 no longer boots after adding the magic word "ro" on the fstab file.
                            Everything else seems to be working including the tmpfs commands
                            Any ideas why this would happen? Do these distros differ fundamentally from Rasbian Jessie?

                            Below are the errors shown on the screen when it hangs:
                            [34.800508] brcmfmac: brcmf_add_if: ERROR: netdev:wlan0 already exists
                            [34.800657] brcmfmac: brcmf_add_if: ignore IF event
                            [35.852809] brcmfmac: brcmf_add_if: ERROR: netdev:wlan0 already exists
                            [35.853037] brcmfmac: brcmf_add_if: ignore IF event

                            Thanks much!

                            1 Reply Last reply
                            • P Offline
                              P Offline
                              powerpuff
                              wrote on last edited by
                              #34

                              Hello again,
                              I realized what my problem was...I was trying to make the GUI system read only (i.e. without removing the x server stuff). This leads me to a second question: Is it possible to make a basic Debian system with a GUI truly read only (like squashfs for an i386 architecture)? I assume the risks of running out of the 1GB Raspi memory, if only I knew how to get there.
                              Many thanks

                              1 Reply Last reply
                              • R Offline
                                R Offline
                                rln-nard
                                wrote on last edited by
                                #35

                                Hi
                                If you ever want to go "one step further", then please have a look at my project Nard SDK. Everything runs from RAM. The SD card isn't used at all (except for boot).
                                http://www.arbetsmyra.dyndns.org/nard/

                                1 Reply Last reply
                                • 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

                                          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


                                          3

                                          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