ckristofek
Posts: 1
Joined: Tue Dec 11, 2012 4:26 pm

Re: Boot with SD readonly?

Mon Jan 14, 2013 9:13 pm

dms75 wrote:Hi,

If you want to take that approach I could provide you with the spi command sequences needed
to initialize the communication and to write protect the card if you need them.

Dirk
Dirk,

I am interested in making an SD card read-only. I'd like to take you up on your offer on the spi command sequences needed to init and write protect the card. I can use a Pi or an Arduino Uno (which ever is easiest).

Chuck

dms75
Posts: 25
Joined: Mon Aug 06, 2012 1:41 pm

Re: Boot with SD readonly?

Wed Jan 16, 2013 1:49 pm

Hi

I just sent you the needed spi command sequences to initialize and writeprotect a sdcard by setting the writeprotectbits in the CSD Register via a pm.
You can use this sequence if you connect the sdcard to the raspberry pi gpio header SPI Pins or with an external microcontroller board, wichever seems easier to you.

In both cases you'll need access to the SPI periferal or need to do SPI by bitbanging some IOs which will be slow, but not really a problem in this case since there is not that much data to send. For the connection you'll need some sort of cardholder and need to connect the cards Ground pins to the GPIO GND, the cards Powersupply Pins to the GPIO 3.3V Pin. You can tie the CS pin to GND too since we only need it to be '0' during CMD0, and after that it doesn't hurt to have the card selected all the time either, ofc. you can also connect it to the SPI CS pin from the SPI Module provided that it is active low ('0' during transmission). Tie unused card dataline inputs to 3.3V. Finally connect the RPi SPI MOSI pin (RPi SPI data out) to the Cards command input pin, the RPi SPI MISO (RPi SPI data input) pin will connect to the cards dataout pin, and the RPi SCLK pin provides the clock signal for the sdcard.
If you lack a sdcard holder and your microcontroller developmentboard doesn't have a sdcard slot either, and if you can live with using a Microsdcard you could solder some wires to an SDCARD Adaptor which comes for free with most microsdcards. You would need a second adaptor that was not handsoldered on for using your microsdcard in the RPi afterwards.
For the Pinout of sdcards a quick search in wikipedia should bring up the pin descriptions easily enough.

Dirk

jeanrocco
Posts: 9
Joined: Sun Jan 27, 2013 4:11 pm

Re: Boot with SD readonly?

Mon Jan 28, 2013 2:02 am

jzu wrote:Here's my /etc/fstab which has been successfully tested by unplugging the power supply while running massive read operations (find /).

Code: Select all

proc            /proc     proc    defaults 0 0
/dev/mmcblk0p1  /boot     vfat    ro       0 0
/dev/mmcblk0p2  /         ext4    ro       0 0
none            /var/run  ramfs   size=1M  0 0
none            /var/log  ramfs   size=1M  0 0
Any idea to improve this setup, or to torture the system in various ways in order to find possible flaws?
This means you run your RP with the original fstab when you are installing/compiling/modifying new soft, and when everything works, you use this modified fstab ? did I get this right ? suis meilleur en français ..

User avatar
jzu
Posts: 26
Joined: Mon Aug 01, 2011 8:02 am
Contact: Website

Re: Boot with SD readonly?

Mon Jan 28, 2013 11:45 am

jeanrocco wrote:This means you run your RP with the original fstab when you are installing/compiling/modifying new soft, and when everything works, you use this modified fstab ? did I get this right ? suis meilleur en français ..
Actually, this is my default fstab. Prior to to editing/modifying anything, I use the following command.

Code: Select all

# mount / -o remount,rw
Next reboot will see filesystems back to readonly.

Je préférerais écrire en français, moi aussi, but this is an international forum after all. ;)

User avatar
dudeman
Posts: 22
Joined: Sun Jan 20, 2013 1:20 am
Location: USA

Re: Boot with SD readonly?

Mon Jan 28, 2013 5:52 pm

I have been thinking about this scenario. The meta solution I have is:

1. Bootstrap from SD card

2. Boot linux into RAM like KNOPPIX

3. Write any appropriate changes to user data (settings) back to SD card as a user initiated action, with warning not to remove power while saving

Even if you don't need step 3, this design would protect the SD card data.

Sorry if I missed where you already explained how KNOPPIX would not work.

jeanrocco
Posts: 9
Joined: Sun Jan 27, 2013 4:11 pm

Re: Boot with SD readonly?

Wed Feb 06, 2013 9:14 pm

jzu wrote:
jeanrocco wrote:This means you run your RP with the original fstab when you are installing/compiling/modifying new soft, and when everything works, you use this modified fstab ? did I get this right ? suis meilleur en français ..
Actually, this is my default fstab. Prior to to editing/modifying anything, I use the following command.

Code: Select all

# mount / -o remount,rw
Next reboot will see filesystems back to readonly.

Je préférerais écrire en français, moi aussi, but this is an international forum after all. ;)
Well thank you, the remount is a good solution, I had to use a another Linux machine to revert to the old fstab, still learning :-), aurevoir !

obcd
Posts: 917
Joined: Sun Jul 29, 2012 9:06 pm

Re: Boot with SD readonly?

Thu Feb 07, 2013 1:09 pm

