Home KVM How To Rescue Virtual Machines With Virt-rescue

How To Rescue Virtual Machines With Virt-rescue

By sk
Published: Updated: 6.6K views

This brief guide describes what is Virt-rescue, and how to rescue virtual machines with Virt-rescue command line utility in Linux operating systems.

What Is Virt-rescue?

Virt-rescue is like a rescue CD, but for virtual machines only. It provides a simple rescue shell and some recovery tools to inspect and correct problems in a virtual machine or disk images.

Please note that Virt-rescue is different from guestfish. Guestfish is an interactive shell for editing and making changes in virtual machines and disk images.

In contrast, Virt-rescue is particularly suited to rescuing a virtual machine that has failed to start. If a VM doesn't boot, you can simply launch a rescue shell on the VM or disk image using virt-rescue and try to fix it using the standard Linux commands.

You can use virt-rescue on any disk image file or device, not just a virtual machine. For example, it can be used on USB drives, SD cards and hard disks. It doesn't require root permission unless you need root to open the disk image.

Virt-rescue is part of libguestfs which provides a lot of command line utilities to access and modify virtual machine disk images.

Rescue Virtual Machines With Virt-rescue

Make sure you have installed libguestfs on your Linux machine as described in the link below.

Now let us go ahead and rescue Virtual machines.

First of all, turn off the virtual machines. You must not run rescue shell on any live virtual machines or disk images.

To run a rescue shell on the problematic virtual machine, do:

$ virt-rescue -d centos8-uefi -i

Replace "centos8-uefi" with your virtual machine's name. You can find the list of available VMs using "virsh list --all" command.

You can also run a rescue shell directly on any disk image(s) like below:

$ virt-rescue -a CentOS_8_Server.img -i

Here, -i (--inspector) flag is used to automatically mount the filesystems of the virtual machines. If you don't use it, you will have to manually mount virtual machine's filesystems in an empty directory called /sysroot.

You will be now landed in an interactive bash shell where you can use many ordinary Linux commands to rescue the virtual machines.

Welcome to virt-rescue, the libguestfs rescue shell.

Note: The contents of / (root) are the rescue appliance.
Use 'cd /sysroot' or 'chroot /sysroot' to see guest filesystems.

groups: cannot find name for group ID 0
The virt-rescue escape key is ‘^]’.  Type ‘^] h’ for help.
libguestfs rescue shell
libguestfs rescue shell

From the rescue shell, you can start using the traditional Linux commands to fix the VM.

As stated above, the guest machine's filesystems are mounted in /sysroot directory.

You can verify it with "ls" command:

><rescue> ls /sysroot/
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

To chroot into the /sysroot directory first:

><rescue> chroot /sysroot

To exit from rescue shell, type exit and hit enter or press Ctrl+d.

Launch VMs In Read-only Mode

As stated earlier, You should not run rescue shell on any live VMs. But if you still wanted to do it for any reason, use --ro option to use "virt-rescue" safely on a live disk image or VM.

$ virt-rescue -d centos8-uefi -i --ro


$ virt-rescue -a CentOS_8_Server.img -i --ro

The --ro option will launch the VM or disk image in read-only mode. It is ideal for experimenting VMs or disk images. No changes will be actually saved. Once you exit from the shell, all changes will be lost!

Enable Network Access For VMs

If you want to download file or package into the virtual machine, you can use --network option while running virt-rescue command:

$ virt-rescue -d centos8-uefi -i --network


$ virt-rescue -a CentOS_8_Server.img -i --network

This option enables network access inside the rescue shell, so you can download stuffs from internet.

Virt-rescue has many options. For more details, refer man pages:

$ man virt-rescue

Featured image by Miguel Á. Padriñán from Pexels.

You May Also Like


Parthiban June 26, 2023 - 1:16 pm

Awesome! It works well thank you so mvuh

Colin Hutchison September 4, 2023 - 7:06 am

Hoped someone would know what to do. You did and it worked brilliantly = although all the data flashing on my monitor was daunting I knew enough to leave it be and go make a cup of tea. 02.30 in the morning and so to bed !!!

1 2 3

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More