project-pegaprox icon indicating copy to clipboard operation
project-pegaprox copied to clipboard

[Bug] ESXi to Proxmox migration fails with Ceph RBD target storage

Open mluenzer opened this issue 3 months ago • 7 comments

Describe the bug

ESXi → Proxmox migration works correctly when local-lvm is used as the target storage, but fails when a standard Proxmox Ceph RBD storage is selected.

The VMware side of the migration works correctly:

  • VM configuration is detected
  • ESXi SSH access works
  • SSHFS mount works
  • VMware datastore is resolved
  • VMDK files are detected
  • Proxmox VM shell is created
  • the RBD image itself is successfully allocated

The migration then fails during target disk preparation with:

Disk allocation failed for disk 0

Detailed error from the migration log:

alloc succeeded (ceph-vmdata:vm-XXX-disk-0) but volume path could not be resolved

The same source VM and migration method works when local-lvm is used instead of Ceph RBD.

This isolates the issue to the Ceph RBD target handling.

The source VM is located on an iSCSI-backed VMFS datastore in VMware.

The relevant PegaProx source file is:

/opt/PegaProx/pegaprox/core/v2p.py

Root cause found in v2p.py

In _pvesm_alloc_disk(), PegaProx already detects both normal filesystem/device paths and librbd URIs:

_plines = [l.strip() for l in str(out_p or '').split('\n') if l.strip()]

dev_path = next(
    (l for l in _plines if l.startswith('/') or l.startswith('rbd:')),
    (_plines[0] if _plines else '')
)

For a normal Proxmox RBD storage, this correctly detects a path such as:

rbd:ceph-vmdata/vm-XXX-disk-0:conf=/etc/pve/ceph.conf:id=admin:keyring=/etc/pve/priv/ceph/ceph-vmdata.keyring

However, immediately afterwards, the success condition only accepts paths beginning with /:

if dev_path.startswith('/') and rc_p == 0:

Therefore, a valid rbd: URI is detected but then rejected.

The code later reaches:

errbuf.append(
    f"alloc succeeded ({vol_id}) but volume path could not be resolved"
)

which matches the observed migration error exactly.

We also tested the KRBD path.

After enabling:

pvesm set ceph-vmdata --krbd 1

pvesm path changes from:

rbd:ceph-vmdata/vm-999-disk-0:conf=/etc/pve/ceph.conf:id=admin:keyring=/etc/pve/priv/ceph/ceph-vmdata.keyring

to:

/dev/rbd-pve/<FSID>/ceph-vmdata/vm-999-disk-0

This gets past the startswith('/') check.

However, the image is not automatically kernel-mapped immediately after allocation.

Also, PegaProx currently calls:

pvesm activate-volume <volume>

inside _ensure_block_device().

On our Proxmox VE installation, this command is not available:

ERROR: unknown command 'pvesm activate-volume'

Manual RBD mapping does work when the Proxmox Ceph configuration and keyring are explicitly supplied:

rbd map ceph-vmdata/vm-999-disk-0 \
  --id admin \
  --keyring /etc/pve/priv/ceph/ceph-vmdata.keyring \
  --conf /etc/pve/ceph.conf

Result:

/dev/rbd0

Afterwards:

rbd showmapped

shows the mapping and:

DEVPATH="$(pvesm path ceph-vmdata:vm-999-disk-0)"

test -b "$DEVPATH" && echo "BLOCKDEVICE OK"

returns:

BLOCKDEVICE OK

Local workaround / patch

We modified the RBD mapping fallback inside:

_ensure_block_device()

Instead of relying only on:

rbd map -p <pool> <image>

we use the Proxmox-managed Ceph configuration and keyring:

rbd map -p <pool> <image> \
  --id admin \
  --keyring /etc/pve/priv/ceph/<storage-id>.keyring \
  --conf /etc/pve/ceph.conf

Conceptually, the change is:

m = re.match(
    r'/dev/rbd-pve/[^/]+/([^/]+)/([^/]+)',
    str(dev_path or '')
)

pool, img = (
    (m.group(1), m.group(2))
    if m else
    (None, None)
)

storage_id = None

if ':' in str(vol_id or ''):
    storage_id, vol_img = vol_id.split(':', 1)

    if not img:
        img = vol_img

