Accessing a Proxmox guest in ZFS from a rescue disk
Testing disaster recovery: what if my Proxmox server dies and I need to get data from a VM disk stored in it in ZFS? The simple thing is to boot Proxmox and use it to recover. But what if I don’t want to use Proxmox to get at my files? It’s possible, at least in theory, using generic ZFS and QEMU tools. I tried this and it seemed to work.
(An aside: I harshly unplugged my ZFS pool disks while Proxmox was running, then plugged them in later. Proxmox didn’t handle this very well, I ended up having to reboot the Proxmox server and then everything was back with no drama.)
Part 1: import the ZFS pool
The first step is to get the ZFS pool online in a rescue environment.
- Boot systemrescue-zfs on some computer.
- Plug the drives from your ZFS pool into the rescue machine
- Run
lsblkto see that the drives are present. - Run
zpool importto see a list of pools. Your Proxmox pool should be there. Proxmox createsrpoolon install, you may have others. - Run
zpool import -f poolnameto import the pool. - Run
zfs listto see what the pool has in it
At this point any normal filesystems in Proxmox are mounted somewhere in the filesystem and you can cd to their directories, copy them as files, etc.
Part 2: access the QEMU virtual disks
I’m after data that’s in a guest virtual machine’s disk. And those aren’t stored in normal files. Instead they are stored in ZFS datasets with funny names like rpool/data/vm-100-disk-1. They are in QEMU disk image format. (I think raw, not qcow2, but I am not certain.)
There’s several options for what to do next. You could zfs send the data somewhere safe. In Proxmox you could access the virtual disks with the qm command line tool. There’s probably a way to use qemu-img dd to get your data. But here in systemrescue-zfs I’m going to mount it via a network block device.
I’m a little out of my depth here but I bashed my way into getting access like this
cd /zvol. In here is filesystem access to the ZFS datasets (as symlinks to block devices)- Find the virtual disk you want, say
vm-100-disk-1 qemu-img info vm-100-disk-1to see if there’s a plausible disk image there.modprobe nbd max_part=8to load a driver for network block devicesqemu-nbd --connect=/dev/nbd0 vm-100-disk-1to make the QEMU disk available as/dev/nbd0. Note this is the whole disk, not just one partition.fdisk /dev/nbd0 -lto see the partition table of the virtual diskmount /dev/nbd0p1 /mnt/hopeto mount the partition 1 filesystem as/mnt/hope.cd /mnt/hopeand there’s your stuff!