forked from rgl/windows-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
220 lines (202 loc) · 9.81 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Disable builtin rules and variables since they aren't used
# This makes the output of "make -d" much easier to follow and speeds up evaluation
# NB you can use make --print-data-base --dry-run to troubleshoot this Makefile.
MAKEFLAGS+= --no-builtin-rules
MAKEFLAGS+= --no-builtin-variables
# Normal (libvirt and VirtualBox) images
IMAGES+= windows-2016
IMAGES+= windows-2019
IMAGES+= windows-2019-uefi
IMAGES+= windows-2022
IMAGES+= windows-2022-uefi
IMAGES+= windows-10-1809
IMAGES+= windows-10-20h2
IMAGES+= windows-11-21h2
IMAGES+= windows-11-21h2-uefi
# Images supporting Hyper-V
HYPERV_IMAGES+= windows-2016
HYPERV_IMAGES+= windows-2019
HYPERV_IMAGES+= windows-2022
HYPERV_IMAGES+= windows-10-1809
HYPERV_IMAGES+= windows-10-20h2
HYPERV_IMAGES+= windows-11-21h2
# Images supporting vSphere
VSPHERE_IMAGES+= windows-2016
VSPHERE_IMAGES+= windows-2019
VSPHERE_IMAGES+= windows-2019-uefi
VSPHERE_IMAGES+= windows-2022
VSPHERE_IMAGES+= windows-2022-uefi
VSPHERE_IMAGES+= windows-10-1809
# Generate build-* targets
VIRTUALBOX_BUILDS= $(addsuffix -virtualbox,$(addprefix build-,$(IMAGES)))
LIBVIRT_BUILDS= $(addsuffix -libvirt,$(addprefix build-,$(IMAGES)))
HYPERV_BUILDS= $(addsuffix -hyperv,$(addprefix build-,$(HYPERV_IMAGES)))
VSPHERE_BUILDS= $(addsuffix -vsphere,$(addprefix build-,$(VSPHERE_IMAGES)))
.PHONY: help $(VIRTUALBOX_BUILDS) $(LIBVIRT_BUILDS) $(VSPHERE_BUILDS)
help:
@echo Type one of the following commands to build a specific windows box.
@echo
@echo VirtualBox Targets:
@$(addprefix echo make ,$(addsuffix ;,$(VIRTUALBOX_BUILDS)))
@echo
@echo libvirt Targets:
@$(addprefix echo make ,$(addsuffix ;,$(LIBVIRT_BUILDS)))
@echo
@echo Hyper-V Targets:
@$(addprefix echo make ,$(addsuffix ;,$(HYPERV_BUILDS)))
@echo
@echo vSphere Targets:
@$(addprefix echo make ,$(addsuffix ;,$(VSPHERE_BUILDS)))
# Target specific pattern rules for build-* targets
$(VIRTUALBOX_BUILDS): build-%-virtualbox: %-amd64-virtualbox.box
$(LIBVIRT_BUILDS): build-%-libvirt: %-amd64-libvirt.box
$(HYPERV_BUILDS): build-%-hyperv: %-amd64-hyperv.box
$(VSPHERE_BUILDS): build-%-vsphere: %-amd64-vsphere.box
%-amd64-virtualbox.box: %.pkr.hcl %/autounattend.xml Vagrantfile.template *.ps1 drivers
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-virtualbox-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-virtualbox-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=virtualbox-iso.$*-amd64 -on-error=abort $*.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-amd64-virtualbox-packer.log \
>$*-amd64-virtualbox-windows-updates.log
@echo BOX successfully built!
@echo to add to local vagrant install do:
@echo vagrant box add -f $*-amd64 $@
%-amd64-libvirt.box: %.pkr.hcl %/autounattend.xml Vagrantfile.template *.ps1 drivers
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-libvirt-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-libvirt-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=qemu.$*-amd64 -on-error=abort $*.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-amd64-libvirt-packer.log \
>$*-amd64-libvirt-windows-updates.log
@echo BOX successfully built!
@echo to add to local vagrant install do:
@echo vagrant box add -f $*-amd64 $@
%-amd64-hyperv.box: %.pkr.hcl Vagrantfile.template *.ps1
rm -f $@
mkdir -p tmp
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-hyperv-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-hyperv-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=hyperv-iso.$*-amd64 -on-error=abort $*.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-amd64-hyperv-packer.log \
>$*-amd64-hyperv-windows-updates.log
@echo BOX successfully built!
@echo to add to local vagrant install do:
@echo vagrant box add -f $*-amd64 $@
%-uefi-amd64-virtualbox.box: %-uefi.pkr.hcl %-uefi/autounattend.xml Vagrantfile-uefi.template *.ps1 drivers
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-virtualbox-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-virtualbox-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=virtualbox-iso.$*-uefi-amd64 -on-error=abort $*-uefi.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-uefi-amd64-virtualbox-packer.log \
>$*-uefi-amd64-virtualbox-windows-updates.log
@echo BOX successfully built!
@echo to add to local vagrant install do:
@echo vagrant box add -f $*-uefi-amd64 $@
%-uefi-amd64-libvirt.box: %-uefi.pkr.hcl %-uefi/autounattend.xml Vagrantfile-uefi.template *.ps1 drivers
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-libvirt-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-libvirt-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=qemu.$*-uefi-amd64 -on-error=abort $*-uefi.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-uefi-amd64-libvirt-packer.log \
>$*-uefi-amd64-libvirt-windows-updates.log
@echo BOX successfully built!
@echo to add to local vagrant install do:
@echo vagrant box add -f $*-uefi-amd64 $@
tmp/windows-10-%-vsphere/autounattend.xml: windows-10/autounattend.xml
mkdir -p "$$(dirname $@)"
@# add the vmware tools iso to the drivers search path.
@# NB we cannot have this in the main autounattend.xml because windows 2016
@# will fail to install when the virtualbox guest additions iso is in E:
@# with the error message:
@# Windows Setup could not install one or more boot-critical drivers.
@# To install Windows, make sure that the drivers are valid, and
@# restart the installation.
sed -E 's,(.+)</DriverPaths>,\1 <PathAndCredentials wcm:action="add" wcm:keyValue="2"><Path>E:\\</Path></PathAndCredentials>\n\0,g' $< >$@
tmp/%-vsphere/autounattend.xml: %/autounattend.xml
mkdir -p "$$(dirname $@)"
@# add the vmware tools iso to the drivers search path.
@# NB we cannot have this in the main autounattend.xml because windows 2016
@# will fail to install when the virtualbox guest additions iso is in E:
@# with the error message:
@# Windows Setup could not install one or more boot-critical drivers.
@# To install Windows, make sure that the drivers are valid, and
@# restart the installation.
sed -E 's,(.+)</DriverPaths>,\1 <PathAndCredentials wcm:action="add" wcm:keyValue="2"><Path>E:\\</Path></PathAndCredentials>\n\0,g' $< >$@
%-amd64-vsphere.box: %-vsphere.pkr.hcl tmp/%-vsphere/autounattend.xml Vagrantfile.template *.ps1
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-vsphere-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-vsphere-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=vsphere-iso.$*-amd64 -on-error=abort $*-vsphere.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-amd64-vsphere-packer.log \
>$*-amd64-vsphere-windows-updates.log
@echo 'Removing all cd-roms (except the first)...'
govc device.ls "-vm.ipath=$$VSPHERE_TEMPLATE_IPATH" \
| grep ^cdrom- \
| tail -n+2 \
| awk '{print $$1}' \
| xargs -L1 govc device.remove "-vm.ipath=$$VSPHERE_TEMPLATE_IPATH"
@echo 'Converting to template...'
govc vm.markastemplate "$$VSPHERE_TEMPLATE_IPATH"
@echo 'Creating the local box file...'
rm -rf tmp/$@-contents
mkdir -p tmp/$@-contents
echo '{"provider":"vsphere"}' >tmp/$@-contents/metadata.json
cp Vagrantfile.template tmp/$@-contents/Vagrantfile
tar cvf $@ -C tmp/$@-contents .
@echo BOX successfully built!
@echo to add to local vagrant install do:
@echo vagrant box add -f $*-amd64 $@
%-uefi-amd64-vsphere.box: %-uefi-vsphere.pkr.hcl tmp/%-uefi-vsphere/autounattend.xml Vagrantfile-uefi.template *.ps1
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-vsphere-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-vsphere-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=vsphere-iso.$*-uefi-amd64 -on-error=abort $*-uefi-vsphere.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-uefi-amd64-vsphere-packer.log \
>$*-uefi-amd64-vsphere-windows-updates.log
@echo 'Removing all cd-roms (except the first)...'
govc device.ls "-vm.ipath=$$VSPHERE_TEMPLATE_IPATH" \
| grep ^cdrom- \
| tail -n+2 \
| awk '{print $$1}' \
| xargs -L1 govc device.remove "-vm.ipath=$$VSPHERE_TEMPLATE_IPATH"
@echo 'Converting to template...'
govc vm.markastemplate "$$VSPHERE_TEMPLATE_IPATH"
@echo 'Creating the local box file...'
rm -rf tmp/$@-contents
mkdir -p tmp/$@-contents
echo '{"provider":"vsphere"}' >tmp/$@-contents/metadata.json
cp Vagrantfile.template tmp/$@-contents/Vagrantfile
tar cvf $@ -C tmp/$@-contents .
@echo BOX successfully built!
@echo to add to local vagrant install do:
@echo vagrant box add -f $*-uefi-amd64 $@
# All the Windows 10 versions depend on the same autounattend.xml
# This allows the use of pattern rules by satisfying the prerequisite
.PHONY: \
windows-10-1809/autounattend.xml \
windows-10-20h2/autounattend.xml
drivers:
@# see https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/index.html
@# see https://github.com/virtio-win/virtio-win-guest-tools-installer
@# see https://github.com/virtio-win/virtio-win-pkg-scripts
if [ ! -f drivers/virtio-win-guest-tools.exe ]; then \
mkdir -p drivers.tmp; \
wget -P drivers.tmp https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.190-1/virtio-win-0.1.190.iso; \
7z x -odrivers.tmp drivers.tmp/virtio-win-*.iso; \
mv drivers.tmp drivers; \
fi;