chesty
Posts: 9
Joined: Tue May 21, 2013 5:32 am

overlay root mount

Sun Dec 13, 2015 3:47 pm

I've uploaded my go at overlay root to github

https://github.com/chesty/overlayroot

It's handy for playing around with your pi, the real root on the sd card is read only, so any changes you make aren't permanent and will be lost the next time you reboot, crashes won't hurt the filesystem, or hard power offs, either.

I don't have a head and can't see shutdown messages and there is a problem with the overlay on usb no being unmounted. ATM if you put the overlay on usb, it will be reformated every boot. Another option is to put the overlay on the sd card as a third partition, not ideal as one of the ideas behind me playing with overlay mount was to limit sd card writes. The third option is to use tmpfs. I believe tmpfs has the drawback of limiting the amount of data you can write. If you edit 1 character of a 100 meg file, you've just used 100 megs of memory. I think the only way to get the memory back is to reboot, and of course, you've just lost the change you've made.

To put overlay mount on a usb stick, put a label on the file system called overlaytmp

mkfs.ext4 -L overlaytmp /dev/sdz1

change sdz1 to your real device, when it boots, if it finds a file system with the label overlaytmp, it will use that, otherwise it will use tmpfs.

if you put overlay mount on a usb stick and you want to go back to tmpfs for a bit, run

tune2fs -L overlayoff /dev/sdz1

that changes the label from overlaytmp and then when you reboot, it won't find overlaytmp and it will use tmpfs

to work on the real read-only root, I use the script rootwork, it sets it up and chroots into it.

I think that's about it.

Kenzimatic
Posts: 2
Joined: Thu Dec 24, 2015 7:35 pm

Re: overlay root mount

Thu Dec 24, 2015 7:41 pm

Chesty, this is awesome! I'm having trouble getting it working, can you offer a hand?

I followed your instructions and now my PI2 boots to an (initramfs) prompt. Taking initramfs out of config.txt gets it up and running again. Is there anything I should be looking for maybe in dmesg that might shed light on why it's getting stuck there?

One more note -
Following your instructions (README.md):
then rerun

initramfs -o /boot/init.gz
I assume you meant mkinitramfs, and there's no need to bother playing with update-initramfs?

Thanks,
- Kenzi

Kenzimatic
Posts: 2
Joined: Thu Dec 24, 2015 7:35 pm

Re: overlay root mount

Sun Dec 27, 2015 3:25 am

Okay, I've got it working relatively well now on my Pi2 - it's mostly solved.
There were a few little problems - basically because Pi2's initramfs is really stripped down and crippled:

For hooks_overlay - there's no awk - so I added copy_exec /usr/bin/awk

For init_bottom_overlay,
There's no cp x y, so I used cat x > y
Mount doesn't support mount -o rbind, so I used mount -o bind for /overlay, /overlay/lower and /overlay/work, /overlay/upper

Also, I'm ending up with 180MB of swap in var on the upper ram drive layer, which is a horrible, horrible idea. I've managed to get the kernel to use a dedicated swap partition instead, but that swap file still appears and then goes unused (or briefly used?) Still working on that... hmm.

But meanwhile, the overlay root is working beautifully on the Pi2, and its speed seems unaffected. My goal was to make the system "safe" to shut down at any time, so I made the FAT partition read-only, the root is an overlay, and the user gets a JFS partition for the desktop only - it's synced pretty quick, and worst-case, the user loses stuff on their desktop. All other system changes revert nicely, so thank you very very much for your work in creating these scripts.

- Kenzi

willembuitendyk
Posts: 12
Joined: Thu Jun 25, 2015 2:52 am

Re: overlay root mount

Sat Jan 23, 2016 8:42 pm

I'm not having much luck. I wonder? Is this using wheezy or jessie?

willembuitendyk
Posts: 12
Joined: Thu Jun 25, 2015 2:52 am

Re: overlay root mount

Sun Jan 24, 2016 12:57 am

It seems the init-bottom-overlay script's use of ${rootmnt} was causing me some problems. On boot up I was seeing the following error:

Code: Select all

/scripts/init-bottom/init-bottom-overlay: 69: /scripts/init-bottom/init-bottom-overlay: cannot create /root/etc/fstab.org : Directory nonexistent

/scripts/init-bottom/init-bottom-overlay: 70: /scripts/init-bottom/init-bottom-overlay: cannot create /root/etc/fstab : Directory nonexistent

/scripts/init-bottom/init-bottom-overlay: 71: /scripts/init-bottom/init-bottom-overlay: cannot create /root/etc/fstab : Directory nonexistent
Instead I ended up using an excellent set of scripts from:

https://github.com/ppisa/rpi-utils/blob ... overlayctl

Remember to create /overlay in the root directory. Works amazingly well. I now have an indestructible Kiosk.

Return to “Advanced users”