Finally Cloudbase Init windows servers

Craig St George

Well-Known Member
Jul 31, 2018
114
14
58
62
OK I finally got some things to Work using Cloudbase-init 0.9.11 eg the current stable

Here is what works
Extending the Disks
Setting up the network
Setting the hostname
Enabling WRM if you need that
Setting the Password ( but it can only support Plain Text Password ) so the hash in /etc/pve/qemu/vmid.conf would need to be changed to plain text the good thing is the Default behavior for Cloudbase it to require password change on first logon but you can change that.

Here is what does not work
Creating a new user ( Openstack configdrive in cloudbase is not supporting that)
Setting the FQDN once again they do not support that

There are other things that I did not fully test them like WRM certs and NTP as I was not using that
But they seem to work

But now for the said news first of All it will not work at all out of the box as Proxmox ISO is not read at all
that is a simple fix

/usr/share/perl5/PVE/QemuServer/Cloudinit.pm needs to be changed so the ISO is recognized
in
commit_cloudinit_disk {
I had to change the run_command([['genisoimage' to include an ISO level
run_command([['genisoimage','-iso-level', '3', '-R', '-V', $label, $path],

Now the disk gets read and also the network setup works


The Second more important problem is the settings in USER_DATA are not used at all
So Password hostname etc will not work
eg. #cloud-config
They read it but they only support a small about of the features in the user_data e.g
https://cloudbase-init.readthedocs.io/en/latest/userdata.html#userdata

They expect the data to be in the meta_data.json currently that only has
"uuid": "$uuid",
"network_config": { "content_path": "/content/0000" },


I added in
"hostname":
and
"admin_pass" in Json format and now that works can also add in SSH keys if you need

But of course this required hacking the Perl code

I m not sure how to work around that password problem as if that also could be done then the it would be almost usable

I was thinking changing the code that makes the /etc/pve/qemu-server/vm.id.conf so if the server was windows allow plain text its not ideal but could work

But even the changes I made for the ISO file and the meta_data.json would be good to get into the core so we can use windows a bit better else I need to hack that file for each new Hypervisor

Thanks
 
  • Like
Reactions: Bruno Garcia
great that that works ! (i never got it to work myselft properly)

does it still work on linux with your changes?
if yes (or even if no), you could post your patches on the pve-devel list (see https://pve.proxmox.com/wiki/Developer_Documentation )
to see if we can integrate them (if they are not too much), also maybe some iterations are needed

this way all would benefit from it
 
It should still work well the NoCloud does for sure let me test with the Configdrive and make some changes if needed
Then I will submit the code . Probably next week as so busy lol

I also have a document with the info about the config files on the Windows side and the correct way to install the Windows program if that is need
 
Either that or a patch to the pve-docs repository would be appreciated. Thank you for putting in all that effort.
 
Sorry for the delay on this I did a lot more looking and found some issues with the DNS servers and there are a few other things
As there are a lot of differences I will refactor my changes so that IF its windows it will use a different set of functions that way it will not have a problem with the existing config drive 2 ( but I would think most people would be using no cloud anyway for Linux )

The things that work are
Networking setup
Expand disk
Add user ( but not the one you have in the Proxmox only the One in the Cloud-base init conf)
Set that users password ( but the password needs to be plain text so need to edit the config)
Enable WinRM
Updates

It would be nice to have another CI field to add WRM cert though as you cant use the SSH one and that is for somthing else anywhay
but SSH cert will not vaildate as a SSL public cert

Anyway it basicly works for me now and I use it to enable winrm then I use Ansible to do the rest of the provisioning

Now for the docs and the diffs
 
Hello,

Are there any updates to this?
I'm trying to get some Windows templates running, but cloudbase-init does nothing for me.
Is there configuration required on cloudbase side? I just ran it, it sysprepped by system, but it has not set any IPs, users, password nothing.
I tried with cloud-init both in nocloud and configdrive2 mode, no luck.

Now that Windows supports OpenSSH server I am tempted to ship templates with it enabled + bundled ssh keys and do my (initial) admin over that.
 
OK here is a patch I have used it for Windows 2012R2 and Windows 2016 I m now trying 2019
IT creates windows only functions in the Cloudinit.pm Linux nocloud and configdrive2 still works
Make sure in your template you set the option to a windows one and then this comes into play

Password kind of works but only plain text eg you need to edit the cipassword:
/etc/pve/qemu-server/xxx.conf

To get arouund this I simplke enable winrm and use some ansible provsioing to do all I want



Backup the
/usr/share/perl5/PVE/QemuServer/Cloudinit.pm
cp /usr/share/perl5/PVE/QemuServer/Cloudinit.pm /root/Cloudinit.pm.org

upload the cloudinit.patch ( I had to add .txt to get this web upload to work
in the directory you uploaded it

patch /usr/share/perl5/PVE/QemuServer/Cloudinit.pm < cloudinit.patch
systemctl restart pvedaemon

The reason dns was not working is the orgianal was using dns_nameservers needs to be dns-nameservers


On your windows image that you are creating start I up I assume you have added Vioscii NetKVM and other drivers you need you will at least need
Virtio Serial

In the Proxmox hardware for that image add a serial port 0 ( make sure you slect one when you install cloudbase-init )


start your image install Cloud base init
cd \

C:\powershell
C:\Set-ExecutionPolicy Unrestricted
C:\Invoke-WebRequest -UseBasicParsing https://www.cloudbase.it/downloads/CloudbaseInitSetup_Stable_x64.msi -OutFile cloudbaseinit.msi

Wait for the download
.\cloudbaseinit.msi

del .\cloudbaseinit.msi

select the serial port
Don't do system prep or shutdown

Now edit the cloudbaseinit config there are two
cloudbase-init
add meta data service if missing
metadata_services=cloudbaseinit.metadata.services.configdrive.ConfigDriveService

add the plugins you need
for mine i have
plugins=cloudbaseinit.plugins.common.mtu.MTUPlugin,cloudbaseinit.plugins.common.sethostname.SetHostNamePlugin,cloudbaseinit.plugins.windows.extendvolumes.ExtendVolumesPlugin

you may also what set password and create user
cloudbaseinit.plugins.windows.createuser.CreateUserPlugin
cloudbaseinit.plugins.windows.setuserpassword.SetUserPasswordPlugin


cloudbase-init-unattend
edit meta data services
metadata_services=cloudbaseinit.metadata.services.configdrive.ConfigDriveService

nothing to do on the plugins here

Now system prep the image
cd C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf
C:\Windows\System32\sysprep\sysprep.exe /generalize /oobe /unattend:Unattend.xml

now it should work when you start the image

If you want to make changes to that config with that same image first
Remove KEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cloudbase Solutions\Cloudbase-Init
that will allow cloudinit to rerun

but if you want the image to be fresh
Remove KEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cloudbase Solutions\Cloudbase-Init
and run the sysprep again
 

Attachments

  • cloudinit.patch.txt
    4.9 KB · Views: 327
  • Like
Reactions: Amin Gholami
I must be even more terrible with Windows than I thought, but after all the modifications, I still got no success whatsoever. No user got created, no password set, no IP, host, nothing. All I got after sysprep was to be asked a new password for the Administrator.

I am giving up on this solution for now and will try to use other methods.
 
In the VM you set the Options to Windows OS right
you have also added a serial device to the windows server and selected that com 1 when you did the install of cloudbase

then when you start the VM you can see the output by going to the console and select the xterm.js

Was the DNS setup and also the new user would probable be created and check that password you used with that
 
when I try to execute your patch I get:
patching file Cloudinit.pm
Hunk #1 FAILED at 37.
Hunk #4 FAILED at 284.
2 out of 4 hunks FAILED -- saving rejects to file Cloudinit.pm.rej
Could you upload your complete Cloudinit.pm @Craig St George?
 
Hey Guys,
This looks perfect but on my VE is not working.

I did patch , password is clean text.

cloudbase-init.conf
Code:
[DEFAULT]
username=Admin
groups=Administrators
inject_user_password=true
config_drive_raw_hhd=true
config_drive_cdrom=true
config_drive_vfat=true
first_logon_behaviour=no
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
logdir=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\
logfile=cloudbase-init.log
default_log_levels=comtypes=INFO,suds=INFO,iso8601=WARN,requests=WARN
logging_serial_port_settings=COM1,115200,N,8
mtu_use_dhcp_config=true
ntp_use_dhcp_config=true
local_scripts_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\
metadata_services=cloudbaseinit.metadata.services.configdrive.ConfigDriveService,
                  cloudbaseinit.metadata.services.httpservice.HttpService,
                  cloudbaseinit.metadata.services.ec2service.EC2Service,
                  cloudbaseinit.metadata.services.maasservice.MaaSHttpService

plugins=cloudbaseinit.plugins.common.mtu.MTUPlugin,
        cloudbaseinit.plugins.common.sethostname.SetHostNamePlugin,
        cloudbaseinit.plugins.windows.extendvolumes.ExtendVolumesPlugin,
        cloudbaseinit.plugins.windows.createuser.CreateUserPlugin,
        cloudbaseinit.plugins.windows.setuserpassword.SetUserPasswordPlugin
       
   
   
   
# Miscellaneous.
allow_reboot=false    # allow the service to reboot the system
# stop_service_on_exit=false

cloudbase-init-unattend

Code:
[DEFAULT]
username=Admin
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
logdir=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\
logfile=cloudbase-init-unattend.log
default_log_levels=comtypes=INFO,suds=INFO,iso8601=WARN,requests=WARN
logging_serial_port_settings=COM1,115200,N,8
mtu_use_dhcp_config=true
ntp_use_dhcp_config=true
local_scripts_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\
metadata_services=cloudbaseinit.metadata.services.configdrive.ConfigDriveService,
                  cloudbaseinit.metadata.services.httpservice.HttpService,
                  cloudbaseinit.metadata.services.ec2service.EC2Service,
                  cloudbaseinit.metadata.services.maasservice.MaaSHttpService
plugins=cloudbaseinit.plugins.common.mtu.MTUPlugin,
        cloudbaseinit.plugins.common.sethostname.SetHostNamePlugin,
        cloudbaseinit.plugins.windows.extendvolumes.ExtendVolumesPlugin
allow_reboot=false
stop_service_on_exit=false
check_latest_version=false

Cloud-Init Drive is mounted on Windows Machine and files are there correct, but after sysprep my machine is asking me to set password and network is not being setup.
 
after you did that patch you did systemctl restart pvedaemon
also once you installed the cloudbase-init you manually ran the sysprep

cd C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf
C:\Windows\System32\sysprep\sysprep.exe /generalize /oobe /unattend:Unattend.xml

add in a serial port into your VM config if you do not have one already and when you start the VM use the xterm.js viewer to see the output of the cloudbase init you can also see it in the log file in the cloudbase directory on the machine that booted up

BTW to make things faster in that config I would remove all the unneeded Meta services so you only have
metadata_services=cloudbaseinit.metadata.services.configdrive.ConfigDriveService
 
i still couldn't figure out windows template the network doesn't configure automatically. as of now with the latest proxmox version do we still need this patch to get cloud-init working?
 
Yes need it . it works with latest. I'm just struggling with tine to submit it. Work gives my too many project's
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!