# Source: autoboot.adoc

*Note: This file could not be automatically converted from AsciiDoc.*

== `autoboot.txt`

`autoboot.txt` is an optional configuration file that can be used to specify the `boot_partition` number.

This can also be used in conjunction with the `tryboot` feature to implement A/B booting for OS upgrades.

`autoboot.txt` is limited to 512 bytes and supports the `[all]`, `[none]` and `[tryboot]` xref:config_txt.adoc#conditional-filters[conditional] filters.

See also xref:raspberry-pi.adoc#fail-safe-os-updates-tryboot[TRYBOOT] boot flow.

=== `boot_partition`
Specifies the partition number for booting unless the partition number was already specified as a parameter to the `reboot` command (e.g. `sudo reboot 2`).

Partition numbers start at `1` and the MBR partitions are `1` to `4`. Specifying partition `0` means boot from the `default` partition which is the first bootable FAT partition.

Bootable partitions must be formatted as FAT12, FAT16 or FAT32 and contain a `start.elf` file (or `config.txt` file on Raspberry Pi 5) in order to be classed as be bootable by the bootloader.

=== The `[tryboot]` filter
This filter passes if the system was booted with the `tryboot` flag set.

[source,console]
----
$ sudo reboot "0 tryboot"
----

=== `tryboot_a_b`
Set this property to `1` to load the normal `config.txt` and `boot.img` files instead of `tryboot.txt` and `tryboot.img` when the `tryboot` flag is set.

This enables the `tryboot` switch to be made at the partition level rather than the file-level without having to modify configuration files in the A/B partitions.

=== Example update flow for A/B booting

The following pseudo-code shows how a hypothetical OS `Update service` could use `tryboot` in `autoboot.txt` to perform a fail-safe OS upgrade.

Initial `autoboot.txt`:

[source,ini]
----
[all]
tryboot_a_b=1
boot_partition=2
[tryboot]
boot_partition=3
----

**Installing the update**

* System is powered on and boots to partition 2 by default
* An `Update service` downloads the next version of the OS to partition 3
* The update is tested by rebooting to `tryboot` mode `reboot "0 tryboot"` where `0` means the default partition

**Committing or cancelling the update**

* System boots from partition 3 because the `[tryboot]` filter evaluates to true in `tryboot mode`
* If tryboot is active (`/proc/device-tree/chosen/bootloader/tryboot == 1`)
 ** If the current boot partition (`/proc/device-tree/chosen/bootloader/partition`) matches the `boot_partition` in the `[tryboot]` section of `autoboot.txt`
  *** The `Update Service` validates the system to verify that the update was successful
  *** If the update was successful
   **** Replace `autoboot.txt` swapping the `boot_partition` configuration
   **** Normal reboot - partition 3 is now the default boot partition
  *** Else
   **** `Update Service` marks the update as failed e.g. it removes the update files.
   **** Normal reboot - partition 2 is still the default boot partition because the `tryboot` flag is automatically cleared
  *** End if
 ** End If
* End If

Updated `autoboot.txt`:

[source,ini]
----
[all]
tryboot_a_b=1
boot_partition=3
[tryboot]
boot_partition=2
----

[NOTE]
======
It's not mandatory to reboot after updating `autoboot.txt`. However, the `Update Service` must be careful to avoid overwriting the current partition since `autoboot.txt` has already been modified to commit the last update. For more information, see xref:configuration.adoc#device-trees-overlays-and-parameters[Device Tree parameters].
======