bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Mon Sep 10, 2012 6:31 pm

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!

User avatar
Licaon_Kter
Posts: 240
Joined: Wed Sep 05, 2012 10:12 am
Location: Between the keyboard and the chair.

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

Tue Sep 11, 2012 6:47 am

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
BFQ+BFS or RT on a RPi? 4'real: https://github.com/licaon-kter/ (source and compiled!)

ghans
Posts: 7871
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

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

Tue Sep 11, 2012 7:03 am

The RPi ignores write lock. (cheap card slot)


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
Licaon_Kter
Posts: 240
Joined: Wed Sep 05, 2012 10:12 am
Location: Between the keyboard and the chair.

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

Tue Sep 11, 2012 7:04 am

ghans wrote:The RPi ignores write lock. (cheap card slot)
interesting
BFQ+BFS or RT on a RPi? 4'real: https://github.com/licaon-kter/ (source and compiled!)

bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Tue Sep 11, 2012 1:02 pm

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?

mole125
Posts: 228
Joined: Tue Jan 10, 2012 2:01 pm

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

Tue Sep 11, 2012 1:09 pm

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

bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Tue Sep 11, 2012 6:34 pm

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...

joyfull
Posts: 1
Joined: Tue Sep 11, 2012 7:05 pm

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

Tue Sep 11, 2012 7:24 pm

have you managed to get any further on this project

hevilp
Posts: 64
Joined: Sun Sep 09, 2012 6:13 pm

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

Tue Sep 11, 2012 8:03 pm

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

bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Tue Sep 11, 2012 8:34 pm

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)

hevilp
Posts: 64
Joined: Sun Sep 09, 2012 6:13 pm

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

Tue Sep 11, 2012 8:46 pm

pls describe your config, i am setting up a car system with pi too.....

bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Tue Sep 11, 2012 8:49 pm

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

User avatar
Licaon_Kter
Posts: 240
Joined: Wed Sep 05, 2012 10:12 am
Location: Between the keyboard and the chair.

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

Wed Sep 12, 2012 3:33 pm

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
BFQ+BFS or RT on a RPi? 4'real: https://github.com/licaon-kter/ (source and compiled!)

bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Wed Sep 12, 2012 3:42 pm

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"

Hexxeh
Posts: 91
Joined: Thu Apr 05, 2012 3:07 pm
Contact: Website

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

Wed Sep 12, 2012 4:05 pm

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.

bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Wed Sep 12, 2012 4:12 pm

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

Alfadaz
Posts: 51
Joined: Tue May 22, 2012 10:18 am
Location: Cwmbran, S.Wales

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

Wed Sep 12, 2012 5:12 pm

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

bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Wed Sep 12, 2012 9:02 pm

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.

bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Thu Sep 13, 2012 10:29 pm

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.

sraue
Posts: 144
Joined: Tue Feb 28, 2012 12:36 am
Location: Switzerland
Contact: Website

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

Fri Sep 14, 2012 9:06 am

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".

bradvido
Posts: 11
Joined: Mon Sep 10, 2012 2:58 pm

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

Fri Sep 14, 2012 8:15 pm

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.

dangardner
Posts: 3
Joined: Sat Sep 15, 2012 8:54 pm

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

Sun Sep 16, 2012 8:03 am

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/

antennas
Posts: 20
Joined: Thu Sep 20, 2012 4:09 pm

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

Thu Sep 20, 2012 5:33 pm

I have been reading this post and was wondering, what are you going to do with it in your car?? Sounds interesting.

Thanks.

dangardner
Posts: 3
Joined: Sat Sep 15, 2012 8:54 pm

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

Sun Sep 30, 2012 8:49 pm

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.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12113
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

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

Sun Sep 30, 2012 8:57 pm

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.

Return to “General discussion”