Change virtual machine password

I have several virtual machines. I want to write a script that automates the following process ...

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

Since I use libvirt, I have some qcow2 virtual machine images. To install the image on my ubuntu, I use the nbd module. Here are the commands I'm trying to do:

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

This gives me an error:

 mount: special device /dev/nbd0p1 does not exist 

When I replace nbd0p1 with nbdo, I get the following error (although I'm not sure what I'm trying to do this)

 mount: you must specify the filesystem type 

Any suggestions that might be a problem ...?

+4
source share
4 answers

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

convert:

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

installation:

  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 
+3
source

Make sure that /sys/modules/nbd/parameters/max_part has the expected value. If it is 0 or too low, the /dev/nbd0p1 , etc. Will not be available to the kernel. This can happen if the nbd kernel nbd has already been loaded (with a different max_part parameter) when modprobe starts.

You can fix this by unloading the module and promoting it again.

+4
source

Could it be that the partition is not in the first MBR slot or is the extended partition used? Check if any other nodes of the nbdXpY device are nbdXpY , or run fdisk , and p copy the partition table.

+1
source

I came across the same problem and the same error, but on vdi

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

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

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

and then:

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

have worked.

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

+1
source

Source: https://habr.com/ru/post/1339315/


All Articles