ivanpianetti
Posts: 4
Joined: Fri Oct 30, 2015 3:08 am

Self-restoring partition?

Thu Nov 21, 2019 3:33 am

Hi everbody!

Lets suppose the raspberry detects a faulty filesystem at boot time which makes it freeze. Is it possible to make the raspberry to restore that bad partition with a new copy which would be of course at the same sd. The idea is to make this process completely unattended.

User avatar
HawaiianPi
Posts: 5711
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Self-restoring partition?

Thu Nov 21, 2019 4:16 am

Let's think about that for a moment. The system can't boot, so you have no running OS, and without an OS how will the recovery software run?

So could it be done, probably, but it would require some specialized software to be automated and unattended. A simpler solution would be a RAM based OS that doesn't write to the SD card, so every boot is a pristine copy, and the card should never wear out. Tiny Core Linux is one such option. The new Raspbian Overlay FS might be another (I haven't tried it yet myself).
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

RonR
Posts: 1194
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Self-restoring partition?

Thu Nov 21, 2019 5:19 am

The most reliable solution is to always have a current backup available to restore in case of a failure. image-backup contained in Image File Utilities will backup a running system to an image file suitable for restoring with Etcher. Following an initial full backup, image-backup can incrementally update an image file as changes occur. I have a cron job run image-backup every day at 4AM to ensure I have a recent backup to use in case of a failure. You can also manually perform an incremental backup anytime to catch up with important changes.

jj_0
Posts: 113
Joined: Wed Jul 11, 2012 7:07 am

Re: Self-restoring partition?

Thu Nov 21, 2019 6:04 am

It can easily be done, you have to use a kernel with built-in initrd (= ramdisk) boot. This is a common boot method that you can find lots of information abiut. I'm not sure if the Pi's kernel uses this already so you might have to recompile the kernel.
In the initrd 'init' script you then add stuff to detect errors on the SD rootfs partition and then rake the necessary steps.

Return to “Advanced users”