Page 1 of 2

RPi in Car: "live" image (read-only)?

Posted: Mon Sep 10, 2012 6:31 pm
by bradvido
I'm planning on using my RPi in my car and having it suddenly lose power when the car turns off. I understand this would inevitably cause corruption on a typical SD card installation where data may be writing to the card when it loses power.

I'm wondering if there is some way to set up an SD image to be like the Linux "live" CD's where nothing is actually written to the disk, it is only read?

Preferably, I would be able to configure the image to my liking before I set to to be read-only/live.

Please don't suggest to have some sort of battery backup to gracefully shutdown the RPi when the car turns off.... this is not the route I want to go.

-Thanks!

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 6:47 am
by Licaon_Kter
most SD cards have a write lock, use that, but the tricky part is to set it up so all the writes are done in memory or disabled

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 7:03 am
by ghans
The RPi ignores write lock. (cheap card slot)


ghans

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 7:04 am
by Licaon_Kter
ghans wrote:The RPi ignores write lock. (cheap card slot)
interesting

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 1:02 pm
by bradvido
Yes, as has been mentioned in other forum posts, the RPi will ignore the switch on the SD card.

Even so though, if there is a script i could run or tutorial to follow to configure Linux to disable logging and have any other writes go to memory instead of disk?

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 1:09 pm
by mole125
I'd suggest searching google on how to create a Linux rescue or live CD image - by definitions these have to ensure nothing is written to disk.

You'll probably also want to configure the fstab file to tell it to enforce readonly (ro) mounting so that the low level drivers prevent files from actually being written.

Of course if you do this then don't expect to rely on the system clock as no logging and no internet means there is no way to update the system clock unless you add an RTC

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 6:34 pm
by bradvido
My googling has brought me to a tool called fsprotect. It seems to be able to automate the process of making the root filesystem read-only. Has anyone used this with the RPi?

I must admin I'm a Linux newbie so I'm not sure if fsprotect is the right solution or not...

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 7:24 pm
by joyfull
have you managed to get any further on this project

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 8:03 pm
by hevilp
why u want to set read-only ?

when u are using the system as media-center in a car, no new important files will be written on the sdcard while only consuming...

anyway you could set up your system and set the partition read-only in fstab

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 8:34 pm
by bradvido
I need read-only to guarantee the SD card won't get corrupted when power is suddenly lost.

I was able to get fsprotect installed on my debian squeeze VM (for testing) and it seems to do exactly what i need. All writes that would normally go to disk are redirected to memory. It can also be toggled on and off relatively easily (for when I need to save reconfigurations to disk)

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 8:46 pm
by hevilp
pls describe your config, i am setting up a car system with pi too.....

Re: RPi in Car: "live" image (read-only)?

Posted: Tue Sep 11, 2012 8:49 pm
by bradvido
This is what I did on my test VM

Code: Select all

log in as root
apt-get install fsprotect
vi /etc/default/grub
Change the line GRUB_CMDLINE_LINUX_DEFAULT and add fsprotect=15% to the command
Run update-grub
reboot
create a file
reboot
verify file is gone after reboot

Re: RPi in Car: "live" image (read-only)?

Posted: Wed Sep 12, 2012 3:33 pm
by Licaon_Kter
bradvido wrote:This is what I did on my test VM
vi /etc/default/grub
we don't have GRUB on the Pi, so like no

Re: RPi in Car: "live" image (read-only)?

Posted: Wed Sep 12, 2012 3:42 pm
by bradvido
Licaon_Kter wrote:
bradvido wrote:This is what I did on my test VM
vi /etc/default/grub
we don't have GRUB on the Pi, so like no
I don't have my RPi yet, but i'm going to be installing Raspbmc which uses grub:
http://www.raspbmc.com/wiki/technical/partitioning/
http://www.raspbmc.com/wiki/technical/partitioning/ wrote:"The fat32 partition contains the firmware files and is mounted at /boot to emulate a traditional Debian setup which stores GRUB there"

