Skip to content

Commit

Permalink
Windows: Add universal support for Microsoft Windows (#166)
Browse files Browse the repository at this point in the history
This PR adds support for the following Microsoft Windows versions:

* Windows Server 2022
* Windows Server 2019
* Windows Server 2016
* Windows 10 Pro 22H2

Support for Windows 11 is in the works and will be added subsequently.

Please kindly review & test and let me know if you encounter any issues.
Please consult the README.md file for details.

Thank you,
Alan

Closes: #3

---------

Co-authored-by: Gabriel Ramirez <[email protected]>
  • Loading branch information
alanbach and g-ramirez authored Dec 11, 2023
1 parent 2ab1383 commit eb8e778
Show file tree
Hide file tree
Showing 15 changed files with 504 additions and 263 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Read more about how [custom images](https://maas.io/docs/how-to-customise-images
| VMWare ESXi 6 | EOL | >= 3.0 |
| VMWare ESXi 7 | Stable | >= 3.0 |
| VMWare ESXi 8 | Beta | >= 3.0 |
| Windows 2016 | Beta | >= 3.3 |
| Windows 2019 | Beta | >= 3.3 |
| Windows 2022 | Beta | >= 3.3 |
| Windows 10 | Beta | >= 3.3 |

### Maturity level

Expand Down
1 change: 1 addition & 0 deletions windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http/Autounattend.xml
49 changes: 49 additions & 0 deletions windows/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/make -f

include ../scripts/check.mk

PACKER ?= packer
PACKER_LOG ?= 0
export PACKER_LOG

ISO ?=
VERSION ?= 2022
BOOT ?= uefi
HEADLESS ?= false

ifeq ($(strip $(VERSION)),10)
TYPE = Windows
EDIT ?= PRO
else ifeq ($(strip $(VERSION)),11)
TYPE = Windows
EDIT ?= PRO
else
TYPE = Windows Server
EDIT ?= SERVERSTANDARD
endif

.PHONY: all clean

all: windows

$(eval $(call check_packages_deps,cloud-image-utils ovmf,cloud-image-utils ovmf))

http/Autounattend.xml: http/Autounattend.xml.${BOOT}.template
sed s#@VERSION@#"${TYPE} ${VERSION} ${EDIT}"#g $< > $@
ifneq ($(strip $(PKEY)),)
sed -i s#@PKEY@#${PKEY}#g $@
sed -i 's/<!--<ProductKey>/<ProductKey>/;s/<\/ProductKey>-->/<\/ProductKey>/' $@
endif
ifeq ($(strip $(VERSION)),10)
sed -i 's/<!--<LocalAccounts>/<LocalAccounts>/;s/<\/LocalAccounts>-->/<\/LocalAccounts>/' $@
else ifeq ($(strip $(VERSION)),11)
sed -i 's/<!--<LocalAccounts>/<LocalAccounts>/;s/<\/LocalAccounts>-->/<\/LocalAccounts>/' $@
endif

.INTERMEDIATE: http/Autounattend.xml

windows: check-deps clean http/Autounattend.xml
${PACKER} init . && ${PACKER} build -var iso_path=${ISO} -var headless=${HEADLESS} windows.pkr.hcl

clean:
${RM} -rf output-* windows.dd.gz http/Autounattend.xml
118 changes: 118 additions & 0 deletions windows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Packer Template for Microsoft Windows

## Introduction

The Packer templates in this directory creates Windows Server images for use with MAAS.


## Prerequisites (to create the image)

* A machine running Ubuntu 18.04+ with the ability to run KVM virtual machines.
* qemu-utils, libnbd-bin, nbdkit and fuse2fs
* qemu-system
* ovmf
* cloud-image-utils
* [Packer](https://www.packer.io/intro/getting-started/install.html), v1.7.0 or newer


## Requirements (to deploy the image)

* [MAAS](https://maas.io) 3.2+
* [Curtin](https://launchpad.net/curtin) 21.0+


## Supported Microsoft Windows Versions

This process has been build and deployment tested with the following versions of
Microsoft Windows:

* Windows Server 2022
* Windows Server 2019
* Windows Server 2016
* Windows 10 Pro 22H2


## Known Issues

* The current process builds UEFI compatible images only.


## windows.json Template

This template builds a dd.tgz MAAS image from an official Microsoft Windows ISO.
This process also installs the latest VirtIO drivers as well as Cloudbase-init.


## Obtaining Microsoft Windows ISO images

You can obtains Microsoft Windows Evaluation ISO images from the following links:

* [Windows Server 2022](https://www.microsoft.com/en-us/evalcenter/download-windows-server-2022)
* [Windows Server 2019](https://www.microsoft.com/en-us/evalcenter/download-windows-server-2019)
* [Windows Server 2016](https://www.microsoft.com/en-us/evalcenter/download-windows-server-2016)


### Building the image

The build the image you give the template a script which has all the
customization:

```shell
sudo make windows ISO=<path-to-iso> VERSION=<windows-version> windows.json
```

### Makefile Parameters

#### BOOT

Currently uefi is the only supported value.

#### EDIT

The edition of a targeted ISO image. It defaults to PRO for Microsoft Windows 10/11
and SERVERSTANDARD for Microsoft Windows Servers. Many Microsoft Windows Server ISO
images do contain multiple editions and this prarameter is useful to build a particular
edition such as Standard or Datacenter etc.

#### HEADLESS

Whether VNC viewer should not be launched. Default is set to false.

#### ISO

Path to Microsoft Windows ISO used to build the image.

#### PACKER_LOG

Enable (1) or Disable (0) verbose packer logs. The default value is set to 0.

#### PKEY

User supplied Microsoft Windows Product Key. When usimg KMS, you can obtain the
activation keys from the link below:

* [KMS Client Activation and Product Keys](https://learn.microsoft.com/en-us/windows-server/get-started/kms-client-activation-keys)

Please note that PKEY is an optional parameter but it might be required during
the build time depending on the type of ISO being used. Evaluation series ISO
images usually do not require a product key to proceed, however this is not
true with Enterprise and Retail ISO images.

#### VERSION

Specify the Microsoft Windows Version. Example inputs include: 2022, 2019, 2016
and 10.


## Uploading images to MAAS

Use MAAS CLI to upload the image:

```shell
maas admin boot-resources create \
name='windows/windows-server' \
title='Windows Server' \
architecture='amd64/generic' \
filetype='ddtgz' \
content@=windows-server-amd64-root-dd.gz
```
7 changes: 7 additions & 0 deletions windows/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## To be implemented (TODO List)

* Complete the support for build-time driver injection.
* Add support for BIOS based deployments.
* Add support for Windows 11 which requires TPM 2.0.
* Migrate scripts/setup-nbd to use fuse.

3 changes: 3 additions & 0 deletions windows/curtin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This has been cloned from the following Git repository:

[Windows Curtin Hooks](https://github.com/cloudbase/windows-curtin-hooks.git)
31 changes: 23 additions & 8 deletions windows/curtin/finalize
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
#!/bin/bash

export PYTHONPATH='/curtin'

# Ubuntu 16.04 only ships with Python 3 while previous versions only ship
# with Python 2.
if type -p python > /dev/null; then
exec python "$0.py" "$@"
else
exec python3 "$0.py" "$@"
PYTHON2=`/bin/which python`
PYTHON3=`/bin/which python3`

PYTHON=${PYTHON2:-$PYTHON3}

if [ -z $PYTHON ]
then
echo "Failed to find python interpretor"
exit 1
fi

SCRIPT_DIR=`/usr/bin/dirname $0`
ABSPATH=`/bin/readlink -m $SCRIPT_DIR`

FINALIZE="$ABSPATH/finalize.py"

if [ ! -e $FINALIZE ]
then
echo "No finalize script available"
exit 0
fi

$PYTHON $FINALIZE

Loading

0 comments on commit eb8e778

Please sign in to comment.