Some Bits: Nelson's log

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.

  1. Boot systemrescue-zfs on some computer.
  2. Plug the drives from your ZFS pool into the rescue machine
  3. Run lsblk to see that the drives are present.
  4. Run zpool import to see a list of pools. Your Proxmox pool should be there. Proxmox creates rpool on install, you may have others.
  5. Run zpool import -f poolname to import the pool.
  6. Run zfs list to 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

  1. cd /zvol. In here is filesystem access to the ZFS datasets (as symlinks to block devices)
  2. Find the virtual disk you want, say vm-100-disk-1
  3. qemu-img info vm-100-disk-1 to see if there’s a plausible disk image there.
  4. modprobe nbd max_part=8 to load a driver for network block devices
  5. qemu-nbd --connect=/dev/nbd0 vm-100-disk-1 to make the QEMU disk available as /dev/nbd0. Note this is the whole disk, not just one partition.
  6. fdisk /dev/nbd0 -l to see the partition table of the virtual disk
  7. mount /dev/nbd0p1 /mnt/hope to mount the partition 1 filesystem as /mnt/hope.
  8. cd /mnt/hope and there’s your stuff!