# Use Rescue Mode

Just like a physical machine, some user operations (such as a major upgrade of the operating system or a modification of the partition layout) could cause a Compute instance to be unable to boot normally.
When an instance cannot boot normally, a rescue mode exists to access the root disk by booting from a different source. In this case, we use an open-source program called [netboot.xyz](https://netboot.xyz/) that can utilize a variety of Linux, BSD, ISO images, specialized installers, or utilities.

## Rescue Mode Prerequisites 
Rescue mode is not a default operation and can be operated only via the CLI or the API. Rescue mode requires:

* a working [`exo` CLI]({{< ref "/tools/command-line-interface/" >}}) environment
* access to an [IAM API key]({{< ref "/product/iam/quick-start/" >}})
* access to the Portal

If you wish to use a custom ISO, it must be loaded in a publicly accessible
URL. You can always use
[Simple Object Storage]({{< ref "/product/storage/object-storage/quick-start/" >}}).

> [!WARNING]
> Rescue Mode relies on netboot.xyz, which does not support Secure Boot.
> Instances with Secure Boot enabled will therefore be unable to boot into Rescue Mode.

> [!WARNING]
> Exoscale is solely responsible for the instance's booting in rescue mode with the `netboot.xyz` loader. 
> Any operation performed in `netboot.xyz` and the repair of the instance itself are outside of Exoscale's standard support scope. > The examples in this guide are intended to point the user in the right direction without guaranteeing their outcome. 
> Knowledge of tooling and operations is required.

> [!WARNING]
> Rescue Mode relies on netboot.xyz, which requires network access for HTTP(S).
> If the rescued instance has security groups restricting egress, you need to allow
> port 80 (HTTP) and 443 (HTTPS) for `netboot.xyz` to properly function.

> [!WARNING]
> On smaller instance types, some `netboot.xyz` recovery modes may exceed
> the RAM allocated to the instance. You nay need first to scale up your instance. 

## Booting Into Rescue Mode
To reboot in rescue mode, first start by shutting down your instance via the
CLI or the Portal in the instance details:

```bash
exo compute instance stop broken-vm
```

Then start your instance in either BIOS or UEFI rescue mode, depending on the
template you are using.

To start an instance in BIOS rescue mode:

```bash
exo compute instance start --rescue-profile=netboot broken-vm
```

To start an instance in UEFI rescue mode:

```bash
exo compute instance start --rescue-profile=netboot-efi broken-vm
```

![](rescue.gif "Start Instance in Rescue Mode")

The instance will now boot the `netboot.xyz` image.

## Accessing the Rescue Mode
To access the rescue mode, log into the Portal and navigate to the instance
detail view. Select `Console` in the `...` menu at the top right header.

A new window will open and display the instance console and the `netboot.xyz` menu:

![](netboot.gif "netboot.xyz Rescue Menu from Console")

> [!NOTE]
> When booting a [Private Instance]({{< ref "/product/compute/instances/how-to/private-instances/" >}}), 
> you need to enter the Failsafe Menu from `netboot.xyz` to perform a manual network configuration.

You can now perform any operations needed to repair the instance and then reboot it normally after you have finished. After the instance has rebooted, it will exit rescue mode and try to boot from its root disk.

## Booting from a Custom ISO Image 
Through rescue mode, it is possible to boot an instance from an external ISO as long as the ISO supports VirtIO storage and network drivers. This method allows for bare metal recovery, for example.

> [!NOTE]
> The custom ISO must be located in a publicly accessible URL. You can always use our 
> [Simple Object Storage]({{< ref "/product/storage/object-storage/quick-start/" >}}).

To boot from an external ISO:

* Start your instance in rescue mode as described above
* From the main netboot.xyz menu, select `Tools -> Utilities`
* Then select `netboot.xyz tools -> Test Distribution ISO`
* Enter the public URL of the target ISO 
  - e.g., https://releases.ubuntu.com/24.04/ubuntu-24.04.2-live-server-amd64.iso boots an Ubuntu Live CD

![](rescue_iso_recovery.gif "Netboot Rescue Menu from Console `iso-image`")

## Booting from a Windows Recovery Image
If you need to recover a Windows instance from a Windows Recovery Image, you can use two ISOs we have provided, where all the needed
[virtIO drivers](https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/)
have already been integrated:

- `http://sos-de-muc-1.exo.io/windows-recovery-image/w2k16` a Windows 2016 recovery image
- `http://sos-de-muc-1.exo.io/windows-recovery-image/w2k19` a Windows 2019 recovery image
- `http://sos-de-muc-1.exo.io/windows-recovery-image/w2k22` a Windows 2022 recovery image

> [!WARNING]
> Although provided for public use, the above Windows Recovery Images are provided as is, without warranties. 
> As for any other rescue mode operation, the user is solely responsible for the outcome of their actions, and 
> rescue operations beyond the booting of the `netboot.xyz` loader are out of the Exoscale standard support scope.

![](rescue-windows-recovery-boot.gif "Netboot rescue menu from console iso-image")

To proceed:

- Start your instance in rescue mode as described above
- From the main `netboot.xyz` menu, select `Distributions -> Windows`
- Select `Options -> Base URL`
- Enter the URL corresponding to your instance's Windows version from the abovementioned options. Then enter any key to return to the `Windows` menu
- After returning to the `Windows` menu, select `Load Microsoft Windows Installer...`
- The Windows Recovery Image will load, and you will be prompted to enter some basic options. Click on __Next__ when ready
- On the next screen, click on __Repair Your Computer__

You can now recover your Windows instance.

## Linux Password Reset via Rescue Environment

Suppose you need to reset a Linux password, such as the root password, and cannot access the system normally. In that case, you can boot into a rescue environment and manually reset the password. Here's a step-by-step guide to doing this using a rescue environment like __`netboot.xyz`__.

__Step 1: Access a Linux Rescue Environment via `netboot.xyz`__

- *Boot from `netboot.xyz`*: Use the ``netboot.xyz` tool to boot into a live or rescue environment for Linux: Stop the VM and boot it in rescue mode. Make sure your VM type is at least LARGE. 

```bash
exo compute instance start --rescue-profile=netboot instance_name
```
- *Select a Distribution*:
In the `netboot.xyz` menu, choose an option to boot into Rescue Mode or a minimal environment. In this example, we will use the __Ubuntu__ rescue environment, but you can use any distribution available in the menu. 

__Step 2: Mount the Root Filesystem__

Once you're in the live environment, you'll need to identify and mount the root partition of your system. Follow these steps:

- *Identify the Root Partition*:

Use the following command to list available partitions and find your root partition:

```bash
fdisk -l
```

Look for a partition named `/dev/sda1` or `/dev/vda1`. This is likely your root partition, where the Linux system is installed.

- *Mount the Root Filesystem*:

Mount the root filesystem to a directory like ``/mnt`` replace `/dev/vdX` with the root partition (e.g., `/dev/vda1`)

```bash
mount /dev/vdX /mnt  
```

- *Mount Additional Filesystems*:

Mount the necessary system filesystems required for `chroot`:
```bash    
mount -t proc /proc /mnt/proc
mount --rbind /sys /mnt/sys
mount --rbind /dev /mnt/dev
```    

__Step 3: Chroot into the Mounted Filesystem__

- *Enter the chroot environment*:

Use `chroot` to change your root directory to the mounted filesystem:
```bash      
chroot /mnt
```    

- *Reset the Password*:

To reset the root password, run the following command:
```bash 
passwd root
```    

If you need to reset the password for a specific user, replace ``root`` with the username:
```bash   
passwd <username>
```    

- *Exit the Chroot Environment*:

After resetting the password, exit the chroot environment by typing:
```bash
exit
```    

__Step 4: Unmount Filesystems and Reboot__

- *Unmount the filesystems*:

Unmount the filesystems you mounted earlier:
```
umount --recursive --lazy /mnt
```
    
- *Reboot the system*:

Reboot the system with the following command:

```bash
exo compute instance reboot "instance-name"
```    
After the reboot, you should be able to log into the system with the new password via the console or SSH.