Re: RPi in Car: "live" image (read-only)?

Posted: Wed Sep 12, 2012 4:05 pm
by Hexxeh
bradvido wrote:
Licaon_Kter wrote:
bradvido wrote:This is what I did on my test VM
vi /etc/default/grub
we don't have GRUB on the Pi, so like no
I don't have my RPi yet, but i'm going to be installing Raspbmc which uses grub:
http://www.raspbmc.com/wiki/technical/partitioning/
http://www.raspbmc.com/wiki/technical/partitioning/ wrote:"The fat32 partition contains the firmware files and is mounted at /boot to emulate a traditional Debian setup which stores GRUB there"
No, that's not quite what it's saying. It's saying a traditional desktop would store parts of GRUB in /boot, but on the Raspberry Pi, you'll find firmware files there.

Re: RPi in Car: "live" image (read-only)?

Posted: Wed Sep 12, 2012 4:12 pm
by bradvido
OK. Well fsprotect does not require GRUB, it just needs to modify the kernal parameter and add "fsprotect=X" to it. So how would I modify kernal/boot parameters on the RPi? EDIT: quick google shows i should add the param to cmdline.txt

From the fsprotect docs:
To enable fsprotect you need to add the fsprotect kernel option. The fsprotect parameter takes one optional argument, which it passes to mount(8) as the size option of the tmpfs. It is the size in bytes, and K/M/G suxes can be used as multiplicators. If no argument is specied, mount(8) will create a tmpfs with size half the system's memory. The syntax is fsprotect=size, where size can be any size that can be under-stood by mount. For example: fsprotect=1024M or just: fsprotect

Re: RPi in Car: "live" image (read-only)?

Posted: Wed Sep 12, 2012 5:12 pm
by Alfadaz
I used to do a fair bit of in car PC stuff back in the day and i would be looking to set it up as follows:

Have the Pi powered from the battery - obviously not directly to the 12v, but your power supply would be always on regardless of the ignition.

Then look at a relay system which would send a signal via the GPIO to the Pi to perform a shutdown and turn on with the ignition.

If you wanted to get clever, i once made a little circuit with a timer, that kept the PC alive for 30 seconds following the ignition being turned off. If you pressed the button i had installed on the dash, the relay wouldnt switch and the pc would stay on until the next time the ignition was turned off or you shut it down manually. This was good when say you stopped in a shop etc when you wanted to the keep the PC running (mine was running XP, so took a while to bootup/shutdown).

Daz

Re: RPi in Car: "live" image (read-only)?

Posted: Wed Sep 12, 2012 9:02 pm
by bradvido
Alfadaz wrote:I used to do a fair bit of in car PC stuff back in the day and i would be looking to set it up as follows:

Have the Pi powered from the battery - obviously not directly to the 12v, but your power supply would be always on regardless of the ignition.

Then look at a relay system which would send a signal via the GPIO to the Pi to perform a shutdown and turn on with the ignition.

If you wanted to get clever, i once made a little circuit with a timer, that kept the PC alive for 30 seconds following the ignition being turned off. If you pressed the button i had installed on the dash, the relay wouldnt switch and the pc would stay on until the next time the ignition was turned off or you shut it down manually. This was good when say you stopped in a shop etc when you wanted to the keep the PC running (mine was running XP, so took a while to bootup/shutdown).

Daz
As stated in the first post, i don't want to have a battery backup solution. I want to be able to kill the power at any time and have it return to its original state without any risk of corruption.

Re: RPi in Car: "live" image (read-only)?

Posted: Thu Sep 13, 2012 10:29 pm
by bradvido
OK, I now have my RPi and have successfully installed Debian Wheezy. I also intalled the fsprotect package using sudo apt-get fsprotect.

Everything installed fine.
I edited /boot/cmdline.txt and added the fsprotect parameter to the end.

