一、libguestfs修改镜像密码
virt-customize命令行工具由libguestfs-tools包提供,可用于在各种Linux发行版上安装, Virt-customize可以通过安装软件包,编辑配置文件等来自定义虚拟机(磁盘映像),它通过修改guest虚拟机或磁盘映像来实现此目的,它适用于raw和qcow2镜像格式
安装libguestfs-tools包
设置镜像的root密码为123456
[root@localhost kvm]# virt-customize -a disk/CentOS-7-x86_64-GenericCloud-1511.qcow2 --root-password password:123456 [ 0.0] Examining the guest ... [ 15.5] Setting a random seed [ 15.5] Setting passwords [ 16.4] Finishing off
使用参数--root-password random设置镜像的root密码为随机
[root@localhost kvm]# virt-customize -a disk/CentOS-7-x86_64-GenericCloud-1511.qcow2 --root-password random [ 0.0] Examining the guest ... [ 1.8] Setting a random seed [ 1.8] Setting passwords virt-customize: Setting random password of root to a2QVjEg6LoYoLW6a [ 2.6] Finishing off
为其他用户设置密码,命令并不能创建用户,只覆盖密码
[root@localhost kvm]# virt-customize -a disk/CentOS-7-x86_64-GenericCloud-1511.qcow2 --password tao:password:taoyuhang [ 0.0] Examining the guest ... [ 2.1] Setting a random seed [ 2.2] Setting passwords [ 2.9] Finishing off
二、Openstack运行脚本注入密码
编辑nova.conf配置文件
[root@controller ~]# vim /etc/nova/nova.conf inject_password=true
启动实例时,在配置处输入自定义脚本直接输入修改密码命令
记得勾选Configuration Drive