User Tools

Site Tools


diskimagescript-usage

This is an old revision of the document!


Using the Diskimage-Builder PowerShell script

This page thoroughly documents the use of this PowerShell script to obtain valid vdh/qcow2 Windows disks from an installation .iso image.

Prerequisites:

Start a PowerShell session from :

start powershell

Downloading and installing dependencies:

Download and install :

(New-Object System.Net.WebClient).DownloadFile("https://msysgit.googlecode.com/files/Git-1.9.0-preview20140217.exe", "$HOME\Git-1.9.0-preview20140217.exe")
cmd.exe /C call $HOME\Git-1.9.0-preview20140217.exe /SILENT

For , download and install the latest tools(as of the making of this article, build date 08.01.2014):

(New-Object System.Net.WebClient).DownloadFile("http://qemu.weilnetz.de/w64/qemu-w64-setup-20140801.exe", "$HOME\qemu-w64-setup-20140801.exe")
cmd.exe /C call $HOME\qemu-w64-setup-20140801.exe /SILENT

Add all dependencies to path, both to the environment variable and for the current session:

$newPath = "$env:Path;${env:ProgramFiles(x86)}\Git\cmd;${env:ProgramFiles}\qemu"
$env:Path = $newPath
setx PATH $newPath

Getting the script:

cd $HOME
git clone https://github.com/slokesh184/windows-diskimage-builder

Running the script:

Start a new PowerShell session as administrator:

Start-Process PowerShell -Verb RunAs

Getting at the file of an :

$mountpoint = Mount-DiskImage -ImagePath C:\Absolute\Path\To\Your\Iso\Image.iso -PassThru
$wimfilePath = ($mountpoint | Get-Volume).DriveLetter + ":\sources\install.wim"

# AFTER succesfully using the .wim in the script, don't forget to dismount the .iso:
Dismount-DiskImage -ImagePath C:\Absolute\Path\To\Your\Iso\Image.iso

Creating a :

cd $HOME\windows-diskimage-builder\windows-diskimage-builder
# previous steps for obtaining the $wimfilePath are assumed to have been done
.\diskimagebuilder.ps1 -SourceFile $wimfilePath -VHDFile $HOME\resultingDiskImage.vhd -VHDSize 16
  • Notes:
    • The script tries to use tools from the HyperV module by default.
    • If for some reason HyperV is unavailable for import, the script will revert to using DiskPart which is present on all Windows systems.
    • Should the above occur, the script will initially spew out a couple of errors but will continue to run properly after the fallback to DiskPart.

Creating a :

.\diskimagebuilder.ps1 -SourceFile $wimfilePath -VHDFile $HOME\resultingDiskImage.vhd -VHDSize 16 -OutputFormat qcow2
  • Notes:
    • Even when creating a .qcow2, the name of the resulting file must have the .vhd extension, lest DiskPart will fail at processing it.
    • After the execution of the script, the result will indeed be a .qcow2 as the script puts the proper extension towards the end of its execution.
FAILURE NOTICE:
  • If for some reason after attempting to create a .qcow2 diskimage you see that no output file was produced, it is because of a failure to call qemu and the script deleting the output by default. To try and debug such a problem, type "qemu-img.exe" in the PowerShell prompt and see what happens:
    • if PowerShell says it cannot find it, recheck to make sure the qemu tools are installed/set to path (review initial instructions).
    • if there is no output whatsoever, it means that there was a problem with the qemu-img binary; in which case you should either try reinstalling the above or another one from their downloads page (choose any one of the "qemu-w64-setup-release_date.exe"'s).

Script parameters and options:

  • -SourceFile C:\Path\To\Wim\File.wim
    • absolute path to the .wim file which will be used as input.
  • -VHDFile C:\Path\To\Output\File.vhd
    • absolute path to the script's output file;
    • must have the .vhd extension initially, even when creating a qcow2.
    • if qcow2 is selected, output's extention is changed to ".qcow2" automatically.
    • represents the exact path to the output file, which must NOT exist beforehand.
  • -VHDSize 16
    • maximum size in GB of the resulting vhd/qcow2 image
    • for most Windows installations, I reccommend at the very least 12, prefferably 16.
    • all output disks are resizeable, so initial size of output may be a lot less than this value.
  • -CloudbaseInitMsiUrl http://someplace.net/someothercloudbaseinit.msi
  • -UnattendedPath C:\Absolute\Path\To\Unattended.xml
    • path to the .xml file which is to be used in unattended mode.
    • default is the Unattended.mxl that can be found right beside the script.
    • the .xml file is placed directly in the root directory of the created image.
  • -DriversPath
    • path to a folder containing drivers that are to be added to the disk.
    • default is none, in which case no additional drivers will be added to the disk image.
  • -VirtIOPath C:\Absolute\Path\To\VirtIO.iso
    • path to a VirtIO .iso from which VirtIO drivers mean to be installed.
    • default is none, in which case no additional drivers will be installed to the disk image.
  • -Feature feature
    • feature to be enabled in the final disk image (ex: TFTP, IIS-WebServer, etc...)
    • this script only specifically enables one feature per image, the default being none.
    • the feature are enabled in the image by DISM.exe, for a full list of features, please review this webpage.
  • -DiskLayout UEFI
    • the layout of the resulting disk, used if booting the disk in UEFI mode is desired.
    • default value is BIOS.
  • -Index 3
    • index of the .wim supplied as input, if applicable.
    • default value is 1 and it will work in the vast majority of cases.
  • -SerialBaudRate 8400
    • baudrate of the serial port that is to be added to the disk.
    • default is 9600 and will work fine in the vast majority of cases.
diskimagescript-usage.1408720993.txt.gz · Last modified: 2014/08/22 18:23 (external edit)