qemu启动的虚拟机系统的密码是随机的,只能修改密码,接下来我们可以通过以下3步将虚拟机的密码修改成功
1. 检查并修改qemu访问虚拟机镜像的权限 /etc/libvirt/qemu.conf,将user = "root" 和group = "root" 取消注释,并重启qemu或重启宿主机
# user = "100" # A user named "100" or a user with uid=100
#
user = "root"# The group for QEMU processes run by the system instance. It can be
# specified in a similar way to user.
group = "root"# Whether libvirt should dynamically change file ownership
# to match the configured user/group above. Defaults to 1.
# Set to 0 to disable file ownership changes.
#dynamic_ownership = 1
若报错 :cannot access storage file (as uid:107, gid:107)permission denied 说明你的qemu权限没有修改哦,看第一步,检查是否修改并重启
2. 安装libguestfs-tools工具:yum install libguestfs-tools
并启动libvirtd,执行命令: systemctl start libvirtd
3. 修改密码
sudo virt-customize -a CentOS-7-x86_64-GenericCloud.qcow2 --root-password password:xxx 修改镜像密码
参考1:centos镜像安装
参考2:cannot access storage file (as uid:107, gid:107)permission denied