-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
454 lines (402 loc) · 19.1 KB
/
CMakeLists.txt
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# CMakeLists.txt
######################################
# Kzenlab Builder
# Copyright (C) 2024 Indra Wahjoedi<[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
######################################
cmake_minimum_required(VERSION 3.15)
project(kzenlab)
######################################
## Shell Environment variables as CMake cache variables
######################################
#### TOOLS
set(VBOX_CMD "/usr/bin/VBoxManage" CACHE STRING "Path to VBoxManage executable")
set(VBOX_IMG_MOUNT "/usr/bin/vboximg-mount" CACHE STRING "Path to VBox Image Mount executable")
set(VBOX_IMG "/usr/bin/vbox-img" CACHE STRING "Path to VBox Image executable")
set(QEMU_PATH "/usr/bin/qemu-system-x86_64" CACHE STRING "Path to VBoxManage executable")
set(GDISK_PATH "/usr/sbin/gdisk" CACHE STRING "Path to GDISK executable")
set(FDISK_PATH "/usr/sbin/fdisk" CACHE STRING "Path to FDISK executable")
set(DEBOOT_PATH "/usr/sbin/debootstrap" CACHE STRING "Path to DEBOOTSTRAP executable")
set(FALLO_PATH "/usr/bin/fallocate" CACHE INTERNAL "Path to Fallocate executable")
set(PARTED_PATH "/usr/sbin/parted" CACHE STRING "Path to Parted executable")
set(UDISKCTL_PATH "/usr/bin/udisksctl" CACHE STRING "Path to UDISKCTL executable")
set(MKFS_PATH "/usr/sbin/mkfs" CACHE STRING "Path to MKFS executable")
set(MKSWAP_PATH "/usr/sbin/mkswap" CACHE STRING "Path to MKSWAP executable")
set(LOSETUP_PATH "/usr/sbin/losetup" CACHE STRING "Path to Losetup executable")
#### VM
set(VM_HYPER_TYPE "VBOX" CACHE STRING "VM Hypervisor type")
set(VM_NAME "KZENLAB" CACHE STRING "VM Name")
set(VM_DOMAIN "codeijoe.org" CACHE STRING "VM Domain")
set(VM_HOSTNAME "kzenlab" CACHE STRING "VM Hostname")
set(VM_DISK_SIZE "0" CACHE STRING "VM Disk size")
#### ISO
set(ISO_HOME "/home/ijoe/ISO/LINUX/DEBIAN" CACHE STRING "ISO DEBIAN Directory")
set(ISO_DEBIAN127_DVD "debian-12.7.0-amd64-DVD-1.iso" CACHE STRING "Debian ISO File")
set(ISO_DEBIAN128_CD "debian-12.8.0-amd64-netinst.iso" CACHE STRING "Debian Netinstall CD ISO File")
set(ISO_DEBIAN128_DVD_1 "debian-12.8.0-amd64-DVD-1.iso" CACHE STRING "Debian Netinstall CD ISO File")
set(ISO_DEBIAN128_LIVE_XFCE "debian-live-12.8.0-amd64-xfce.iso" CACHE STRING "Debian Netinstall CD ISO File")
#### QEMU
set(QEMU_HOME "/home/ijoe/QEMU_VM" CACHE STRING "QEMU VM Home Directory")
set(QEMU_VM_HOME "${QEMU_VM}/VM" CACHE STRING "QEMU VM Home Directory")
#### QEMU DISK
set(QEMU_DISK_HOME "${QEMU_HOME}/DISK" CACHE STRING "QEMU VM Home Directory")
#### VBOX
set(VBOX_HOME "/media/89fbfc92-6afb-4c5a-a889-199bc5f66e21/ijoe/VBOX_VM" CACHE STRING "VBOX Home Directory")
set(VBOX_VM_HOME "/media/89fbfc92-6afb-4c5a-a889-199bc5f66e21/ijoe/VBOX_VM/VM" CACHE STRING "VBOX VM Home Directory")
#### VBOX DISK
set(VBOX_DISK_HOME "${VBOX_HOME}/DISK" CACHE STRING "VM Disk Home Directory")
set(VM_RAWDISK_4GB "${VBOX_HOME}/flat4GB.vmdk" CACHE STRING "Raw Disk 4GB")
set(VM_RAWDISK_8GB "${VBOX_HOME}/flat8GB.vmdk" CACHE STRING "Raw Disk 8GB")
set(VM_RAWDISK_16GB "${VBOX_HOME}/flat16GB.vmdk" CACHE STRING "Raw Disk 16GB")
set(VM_RAWDISK_32GB "${VBOX_HOME}/flat32GB.vmdk" CACHE STRING "Raw Disk 32GB")
set(VM_RAWDISK_64GB "${VBOX_HOME}/flat64GB.vmdk" CACHE STRING "Raw Disk 64GB")
set(VBOX_DISK_4GB "${VM_NAME}.vdi" CACHE STRING "4GB Disk")
set(VBOX_DISK_8GB "${VM_NAME}--8GB.vdi" CACHE STRING "8GB Disk")
set(VBOX_DISK_16GB "${VM_NAME}--16GB.vdi" CACHE STRING "16GB Disk")
set(VBOX_DISK_32GB "${VM_NAME}--32GB.vdi" CACHE STRING "32GB Disk")
set(VBOX_DISK_64GB "${VM_NAME}--64GB.vdi" CACHE STRING "64GB Disk")
#### DEBIAN
set(EFI_PART "default" CACHE STRING "EFI Partition")
set(ROOT_PART "default" CACHE STRING "ROOT Partition")
#=========================================
######################################
## Adding Stages
######################################
#### Raw Disk Stage
add_subdirectory(raw-disk)
#### Base OS Stage
#add_subdirectory(base-os)
########## TARGET ############
######################################
# TARG: print_vm_env
# PROC: init/env
# DESC: Print Virtual Machine Environment to screen
######################################
add_custom_target(
print_vm_env
COMMAND ${CMAKE_COMMAND} -E echo "VM_HYPER_TYPE: ${VM_HYPER_TYPE}"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_CMD: ${VBOX_CMD}"
COMMAND ${CMAKE_COMMAND} -E echo "QEMU_PATH: ${QEMU_PATH}"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_HOME: ${VBOX_HOME}"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_VM_HOME: ${VBOX_VM_HOME}"
COMMAND ${CMAKE_COMMAND} -E echo "VM_NAME: ${VM_NAME}"
COMMAND ${CMAKE_COMMAND} -E echo "ISO_HOME: ${ISO_HOME}"
COMMAND ${CMAKE_COMMAND} -E echo "ISO_DEBIAN128_CD: ${ISO_DEBIAN128_CD}"
COMMAND ${CMAKE_COMMAND} -E echo "ISO_DEBIAN128_DVD: ${ISO_DEBIAN128_DVD}"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_HOME: ${VBOX_DISK_HOME}"
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_4GB: ${VM_RAWDISK_4GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_8GB: ${VM_RAWDISK_8GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_16GB: ${VM_RAWDISK_16GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_32GB: ${VM_RAWDISK_32GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_64GB: ${VM_RAWDISK_64GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_4GB: ${VBOX_DISK_4GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_8GB: ${VBOX_DISK_8GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_16GB: ${VBOX_DISK_16GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_32GB: ${VBOX_DISK_32GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_64GB: ${VBOX_DISK_64GB}"
COMMAND ${CMAKE_COMMAND} -E echo "VM_HOSTNAME: ${VM_HOSTNAME}"
COMMAND ${CMAKE_COMMAND} -E echo "VM_DOMAIN: ${VM_DOMAIN}"
COMMENT "Printing VM environment variables"
)
######################################
# TARG: write_vm_env
# PROC: init/env
# DESC: Print Virtual Machine Environment to vm_env.sh
######################################
add_custom_target(
write_vm_env
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_HOME=${VBOX_HOME}" > vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VM_HYPER_TYPE=${VM_HYPER_TYPE}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_VM_HOME=${VBOX_VM_HOME}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_CMD=${VBOX_CMD}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "QEMU_PATH=${QEMU_PATH}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VM_NAME=${VM_NAME}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "ISO_HOME=${ISO_HOME}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "ISO_DEBIAN128_CD=${ISO_DEBIAN128_CD}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "ISO_DEBIAN128_DVD=${ISO_DEBIAN128_DVD}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_HOME=${VBOX_DISK_HOME}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_4GB=${VM_RAWDISK_4GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_8GB=${VM_RAWDISK_8GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_16GB=${VM_RAWDISK_16GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_16GB=${VM_RAWDISK_32GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VM_RAWDISK_16GB=${VM_RAWDISK_64GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_4GB=${VBOX_DISK_4GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_8GB=${VBOX_DISK_8GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_16GB=${VBOX_DISK_16GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_32GB=${VBOX_DISK_32GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VBOX_DISK_64GB=${VBOX_DISK_64GB}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VM_HOSTNAME=${VM_HOSTNAME}" >> vm_env.sh
COMMAND ${CMAKE_COMMAND} -E echo "VM_DOMAIN=${VM_DOMAIN}" >> vm_env.sh
#COMMAND ${CMAKE_COMMAND} -E env bash -c "build/vm_env.sh 2>&1" || (echo 'Fail to export ENV.' && exit 1)
#COMMAND ${CMAKE_COMMAND} -E env -- bash -c "source vm_env.sh"
COMMENT "Writing VM environment variables to vm_env.sh"
)
######################################
## CHECK REQUIRMENT TOOLS
######################################
add_custom_target(
check_tools
DEPENDS check_or_create_directory
DEPENDS log/vbox
DEPENDS log/qemu
DEPENDS log/udisksctl
DEPENDS log/losetup
DEPENDS log/gdisk
DEPENDS log/fdisk
DEPENDS log/mkswap
DEPENDS log/mkfs
DEPENDS log/falloc
DEPENDS log/deboot
COMMENT "Checking tools installation"
VERBATIM
)
add_custom_target(
check_or_create_directory
COMMAND ${CMAKE_COMMAND} -E echo "Checking if directory ${VBOX_HOME} exists..."
COMMAND ${CMAKE_COMMAND} -E make_directory ${VBOX_HOME}
COMMAND ${CMAKE_COMMAND} -E echo "Directory ${VBOX_HOME} is ready."
COMMAND ${CMAKE_COMMAND} -E make_directory ${VBOX_VM_HOME}
COMMAND ${CMAKE_COMMAND} -E echo "Directory ${VBOX_VM_HOME} is ready."
COMMAND ${CMAKE_COMMAND} -E make_directory ${QEMU_HOME}
COMMAND ${CMAKE_COMMAND} -E echo "Directory ${QEMU_HOME} is ready."
COMMAND ${CMAKE_COMMAND} -E make_directory ${ISO_HOME}
COMMAND ${CMAKE_COMMAND} -E echo "Directory ${ISO_HOME} is ready."
COMMAND ${CMAKE_COMMAND} -E make_directory log
COMMENT "Checking and creating directory"
)
add_custom_target(
clean_cmake
COMMAND ${CMAKE_COMMAND} -E rm -rf ${CMAKE_BINARY_DIR}/*
DEPENDS unloop_raw_disk
DEPENDS unmounting_raw_disk
COMMENT "Cleaning the build directory and unmount and unloop device... ${CMAKE_BINARY_DIR}"
)
add_custom_target(
setup_env
#if ( ${VM_HYPER_TYPE} STREQUAL "VBOX" )
#message(STATUS "YAELAAAH...")
DEPENDS write_vm_env print_vm_env check_or_create_directory
COMMENT "Checking and setting..."
)
#=========================================
########## COMMAND ############
######################################
# COMD: log/deboot
# PROC: init/check
# DESC: Checking `debootstrap` availability
######################################
add_custom_command(
OUTPUT log/deboot
COMMAND ${CMAKE_COMMAND} -E env bash -c "which ${DEBOOT_PATH} > log/deboot 2>&1 || (echo '`debootstrap` not installed. Please install `debootstrap`.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "`debootstrap` found at ${DEBOOT_PATH}."
COMMENT "Checking `debootstap` installation..."
VERBATIM
)
######################################
# COMD: log/falloc
# PROC: init/check
# DESC: Checking `fallocate` availability
######################################
add_custom_command(
OUTPUT log/falloc
COMMAND ${CMAKE_COMMAND} -E env bash -c "which ${FALLO_PATH} > log/falloc 2>&1 || (echo '`fallocate` not installed. Please install `fallocate`.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "`fallocate` found at ${FALLO_PATH}."
COMMENT "Checking `fallocate` installation..."
VERBATIM
)
######################################
# COMD: log/losetup
# PROC: init/check
# DESC: Checking `losetup` availability
######################################
add_custom_command(
OUTPUT log/losetup
COMMAND ${CMAKE_COMMAND} -E env bash -c "which ${LOSETUP_PATH} > log/losetup 2>&1 || (echo '`losetup` not installed. Please install `losetup`.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "`losetup` found at ${LOSETUP_PATH}."
COMMENT "Checking `losetup` installation..."
VERBATIM
)
######################################
# COMD: log/mkswap
# PROC: init/check
# DESC: Checking `mkswap` availability
######################################
add_custom_command(
OUTPUT log/mkswap
COMMAND ${CMAKE_COMMAND} -E env bash -c "which ${MKSWAP_PATH} > log/mkswap 2>&1 || (echo '`mkswap` not installed. Please install `mkswap`.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "`mkswap` found at ${MKSWAP_PATH}."
COMMENT "Checking `mkswap` installation..."
VERBATIM
)
######################################
# COMD: log/mkfs
# PROC: init/check
# DESC: Checking `mkfs` availability
######################################
add_custom_command(
OUTPUT log/mkfs
COMMAND ${CMAKE_COMMAND} -E env bash -c "which ${MKFS_PATH} > log/mkfs 2>&1 || (echo '`mkfs` not installed. Please install `mkfs`.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "`mkfs` found at ${MKFS_PATH}."
COMMENT "Checking `mkfs` installation"
VERBATIM
)
######################################
# COMD: log/fdisk
# PROC: init/check
# DESC: Checking `fdisk` availability
######################################
add_custom_command(
OUTPUT log/fdisk
COMMAND ${CMAKE_COMMAND} -E env bash -c "which ${FDISK_PATH} > log/fdisk 2>&1 || (echo '`fdisk` not installed. Please install `fdisk`.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "`fdisk` found at ${FDISK_PATH}."
COMMENT "Checking `fdisk` installation"
VERBATIM
)
######################################
# COMD: log/gdisk
# PROC: init/check
# DESC: Checking `gdisk` availability
######################################
add_custom_command(
OUTPUT log/gdisk
COMMAND ${CMAKE_COMMAND} -E env bash -c "which ${GDISK_PATH} > log/gdisk 2>&1 || (echo '`gdisk` not installed. Please install `gdisk`.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "`gdisk` found at ${GDISK_PATH}."
COMMENT "Checking `gdisk` installation"
VERBATIM
)
######################################
# COMD: log/udisksctl
# PROC: init/check
# DESC: Checking `udisksctl` availability
######################################
add_custom_command(
OUTPUT log/udisksctl
COMMAND ${CMAKE_COMMAND} -E env bash -c "which ${UDISKCTL_PATH} > log/udiskctl 2>&1 || (echo '`udiskctl` not installed. Please install `udiskctl`.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "`udiskctl` found at ${UDISKCTL_PATH}."
COMMENT "Checking `udiskctl` installation"
VERBATIM
)
######################################
# COMD: log/vbox
# PROC: init/check
# DESC: Checking Virtual Box availability
######################################
add_custom_command(
OUTPUT log/vbox
COMMAND ${CMAKE_COMMAND} -E env sh -c "which ${VBOX_CMD} > log/vbox 2>&1 || (echo 'VBOX not installed. Please install VirtualBox.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "VBOX found at ${VBOX_CMD}."
COMMENT "Checking VBOX installation"
VERBATIM
)
######################################
# COMD: log/qemu
# PROC: init/check
# DESC: Checking Qemu availability
######################################
add_custom_command(
OUTPUT log/qemu
COMMAND ${CMAKE_COMMAND} -E env bash -c "which ${QEMU_PATH} > log/qemu 2>&1 || (echo 'QEMU not installed. Please install QEMU.' && exit 1)"
COMMAND ${CMAKE_COMMAND} -E echo "QEMU found at ${QEMU_PATH}."
COMMENT "Checking QEMU installation"
VERBATIM
)
########## VBOX TARGET ##########
add_custom_target(
build_empty_vbox_4gb
COMMAND ${VBOX_CMD} storageattach ${VM_NAME} --storagectl "SATA01" --port 1 --device 0 --type hdd --medium ${VBOX_DISK_HOME}/${VM_NAME}.vdi
DEPENDS ${VBOX_VM_HOME}/${VM_NAME}/${VM_NAME}.vbox
DEPENDS ${VBOX_DISK_HOME}/${VM_NAME}.vdi
DEPENDS setup_env
COMMENT "Building empty VBOX 4GB Virtual Machine"
)
add_custom_target(
demolish_empty_vbox_4gb
COMMAND ${VBOX_CMD} unregistervm ${VM_NAME} --delete-all
COMMENT "Demolish empty VBOX 4GB Virtual Machine"
)
#
add_custom_target(
vbox_showvminfo
IF( EXISTS ${VBOX_HOME}/${VM_NAME}/${VM_NAME}.vbox )
COMMAND ${VBOX_CMD} showvminfo ${VM_NAME}
ENDIF()
COMMENT "Show information of VBOX 4GB Virtual Machine"
)
########## VBOX COMMAND ##########
#### Create empty 4GB VDI
add_custom_command(
OUTPUT ${VBOX_DISK_HOME}/${VM_NAME}.vdi
COMMAND ${VBOX_CMD} createmedium disk --filename ${VBOX_DISK_HOME}/${VM_NAME} --format=VDI --variant Standard --size=3500
COMMENT "Create 4GB VDI..."
VERBATIM
)
#### Create empty 8GB VDI
add_custom_command(
OUTPUT ${VBOX_DISK_HOME}/${VBOX_DISK_8GB}
COMMAND ${VBOX_CMD} createmedium disk --filename ${VBOX_DISK_HOME}/${VBOX_DISK_8GB} --format=VDI --variant Standard --size=7500
COMMENT "Create 8GB VDI..."
VERBATIM
)
#### Create empty 16GB VDI
add_custom_command(
OUTPUT ${VBOX_DISK_HOME}/${VBOX_DISK_16GB}
COMMAND ${VBOX_CMD} createmedium disk --filename ${VBOX_DISK_HOME}/${VBOX_DISK_16GB} --format=VDI --variant Standard --size=15500
COMMENT "Create 16GB VDI..."
)
#### Create empty 32GB VDI
add_custom_command(
OUTPUT ${VBOX_DISK_HOME}/${VBOX_DISK_32GB}
COMMAND ${VBOX_CMD} createmedium disk --filename ${VBOX_DISK_HOME}/${VBOX_DISK_32GB} --format=VDI --variant Standard --size=31500
COMMENT "Create 32GB VDI..."
)
#### Create empty 64GB VDI
add_custom_command(
OUTPUT ${VBOX_DISK_HOME}/${VBOX_DISK_64GB}
COMMAND ${VBOX_CMD} createmedium disk --filename ${VBOX_DISK_HOME}/${VBOX_DISK_64GB} --format=VDI --variant Standard --size=63500
COMMENT "Create 64GB VDI..."
)
#### Create VBOX Virtual Machine
add_custom_command(
OUTPUT ${VBOX_VM_HOME}/${VM_NAME}/${VM_NAME}.vbox
COMMAND ${VBOX_CMD} createvm --basefolder=${VBOX_VM_HOME} --name ${VM_NAME} --register
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --description "Klaudizen Lab ${VM_NAME}"
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --memory=2048 --vram=128 --acpi=on --ioapic=on --cpus=3 --pae=on --long-mode=on
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --hwvirtex=on --paravirt-provider=kvm --nested-paging=on --nested-hw-virt=on
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --chipset=piix3
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --graphicscontroller vmsvga
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --tpm-type 2.0
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --firmware efi64
COMMAND ${VBOX_CMD} modifynvram ${VM_NAME} inituefivarstore
COMMAND ${VBOX_CMD} modifynvram ${VM_NAME} enrollmssignatures
COMMAND ${VBOX_CMD} modifynvram ${VM_NAME} enrollorclpk
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --mouse=ps2 --keyboard=ps2
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --uart1 0x3f8 4 --uart-type1=16550A --uart-mode1 server /tmp/vbox
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --nic1=nat --nic-type1=Am79C973 --cable-connected1=on
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --nat-pf1 "SSH,tcp,,2200,,22"
COMMAND ${VBOX_CMD} modifyvm ${VM_NAME} --nat-pf1 "VNC,tcp,,15900,,5900"
COMMAND ${VBOX_CMD} storagectl ${VM_NAME} --name "SATA01" --add sata --controller IntelAHCI
COMMAND ${VBOX_CMD} storageattach ${VM_NAME} --storagectl "SATA01" --port 0 --device 0 --type dvddrive --medium ${ISO_HOME}/${ISO_DEBIAN128_CD}
COMMENT "Create VBOX VM ${VM_NAME}"
)
#### Control VBOX Virtual Machine
##### Partition Setup #####
add_custom_command(
OUTPUT ${VBOX_VM_HOME}/${VM_NAME}/partsetup
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_LIST_DIR}/mnt
COMMAND ${VBOX_IMG} info --filename ${VBOX_DISK_HOME}/${VM_NAME}.vdi
COMMAND ${VBOX_IMG_MOUNT} --image ${VBOX_DISK_HOME}/${VM_NAME}.vdi ${CMAKE_CURRENT_LIST_DIR}/mnt
COMMENT "Information of ${VM_NAME}'s VDI..."
)