Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Add universal support for Microsoft Windows #166

Merged
merged 37 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
19b3e63
Add a make example to build cloudimg based images.
alanbach Nov 9, 2023
c9711b2
Increase the base disk size from 4G to 6G
alanbach Nov 9, 2023
4feb7fe
Revert previous commit.
alanbach Nov 9, 2023
d5541a7
Removed sudo as it is not required.
alanbach Nov 14, 2023
82c7d79
Merge branch 'canonical:main' into main
alanbach Nov 14, 2023
3774491
Merge branch 'canonical:main' into main
alanbach Nov 14, 2023
b4d87d7
Merge branch 'canonical:main' into main
alanbach Nov 14, 2023
1ea8744
adding windows-efi template-#3
g-ramirez Jan 21, 2021
d170196
Merge branch 'canonical:main' into main
alanbach Nov 24, 2023
3d12dfc
Merge remote-tracking branch 'upstream/windows' into windows
alanbach Nov 26, 2023
8a57546
Rename Autounattend.xml > Autounattend.xml.template
alanbach Nov 26, 2023
6549b0d
Added windows/.gitignore
alanbach Nov 26, 2023
b39c98d
Remove obsolete curtin/python_wrapper
alanbach Nov 26, 2023
ebdb06e
Synced curtin/* with upstream.
alanbach Nov 26, 2023
6adfac6
Added curtin/README.md
alanbach Nov 26, 2023
8196bdb
Added scripts/setup-nbd
alanbach Nov 26, 2023
959c8fc
Removed obsolete http/cloudbase-init/
alanbach Nov 26, 2023
d572b65
http/Autounattend.xml.template:
alanbach Nov 27, 2023
5ae676b
http/logon.ps1:
alanbach Nov 27, 2023
6d0635e
windows.json:
alanbach Nov 27, 2023
a825bb1
Added Makefile README.md TODO.md
alanbach Nov 27, 2023
1532d28
Rename http/Autounattend.xml.template > http/Autounattend.xml.uefi.te…
alanbach Nov 27, 2023
72f782b
Added BOOT CLI parameter support.
alanbach Nov 27, 2023
64fdba4
README.md: Additions and improvements.
alanbach Nov 27, 2023
5773dee
Delete http/Autounattend.xml on clean.
alanbach Nov 28, 2023
2fb87bd
Further updates for README.md and TODO.md
alanbach Nov 28, 2023
ca77935
Added a note for scripts/setup-nbd
alanbach Nov 28, 2023
141f736
Added default language XML tags and a local account for Windows 10/11.
alanbach Nov 28, 2023
fbcbf53
Enable LocalAccounts for Windows 10/11.
alanbach Nov 28, 2023
d8fd5c3
Updated support matrix table for Windows.
alanbach Nov 28, 2023
de46b89
Rebase with upstream/windows
alanbach Nov 30, 2023
4e4ffcd
Delete obsolete artifacts after remerge.
alanbach Nov 30, 2023
bfb6535
Converted windows.json to windows.pkr.hcl
alanbach Dec 10, 2023
a3d0071
Updated the build path to match
alanbach Dec 11, 2023
86f9c8e
Changed the autogenerated name, updated
alanbach Dec 11, 2023
677b713
Implemented the requested changes
alanbach Dec 11, 2023
9a634ab
Additional windows.pkr.hcl and Makefile
alanbach Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 48 additions & 0 deletions windows/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/make -f

include ../scripts/check.mk

PACKER ?= packer
PACKER_LOG ?= 0
export PACKER_LOG

ISO ?=
VERSION ?= 2022
BOOT ?= uefi

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} build -var iso_path=${ISO} windows.pkr.hcl

clean:
${RM} -rf output-* windows.dd.gz http/Autounattend.xml
114 changes: 114 additions & 0 deletions windows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# 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.

#### 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