How to boot Ubuntu Core in recovery mode

Key Value
Summary Ubuntu Core can be booted into normal, recovery and reinstall modes. This tutorial will show you how to make use of this feature for debugging production issues and reverting a system to “factory” defaults.
Categories iot
Difficulty 1
Author david.beamonte@canonical.com

Overview

In this tutorial we cover device recovery fundamentals on Ubuntu Core and show you how to use the different recovery modes offered by Ubuntu Core for restoring a device to a safe system.

Bear in mind, Ubuntu Core is production-friendly, not necessarily developer-friendly. We recommend you use Ubuntu Core for “fire and forget” purposes where you won’t want to iterate on the software.

With Ubuntu Core, you are able to execute remote updates and patches for your appliances and devices, but for development and prototyping, we recommend Ubuntu Server. Let’s start!

What you’ll learn

  1. Recovery mode fundamentals
  2. How to use recovery mode

What you’ll need

  • A device with an installed and configured Ubuntu Core image
  • A monitor with HDMI interface
  • An HDMI cable
  • A keyboard

Understanding Recovery Mode

Ubuntu Core 20 is inherently robust. But if data-corruption issues do occur, either on boot or on data partitions, Ubuntu Core can still access recovery mode to help repair, restore or reinstall on an impaired device.

The following booting modes are currently available on boot:

  • Run mode: Normal boot mode
  • Recovery mode: reboot into recovery mode for maintenance or repairing the system
  • Reinstall mode: initialise the device from an onboard system image

These functions can be used with any of the following methods:

  • Recovery hidden menu on boot
  • Snap reboot command from console
  • Snapd REST API

After a clean Ubuntu Core installation, a first recovery system is created so that it is possible to recreate a clean factory system at any time with the Reinstall mode.

Run mode

When booting in run mode, the device attempts to boot normally, with no option to recover or reinstall the system.

Recovery mode

In recovery mode, the device boots to a temporary system and operates as it would from a pristine initial installation, including its snaps. This allows you to log in to the system using prior credentials to recover your data, either via SSH or locally after setting up a password for the user.

Modifications done to the system during recovery mode are temporary and are lost once the device is rebooted.

Reinstall mode

In reinstall mode, all existing user data on the device is removed and the device is initialised from the recovery system image.

The full process of installation and configuration is followed in a similar way to a first boot after Ubuntu Core installation.

Using recovery hidden boot menu

Accessing recovery hidden boot menu

If you prefer to recover the system when booting or if the system is no longer accessible via the network, you can use the recovery hidden menu:

  1. Start or reboot the device with the ‘1’ key held on a connected keyboard. In some systems or with some keyboards it is necessary to press the key repeatedly.

  2. After the initial boot process completes, a status screen appears to show “System mode selection triggered. Proceed to select one of the available systems and actions.”. Press OK.

  3. On the next screen, select with TAB or cursor keys the desired action and press ENTER.

  4. A message indicating the selected mode is displayed. Press CONFIRM to proceed.

If “Run normally” has been selected, the system boots in run mode.

If “Recover” has been selected, the system boots in recovery mode.

If “Reinstall” has been selected, the system boots in reinstall mode.

Using console

SSH in

First you have to log into your device using SSH. Run the ssh command which will be something like:

ssh <user>@<device_address>

And you should be welcome to Ubuntu Core:

Listing recovery points

Once you are in the device console, you can check the list of recovery systems that can be used for recovering.

snap recovery

Which should show a list of labels like this

Recovery mode from console

The snap reboot command allows you to boot in the different booting modes (run, recovery, install) from the console. The procedure is as simple as just typing the following command:

sudo snap reboot --recover 20210112

The system shows a message on the console indicating that it is going to reboot with the system indicated in the label.

This process takes some time. The device will be accessible via SSH but the snaps take some time to install and update.

You can check by running the command “snap list” until the full list of packages is up to date.

Using Recovery mode

Once the system has booted in recovery mode, you can access via SSH with your prior credentials, and have a clean system where the desired maintenance action can be performed.

For exiting recovery mode, you can use any of the following options:

  • Enter the following command
snap reboot --run
  • Power off and on the system

Either method returns the system to run mode, and all changes done to the temporary system are lost.

Alternatively, if a normal reboot is done with the command sudo reboot, the system eventually stops on the next boot showing the ‘Recovery chooser’ menu, so this method is not recommended.

Wrapping up

Ubuntu Core offers the ability to repair, recover or reinstall the system, should any corruption happen to the device. Recovery modes described in this tutorial guarantee that the system can always be restored to a safe or known state.

Further reading

2 Likes

i have issue here.
this doesn’t work on ubuntu core 20.04 running on raspberry pi4.
i tried also shift key and esc key.

1 Like

Hi there!! This tutorial was helpful. Thank you for sharing!

Thank you for sharing!.
.

Hi,
Thanks for the tutorial :slight_smile:

I have a question regarding this sentence:

Is this correct?
I don’t understand how to “repair” the system if changes we do to the system are lost? Am I missing or misunderstanding something?

Tks again.
BR,