However, when i reboot, it seems that fsprotect does not initialize. Files i create will stay there after reboot.

Any ideas? I'm not sure what the easiest way is to check if fsprotect is running besided creating a file, rebooting, and checking if the file persisted over the reboot.

Re: RPi in Car: "live" image (read-only)?

Posted: Fri Sep 14, 2012 9:06 am
by sraue
bradvido wrote:I'm planning on using my RPi in my car and having it suddenly lose power when the car turns off. I understand this would inevitably cause corruption on a typical SD card installation where data may be writing to the card when it loses power.

I'm wondering if there is some way to set up an SD image to be like the Linux "live" CD's where nothing is actually written to the disk, it is only read?

Preferably, I would be able to configure the image to my liking before I set to to be read-only/live.

Please don't suggest to have some sort of battery backup to gracefully shutdown the RPi when the car turns off.... this is not the route I want to go.

-Thanks!
if you want to use a XBMC based distro, you should look at OpenELEC (http://www.openelec.tv). It is designed for such usecases from ground up. the needed read/write parts are done in ramfs mounts (and will be recreated on boot), the storage where the user can store the medias and XBMC saves the database and settings on changes. the rest is readonly and nearly "unbrickable".

Re: RPi in Car: "live" image (read-only)?

Posted: Fri Sep 14, 2012 8:15 pm
by bradvido
Thanks for the tip on openelec. That would work perfectly if i only needed XBMC.

Reading up on the docs for fsprotect, it details how it protects the root file system. As i said, I'm a Linux newbie, so is this even possible on the Rpi? Does the Rpi have a "initramfs boot stage"?
The root fillesystem must be protected at the very first stages of the boot procedure. This is done during the initramfs boot stage where the root filesystem is mounted but hasn't become / yet (no pivot_root done). This is accomplished by adding a local-bottom script to the initramfs.

Re: RPi in Car: "live" image (read-only)?

Posted: Sun Sep 16, 2012 8:03 am
by dangardner
I have got fsprotect working with the Raspbmc distribution. I had to build a new kernel with the aufs patches and enable CONFIG_BLK_DEV_INITRD and CONFIG_AUFS_FS, then create an initrd using mkinitramfs and add that to config.txt before everything worked.

Useful links which should contain everything you need:

http://elinux.org/RPi_Kernel_Compilation
http://pastebin.com/raw.php?i=YrtntGtU
http://www.raspberrypi.org/phpBB3/viewt ... =24&t=7626
http://www.raspberrypi.org/phpBB3/viewt ... 63&t=10532
http://aufs.sourceforge.net/

Re: RPi in Car: "live" image (read-only)?

Posted: Thu Sep 20, 2012 5:33 pm
by antennas
I have been reading this post and was wondering, what are you going to do with it in your car?? Sounds interesting.

Thanks.

Re: RPi in Car: "live" image (read-only)?

Posted: Sun Sep 30, 2012 8:49 pm
by dangardner
I have salvaged a couple of old in-car twin screen DVD players. These use composite video + stereo audio between the satellite screen and the screen with the optical drive in it, so I've ignored the players (for now) and used only the satellite screens. I've made up some cables for the Pi to connect to them and it all works nicely with XBMC. Once I get the car working again, I'll be installing it as in-car entertainment for my kids.

Re: RPi in Car: "live" image (read-only)?

Posted: Sun Sep 30, 2012 8:57 pm
by mahjongg
ghans wrote:The RPi ignores write lock. (cheap card slot)


ghans
yes, the PI ignores the write lock, but it has nothing to do with the card slot, as the card slot has a write lock switch, its just not connected up, as a normal distro needs to be able to write to its storage medium, so the designers of the PI didn't think it necessary to wire up the switch.

A live CD expects everything that changes to be lost at a reboot, and only stores things in RAM. The PI's distro's are not set up for read only operation like that.