How to recover data from Linux KVM virtual machines?
Read this article to find out how to install QEMU– KVM hypervisor kernel modules, and add a virtual machine manager in a Linux operating system. Also, you’ll learn to create a virtual machine with Windows, and how to recover data from a KVM virtual machine disk.
- How to check virtualization support
- Installing KVM on Ubuntu 20.04
- How to create a virtual machine in Ubuntu 20.04
- How to recover data from a virtual machine
- Questions and answers
KVM (Kernel-based Virtual Machine) is an open-source full virtualization solution for Linux systems. Similarly to VirtualBox and VMware Workstation, KVM is a Linux kernel virtualization tool that turns it into a hypervisor.
Such hypervisor lets users run isolated instances of other operating systems within the host system.
A virtual machine manager is a piece of software with graphical interface used to control virtual machines: with this manager, you can operate a virtual machine both locally and over the network, for example, via SSH protocol.
If there is a reason preventing you from installing VirtualBox or VMware on Linux, you can try KVM instead.
Before you begin, it’s necessary to find out if your computer’s CPU supports KVM and hardware virtualization features.
egrep -c '(vmx|svm)' /proc/cpuinfo
If this command returns the result “0” - your CPU doesn’t support virtualization. Luckily, everything is OK in my case, so we can continue with the installation.
The next step is to add one more tool to check compatibility: use this command
sudo apt install cpu-checker
After that, check if KVM can be used, with another command
If KVM is supported, the operating system will inform you about your chances to use KVM acceleration:
KVM acceleration can be used
If your hardware is incompatible, you’ll see a notification saying KVM can’t be run.
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
Before installation, update repositories with the command “apt update”
sudo apt update
To add required KVM packages, run the command “Install” with the package names:
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager
Software ensuring hardware emulation for KVM hypervisor - qemu-kvm.
Configuration files required to run libvirt as a system service - libvirt-daemon-system.
Software to manage virtualization platform - libvirt-clients.
A set of command prompt tools to configure Ethernet bridges - bridge-utils.
A set of command prompt tools to create virtual machines – virtinst.
A graphical interface and command prompt tools required to manage virtual machines via libvirt - virt-manager.
When asked to agree or disagree, hit Yes, press Enter, and wait until the installation is complete.
After KVM packages are installed, run the commands to start and enable their booting with the operating system.
sudo systemctl start libvirtd
sudo systemctl enable libvirtd
If the virtual machine manager displays an error message, restart the computer.
Now that the server is configured, let’s run the virtual machine manager with this command:
Or do it with the applications menu by clicking on the program’s shortcut. In order to create a virtual machine, click on the computer icon in the top left corner. In the window that opens, choose how to install a virtual machine - with the help of ISO image, and click “Forward”.
In the next window, specify the path to the previously downloaded ISO image of the operating system by clicking the Browse button. Select it, click “Choose volume” and then “Forward”.
After that, specify the amount of system memory and number of processors you’d like to allocate for this virtual machine. Finally, give the name for this machine, and click “Finish”.
When you do it, the virtual machine will boot automatically, and the installation of the operating system from the image will begin.
As we know, losing data is something inevitable that every user has to face, sooner or later.
Here is a list of things that typically cause loss of data from a virtual machine:
- Accidentally removed files;
- Disk formatting;
- Failure to mount a virtual file
- Damage to index files
- Unexpected power failure
- Hypervisor issues, etc.
To restore virtual machine files, you need specialized software to find the missing information - a data recovery tool.
For starters, let’s explore where to look for virtual machine files and how to recover them if the machine cannot be opened, its operating system refuses to boot, or if some files were accidentally removed or damaged.
To extract virtual machine files from the disk, use Hetman Partition Recovery.
It supports all popular file system formats and it can help you restore data after deleting, formatting, and hardware or software errors. Connect the hard disk to a Windows computer and start the scan. You can find KVM virtual machine files by following this path:
The file name corresponds to the virtual machine name, and this is a file with the extension .qcow2. Recover it to any available location.
If you have a Linux computer, you can try to access the files even without using specialized tools. Upload the virtual machine file into the manager, start the machine, and get the information you are looking for.
If you failed to boot a virtual machine after system repair operations, or if there is an error when you try to start it, don’t give up: use our program to open that file and recover all of its data. To do it, find the Tools tab - click “Mount Disk”; in the window that opens, you will choose the disk image type, then check the list for your virtual machine name, or choose the corresponding file extension, and click “Next”.
Give the path to the folder containing the files by clicking on “Select Folder”. The program will display all virtual machine files which exist in such folder, and you can uncheck the boxes for the ones you don’t need now.
To begin searching for data, right-click on the disk and choose “Open”. Then choose the analysis type. We recommend starting with “Fast scan”.
The program can find all files remaining on the disk without difficulty. The red cross indicates the ones which have been deleted. Click on a file to see its contents in the preview window. To quickly find a specific file, there is a search-by-name feature.
Select the files you need to restore and click “Recovery”, specify the disk where to save the files and click “Recovery” again.
As we know, virtual machines offer a good protection against data loss. However, even with all their advantages, such machines cannot guarantee full protection. While working with them, you may encounter various issues such as software errors, crashes, human errors like accidentally removing files or formatting the hard disk and so on. If you ever lose data from a virtual machine, we recommend using a powerful data recovery tool, Hetman Partition Recovery. It supports most virtual disk file formats such as: .vmdk, .vdi, .vhd, .vhdx, .hdd, .hds, .qcow, qcow2, .img, .cow, .qed.
With a trial version, you can evaluate the program’s effectiveness before actually paying for the license: you only need the full version to save the files.