# No parts in /dev/nbd* devices

## jwackito

Hi:

I'm trying to mount a qcow2 kvm image file using qemu-nbd in this way

```
#qemu-nbd --connect=/dev/nbd0 live-lihuen-tests.img
```

After that, I'm able to use fdisk to see the partition table from ndb0 device... this is the output of 'p' fdisk command.

```
Disposit. Inicio    Comienzo      Fin      Bloques  Id  Sistema

/dev/nbd0p1   *           1        2496    20049088+  83  Linux

/dev/nbd0p2            2497        2610      915705    5  Extendida

/dev/nbd0p5            2497        2610      915673+  82  Linux swap / Solaris

```

But when I try to use mount command to mount /dev/nbd0p1 I get an error message indicating the device doesn't exist.

```
# mount /dev/nbd0p1 /mnt/cdrom

mount: el dispositivo especial /dev/nbd0p1 no existe
```

The NBD support is compiled built in the kernel (2.6.32 downloaded manually from kernel.org)

```
zcat /proc/config.gz |grep -i nbd

CONFIG_BLK_DEV_NBD=y
```

qemu-nbd version 0.0.1

If you need more information related to this problem, please let me know.

regards and thanks in advance

----------

## Sadako

Try running `partx -a /dev/nbd0`, that should create the /dev/nbd0p* device nodes (assuming they are indeed missing from /dev).

----------

## jwackito

I get this error message

```
# partx -a /dev/nbd0

HDIO_GETGEO: Inappropriate ioctl for device
```

----------

## b0nafide

thread revival... 

I can mount virtualbox vdi images now!

It works with some of the /dev/nbd devices, but not all of them. On a different distro I can use any of the /dev/nbds

So, it's working fine using /dev/nbd4 on my gentoo box, so I'm keeping it that way for now. But it doesn't make sense. 

Here's the script I chucked together to speed things up for me: 

```
#!/bin/bash

# vdi mounter v0.0.2 by bonafide a_t martica d_o_t org (sorry about v0.0.1)

# thanks to http://bethesignal.org/blog/2011/01/05/how-to-mount-virtualbox-vdi-image/

#

# requires nbd and qemu

# don't forget to load the nbd module with max_part=8 or so...

# Some important configuration:

nbd="/dev/nbd0"         # default network block device

mntdir="/mnt"           # folder where mount points will be created (and destroyed)

mountoptions="-o ro"    # some paranoia

qemunbdoptions="-r"     # ro also (see above)

verbose=0

# wait for fdisk to see partitions

sleepinterval=0.25      # seconds

sleeptimeout=5          # seconds

iterations=`bc <<< "$sleeptimeout / $sleepinterval"`

blather () {

 if [ $verbose == 1 ]; then

  echo -e -n "$1"

 fi

}

stopit () {

  qemu-nbd -d $nbd > /dev/null

}

getname () {

 partname=$(sed -e "s/\/dev\//`sed -e "s/^.*\///;s/ /_/g" <<< $1`_/" <<< $part)

}

while getopts d:vh options; do   

 case "$options" in

  [?]|h) echo "Usage: $0 [options] [vdi file]"

         echo " -d [network block device] default is $nbd"

         echo " -v Be verbose."

         echo " -h This help text."

         exit 1;;

      v) verbose=1;;

      d) nbd="$OPTARG";;

 esac

done

shift $(( OPTIND - 1 ))

if [ "`file $nbd`" == "${nbd}: block special" ]; then

 error=0

 if ! [ -e "$1" ]; then

  echo "VDI file does not exist."

  error=1

 else

  if [ "`qemu-img check "$1" 2> /dev/null; echo $?`" == "1" ]; then

   echo "VDI file $1 is invalid."

   error=1

  fi

 fi

 if [ $error == 1 ]; then

  echo "Quitting."

  exit 1

 fi

 blather "`qemu-img info "$1"`\n"

 blather "Attaching image $1 to $nbd "

 qemu-nbd $qemunbdoptions -c $nbd "$1"

 timeout=0

 while [ $timeout -le $iterations ]; do

  parts=`fdisk -l $nbd | sed -n -e '/swap\|Extended/d;/^\/dev\//p' | awk '{ print $1 }'`

  if [ "$parts" == "" ]; then

   timeout=$(( $timeout + 1 ))

   blather "."

   sleep $sleepinterval

  else

   break

  fi

 done

 blather "\n"

 if [ $timeout -ge $iterations ]; then

  blather "Can't attach image $1 to $nbd \n"

  stopit

  exit 1

 fi

 for part in $parts; do

  getname "$1"

  blather "Mounting partition $part on $mntdir/$partname\n"

  mkdir $mntdir/$partname

  mount $mountoptions $part $mntdir/$partname

 done

 echo "Done! Press enter to unmount volume(s)."

 read somevalue

 for part in $parts; do

  getname "$1"

  blather "Unmounting partition $part\n"

  umount $part

  rmdir $mntdir/$partname

 done

 blather "Deattaching image $1 from $nbd ... "

 stopit

 blather "Finished.\n"

 exit 0

else

 echo "$nbd is not a block device?"

fi

exit 1
```

