更改虚拟机的密码
我有一些虚拟机。我想编写一个脚本来自动执行以下过程...
- 它将虚拟机(以 linux 作为操作系统)安装到 /mnt/image 的位置
- 它修改 /etc/passwd (或等效文件)以更改用户的密码
- 卸载虚拟机
因为我使用的是 libvirt,所以我有一些虚拟机的 qcow2 映像。为了将映像安装到我的 ubuntu 上,我使用 nbd 模块。以下是我正在尝试的命令:
modprobe nbd max_part=63
qemu-nbd -c /dev/nbd0 image.qcow2
mount /dev/nbd0p1 /mnt/image
它给了我错误:
mount: special device /dev/nbd0p1 does not exist
当我用 nbdo 替换 nbd0p1 时,我收到以下错误(尽管我不确定我要做什么)
mount: you must specify the filesystem type
任何建议,例如可能是什么问题... ?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查
/sys/modules/nbd/parameters/max_part
是否具有预期值。如果它为 0 或太低,则内核将无法使用分区/dev/nbd0p1
等。如果在运行modprobe
时已加载nbd
内核模块(使用不同的max_part
参数),则可能会发生这种情况。您可以通过卸载模块并再次对其进行 modprobing 来解决此问题。
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 thenbd
kernel module was already loaded (with a differentmax_part
parameter) when you ranmodprobe
.You can fix that by unloading the module and modprobing it again.
[不是问题的直接答案,而是替代答案]
您可以尝试将 qcow2 映像转换为原始映像,然后挂载原始映像。
转换:
安装:
[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:
mount:
是否该分区不在 MBR 的第一个插槽中,或者正在使用扩展分区?检查是否正在创建任何其他
nbdXpY
设备节点,或者在其上运行fdisk
并p
rint分区表。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 runfdisk
on it andp
rint the partition table.我偶然发现了同样的问题和同样的错误,但在 vdi 上,
对我来说解决方案很简单,我只需将 nbd0 更改为 nbd1
,然后:
工作了。
如果这也适合您以及适用于什么类型的图像,请发表评论。
I stumbled on the same issue and same error but on a vdi
for me the solution was simple I just changed
nbd0
tonbd1
and then:
worked.
Please leave a comment if this worked for you also and on what type of image.