Changing password of a Virtual Machine

发布于 2022-09-06 12:33:21 字数 1011 浏览 15 评论 0

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... ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

早茶月光 2022-09-13 12:33:21

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.

情绪 2022-09-13 12:33:21

[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
夕色琉璃 2022-09-13 12:33:21

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.

温柔一刀 2022-09-13 12:33:21

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文