treczoks
Posts: 36
Joined: Tue Jan 03, 2012 9:55 am

Re: SD Card Read-Only switch

Sat Mar 17, 2012 1:03 pm

Hi!

I was just wondering (after diggging the documentation without success) if the Pi honors the SD cards "read-only" switch.

Some embedded devices do, some don't, some even have hardware to prevent write access if the switch is set instead of just relying on software.

So how is it handled on the RPi?

Yours, Christian

Kernel
Posts: 395
Joined: Sat Mar 03, 2012 12:53 pm

Re: SD Card Read-Only switch

Sat Mar 17, 2012 1:50 pm

A good question! I didn't know some devices don't obey the switch - obviously it would cause problems if you had swap on the card or wanted to update OS components if it is read-only but if you are using other storage for files it could work with read-only

nicknml
Posts: 200
Joined: Thu Mar 15, 2012 8:44 pm

Re: SD Card Read-Only switch

Sat Mar 17, 2012 1:53 pm

Interesting, I thought that the read-only switch told the controller on the card to refuse to perform writes, didn't know that it just told the card reader to prevent writes. Ya learn something new everyday.

Smartybones
Posts: 176
Joined: Wed Feb 08, 2012 5:03 pm

Re: SD Card Read-Only switch

Sat Mar 17, 2012 2:23 pm

nicknml said:


Interesting, I thought that the read-only switch told the controller on the card to refuse to perform writes, didn't know that it just told the card reader to prevent writes. Ya learn something new everyday.


It does not tell the controller on the card anything, its exactly the same as the old fashioned cut out notch in a old floppy disk... if its in one position, the OS is told not to write to it, in the other writing is ok.

if you break the switch on a card, you can "fix" it by putting a little bit of tape over the gap where the switch was....

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: SD Card Read-Only switch

Sat Mar 17, 2012 3:23 pm

Swap notwithstanding it would be interesting to know how a raspi behaves with a read-only sd card. I suppose its easy to test in qemu by making the fs image file set read-only. . .
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: SD Card Read-Only switch

Sat Mar 17, 2012 3:32 pm

Surely this is something that can't be accurately emulated.

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: SD Card Read-Only switch

Sat Mar 17, 2012 3:42 pm

You can emulate what the os would do if it can"t write to any disk. All the logging in /var/adm/messages would of course fail instantly
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: SD Card Read-Only switch

Sat Mar 17, 2012 3:56 pm

I would have thought we were relying on the ability of the card reader to recognize that write protection had been activated on the  SD card and act on it. If the circuitry is not there or is faulty the OS will never be told about the state of the card.

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: SD Card Read-Only switch

Sat Mar 17, 2012 4:29 pm

well I tried it in QEMU set the img file 444 r--r--r-- and guess what - qemu updated the bl**dy img file!!! how does that work then?
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: SD Card Read-Only switch

Sat Mar 17, 2012 4:42 pm

Presumably because there is no physical card or physical card reader.

User avatar
Burngate
Posts: 6013
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: SD Card Read-Only switch

Sat Mar 17, 2012 5:18 pm

On floppy drives, the read-only switch connected to the drive's electronics, and disabled the write current - the computer had no say in what happened.

The SD card holder has no electronics, the card is connected directly to the SoC. So read-only requires the software to play nicely, or the card itself to refuse to write. I would expect neither of these to be fool-proof.

11 + 12    my highest yet

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: SD Card Read-Only switch

Sat Mar 17, 2012 5:40 pm

There must be some physical sensor within the card reader to recognize what position the tab is in.

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: SD Card Read-Only switch

Sat Mar 17, 2012 5:44 pm

Apparently there is an optical sensor. If your lock breaks and falls off you can fool it with a little bit of silver foil and some sellotape.

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: SD Card Read-Only switch

Sat Mar 17, 2012 10:24 pm

SN said:


well I tried it in QEMU set the img file 444 r–r–r– and guess what – qemu updated the bl**dy img file!!! how does that work then?


If you change the permissions after QEMU has already opened the file then it is normal and correct for the system to continue to allow writes via the existing file descriptor.

If you run QEMU as root then the file permissions are ignored completely.  (I would not recommend running the emulator as root if it can possibly be avoided.)

Otherwise, QEMU should fail to start if the image is not writeable.  You will need to change "-hda raspberry.img" to "-drive media=disk,readonly,file=raspberry.img".  None of the official images boot acceptably in this configuration.

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: SD Card Read-Only switch

Sat Mar 17, 2012 10:28 pm

don't believe I was running qemu as root.  and changed permissions whilst qemu not running.

I saw in the startup script in qemu that there was a read/only filesystem message followed a bit later by a 'remount' read/write message (didn't capture exact words)

anyway, I only tried it to see how the boot sequence in the Fedora Remix image would handle it, so I'm not going to play with it any more
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

Return to “General discussion”