I have a VM from Azure (Ubuntu 20.04). I can't pay anymore and want to get the files, but I can't start the VM. I downloaded the disk (DOS/MBR boot sector, extended partition table (last)) and don't know what to do.
-
In what format are those disk images? Just raw bytes or vmdk, qcow2... ? Running `file` on them may help identify the format. – Stéphane Chazelas Aug 06 '22 at 11:34
-
Why can't you start the VM? Have you tries `kvm -hda the-disk.img -m 2048 -snapshot` on it (where `-snapshot` makes sure the img is not modified)? – Stéphane Chazelas Aug 06 '22 at 11:52
-
@StéphaneChazelas `file` gives me what I said above. And I can't start because I don't have credits to start. – João Vitor Torres Tedesco Aug 06 '22 at 12:04
-
@StéphaneChazelas I found another way to download the disk (think is better), its a .vhd file now (`file` says the same thing), I did the command above and this happens: `Could not access KVM kernel module: No such file or directory kvm: failed to initialize kvm: No such file or directory kvm: falling back to tcg gtk initialization failed` – João Vitor Torres Tedesco Aug 06 '22 at 18:50
-
Yes, you need a Linux machine, Windows won't do and is off topic here. Note that qemu / kvm supports raw images (which would have been the format of those images you had initially if that's what `file` outputs for them). – Stéphane Chazelas Aug 06 '22 at 18:58
-
@StéphaneChazelas Ok, so WSL don't work for that, that's is the unique way to get any file from there? – João Vitor Torres Tedesco Aug 06 '22 at 21:29
2 Answers
If the disk images are in one of the formats supported by qemu (raw, VMDK, VDI, VHD (vpc), VHDX, qcow1 and QED), you can make the disk available as a nbd device with (as root):
modprobe nbd max_part=31
qemu-nbc -c /dev/nbd0 disk.img
(qemu-nbd from the qemu-utils package on Debian-based systems).
Then, if the file systems are directly on partitions, mount them with:
mount -r /dev/nbd0p1 /some/mountpoint
(here for the first partition).
If LVM was used on the VM, you may need to also install lvm locally and activate the VM's volume group with vgchange and mount the logical volumes after that.
The libguestfs-tools package on Debian-based systems at least has a few utilities to explore VM disk images, including a guestfish shell-like utility to explore them interactively:
$ sudo guestfish --ro -a slackware.qcow2
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.
Type: ‘help’ for help on commands
‘man’ to read the manual
‘quit’ to quit the shell
><fs> launch
100% ⟦▒▒▒▒▒▒⟧ 00:00
><fs> list-filesystems
/dev/sda1: ext2
/dev/sda2: ext2
/dev/sda3: ext2
/dev/sda4: vfat
><fs> mount /dev/sda1 /
><fs> ls /
.bash_history
.emacs
.kermrc
.less
.lessrc
.profile
.term
bin
conf
dev
dos
etc
home
inst
install
lastlog
lib
linux
lost+found
mnt
os2
proc
root
tmp
user
usr
var
zImage
- 522,931
- 91
- 1,010
- 1,501
-
I can't do the first command, this happens: `modprobe: FATAL: Module nbd not found in directory /lib/modules/5.10.16.3-microsoft-standard-WSL2`. – João Vitor Torres Tedesco Aug 06 '22 at 13:09
You can use qemu:
For .vdi
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd1 ./linux_box/VM/image.vdi
if they are not installed you can install them (on Ubuntu is this comand)
sudo apt install qemu-utils
and then mount it
mount /dev/nbd1p1 /mnt
For .vmdk
sudo modprobe nbd
sudo qemu-nbd -r -c /dev/nbd1 ./linux_box/VM/image.vmdk
notice that I use the option -r that's because VMDK version 3 must be read only to be able to be mounted by qemu
and then I mount it
mount /dev/nbd1p1 /mnt
I use nbd1 because nbd0 sometimes gives 'mount: special device /dev/nbd0p1 does not exist'
For .ova
tar -tf image.ova
tar -xvf image.ova
The above will extract the .vmdk disk and then mount that.
- 11,153
- 18
- 57
- 67