docs/atomic-rollbacks: Add a section on rollbacks
authorEric Curtin <ecurtin@redhat.com>
Tue, 13 Feb 2024 10:39:20 +0000 (10:39 +0000)
committerEric Curtin <ecurtin@redhat.com>
Tue, 13 Feb 2024 17:07:17 +0000 (17:07 +0000)
Describing how different types of rollbacks work.

Signed-off-by: Eric Curtin <ecurtin@redhat.com>
19 files changed:
docs/CONTRIBUTING.md
docs/README-historical.md
docs/adapting-existing.md
docs/atomic-rollbacks.md [new file with mode: 0644]
docs/atomic-upgrades.md
docs/authenticated-repos.md
docs/bootloaders.md
docs/buildsystem-and-repos.md
docs/composefs.md
docs/contributing-tutorial.md
docs/deployment.md
docs/formats.md
docs/ima.md
docs/index.md
docs/introduction.md
docs/related-projects.md
docs/repo.md
docs/repository-management.md
docs/var.md

index f7d7a5caa148f480fc91e82195ee42bc22181de7..8ee1fdcc79edb37b67d8987e8a1fa110923b2c29 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 19
+nav_order: 190
 ---
 
 # Contributing
index eebf5b2fe385dc63dff068816d3151fcb4f73277..eba0960f15abd00fcfa850ad08378c3cfec77c84 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 99
+nav_order: 990
 title: Historical OSTree README
 ---
 
index 12df966f2b810e9024a1bae150f2428edd74dfcc..422ba498ccd8daccc6ee8082e26e7478d153774f 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 6
+nav_order: 70
 ---
 
 # Adapting existing mainstream distributions
