Created
November 25, 2019 16:12
-
-
Save chrisoldwood/aeec1e6876dadcc407109896d8d8aac7 to your computer and use it in GitHub Desktop.
Example Packer configuration files for creating a Windows 10 VM on QEMU/KVM/libvirt.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<unattend xmlns="urn:schemas-microsoft-com:unattend"> | |
<settings pass="windowsPE"> | |
<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<SetupUILanguage> | |
<UILanguage>en-US</UILanguage> | |
</SetupUILanguage> | |
<SystemLocale>en-US</SystemLocale> | |
<UILanguage>en-US</UILanguage> | |
<UserLocale>en-US</UserLocale> | |
</component> | |
<component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<DiskConfiguration> | |
<Disk wcm:action="add"> | |
<CreatePartitions> | |
<CreatePartition wcm:action="add"> | |
<Order>1</Order> | |
<Type>Primary</Type> | |
<Extend>true</Extend> | |
</CreatePartition> | |
</CreatePartitions> | |
<ModifyPartitions> | |
<ModifyPartition wcm:action="add"> | |
<Active>true</Active> | |
<Extend>false</Extend> | |
<Format>NTFS</Format> | |
<Letter>C</Letter> | |
<Order>1</Order> | |
<PartitionID>1</PartitionID> | |
<Label>Windows 10</Label> | |
</ModifyPartition> | |
</ModifyPartitions> | |
<DiskID>0</DiskID> | |
<WillWipeDisk>true</WillWipeDisk> | |
</Disk> | |
</DiskConfiguration> | |
<ImageInstall> | |
<OSImage> | |
<InstallTo> | |
<DiskID>0</DiskID> | |
<PartitionID>1</PartitionID> | |
</InstallTo> | |
</OSImage> | |
</ImageInstall> | |
<UserData> | |
<AcceptEula>true</AcceptEula> | |
<FullName>Packer Admin</FullName> | |
<Organization></Organization> | |
<ProductKey> | |
<Key>W269N-WFGWX-YVC9B-4J6C9-T83GX</Key> | |
</ProductKey> | |
</UserData> | |
</component> | |
<component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<DriverPaths> | |
<PathAndCredentials wcm:action="add" wcm:keyValue="1"> | |
<Path>E:\NetKVM\w10\amd64\</Path> | |
</PathAndCredentials> | |
<PathAndCredentials wcm:action="add" wcm:keyValue="3"> | |
<Path>E:\viostor\2k16\amd64\</Path> | |
</PathAndCredentials> | |
</DriverPaths> | |
</component> | |
</settings> | |
<settings pass="oobeSystem"> | |
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<UserAccounts> | |
<LocalAccounts> | |
<LocalAccount wcm:action="add"> | |
<Password> | |
<Value>packer</Value> | |
<PlainText>true</PlainText> | |
</Password> | |
<Description></Description> | |
<DisplayName>Packer Admin</DisplayName> | |
<Group>Administrators</Group> | |
<Name>packer</Name> | |
</LocalAccount> | |
</LocalAccounts> | |
</UserAccounts> | |
<AutoLogon> | |
<Password> | |
<Value>packer</Value> | |
<PlainText>true</PlainText> | |
</Password> | |
<Enabled>true</Enabled> | |
<Username>packer</Username> | |
</AutoLogon> | |
<OOBE> | |
<NetworkLocation>Work</NetworkLocation> | |
<HideEULAPage>true</HideEULAPage> | |
<ProtectYourPC>3</ProtectYourPC> | |
<SkipMachineOOBE>true</SkipMachineOOBE> | |
<SkipUserOOBE>true</SkipUserOOBE> | |
</OOBE> | |
<FirstLogonCommands> | |
<SynchronousCommand wcm:action="add"> | |
<CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> | |
<Description>Set Execution Policy 64 Bit</Description> | |
<Order>1</Order> | |
<RequiresUserInput>true</RequiresUserInput> | |
</SynchronousCommand> | |
<SynchronousCommand wcm:action="add"> | |
<CommandLine>cmd.exe /c powershell -File a:\fixnetwork.ps1</CommandLine> | |
<Description>Fix public network</Description> | |
<Order>2</Order> | |
<RequiresUserInput>true</RequiresUserInput> | |
</SynchronousCommand> | |
<SynchronousCommand wcm:action="add"> | |
<CommandLine>cmd.exe /c powershell -File "a:\ConfigureRemotingForAnsible.ps1"</CommandLine> | |
<Description>Enable WinRM</Description> | |
<Order>3</Order> | |
<RequiresUserInput>true</RequiresUserInput> | |
</SynchronousCommand> | |
<SynchronousCommand wcm:action="add"> | |
<CommandLine>cmd.exe /c reg add "HKLM\System\CurrentControlSet\Control\Network\NewNetworkWindowOff"</CommandLine> | |
<Description>Network prompt</Description> | |
<Order>4</Order> | |
<RequiresUserInput>true</RequiresUserInput> | |
</SynchronousCommand> | |
</FirstLogonCommands> | |
</component> | |
</settings> | |
<settings pass="specialize"> | |
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<ComputerName>Win10-Packer</ComputerName> | |
<ProductKey>W269N-WFGWX-YVC9B-4J6C9-T83GX</ProductKey> | |
</component> | |
</settings> | |
</unattend> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"builders": | |
[ | |
{ | |
"vm_name": "windows-10", | |
"type": "qemu", | |
"accelerator": "kvm", | |
"cpus": 1, | |
"memory": 4096, | |
"disk_size": 15360, | |
"iso_url": "Win10_1909_English_x64.iso", | |
"iso_checksum": "86c16116ebacf9b29e4766dd479b5a79", | |
"iso_checksum_type": "md5", | |
"floppy_files": | |
[ | |
"autounattend.xml", | |
"fixnetwork.ps1", | |
"ConfigureRemotingForAnsible.ps1" | |
], | |
"output_directory": "qemu-drives", | |
"qemuargs": | |
[ | |
[ "-drive", "file=qemu-drives/{{ .Name }},if=virtio,cache=writeback,discard=ignore,format=qcow2,index=1" ], | |
[ "-drive", "file=./virtio-win.iso,media=cdrom,index=3" ] | |
], | |
"communicator": "winrm", | |
"winrm_username": "packer", | |
"winrm_password": "packer", | |
"winrm_use_ssl": "true", | |
"winrm_insecure": "true", | |
"winrm_timeout" : "1h", | |
"shutdown_command": "shutdown /s /t 30 /f", | |
"shutdown_timeout": "15m" | |
} | |
] | |
} |
If you prefer to use the Git for Windows Bash implementation for the Windows-side shell for SSH you can enable it like so:
{
"type": "powershell",
"inline":
[
"$ErrorActionPreference = 'stop'",
"# Install Chocolatey package manager",
"Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))",
"# Install git",
"choco install git -y"
"# Set bash as OpenSSH shell (as last step, in order not to interfere with powershell provisioners above)",
"Set-ItemProperty -Path HKLM:\\SOFTWARE\\OpenSSH -Name DefaultShell -Value 'C:\\Program Files\\Git\\bin\\bash.exe' -Force"
]
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To enable a shared clipboard between host and guest when using the console, e.g. via
virt-manager
you need to install the SPICE agent: