0

qemu-nbd - QEMU Disk Network Block Device Server failing with Debian 10.2

Works perfect with Debian 9.12. Does not work any longer with Debian 10.2. Any suggestion of what I might be doing wrong?

modprobe nbd
qemu-nbd --connect /dev/nbd0 -f qcow2 /tmp/image.qcow2
# -----
qemu-nbd -d /dev/nbd0
modprobe -r nbd

At the end it gives the following error message: modprobe: FATAL: Module nbd is in use. It works how it should in Debian 9.12. (Opens and closed the connection properly without leaving open connections).

In memory there are two processes open: [kworker/u9:0-knbd0-recv] and [knbd0-recv]

These two processes should be closed when executing qemu-nbd -d /dev/nbd0

[EDIT] There is no qemu-nbd process running. The nbd device is still seen in /proc/partitions.

In dmesg:

 113.620404]  nbd0: p1 p2 < p5 >
[  117.767674] EXT4-fs (dm-10): mounted filesystem with ordered data mode. Opts: (null)
[  156.688684] block nbd0: NBD_DISCONNECT
[  156.688696] block nbd0: Disconnected due to user request.
[  156.688697] block nbd0: shutting down sockets
[  163.869378] blk_update_request: I/O error, dev nbd0, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0

This is what I see in the Debian 9.12 server with the same qcow2 image file:

[181586.110052] block nbd0: NBD_DISCONNECT
[181586.110063] block nbd0: shutting down sockets
[181617.936407]  nbd0: p1 p2 < p5 >
[181748.735336] EXT4-fs (dm-14): 6 orphan inodes deleted
[181748.735337] EXT4-fs (dm-14): recovery complete
[181748.755426] EXT4-fs (dm-14): mounted filesystem with ordered data mode. Opts: (null)
[181772.254622] block nbd0: NBD_DISCONNECT

[SOLUTION] Make sure you execute vgchange -a n nbdvg before disconnecting.

6
  • 1
    No qemu-nbd process? The nbd device itself still in /proc/partitions? What happens when you try to read it? Anything in dmesg? Should be NBD_DISCONNECT, shutting down sockets or the like. – frostschutz Mar 5 '20 at 13:04
  • 1
    The nbd device is still in /proc/partitions. I see many errors with blk_update_request with dmesg I/O error, dev nbd0, sector 0 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0. Thanks, I will update my question. – LincolnP Mar 5 '20 at 15:31
  • I have checked the physical disck with smartctl and has no errors. I have also passed fsck to the partitions in the qcow2 image file (two LVM2 partitions, root and swap) – LincolnP Mar 5 '20 at 16:06
  • Are those ext4 dm-10 messages random bystanders or do you have it mounted or other dependencies on that NBD device like LVM/cryptsetup/integrity/loop/mdadm devices, etc.? That could prevent the proper removal of the device. I can only guess at what the problem may be since it works just fine for me. For a quick check, lsblk might suffice, should have nothing under the nbd0 tree. – frostschutz Mar 5 '20 at 16:14
  • for LVM in particular you'd need a vgchange -a n nbdvg before disconnecting it. And these may be active unexpectedly as there's stuff with udev rules, lvmetad etc. happening in the background, so have to double check it's clear for removal – frostschutz Mar 5 '20 at 16:16
1

When using LVMs, execute vgchange -a n nbdvg before disconnecting:

this is the correct order:

modprobe nbd
qemu-nbd --connect /dev/nbd0 -f qcow2 /tmp/image.qcow2
# -----
vgchange -a n nbvg
qemu-nbd -d /dev/nbd0
modprobe -r nbd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.