Sometimes people don't need advice, they just need someone to listen and care.
Toggle navigation
Home
Archives
Tags
About
更改虚拟机镜像 root 密码
2022-07-29 09:58:46
73
0
0
william
有一天使用 qcow2 镜像创建虚机,但是忘记了 root 密码,经过查询资料,总结如下: 1)mount qcow2格式的image文件,这个需要借助于qemu-nbd这个命令,具体如下: 先加载nbd模块 ```shell $ modprobe nbd max_part=8 ``` 为image文件创建一个和nbd设备关联的连接 ```shell $ qemu-nbd -c /dev/nbd0 centos-7.9-amd64-uefi.qcow2 ``` 检查连接是否创建成功,如果有nbd0p1设备就算成功 ```shell $ ls -l /dev/nbd0* ``` mount image文件 ```shell $ mount /dev/nbd0p1 /mnt/img ``` 如果,/mnt/img/目录下有文件,表明已经成功了。 2)使用chroot来更改root的密码。 既然我们已经把OS的image mount上来了,我们就可以为所欲为了。 登录到虚拟机的shell里 ```shell $ /mnt/img/bin/sh sh-4.1# ``` 先chroot,然后再更改root的密码 ```shell sh-4.1# chroot /mnt/img/ /mnt/img/bin/sh [root@server-185 /]# passwd root ``` 到目前为止,密码已经更改了,可以重新登录虚拟机了。But,别忘了umount image、删除nbd连接。 3)善后工作 ```shell $ umount /mnt/img $ qemu-nbd -d /dev/nbd0 ```
Pre: No Post
Next:
QEMU 5.0 命令
0
likes
73
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus
Table of content