源镜像:

https://cloudbase.it/euladownload.php?h=kvm

1、首先,下载cloud-init:
https://cloudbase.it/downloads/CloudbaseInitSetup_1_1_4_x64.msi
我下载的是 CloudbaseInitSetup_1_1_4_x64.msi 版本

2、下载修改密码用的 qemu-ga

https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-qemu-ga/qemu-ga-win-7.5.0-2.el7ev/qemu-ga-x86_64.msi

3、下载notepad++

https://softdown.365xiazai.com/down/2023down/6/29/npp.8.5.3.Installer.exe

3、安装cloud-init

使用notepad++按pdf教程 基于Openstack的windows镜像制作.pdf 安装 cloud-init 和 qemu-ga

4、修改cloud-init配置文件

路径:

C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf

修改为:

[DEFAULT]
username=Administrator
groups=Administrators
inject_user_password=true
config_drive_raw_hhd=true
config_drive_cdrom=true
config_drive_vfat=true
bsdtar_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\bsdtar.exe
mtools_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\
verbose=true
debug=true
log_dir=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\
log_file=cloudbase-init.log
default_log_levels=comtypes=INFO,suds=INFO,iso8601=WARN,requests=WARN
logging_serial_port_settings=
mtu_use_dhcp_config=true
ntp_use_dhcp_config=true
local_scripts_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\
check_latest_version=true
netbios_host_name_compatibility=false
plugins=plugins=cloudbaseinit.plugins.common.localscripts.LocalScriptsPlugin,cloudbaseinit.plugins.common.mtu.MTUPlugin,cloudbaseinit.plugins.common.setuserpassword.SetUserPasswordPlugin,cloudbaseinit.plugins.common.sethostname.SetHostNamePlugin,cloudbaseinit.plugins.windows.extendvolumes.ExtendVolumesPlugin,cloudbaseinit.plugins.common.userdata.UserDataPlugin,cloudbaseinit.plugins.windows.licensing.WindowsLicensingPlugin
random_password=false
first_logon_behaviour=no

5、修改源代码,实现从user_data获取admin_Pass

C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\Lib\site-packages\cloudbaseinit\metadata\services\baseopenstackservice.py

def get_admin_password(self):
meta_data = self._get_meta_data()
meta = meta_data.get('meta')

if meta and 'admin_pass' in meta:
password = meta['admin_pass']
return password
elif 'admin_pass' in meta_data:
password = meta_data['admin_pass']
return password
else:
password = None
user_data = self.get_user_data().strip()
# 提取 password
LOG.debug('user_data begin')
LOG.debug(user_data)
LOG.debug('user_data end')
user_data=str(user_data)
start = user_data.find('password: ') + len('password: ')
LOG.debug(start)
end = user_data.find(r'\n\n', start)
LOG.debug(end)
password = user_data[start:end]
LOG.debug('password begin')
LOG.debug(password)
LOG.debug('password end')
return password

备注:

如何调试 windows 下的cloud-init

打开注册表:

运行-》regedit

HKEY_LOCAL_MACHINE\SOFTWARE\Cloudbase Solutions\Cloudbase-Init\a7531c6c-a2bd-49e2-9854-2ca9977d2326\Plugins

删除里面的项重启就会重新初始化cloud-init了

修改系统语言为中文:

Windows Server 2012 修改系统语言为中文的方法 « 老薛主机帮助中心 (laoxuehost.com)

关机,

压缩镜像:

qemu-img convert -f qcow2 -O qcow2 -c windows_server_2012_r2_standard_eval_kvm_20170321.qcow2 windows_server_2012_r2.qcow2
上传镜像:

glance image-create --disk-format qcow2 --container-format=bare --file /var/lib/libvirt/images/windows_server_2012_r2.qcow2 --progress --name windows2012r2 --property hw_qemu_guest_agent=yes --property os_type="windows"

发表评论

邮箱地址不会被公开。 必填项已用*标注