Search by Tags

OSTree

 
Applicable for

Article updated at 26 Jul 2019
Subscribe for this article updates

Warning: the Torizon Update System is a project currently under development at Toradex Labs. It is still an experimental project in it's early stages which is subject to changes without notice. This might impact new releases and/or iterations.

Introduction

OSTree is a library - actualy libostree - that handles updates for filesystem trees, that is, the entire Linux image. It applies updates atomically, therefore guaranteeing the system integrity in case of a failure provided by a power-cut or dropped internet connectivity for instance. Different from the A/B partition mechanism of updates, OSTree works in a git-like model, providing file updates and thus saving storage space as well as connection bandwidth and allowing more than 2 software revisions on the device at the same time. In addition, some directories such as /var and /etc and handled as special cases, providing persistent configuration and user data to be preserved between updates.

OSTree is a key technology used by the Torizon Update System, but it is not meant to be used standalone. That being said, this article shows how to use OSTree directly from command-line, for demonstration purposes.

This article complies to the Typographic Conventions for Torizon Documentation.

Prerequisites

Manual OSTree Demonstration

Here's a quick demo on performing an update using the underlying OSTree technology on the device manually. It helps to understand how things are done, which can then be used for automation.

Whenever you build TorizonCore a directory ostree_repo gets produced during the build. This directory is git-like containing the meta-data for that build's filesystem. Toradex uploads the nightly and release Torizon builds OSTree repository and makes them available. Feeds can be found at the following location:

http://feeds.toradex.com/ostree/torizon-<BRANCH>/<BUILD-PURPOSE>/<MACHINE>
  • BRANCH: master, thud, warrior
  • BUILD-PURPOSE: nightly, release
  • MACHINE: colibri-imx6, colibri-imx6ull,colibri-imx7, apalis-imx6

Example: http://feeds.toradex.com/ostree/torizon-master/nightly/apalis-imx6/

Attention: All device commands must be executed as root, so you have to login as root on the device or, if you are logged-in using the torizon user, prefix the following command lines with "sudo" to execute them as root.

OSTree Update From Toradex Feeds

Here is an example how to update using the Toradex feeds.

  • On the board, using OSTree you can add this repository like how one would add a remote git repo:
# ostree remote add --no-gpg-verify toradex-nightly \
       http://feeds.toradex.com/ostree/torizon-master/nightly/apalis-imx6/

  • Check that it was successful:
# ostree remote refs toradex-nightly
toradex-nightly:torizon-core-balena
toradex-nightly:torizon-core-docker
toradex-nightly:torizon-core-lite
  • Following standard git procedure you'd then perform a pull:
# ostree pull toradex-nightly:torizon-core-docker
172 metadata, 485 content objects fetched; 17704 KiB transferred in 12 seconds 
  • To see which files got updated, ostree diff can be used:
# ostree diff toradex-nightly:torizon-core-docker
M    /usr/package.manifest
M    /usr/etc/manifest.xml
...
  • Next, you queue the commit for deployment upon next boot:
# ostree admin deploy toradex-nightly:torizon-core-docker
Copying /etc changes: 5 modified, 2 removed, 7 added
Transaction complete; bootconfig swap: yes; deployment count change: 1
  • OSTree shows that there is a switch to a new tree pending:
# ostree admin status
  torizon 0cbeafe2973079d5edb4457839054af3c1bb8ea09678c92bcf022eea2ca92e60.0 (pending)
    origin refspec: toradex-nightly:torizon-core-docker
* torizon 4fc80f14d5ee2160004e3252080226f8f1d6f6ad4d8d7024b4198584c23afaa6.0
    origin refspec: 4fc80f14d5ee2160004e3252080226f8f1d6f6ad4d8d7024b4198584c23afaa6
  • After a quick reboot you can see the new OSTree active:
# reboot
  • Finally, you can view your current and previous deployment which you can rollback to if need be:
# ostree admin status
* torizon 0cbeafe2973079d5edb4457839054af3c1bb8ea09678c92bcf022eea2ca92e60.0
    origin refspec: toradex-nightly:torizon-core-docker
  torizon 4fc80f14d5ee2160004e3252080226f8f1d6f6ad4d8d7024b4198584c23afaa6.0 (rollback)
    origin refspec: 4fc80f14d5ee2160004e3252080226f8f1d6f6ad4d8d7024b4198584c23afaa6

OSTree Update From a Local TorizonCore Build

If you are building TorizonCore image locally you may provide an ostree repo directly from your PC. If you have Python installed, just move to the ostree_repo folder of your build directory (should be under deploy/images/$MACHINE/ostree_repo) and bring-up the Python built-in simple HTTP server:

$ python -m SimpleHTTPServer 8081

In this way your PC will be sharing the image you just built on port 8081. You can replace http://feeds.toradex.com/ostree/nightly/apalis-imx6/ in the above instructions with <your PC ip address>:8081 and update your device directly from your build machine.

Please notice that this kind of operation is not secure and such a configuration should be used only for debugging purposes.

OSTree Update from a USB thumb drive

If you don't have network connectivity on target board, In that case, keep the OStree repo to the USB thumb drive then connect the USB thumb drive to the target board and then can do the update by following the instructions below.

If you are building Torizoncore image locally the OSTree files will be in deploy/images/$MACHINE/ostree_repo path.

  • List the refs:
# ostree refs --repo=PATH_TO_REPO_DIRCTORY

Example:

# ostree refs --repo=/home/root/pendrive/ostree_repo/
torizon/torizon-core-docker
torizon/torizon-core-docker-torizon-core-docker
  • Pull the repo from USB thumb drive to the target board:
# ostree pull-local PATH_TO_USB_REPO REFS_NAME

Example:

# ostree pull-local /home/root/pendrive/ostree_repo/ torizon/torizon-core-docker
  • Deploy the tree for the next boot:
# ostree admin deploy REFS

Example:

e.g. ostree admin deploy torizon/torizon-core-docker
  • OSTree shows that there is a switch to a new tree pending:
# ostree admin status
  torizon 1d98e25015a390556e7ab93c9b94e01e8632d30d800b36bff1ddd54fa9fc7cf4.0 (pending)
    origin refspec: torizon/torizon-core-docker
* torizon d0d53487d305358ad50c37b1b2a94fc78eaea5e770749a33f5607573e2447660.0
    origin refspec: d0d53487d305358ad50c37b1b2a94fc78eaea5e770749a33f5607573e2447660
  • After a reboot you can see the new OSTree active:
# reboot

Finally, you can view your current and previous deployment which you can rollback to if need be.

# ostree admin status
* torizon 1d98e25015a390556e7ab93c9b94e01e8632d30d800b36bff1ddd54fa9fc7cf4.0
    origin refspec: torizon/torizon-core-docker
  torizon d0d53487d305358ad50c37b1b2a94fc78eaea5e770749a33f5607573e2447660.0 (rollback)
    origin refspec: d0d53487d305358ad50c37b1b2a94fc78eaea5e770749a33f5607573e2447660