Giter Club home page Giter Club logo

update-reset's Introduction

update-reset

CoderBot is a RaspberryPI-based programmable robot for educational purposes. Check the project website for more information.

This repository implements an update (and restore) system using OverlayFS.

Overview

OverlayFS article on Arch Wiki

With overlays we can keep the root partition (overlay lowerdir) read only and an upper partition write-able for modifications.

We can trigger a restore event (from a file, physical button, ..) which at boot will delete modifications in upper file-system, effectively resulting in a factory reset.

Overlay is mounted by an init script. It mounts upper file-system, merge rootfs and upper into an overlayfs making this the new rootfs. Then calls systemd.

If the restore event is raised it cleans the upper fs.

Setup

Create of the upper partition or use part_overlay

Partition Setup

Check fs usage with:
df -h
File system Dim. Usati Dispon. Uso% Montato su  
/dev/mmcblk0p1              42M   22M     20M  53% /boot  
/dev/mmcblk0p2             6,3G  4,2G    2,1G  33% /  

Resize /dev/mmcblk0p2 filesystem to 3G:

sudo e2fsck -f /dev/mmcblk0p2
sudo resize2fs /dev/mmcblk0p2 3G

Resize /dev/mmcblk0p2 partition to 3G:

sudo fdisk /dev/mmcblk0

Type p to list partition, take note of /dev/mmcblk0p2's Start sector
Type d, then 2 to delete second partition
Type n, then p for primary, then 2 to recreate the second partition
Insert old /dev/mmcblk0p2's Start sector, then type +3G as last sector to obtain a 3GB partition Do NOT remove fs signature
Type w to write changes
Type q to exit

Create new partition:

sudo fdisk /dev/mmcblk0

Type p to list
Type n, then p, then 3 to create 3rd partition
Choose first sector increasing by 1 /dev/mmcblk0p2's End sector, press ENTER to accept last sector
Type w Type q

Create fs:

sudo /sbin/create_overlay

or

sudo mkfs -t ext4 -L overlay /dev/mmcblk0p3
sudo mount /dev/mmcblk0p3 /mnt
sudo mkdir /mnt/upper /mnt/work
sudo umount /mnt

Boot raspberry pi

Install scripts

git clone https://github.com/CoderBotOrg/overlay-factory-reset
cd overlay-factory-reset
sudo make install DESTDIR=/

Install desktop scripts

git clone https://github.com/CoderBotOrg/overlay-factory-reset
cd overlay-factory-reset
sudo make desktop DESTDIR=.

Enable overlay

Add this line to /etc/fstab or use enable_overlay:

/dev/mmcblk0p3	/overlay	ext4	defaults,noatime,nofail	  0	  3

Create mountpoints or use enable_overlay:

Overlay:

sudo mkdir /overlay

ROM:

sudo mkdir /rom

Add this line to /boot/cmdline.txt or use enable_overlay:

init=/sbin/init_overlay

Restore boot partition

To be correctly restored boot partition should be backed up in /etc/coderbot/boot.tar.xz with a optional sigfile /etc/coderbot/boot.sig (you can use tar_sig from update).

Whitout signature:

tar cfvJ /etc/coderbot/boot.tar.xz -C /boot .

or simply

backup_boot

/sbin/restore_boot formats boot partition, verify the backup signature (if present) with /etc/coderbot/coderbot.pub as key, then restore it to boot.
To export the public key:

gpg --output coderbot.pub --export KEY

Then put it in /etc/coderbot/coderbot.pub

Uninstall scripts

git clone https://github.com/CoderBotOrg/overlay-factory-reset
cd overlay-factory-reset
sudo make uninstall DESTDIR=/

Uninstall desktop scripts

git clone https://github.com/CoderBotOrg/overlay-factory-reset
cd overlay-factory-reset
sudo make desktop-uninstall DESTDIR=.

TODO

apt shouldn't update /boot/cmdline.txt

Further references

This work is also described in this thesis (Italian only)

update-reset's People

Contributors

avivace avatar previ avatar rpo19 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

update-reset's Issues

init_overlay crash at boot

when init_overlay is called at boot (overlay enabled), boot hang on undefined error (no messages in logfile)

If a folder is named "scripts", coderbot_update ignores it

For some obscure reason (probably related to the fact that update/scripts is the folder containing install-scripts) if a folder is named scripts, it does NOT get copied in a update.

Example situation to reproduce, using the sample update in this repo:

files/install
/home/pi/coderbot/scripts/check_conn.sh

produce the update, with the script handling files doing this:

FILES=${FILES:-../files}

[ -d "${FILES}/install/" ] && cp -a ${FILES}/install/. $ROOT

No errors reported, update_status remains at done showing success.. everything else is copied correctly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.