Is there a way to remout read only again after you mounted with rw rights, without the need to reboot the system?
I tried this but couldn't get it to work.
Some stuff doesn't like "read only root fs" very much like smb sharing a folder. (read only of cause)
I think dhcpd is another one, as it likes to store the dns servers.
logging should be possible on a tmpfs folder in ram.
Some routines expect the files they use for logging to already exist there.

Motlib
Posts: 2
Joined: Mon Aug 06, 2012 6:12 pm

Re: Boot with SD readonly?

Fri Feb 15, 2013 9:29 am

Is there a way to remout read only again after you mounted with rw rights, without the need to reboot the system? I tried this but couldn't get it to work.
You can use

Code: Select all

mount / -o remount,rw
for read-write operations and

Code: Select all

mount / -o remount,ro
to mount the filesystem read-only again. You can check by executing mount without parameters if a filesystem is mounted read-only or read-write.

<advertising>In the last few days I have tried to set up a read-only root filesystem and it works quite well. You can find a few hints in my blog post here: http://blog.a-netz.de/2013/02/read-only ... ilesystem/. There are also two posts about how to work with ramdisks to prevent too much write cycles to the sd card: http://blog.a-netz.de/2013/02/ramdisks- ... raspberry/ and http://blog.a-netz.de/2013/02/persisten ... -ramdisks/.

oweno
Posts: 28
Joined: Sat Feb 16, 2013 3:40 pm

Re: Boot with SD readonly?

Sun Feb 17, 2013 2:12 pm

I have been mounting root read only (using the fstab posted here):

Code: Select all

proc            /proc     proc    defaults 0 0
/dev/mmcblk0p1  /boot     vfat    ro       0 0
/dev/mmcblk0p2  /         ext4    ro       0 0
none            /var/run  ramfs   size=1M  0 0
none            /var/log  ramfs   size=1M  0 0

power cycling many times so far, I have not had any problems!

But does this really eliminate all write operations to SD card? I ran across some confusing messages in /var/log/messages, trying to understand the boot process:

Code: Select all

...
Feb 16 16:38:16 raspberrypi kernel: [    1.283769] mmc0: new high speed SDHC card at address b368
Feb 16 16:38:16 raspberrypi kernel: [    1.287000] mmcblk0: mmc0:b368       3.73 GiB
Feb 16 16:38:16 raspberrypi kernel: [    1.291177]  mmcblk0: p1 p2
Feb 16 16:38:16 raspberrypi kernel: [    1.348654] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
Feb 16 16:38:16 raspberrypi kernel: [    1.360825] VFS: Mounted root (ext4 filesystem) on device 179:2.
...
and then later on

Code: Select all

...
Feb 16 16:38:16 raspberrypi kernel: [   12.863151] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
...
seems the card is mounted in ordered data mode, and then remounted later on (with Opts null, even though ro is specified in fstab) ... Can anyone shed some light on the boot process?

User avatar
JohnBeardmore
Posts: 211
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Re: Boot with SD readonly?

Thu Oct 10, 2013 12:00 am

I don't know if anybody of still reading this thread, but I tried getting my pi to boot using the fstab shown earlier in this thread and it seems to boot fine.

The only thing that seems to be functioning is apache. I thought to begin with that it might be a problem with /run or /var/run, but these are linked, and both can be written to.

Is there something else that might be causing apache problems ?

Other than that, BRILLIANT ! (But I do need apache up and running !)

Cheers, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

User avatar
JohnBeardmore
Posts: 211
Joined: Thu Nov 15, 2012 11:03 pm
Location: Derbyshire UK.
Contact: Website

Re: Boot with SD readonly?

Thu Oct 10, 2013 12:23 am

OK, sorted it.

It turns out that apache writes its log file under /var/log. This should be fine because /var/log is writable ramfs, but it didn't work because apache is trying to open and write the file to /var/log/apache2

Starting apache2 by hand results in this rather quaint error message:

apache2: could not open error log file /var/log/apache2/error.log
....
The Apache error log may have more information.

Ha !

Anyway - If you make an apache2 directory in /var/log it works.

It also looks as if changing APACHE_LOG_DIR in /etc/apache2/envvars might also fix that, but I can't test this now the file system is ro.

Thanks for the messages folks. It's so great to be able to search them !

Cheers, J/.
Author of oBeMS open source Building energy Management System.
Automatic Meter Reading (AMR), Building Management System (BMS),
Building Energy Management System (BEMS), Infrastructure Control System (ICS).
See: http://t4sustainability.co.uk/oBeMS/

User avatar
jzu
Posts: 26
Joined: Mon Aug 01, 2011 8:02 am
Contact: Website

Re: Boot with SD readonly?

Thu Oct 10, 2013 8:08 pm

Glad your system works, and your issue is interesting as it is typical of embedded systems with read-only filesystems and volatile ram disks.

Of course, a blank ramfs is created at boottime, and it needs to be populated if some software is configured so as to write in one of its subdirectories. In your case, you can "mkdir /var/log/apache2" before the Apache daemon starts, but I think /etc/rc.local is executed too late, after standard init scripts in /etc/rc2.d/ - so you'd have to either modify your /etc/init.d/apache2 script (and risk see it being rightfully overwritten next time you update), or create a dedicated init script in /etc/rcS.d/ to populate /var/log (slightly better, still clumsy).

I'd rather modify the APACHE_LOG_DIR variable in the Apache configuration file /etc/apache2/envvar, which exists for a reason. When you update, the system should ask you if you want to keep your changes, overwrite the file, see the differences, etc.

Return to “Advanced users”