if pool and img:

    ceph_conf = '/etc/pve/ceph.conf'
    keyring = f'/etc/pve/priv/ceph/{storage_id}.keyring'

    map_cmd = (
        f"rbd map -p {shlex.quote(pool)} "
        f"{shlex.quote(img)} "
        f"--id admin "
        f"--keyring {shlex.quote(keyring)} "
        f"--conf {shlex.quote(ceph_conf)} 2>&1"
    )

    rc_map, out_map, err_map = _pve_node_exec(
        pve_mgr,
        node,
        map_cmd,
        timeout=40
    )

    _pve_node_exec(
        pve_mgr,
        node,
        "udevadm settle 2>/dev/null || true",
        timeout=15
    )

    for _ in range(5):
        if _is_block():
            return True
        time.sleep(1)

This reproduces the manually verified working RBD mapping.

Suggested upstream solution

The KRBD workaround confirms where the issue is, but ideally PegaProx should not require an administrator to enable:

krbd 1

on an existing Proxmox RBD storage just to perform an ESXi migration.

A normal Proxmox RBD storage already returns a complete librbd URI:

rbd:ceph-vmdata/vm-XXX-disk-0:conf=/etc/pve/ceph.conf:id=admin:keyring=/etc/pve/priv/ceph/ceph-vmdata.keyring

PegaProx already detects this URI.

A cleaner implementation would support both target types:

if rc_p == 0 and dev_path.startswith('/'):
    # filesystem / block-device target

elif rc_p == 0 and dev_path.startswith('rbd:'):
    # direct librbd target

For an rbd: target, PegaProx could use qemu-img / librbd directly instead of requiring a kernel RBD mapping.

This would avoid:

  • requiring krbd 1
  • changing the existing Proxmox storage configuration
  • requiring /dev/rbd*
  • requiring pvesm activate-volume
  • hard-coding the Ceph user
  • hard-coding the keyring path
  • manually reconstructing the Ceph connection information

The exact RBD connection string is already returned by Proxmox.


Steps to Reproduce

  1. Configure a normal Proxmox Ceph RBD storage without krbd 1:
rbd: ceph-vmdata
        content rootdir,images
        pool ceph-vmdata
  1. Verify the storage is active:
pvesm status
  1. Verify that Proxmox itself can allocate an RBD volume:
pvesm alloc ceph-vmdata 999 vm-999-disk-0 1G

Expected result:

successfully created 'ceph-vmdata:vm-999-disk-0'
  1. Verify that the image exists:
rbd -p ceph-vmdata ls | grep '^vm-999-disk-0$'
  1. Check the path returned by Proxmox:
pvesm path ceph-vmdata:vm-999-disk-0

Result:

rbd:ceph-vmdata/vm-999-disk-0:conf=/etc/pve/ceph.conf:id=admin:keyring=/etc/pve/priv/ceph/ceph-vmdata.keyring
  1. Connect VMware vCenter / ESXi to PegaProx.

  2. Select a VM for migration.

  3. Select:

    • Target node: Proxmox node in the cluster
    • Target storage: ceph-vmdata
    • Transfer mode: Offline Copy
  4. Start the migration.

  5. PegaProx successfully mounts the VMware datastore and finds the source VMDK, but fails at target disk preparation with:

Disk allocation failed for disk 0

and:

alloc succeeded (ceph-vmdata:vm-XXX-disk-0) but volume path could not be resolved
  1. Repeat the same migration using local-lvm as the destination.

The migration works.


Expected behavior

A standard Proxmox Ceph RBD storage should be usable directly as an ESXi migration target.

The migration should work without requiring:

krbd 1

and without requiring an intermediate migration to local-lvm.

Ideally PegaProx should accept the rbd: URI returned by pvesm path and use librbd-capable tooling such as qemu-img for the transfer.


Environment

  • PegaProx Version: 1.0
  • Installation Method: Manual (native installation, not Docker)
  • OS: Debian
  • Browser: Chrome
  • Behind Reverse Proxy? No
  • UI? Modern Layout

Additional environment information:

Source:
VMware vCenter
4 x ESXi
VM datastore: iSCSI-backed VMFS

Target:
Proxmox VE cluster
3 nodes
Ceph RBD
Storage ID: ceph-vmdata

Transfer mode:
Offline Copy

The same RBD problem was also observed with a previous 0.9.x version.


Logs

VM shell created

Phase: pre_sync

=== PRE-SYNC: VM continues running on VMware ===

