cloudbase / windows-imaging-tools

Tools to automate the creation of a Windows image for OpenStack, supporting KVM, Hyper-V, ESXi and more.
Apache License 2.0
675 stars 227 forks source link

change the disk type from vhdx to qcow2 #275

Closed VuNgocTan closed 5 years ago

VuNgocTan commented 5 years ago

Hi, I changed some setting in the config file, such as: The destination of the generated image. image_path=C:\windows2k8r2.qcow2 Select between VHD, VHDX, QCOW2, VMDK or RAW formats: virtual_disk_format = QCOW2 image_type = qcow2 but the output of the image is still vhdx, what config file I have to change to make this right ? thanks for your help

ilenghel commented 5 years ago

Hello,

The image_type parameter accepts only Hyper-V, KVM, MAAS and VMware as values. Please also check the virtual_disk_format parameter, and set that to Qcow2 as well.

VuNgocTan commented 5 years ago

I already set it as qcow2

Select between VHD, VHDX, QCOW2, VMDK or RAW formats: virtual_disk_format = QCOW2

ader1990 commented 5 years ago

@VuNgocTan

        @{"Name" = "image_type"; "DefaultValue" = "HYPER-V";
          "Description" = "This parameter allows to choose between MAAS, KVM, VMware and Hyper-V specific images.
                           For HYPER-V, cloudbase-init will be installed and the generated image should be in vhd or vhdx format.
                           For MAAS, in addition to cloudbase-init, the curtin tools are installed
                           and the generated image should be in raw.tgz format.
                           For KVM, in addition to cloudbase-init, the VirtIO drivers are installed
                           and the generated image should be in qcow2 format.

What command did you run: New-WindowsCloudImage or New-WindowsOnlineImage?

VuNgocTan commented 5 years ago

I tried to ran both:

New-WindowsCloudImage

this command asks for the product key, I tried to insert the product key into the script but it's still ask for it, I added like this

Set-IniFileValue -Path $configFilePath -Section "Default" -Key "product_key" -Value "XXXX-XXXX-XXXX-XXXX-XXXX"

but it says " New-WindowsCloudImage : The property 'product_key' cannot be found on this object. Verify that the property exists. At line:1 char:1"

for this command:

New-WindowsOnlineImage

it asks for the "external_switch" which I have already provided the name of the switch in the config file, I tried many config files like: config.ini, create-windows-cloud-image.ps1 in the folder examples, only the "config.ini" run after I provided the name of the vswitch, this create-windows-cloud-image.ps1 wont run even I provide the name of the vswitch I use

both commands still result in .vhdx format, I double check the config many time, this is the detail of the file config.ini

[DEFAULT] The location of the WIM file from the mounted Windows ISO. wim_file_path=E:\Sources\install.wim This is the complete name of the Windows version that will be generated. In order to find the possible options, use the Get-WimFileImagesInfo command and look for the Name property. image_name=Windows Server 2008 R2 SERVERSTANDARD The destination of the generated image. image_path=C:\windows2k8r2.qcow2 Select between VHD, VHDX, QCOW2, VMDK or RAW formats. virtual_disk_format=qcow2 This parameter allows to choose between MAAS, KVM, VMware and Hyper-V specific images. For HYPER-V, cloudbase-init will be installed and the generated image should be in vhd or vhdx format. For MAAS, in addition to cloudbase-init, the curtin tools are installed and the generated image should be in raw.tgz format. For KVM, in addition to cloudbase-init, the VirtIO drivers are installed and the generated image should be in qcow2 format. image_type=qcow2 This parameter can be set to either BIOS or UEFI. disk_layout=BIOS The product key for the selected OS. product_key="XXXX-XXXX-XXXX-XXXX-XXXX" A comma separated array of extra features that will be enabled on the resulting image. These features need to be present in the ISO file. extra_features="" A comma separated array of extra capabilities that will be enabled on the resulting image. These capabilities need to be present in the ISO file. extra_capabilities="" It will force the image generation when RunSysprep is False or the selected SwitchName is not an external one. Use this parameter with caution because it can easily generate unstable images. force=False If set to true, MAAS Windows curtin hooks will be copied to the image root directory. install_maas_hooks=False Select between tar, gz, zip formats or any combination between these. compression_format="" If this parameter is set, after the image is generated, a password protected zip archive with the image will be created. zip_password="" It will stop the image generation after the updates are installed and cleaned. gold_image=False This is the full path of the already generated golden image. It should be a valid VHDX path. gold_image_path="" This is a full path to the VMware-tools.exe version that you want to install. vmware_tools_path="" This is the full path of a folder with custom resources which will be used by the custom scripts. The resources found at this path will be copied recursively to the image UnattendResources\CustomResources folder. custom_resources_path="" This is the full path of the folder which can contain a set of PS scripts, that will be copied and executed during the online generation part on the VM. The PowerShell scripts, if existent, will be started by Logon.ps1 script, at different moments during image generation. The purpose of these scripts is to offer to the user a fully customizable way of defining additional logic for tweaking the final image. The scripts files can have the following names: RunBeforeWindowsUpdates.ps1, RunAfterWindowsUpdates.ps1, RunBeforeCloudbaseInitInstall.ps1, RunAfterCloudbaseInitInstall.ps1, RunBeforeSysprep.ps1, RunAfterSysprep.ps1. The script names contain the information on when the script will be executed. One can define only some of the hook scripts and it is not mandatory to define all of them. If a script does not exist, it will not be executed. custom_scripts_path="" If set to true the Administrator account will be enabled on the client versions of Windows, which have the Administrator account disabled by default enable_administrator_account=True If set, it will replace the Cloudbase Solutions wallpaper to the one specified. The wallpaper needs to be a valid .jpg/.jpeg image. wallpaper_path="C:\Users\Administrator\Downloads\2008r2.jpg" If set, it will replace the Cloudbase Solutions wallpaper to a solid color. Currently, the only allowed solid color is '0 0 0' (black). If both wallpaper_path and wallpaper_solid_color are set, the script will throw an error. wallpaper_solid_color="" If set to true and the target image format is QCOW2, the image conversion will use qemu-img built-in compression. The compressed qcow2 image will be smaller, but the conversion will take longer time. compress_qcow2=True If set to true, during final cleanup, https://github.com/felfert/ntfszapfree will be used to zero unused space. This helps qemu-img to minimize image size. In order to benefit from this, an additional invocation of qemu-img convert has to be performed after the initial run of the image has shutdown. zero_unused_volume_sectors=False A comma separated list of extra packages (referenced by filepath) to slipstream into the underlying image. This allows additional local packages, like security updates, to be added to the image. extra_packages="" [vm] This will be the Administrator user's, so that AutoLogin can be performed on the instance, in order to install the required products, updates and perform the generation tasks like sysprep. administrator_password=P@ssword Used to specify the virtual switch the VM will be using. If it is specified but it is not external or if the switch does not exist, you will get an error message. external_switch=external The number of CPU cores assigned to the VM used to generate the image. cpu_count=2 RAM (in bytes) assigned to the VM used to generate the image. ram_size=4294967296 Disk space (in bytes) assigned to the VM used to generate the image. disk_size=26843545600 [drivers] The path to the ISO file containing the VirtIO drivers. virtio_iso_path="C:\Users\Administrator\Downloads\virtio-win-0.1.141.iso" The location where the VirtIO drivers are found. For example, the location of a mounted VirtIO ISO. VirtIO versions supported >=0.1.6.x virtio_base_path="F:" The location where additional drivers that are needed for the image are located. drivers_path="" [updates] If set to true, the latest updates will be downloaded and installed. install_updates=False If set to true, will run DISM with /resetbase option. This will reduce the size of WinSXS folder, but after that Windows updates cannot be uninstalled. purge_updates=False [sysprep] Used to clean the OS on the VM, and to prepare it for a first-time use. run_sysprep=True The path to the Unattend XML template file used for sysprep. unattend_xml_path=UnattendTemplate.xml DisableSwap option will disable the swap when the image is generated and will add a setting in the Unattend.xml file which will enable swap at boot time during specialize step. This is required, as by default, the amount of swap space on Windows machine is directly proportional to the RAM size and if the image has in the initial stage low disk space, the first boot will fail due to not enough disk space. The swap is set to the default automatic setting right after the resize of the partitions is performed by cloudbase-init. disable_swap=False In case the hardware on which the image is generated will also be the hardware on which the image will be deployed this can be set to true, otherwise the spawned instance is prone to BSOD. persist_drivers_install=True [cloudbaseinit] This is a switch that allows the selection of Cloudbase-Init branches. If set to true, the beta branch will be used: https://cloudbase.it/downloads/CloudbaseInitSetup.msi, where arch can be x86 or x64 otherwise the stable branch will be used: https://cloudbase.it/downloads/CloudbaseInitSetup_Stable_.msi, where arch can be x86 or x64 beta_release=False Serial log port for Cloudbase-Init. If set to null, the first serial port (if any) from the generation VM will be used serial_logging_port=COM1 If set, the Cloudbase-Init msi at this path will be used. The path needs to be a locally accesible file path. msi_path=""

ilenghel commented 5 years ago

From the config file you have provided, I can see that image_type=qcow2, and it should be image_type=KVM.

Can you please set it like this and give it a try?

VuNgocTan commented 5 years ago

no man, still can't

PS C:\Users\Administrator\windows-openstack-imaging-tools> New-WindowsCloudImage -ConfigFilePath $ConfigFilePath 6/18/2019 4:31:35 PM - Cloud image generation started. 6/18/2019 4:31:36 PM - Creating Virtual Disk Image: C:\windows2k8r2.vhdx... 6/18/2019 4:31:43 PM - Successfuly created disk: C:\windows2k8r2.vhdx

ader1990 commented 5 years ago

First of all, you should start with a clean powershell environment, to make sure there are no issues.

Secondly, use one of the examples you have in the Examples directory, choose one which is closer that is closer to your scenario and change it according to your needs.

If something is not working as it should, please attach here the code you run to start the image generation and the config generation, the config file and the image generation log. From the config file you posted before, neither the image_type or the product key is properly set.

On which Windows host version are you trying to generate the image?

VuNgocTan commented 5 years ago

yes, I delete everything and redo it, I generate the image on windows 2016

ilenghel commented 5 years ago

From the powershell snippet you have posted I can understand that you are bothered by the "successfully created disk: C:\windows2k8r2.VHDX", right?

The workflow of the New-WindowsOnlineImage is as follows (some main points, not the entire workflow):

The entire generation process is done on a .VHDX file, and the final image can be a .img (for MAAS), a .vmdk (for VMware) or a .qcow2 (for KVM), depengind on the values of the parameters supplied.

Please let us know if the final image you obtain after New-WindowsOnlineImage has finished its execution is still a VHDX.

VuNgocTan commented 5 years ago

no my friend, I know it will convert from vhdx to other format because I ask a friend of mine to run it, and the command executed successfully, but in my server, I let the process 100% complete and it wont convert the file type to any other type, that's why I redo everything

ilenghel commented 5 years ago

What Windows host are you trying to generate the image on? Can you check that qemu-img is present in your "windows-openstack-imaging-tools" directory? Isn't there any error or warning in the powershell console when the script finishes?

VuNgocTan commented 5 years ago

Hi friend, I use windows 2016 to generate the image, I figure out that I have to connect to the VM via Hyper-V while it is preparing for sysrep, I can create image now, thanks a lot for you help, I appreciate

VuNgocTan commented 5 years ago

Hi, I want to disable onedrive and install qemu-guest agent while creating the windows image, how can I do it ?

ilenghel commented 5 years ago

Hello,

The Windows-Openstack-Imaging-Tools offer a set of scripts that will be executed at certain moments during the image generation process. These scripts do not exist, you'll have to create them, and the automation will execute them for you.

You will need to set the custom_scripts_path parameter to a directory containing a .ps1 script with one of the following names: RunBeforeWindowsUpdates.ps1, RunAfterWindowsUpdates.ps1, RunBeforeCloudbaseInitInstall.ps1, RunAfterCloudbaseInitInstall.ps1, RunBeforeSysprep.ps1, RunAfterSysprep.ps1.

The names indicate when the script will be run. Let's say you'd want your OneDrive to be uninstalled before Windows updates. In this case you'll have to create a powershell script with the name "RunBeforeWindowsUpdates.ps1" and inside that script you'll need to have the appropriate commands to uninstall OneDrive.

Also, you can set the custom_resources_path parameter to point to the directory where you have the installer for qemu-guest, and it will be copied on the image. You can also use the above mentioned script to install qemu-guest.

Let us know if you have any issues with the process.

VuNgocTan commented 5 years ago

Hi friend, very detail of your answer, thank you so much, I followed what you said, however it just copied the file into the image, I'm suck at scripting so I can't make it run automatically, but yeah, it's done manually.

ilenghel commented 5 years ago

Glad you got this solved. Just as an idea for future use of this tool, you can edit UnattendResources\Logon.ps1 and add a "Pause" statement wherever you want the script execution to be paused. It will then wait for an "Enter" key to continue execution. During this time you can make any changes to your image. The Pause statement must be added before starting the image generation.

VuNgocTan commented 5 years ago

another thing to learn, thanks, good day to you man

VuNgocTan commented 5 years ago

Hi friend, I see that this script only support up to windows server 2016, can you guys help me to generate windows server 2019 ?

ilenghel commented 5 years ago

Hi there, Since those are different issues and this particular one has been closed, can you please open another issue for this matter?

Also, regarding the question, the generation process of 2019 images is exactly the same as on Windows Server 2016. In the new issue please specify what exactly are you trying to accomplish so we can have a better understanding of your problem (hypervisor type, issue encountered, config file used).

Thank you.