It is relatively unknown that SD/MMC cards also have an electronic write protection system.
Every card has two programmable flags, one for temporary write protection and
one to lock the card forever. Writing these flags is not supported by most SD host devices.
To remedy this, this page presents a program that allows a Linux host to configure the protection register.
Usage of the program is simple:
./sdtool [device] [command] where device is the mmc block device, for example /dev/mmcblk0 and command is
one of the following:
|status||Show current write protection setting.|
|unlock||Disable write protection.|
|lock||Enable temporary write protection.|
|permlock||Enable permanent write protection (untested).|
|reset||Send go_idle_state command to all cards.|
You can download the source code of the tool here.
Note that you must be able to access the MMC device directly. Some SD card readers connect over USB and export a Mass
Storage Device (ex. /dev/sda), which cannot be used. My Dell Vostro 1310 laptop shows the card to the operating system as
a MMC device. Most embedded boards, such as the Raspberry Pi, do the same. Therefore, I have compiled a static binary
that you can use on your Raspberry Pi and most other Linux based ARM embedded systems.
You can download it here.
As a side effect, you can also use it to make the Raspberry Pi boot volume read-only as an extra precaution against corruption.
Do this only if you mount your root filesystem read-only. In the future I will publish instructions and software that can be
used to automatically make hard-shutdown proof Raspberry Pi OS images (using buildroot).
Run the following command on your Raspberry Pi to make it read-only:
wget http://bertold.org/sdtool/sdtool-rpi -O /tmp/sdtool;chmod +x /tmp/sdtool;/tmp/sdtool /dev/mmcblk0 lock
The license for the program and static binary can be found here.