If anybody has run into a similar problem with nbd or has any suggestions I'm all ears. I have no idea what would cause some, but not all of the nbd devices to work with qemu-nbd ... 

Edit: 

```

# ls -l /dev/nbd*

brw-rw---- 1 root disk 43,   0 Sep 18 12:29 /dev/nbd0

brw-rw---- 1 root disk 43,  32 Sep 18 12:29 /dev/nbd1

brw-rw---- 1 root disk 43, 320 Sep 18 12:29 /dev/nbd10

brw-rw---- 1 root disk 43, 352 Sep 18 12:29 /dev/nbd11

brw-rw---- 1 root disk 43, 384 Sep 18 12:29 /dev/nbd12

brw-rw---- 1 root disk 43, 416 Sep 18 12:29 /dev/nbd13

brw-rw---- 1 root disk 43, 448 Sep 18 12:29 /dev/nbd14

brw-rw---- 1 root disk 43, 480 Sep 18 12:29 /dev/nbd15

brw-rw---- 1 root disk 43,  64 Sep 18 12:29 /dev/nbd2

brw-rw---- 1 root disk 43,  96 Sep 18 12:29 /dev/nbd3

brw-rw---- 1 root disk 43, 128 Sep 18 21:40 /dev/nbd4

brw-rw---- 1 root disk 43, 160 Sep 18 12:29 /dev/nbd5

brw-rw---- 1 root disk 43, 192 Sep 18 12:29 /dev/nbd6

brw-rw---- 1 root disk 43, 224 Sep 18 12:29 /dev/nbd7

brw-rw---- 1 root disk 43, 256 Sep 18 12:29 /dev/nbd8

brw-rw---- 1 root disk 43, 288 Sep 18 12:29 /dev/nbd9

# qemu-nbd --version

qemu-nbd version 0.0.1

```

After poking around some more it appears that nbd0-3 and nbd5 don't work, but the rest do???

CheersLast edited by b0nafide on Tue Sep 20, 2011 2:30 am; edited 3 times in total

----------

## b0nafide

Further observations: 

All the /dev/nbd devices work with qemu-0.14.0 on another gentoo box with the same kernel sources.

----------

## b0nafide

 :Embarassed: 

This problem is fixed when using qemu >= 0.14.0

Well, it works now!

----------

## marsark

Hi, I have also this problem with missing partitions in /dev on nbd device. I'm using nbd-client from sys-block/nbd. After connection I'm able to see partitions in the fdisk. But missing in /dev/nbd0*.

I have tried to create them with partx, but no success.

```

partx -a /dev/nbd0

partx: /dev/nbd0: error adding partition 1

partx: /dev/nbd0: error adding partition 3

```

Block device has following structure:

```

Disk identifier: 0xddde93b1

     Device Boot      Start         End      Blocks   Id  System

/dev/nbd0p1   *          63    60597179    30298558+  83  Linux

/dev/nbd0p3        60597180   625137344   282270082+  83  Linux

```

What's wrong?

----------

## nativemad

I've got the same problem just now...

It worked correctly with nbd as module and "modprobe nbd max_part=16".

Cheers

----------