Mounting ESXi datastore via SSHFS...

TMPDIR for subprocesses: /var/tmp

Resolved datastore symlink: LUN_01 → /vmfs/volumes/63a58d68-11c64f77-1281-507c6f288848

SSHFS mounted: /tmp/v2p-6d670f56

VMDK files via SSHFS: 9

=== TRANSFER MODE: Offline Copy ===

Stopping VM first, then full disk copy via SSH

VMware VM already off

Copying disk 0: CSV2PDF.vmdk (200.0 GB)

Source: CSV2PDF-flat.vmdk (200.0 GB)

Datastore: LUN_01

Disk allocation failed for disk 0

Detailed error observed in previous runs:

alloc succeeded (ceph-vmdata:vm-XXX-disk-0) but volume path could not be resolved

Manual verification:

pvesm alloc ceph-vmdata 999 vm-999-disk-0 1G
successfully created 'ceph-vmdata:vm-999-disk-0'

rbd -p ceph-vmdata ls
vm-999-disk-0

With KRBD enabled:

pvesm path ceph-vmdata:vm-999-disk-0
/dev/rbd-pve/<FSID>/ceph-vmdata/vm-999-disk-0

Before manual mapping:

rbd showmapped
<no output>

test -b "$(pvesm path ceph-vmdata:vm-999-disk-0)"
NO BLOCKDEVICE

Manual mapping:

rbd map ceph-vmdata/vm-999-disk-0 \
  --id admin \
  --keyring /etc/pve/priv/ceph/ceph-vmdata.keyring \
  --conf /etc/pve/ceph.conf

/dev/rbd0

Afterwards:

rbd showmapped

id  pool         namespace  image          snap  device
0   ceph-vmdata             vm-999-disk-0  -     /dev/rbd0

and:

BLOCKDEVICE OK

Screenshots

Not required for reproduction.

The issue is reproducible from the migration logs and CLI tests above.


Checklist

  • [x] I have searched existing issues to make sure this is not a duplicate
  • [x] I am using the latest version of PegaProx

mluenzer avatar Aug 20 '26 13:08 mluenzer

This is a genuinely excellent report — you've root-caused it precisely, and both findings check out against the code:

  1. _pvesm_alloc_disk does detect the rbd: librbd URI in the next(...) line, but the very next success gate is if dev_path.startswith('/') and rc_p == 0: — so a valid rbd: URI is found and then rejected, which is exactly the volume path could not be resolved you hit on a non-krbd RBD storage.
  2. And you're right that pvesm activate-volume isn't universally available — it's a best-effort call there, and the real work needs an explicit rbd map with the pool/image + conf/keyring (which _ensure_block_device only reaches once dev_path already starts with /).

So the fix is to handle the rbd:-URI case directly: parse the pool/image + conf/keyring out of the URI and rbd map it to a /dev/rbdN device (instead of requiring krbd), then hand that block device to the transfer — reusing the mapping _ensure_block_device already does for the krbd path. Since this writes real data via dd, I want the block-device resolution airtight (a wrong path = silent data loss), so it'll go onto Testing first.

You clearly have the exact repro and a Ceph RBD target — would you be up for testing a Testing build once it's wired? You've basically written the fix; a live confirm on your setup would be the ideal validation. Thanks for the detail.

mkellermann97 avatar Aug 20 '26 13:08 mkellermann97

Yes, I can test the Testing build on our Ceph RBD setup.

The issue is reproducible here, so I can verify whether the fix works with the normal RBD configuration and without enabling krbd 1.

Just send me the build once it is ready.

mluenzer avatar Aug 20 '26 13:08 mluenzer

Fix is on the Testing branch now (c0352eb).

What it does: on a non-krbd RBD alloc we now parse that rbd:<pool>/<image>:conf=…:id=…:keyring=… URI and rbd map it (honouring whatever conf/id/keyring/mon_host the URI carries) to a real /dev/rbdN, then hand that block device to the raw copy — instead of rejecting the URI. It's fail-closed: if the image can't be mapped it drops the empty volume and gives a clear error rather than dd-ing into a phantom file. The working krbd path is untouched.

