Question

I have some virtual machines with me. I want to write a script which automates the following process...

  • It mounts the virtual machine (with linux as the os) to a location say /mnt/image
  • It modifies the /etc/passwd (or the equivalent file) to change the password of the user
  • Unmount the virtual machine

Since, I am using libvirt I am having some qcow2 images of the virtual machine. to mount the image on my ubuntu, I am using nbd module. Here are the commands that I am trying :

modprobe nbd max_part=63
qemu-nbd -c /dev/nbd0 image.qcow2
mount /dev/nbd0p1 /mnt/image

It gives me the error:

mount: special device /dev/nbd0p1 does not exist

When I replace nbd0p1 with nbdo I am getting the following error (though I am not sure what I am trying to do by this)

mount: you must specify the filesystem type

Any suggestions so as what could be the problem... ?

Was it helpful?

Solution

[Not a direct answer to the question, but an alternate]
You can try to convert qcow2 image to raw and then, mount the raw image.

convert:

qemu-img convert -f qcow2 image.qcow2 -O raw image_raw.raw

mount:

    sudo losetup /dev/loop0 image_raw.raw
    sudo kpartx -a /dev/loop0
    sudo mount /dev/mapper/loop0p3 /mnt/image
    sudo mount /dev/mapper/loop0p2 /mnt/image/boot

OTHER TIPS

Check that /sys/modules/nbd/parameters/max_part has the expected value. If it's 0 or too low, the partitions /dev/nbd0p1, etc. will not be made available by the kernel. This can happen if the nbd kernel module was already loaded (with a different max_part parameter) when you ran modprobe.

You can fix that by unloading the module and modprobing it again.

Could it be that the partition isn't in the first slot in the MBR, or an extended partition is in use? Check to see if any other nbdXpY device nodes are being created, or run fdisk on it and print the partition table.

I stumbled on the same issue and same error but on a vdi

qemu-nbd -c /dev/nbd0 image.vdi

for me the solution was simple I just changed nbd0 to nbd1

qemu-nbd -c /dev/nbd1 image.vdi

and then:

sudo mount  /dev/nbd1p1 /media/eddie/virtual 

worked.

Please leave a comment if this worked for you also and on what type of image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top