-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
295 lines (230 loc) · 8.61 KB
/
Copy pathMakefile
File metadata and controls
295 lines (230 loc) · 8.61 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#obviously one can and should override these defaults
HOSTNAME= target.mydomain
IP= DHCP
IPV6= inet6 accept_rtadv
### example: IP=1.2.3.4/24
BSD_VERSION= 11.1
BSD_ARCH= amd64
TIMEZONE= Europe/Athens
#DISTRIBUTIONS=src.txz kernel.txz base.txz lib32.txz
DISTRIBUTIONS= kernel.txz base.txz
MIRROR= ftp.gr.freebsd.org
SIZE_GB= 3
SIZE_SWAP= 1
SIZE_UFS!= expr $(SIZE_GB) - $(SIZE_SWAP)
NET_NAME= native_network
MEMORY= 512
NCPUS= 1
PASSWORD_HASH= password_hash
NAMESERVER= 8.8.8.8
NAMESERVER+= 8.8.4.4
PKGNG= vim-lite
PKGNG+= puppet4
PUPPET= init.pp
NETDEVICE= e1000
#these should probably remain as-is
RAW_IMAGE=FreeBSD-$(BSD_VERSION)-RELEASE-$(BSD_ARCH).raw
RAW_IMAGE_COMPRESSED=$(RAW_IMAGE).xz
MD_NUMBER=98
ZROOT=zroot
DISTDIR=distdir-$(BSD_VERSION)-$(BSD_ARCH)
DISTSITE=ftp://$(MIRROR)/pub/FreeBSD/releases/$(BSD_ARCH)/$(BSD_VERSION)-RELEASE
#do not touch
MODE=ufs
ZPOOL_DIR=
.if (defined(ZFS))
MODE=zfs
ZPOOL_DIR=$(ZROOT)/
.endif
#handle errors
ERROR_TARGET=$(MODE)_umount delete_metadevice
.ERROR: $(ERROR_TARGET)
show:
@echo distributions=$(DISTRIBUTIONS) size_ufs=$(SIZE_UFS) zpool_dir=$(ZPOOL_DIR) mode=$(MODE) ip=$(IP_RC) common_settings=$(COMMON_SETTINGS) ns=$(NAMESERVER)
@echo environment follows:
@env | sort
#################################################################################
SYSRC= sysrc -f /mnt/$(ZPOOL_DIR)etc/rc.conf
COMMON_SETTINGS+=set_hostname
set_hostname:
#echo hostname=\"$(HOSTNAME)\" > /mnt/$(ZPOOL_DIR)etc/rc.conf
${SYSRC} hostname="$(HOSTNAME)"
.if ${NETDEVICE} == "vmxnet3"
INTERFACE= vmx0
.else
INTERFACE= em0
.endif
.if ! $(IP) == "DHCP"
IP_RC=inet $(IP) netmask $(NETMASK)
.else
IP_RC=$(IP)
.endif
COMMON_SETTINGS+=ifconfig
ifconfig:
${SYSRC} ifconfig_${INTERFACE}="$(IP_RC)"
.if $(IPV6) != ""
COMMON_SETTINGS+=ipv6
.endif
ipv6:
${SYSRC} ifconfig_${INTERFACE}_ipv6="$(IPV6)"
.if (defined(DEFAULTROUTER))
COMMON_SETTINGS+=defaultrouter
.endif
defaultrouter:
${SYSRC} defaultrouter="$(DEFAULTROUTER)"
COMMON_SETTINGS+=cmos
cmos:
touch /mnt/$(ZPOOL_DIR)etc/wall_cmos_clock
COMMON_SETTINGS+=timezone
timezone:
cp /mnt/$(ZPOOL_DIR)usr/share/zoneinfo/$(TIMEZONE) /mnt/$(ZPOOL_DIR)etc/localtime
COMMON_SETTINGS+=dumpdev
dumpdev:
#echo dumpdev="AUTO" >> /mnt/$(ZPOOL_DIR)etc/rc.conf
${SYSRC} dumpdev="AUTO"
COMMON_SETTINGS+=kern_securelevel
kern_securelevel:
#echo kern_securelevel_enable="NO" >> /mnt/$(ZPOOL_DIR)etc/rc.conf
#echo kern_securelevel="1" >> /mnt/$(ZPOOL_DIR)etc/rc.conf
${SYSRC} kern_securelevel_enable="NO"
${SYSRC} kern_securelevel="1"
COMMON_SETTINGS+=sshd_enable
sshd_enable:
#echo sshd_enable="YES" >> /mnt/$(ZPOOL_DIR)etc/rc.conf
${SYSRC} sshd_enable="YES"
COMMON_SETTINGS+=set_password
set_password:
cat $(PASSWORD_HASH) | chroot /mnt/$(ZPOOL_DIR) pw usermod root -H 0
.if $(NAMESERVER) != ""
COMMON_SETTINGS+=set_resolv_conf
.endif
set_resolv_conf:
for i in $(NAMESERVER); do echo nameserver $$i >> /mnt/$(ZPOOL_DIR)etc/resolv.conf ; done
.if $(PKGNG) != ""
COMMON_SETTINGS+=pkgng
.endif
ASSUME_ALWAYS_YES=true
.export ASSUME_ALWAYS_YES
pkgng: pkgng_bootstrap pkgng_install
pkgng_bootstrap:
env NAMESERVER= chroot /mnt/$(ZPOOL_DIR) pkg bootstrap
@sleep 5
pkgng_install:
### Incredible, for some stupid reason the NAMESERVER variable seems to make pkg freak out
env NAMESERVER= chroot /mnt/$(ZPOOL_DIR) pkg install $(PKGNG)
.if $(PUPPET) != ""
COMMON_SETTINGS+=puppet
.endif
puppet:
mkdir -p /mnt/$(ZPOOL_DIR)root/freebsd-cooker/
cp $(PUPPET) /mnt/$(ZPOOL_DIR)root/freebsd-cooker/
for i in $(PUPPET); do chroot /mnt/$(ZPOOL_DIR) puppet apply /root/freebsd-cooker/$$i ; done
common_settings: $(COMMON_SETTINGS)
#################################################################################
vmx:
- rm target.vmsd target.vmxf nvram vmware-*.log vmware.log
cp target.vmx.template target.vmx
chmod a+w target.*
vmdk:
qemu-img convert -f raw -O vmdk -o adapter_type=lsilogic,subformat=streamOptimized,compat6 target.disk target.vmdk
ova:
cp template.ovf target.ovf
sed -i .bak -e 's/___NETNAME___/$(NET_NAME)/g' -e 's/___DISK_SIZE___/$(SIZE_GB)/g' -e 's/___MEMORY___/$(MEMORY)/g' -e 's/___HOSTNAME___/$(HOSTNAME)/g' -e 's/___NCPUS___/$(NCPUS)/g' target.ovf
VMDK_CHECKSUM=`sha1 -q target.vmdk` \
OVF_CHECKSUM=`sha1 -q target.ovf` ; \
echo SHA1\(target.vmdk\)= $$VMDK_CHECKSUM > target.mf ; \
echo SHA1\(target.ovf\)= $$OVF_CHECKSUM >> target.mf ;
gtar cvf target.ova target.ovf target.mf target.vmdk
#################################################################################
clean:
- rm `pwd`/$(DISTDIR)/src.txz
- rm `pwd`/$(DISTDIR)/base.txz
- rm `pwd`/$(DISTDIR)/lib32.txz
- rm `pwd`/$(DISTDIR)/doc.txz
- rm target.disk
- rm target.ova
- rm target.ovf
#################################################################################
emptyimage:
#dd if=/dev/zero of=target.disk bs=1G count=$(SIZE_GB)
truncate -s ${SIZE_GB}G target.disk
metadevice:
mdconfig -f target.disk -u$(MD_NUMBER)
delete_metadevice:
mdconfig -d -u$(MD_NUMBER)
ufs_partition:
#newfs -O 2 -U -a 4 -b 32768 -d 32768 -e 4096 -f 4096 -g 16384 -h 64 -i 8192 -j -k 6408 -m 8 -o time /dev/md$(MD_NUMBER)
bsdinstall scriptedpart md$(MD_NUMBER) GPT { $(SIZE_UFS)G freebsd-ufs / , auto freebsd-swap }
ufs_mount:
mount /dev/md$(MD_NUMBER)p2 /mnt
ufs_umount:
- umount /mnt
entropy:
mkdir /mnt/boot/
env BSDINSTALL_CHROOT=/mnt/$(ZPOOL_DIR) bsdinstall entropy
.export DISTRIBUTIONS
create_distdir: $(DISTDIR)
$(DISTDIR):
mkdir -p $(DISTDIR)
distfetch-bsdinstall: create_distdir
env BSDINSTALL_DISTDIR=`pwd`/$(DISTDIR) BSDINSTALL_DISTSITE=ftp://$(MIRROR)/pub/FreeBSD/releases/$(BSD_ARCH)/$(BSD_VERSION)-RELEASE bsdinstall distfetch
distfetch-manual: create_distdir
cd $(DISTDIR) ; for i in $(DISTRIBUTIONS); do fetch -m $(DISTSITE)/$$i ; done
DISTFETCH_METHOD=manual
distfetch: distfetch-$(DISTFETCH_METHOD)
distextract:
env BSDINSTALL_CHROOT=/mnt/$(ZPOOL_DIR) BSDINSTALL_DISTDIR=`pwd`/$(DISTDIR) BSDINSTALL_DISTSITE=ftp://$(MIRROR)/pub/FreeBSD/releases/$(BSD_ARCH)/$(BSD_VERSION)-RELEASE bsdinstall distextract
bsdinstall_config:
env BSDINSTALL_CHROOT=/mnt/$(ZPOOL_DIR) BSDINSTALL_DISTDIR=`pwd`/$(DISTDIR) BSDINSTALL_DISTSITE=ftp://$(MIRROR)/pub/FreeBSD/releases/$(BSD_ARCH)/$(BSD_VERSION)-RELEASE bsdinstall config
ufs_fstab:
cp fstab.template /mnt/etc/fstab
create_ufs: emptyimage metadevice ufs_partition ufs_mount entropy distfetch distextract bsdinstall_config ufs_fstab common_settings ufs_umount delete_metadevice
zpart:
gpart create -s gpt md$(MD_NUMBER)
gpart add -a 4k -s 512k -t freebsd-boot md$(MD_NUMBER)
# this will fill the rest of the image
gpart add -a 4k -t freebsd-zfs -l gpt_root md$(MD_NUMBER)
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 md$(MD_NUMBER)
zpool create -f -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot /dev/md$(MD_NUMBER)p2
#zpool export zroot
#zpool import -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot
# a big thanks to this: https://calomel.org/zfs_freebsd_root_install.html
zpool set bootfs=zroot zroot
zpool set listsnapshots=on zroot
zpool set autoreplace=on zroot
zfs set checksum=fletcher4 zroot
zfs set compression=lz4 zroot
zfs set atime=off zroot
zfs set copies=3 zroot
zfs create -V 1G zroot/swap
zfs set org.freebsd:swap=on zroot/swap
create_zfs: emptyimage metadevice zpart entropy distfetch distextract bsdinstall_config common_settings zfs_settings zfs_umount delete_metadevice
zfs_settings:
cp /var/tmp/zpool.cache /mnt/$(ZPOOL_DIR)/boot/zfs/zpool.cache
cd /mnt/$(ZPOOL_DIR) ; ln -s usr/home home
echo 'zfs_enable="YES"' >> /mnt/$(ZPOOL_DIR)/etc/rc.conf
echo 'zfs_load="YES"' >> /mnt/$(ZPOOL_DIR)/boot/loader.conf
echo 'vfs.root.mountfrom="zfs:zroot"' >> /mnt/$(ZPOOL_DIR)/boot/loader.conf
echo "# use gpt ids instead of gptids or disks idents"
echo 'kern.geom.label.disk_ident.enable="0"' >> /mnt/$(ZPOOL_DIR)/boot/loader.conf
echo 'kern.geom.label.gpt.enable="1"' >> /mnt/$(ZPOOL_DIR)/boot/loader.conf
echo 'kern.geom.label.gptid.enable="0"' >> /mnt/$(ZPOOL_DIR)/boot/loader.conf
rm /mnt/$(ZPOOL_DIR)/etc/fstab
touch /mnt/$(ZPOOL_DIR)/etc/fstab
zfs_umount:
# to unmount the filesystem before packaging
zpool export zroot
# if I wanted to reimport I'd zpool import -o altroot=/mnt [the numeric id] or zroot
create: create_$(MODE)
all: create vmdk ova
###########################################################
# the below section is no longer actively used, kept here
# lest it is used in the future
# #########################################################
download-image:
fetch ftp://$(MIRROR)/pub/FreeBSD/releases/VM-IMAGES/$(BSD_VERSION)-RELEASE/$(BSD_ARCH)/Latest/$(RAW_IMAGE_COMPRESSED)
uncompress-image:
xz -d $(RAW_IMAGE_COMPRESSED)
mount-image:
mdconfig -f $(RAW_IMAGE) -u$(MD_NUMBER)
mount /dev/md$(MD_NUMBER)p3 /mnt