I've unit-tested the parsing + the map command, but I don't have a non-krbd Ceph RBD target to E2E it end-to-end — and you've got the exact repro. Would you give a Testing build a run on your setup? Two things I'd love you to watch:

  1. Does the ESXi→PVE migration into the non-krbd rbd storage now complete and the guest boot correctly?
  2. After it's done, is there a leftover rbd device list mapping for that image on the node? (We map it kernel-side for the copy; I want to confirm whether it needs an explicit unmap in the teardown, or if it's harmless on your PVE version.)

If it works I'll get it lined up for the next release. Thanks again for doing the root-cause legwork — made this straightforward.

mkellermann97 avatar Aug 23 '26 17:08 mkellermann97

Tested c0352eb end-to-end on our non-krbd Ceph RBD setup.

The ESXi → PVE migration now completes successfully and the guest boots correctly from the Ceph RBD disk.

The relevant result:

COMPLETED (vmkfstools_clone, downtime ~3.0s): PegaproxTest -> VMID 105

The resulting VM is running normally with:

scsi0: ceph-vmdata:vm-105-disk-0,size=16G

So the new non-krbd mapping logic works as intended.

One thing remains: after the migration completes, the kernel-side RBD mapping is still present on the target node:

id  pool         namespace  image          snap  device
0   ceph-vmdata             vm-105-disk-0  -     /dev/rbd0

rbd showmapped shows the same mapping, so it looks like an explicit rbd unmap is still needed during cleanup/teardown.

There was also one non-fatal message during the migration:

EFI fallback loader skipped (non-fatal): rc=0 volume not a block device

It did not prevent the migration or the guest from booting successfully, but it may be worth checking whether that EFI fallback path also still expects a block-device path.

So overall:

  • non-krbd Ceph RBD migration: working
  • guest boot: working
  • temporary RBD mapping cleanup: still needed

Thanks — the main fix works on our setup.

mluenzer avatar Aug 25 '26 06:08 mluenzer

That's exactly the confirmation I was hoping for — thanks for the thorough end-to-end test on a real non-krbd Ceph RBD setup. Great to see the migration complete and the guest boot straight off the RBD disk with the new mapping logic.

Both of your follow-ups are spot on:

  1. Lingering RBD map. Right — since the storage is librbd/qemu, the guest runs off librbd and the kernel /dev/rbd0 map we create for the raw copy is left dangling afterwards. Harmless to the running guest, but it should be cleaned up. I'll add an explicit rbd unmap in the migration teardown for the devices we mapped, so rbd showmapped comes back clean after a run.

  2. EFI fallback "not a block device". Good catch. That path most likely still resolves the EFI/vars volume the old way and hits the same rbd: URI → non-block situation the main disk did. It's non-fatal here because the EFI disk isn't required to boot in your case, but I'll route it through the same mapping so it's consistent.

I'll get both onto the Testing branch and ping you for another quick validation run when they're ready — the teardown one especially is worth re-confirming rbd showmapped is empty on your setup afterwards. Really appreciate you closing the loop with hard evidence; made this easy to trust.

mkellermann97 avatar Aug 25 '26 07:08 mkellermann97

Both follow-ups are on Testing now:

  • The /dev/rbdN we kernel-map for the raw copy is released in the migration teardown (an explicit rbd unmap of exactly the devices we mapped — a krbd storage is never touched, and the guest runs through librbd anyway, so the map was pure leftover).
  • The EFI fallback loader now routes the EFI volume through the same rbd mapping, so it no longer bails with "volume not a block device" on a non-krbd RBD target.

Whenever you get a chance, a re-validation on your non-krbd Ceph setup would confirm both end-to-end — rbd showmapped should come back empty after a migration, and the EFI step should install the loader instead of skipping it. Thanks again for the earlier E2E and the precise root-causing.

mkellermann97 avatar Aug 30 '26 11:08 mkellermann97

Closing this one — it has been quiet for a few weeks and everything in it is out.

Your end-to-end test confirmed the core mapping logic back in August, and both follow-ups from that thread shipped with 1.1.0: the /dev/rbdN we kernel-map for the raw copy gets released in the migration teardown, and the EFI fallback routes through the same mapping. They have been in a release since the end of August without anyone coming back on them.

Thanks for the actual hardware test — non-krbd Ceph RBD is not something we can reproduce here, so that was the whole reason this got fixed properly rather than guessed at.

Reopen if it resurfaces.

Marcus

(we run on what people chip in, if you ever feel like it: https://opencollective.com/pegaprox)

mkellermann97 avatar Sep 21 '26 15:09 mkellermann97