diff --git a/docs/atomic-rollbacks.md b/docs/atomic-rollbacks.md
new file mode 100644 (file)
index 0000000..6140566
--- /dev/null
@@ -0,0 +1,176 @@
+---
+nav_order: 60
+---
+
+# Atomic Rollbacks
+{: .no_toc }
+
+1. TOC
+{:toc}
+
+## Automatic rollbacks
+
+See [greenboot](https://github.com/fedora-iot/greenboot/blob/main/README.md) for information on automatic rollbacks and how to integrate
+without your bootloader.
+
+## Manual rollbacks
+
+Ostree writes bootloader entries that are interpreted by the bootloader. To
+manually rollback, for bootloaders such as GRUB and syslinux that have an
+interactive UI, it is possible to select a previous boot entry. In the case of
+an Android bootloader, a slot switch may be triggererd using an AB switching
+tool. This may be useful for testing purposes.
+
+## Rollbacks
+
+```
+                        +------------------------------------------------+
++------------------+    |                                                |
+|                  |    |                                                |
+|                  |    |                                                |
+|                  |    |      (ostree:0) latest     (multi-user.target) |
+|                  |    |                                                |
+| Bootloader       |--->+ root                                           |
+|                  |    |                                                |
+|                  |    |      (ostree:1) latest - 1 (multi-user.target) |
+|                  |    |                                                |
+|                  |    |                                                |
++------------------+    |                                                |
+                        +------------------------------------------------+
+```
+
+Bootloaders have multiple boot entries to choose from after upgrade. On
+rollback, the bootloader will boot the "latest - 1" version, rather than the
+latest version of the OS.
+
+## Alternate rollback techniques
+
+Below is an alternate technique to traditional AB switching that can be used.
+On rollback, an alternative boot target is used, rather than booting as
+default.target.
+
+```
+                        +------------------------------------------------+
++------------------+    |                                                |
+|                  |    |                                                |
+|                  |    |                                                |
+|                  |    |      (ostree:0) latest     (multi-user.target) |
+|                  |    |                                                |
+| Bootloader       |--->+ root                                           |
+|                  |    |                                                |
+|                  |    |      (ostree:1) latest - 1 (rescue.target)     |
+|                  |    |                                                |
+|                  |    |                                                |
++------------------+    |                                                |
+                        +------------------------------------------------+
+```
+
+In this case, instead of rolling back to an older version, we also boot
+into an alternate systemd boot target. Here we will describe how you can put
+togther an alternate systemd boot target, using the built-in rescue.target as
+an example.
+
+Below is a rescue.service file, it essentially executes systemd-sulogin-shell
+rescue when this service is activated.
+
+rescue.service:
+
+```
+#  SPDX-License-Identifier: LGPL-2.1-or-later
+#
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Rescue Shell
+Documentation=man:sulogin(8)
+DefaultDependencies=no
+Conflicts=shutdown.target
+After=sysinit.target plymouth-start.service
+Before=shutdown.target
+
+[Service]
+Environment=HOME=/root
+WorkingDirectory=-/root
+ExecStartPre=-/usr/bin/plymouth --wait quit
+ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue
+Type=idle
+StandardInput=tty-force
+StandardOutput=inherit
+StandardError=inherit
+KillMode=process
+IgnoreSIGPIPE=no
+SendSIGHUP=yes
+```
+
+Below is a rescue.target file, it is reached once rescue.service is complete.
+
+rescue.target:
+
+```
+#  SPDX-License-Identifier: LGPL-2.1-or-later
+#
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Rescue Mode
+Documentation=man:systemd.special(7)
+Requires=sysinit.target rescue.service
+After=sysinit.target rescue.service
+AllowIsolate=yes
+```
+
+This is a simple bash script, it checks whether `ostree admin status -D` is
+`not-default` and if it is, it notifies systemd to alternatively boot into
+rescue.target.
+
+In the happy path, when we have booted the latest version
+`ostree admin status -D` would output `default`.
+
+ostree-rollback-to-rescue:
+
+```
+#!/usr/bin/bash
+
+set -euo pipefail
+
+if [ "$(ostree admin status -D)" = "not-default" ]; then
+  exec systemctl --no-block isolate rescue.target
+fi
+```
+
+This is a systemd service file that runs ostree-rollback-to-rescue early in the
+boot sequence, it is essential that this service is run early to ensure we
+don't execute a full boot sequence, hence options `DefaultDependencies=no` and
+`Before=` are used.
+
+ostree-rollback-to-rescue.service
+
+```
+[Unit]
+Description=OSTree rollback to rescue
+DefaultDependencies=no
+OnFailure=emergency.target
+OnFailureJobMode=replace-irreversibly
+After=initrd-root-fs.target initrd-fs.target initrd.target boot.mount
+Before=cryptsetup.target integritysetup.target remote-fs.target slices.target swap.target veritysetup.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/sbin/ostree-rollback-to-rescue
+
+[Install]
+WantedBy=sysinit.target
+```
+
+###### Licensing for this document:
+`SPDX-License-Identifier: (CC-BY-SA-3.0 OR GFDL-1.3-or-later)`
index 92ae2c49f188277665621b08ade7f5fa829d9aa3..414bdccd7b0d4a14e848fe202fd0e0fe5be401e9 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 5
+nav_order: 50
 ---
 
 # Atomic Upgrades
index 7c872dc31ecf4824bb69776d7c2edf7926b56d31..65d360acc1571cdacb8bcef3ddd87791224d969c 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 9
+nav_order: 100
 ---
 
 # Handling access to authenticated remote repositories
index cb33d6f8ba51ccdf69bd8887fd578cdf6b8990a2..b93b18c6ca6f196476e31247f5d618dec4b90209 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 11
+nav_order: 120
 ---
 
 # Bootloaders
index e265ee7a034bdba94a498a4e239444bba7f45e02..5c57813111f8b26d101fdcab91b12fb3c52f1c8b 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 8
+nav_order: 90
 ---
 
 # Writing a buildsystem and managing repositories
index b95c61f6b429aee329bef4040b9f50a7520b9063..528141a375ae198a35e4ab983c1f5f16c0b801eb 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 10
+nav_order: 110
 ---
 
 # Using composefs with OSTree
index d3db4cf70f6766e21baa4832b7fdaa5503e39e97..3341ad9009bac1b588944906a3bc37488d7d0d12 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 20
+nav_order: 200
 ---
 
 # OSTree Contributing Tutorial
index 98a1bdb87610c9049f52437d45124290175b4409..7df292d5a7f9222ab3f17e93ec6cff5786fa2f30 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 4
+nav_order: 40
 ---
 
 # Deployments
index c372327999208694a2346231695441c4c2226d42..74be428fd0194681213820e8840fff41328afb8c 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 7
+nav_order: 80
 ---
 
 # OSTree data formats
index 53fd10d89396e2173dc58dc58b091844c209d0e4..bebb3817ff50ea3c82bccd3a205526ff59b2b9b9 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 10
+nav_order: 110
 ---
 
 # Using Linux IMA with OSTree
index 1de55f2f422bb0ff8969eb55786cd715fc43c048..23dfe57ed661eda27c6100d4bed751ff259dc6f2 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 1
+nav_order: 10
 ---
 
 # libostree
index a6fa22528b76936e27b7fb7e121718b6d0fab430..df64b5850a12ebaa0d5dbe64d31fadcfd8652612 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 2
+nav_order: 20
 ---
 
 # OSTree Overview
index a2ba547de6782f0067753003478db565376da7f8..7eb464ccc2808b929023a4a69546799180705f6a 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 10
+nav_order: 110
 ---
 
 # Related Projects
index 580281cacb5c8d9941442bdac527bb0e3d0eb658..31e6d809d040b60e88e422b1b004fe396efca02c 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 3
+nav_order: 30
 ---
 
 # Anatomy of an OSTree repository
index 2db6383a8652248d9e5952d8fb93dd959c3382ef..9760bf690a500c2ca48929b116b2970dda31484c 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 9
+nav_order: 100
 ---
 
 # Managing content in OSTree repositories
index 625359892d721d97f0eb1d636e51b6e7ed6fc335..90c119805fc8c8f0685ef360b20ffd2099c31c6e 100644 (file)
@@ -1,5 +1,5 @@
 ---
-nav_order: 6
+nav_order: 70
 ---
 
 # OSTree and /var handling