-
Notifications
You must be signed in to change notification settings - Fork 1
/
virtualbox-iso.pkr.hcl
151 lines (141 loc) · 4.26 KB
/
virtualbox-iso.pkr.hcl
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
variable "iso_url" {
type = string
default = "https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86/alpine-standard-3.18.2-x86.iso"
}
variable "iso_checksum" {
type = string
default = "sha256:4b5d0762629d520422daeaaac55f7a159caee5e93bcab8860b0386ff51bc0e71"
}
variable "vm_name" {
type = string
default = "alpine-3.18.2-x86"
}
variable "guest_os_type_virtualbox" {
type = string
default = "Linux26"
}
variable "guest_os_type_vmware" {
type = string
default = "other5xlinux"
}
variable "install_dev" {
type = string
default = "/dev/sda"
}
variable "msys_dev" {
type = string
default = "/dev/sda3"
}
variable "root_password" {
type = string
default = "vagrant"
}
variable "vagrant_password" {
type = string
default = "vagrant"
}
# https://developer.hashicorp.com/packer/plugins/builders/virtualbox/iso
source "virtualbox-iso" "alpine" {
vm_name = "${var.vm_name}"
communicator = "ssh"
# cdrom_adapter_type = "sata"
disk_size = "8192"
# disk_adapter_type = "nvme"
format = "ova"
guest_additions_mode = "disable"
guest_os_type = "${var.guest_os_type_virtualbox}"
headless = false
iso_checksum = "${var.iso_checksum}"
iso_url = "${var.iso_url}"
# keep_registered = true
output_directory = "output-${var.vm_name}"
shutdown_command = "/sbin/poweroff"
# skip_export = true
ssh_password = "${var.root_password}"
ssh_timeout = "3m"
ssh_username = "root"
usb = true
vboxmanage = [
["modifyvm", "{{ .Name }}", "--memory", "256"],
["modifyvm", "{{ .Name }}", "--vram", "33"],
["modifyvm", "{{ .Name }}", "--ioapic", "on"],
["modifyvm", "{{ .Name }}", "--cpus", "2"],
["modifyvm", "{{ .Name }}", "--rtcuseutc", "on"],
["modifyvm", "{{ .Name }}", "--graphicscontroller", "vmsvga"],
["modifyvm", "{{ .Name }}", "--chipset", "ich9"],
["modifyvm", "{{ .Name }}", "--nic1", "nat"],
["modifyvm", "{{ .Name }}", "--nictype1", "virtio"],
["modifyvm", "{{ .Name }}", "--cableconnected1", "on"],
["modifyvm", "{{ .Name }}", "--nat-localhostreachable1", "on"],
["modifyvm", "{{ .Name }}", "--audio-enabled", "off"],
["modifyvm", "{{ .Name }}", "--audio-in", "off"],
["modifyvm", "{{ .Name }}", "--audio-out", "off"],
["modifyvm", "{{ .Name }}", "--audio-controller", "ac97"],
["modifyvm", "{{ .Name }}", "--vrde", "off"],
["modifyvm", "{{ .Name }}", "--usbohci", "off"],
["modifyvm", "{{ .Name }}", "--usbehci", "off"],
["modifyvm", "{{ .Name }}", "--usbxhci", "off"]
]
# boot_key_interval = "15ms"
boot_wait = "20s"
boot_command = [<<EOF
root<enter><wait1>
date -u -s ${formatdate("YYYYMMDDhhmm.ss", timestamp())}<enter><wait>
hwclock -u -w<enter><wait>
cat<<EOA>answers<enter>
KEYMAPOPTS="us us"<enter>
HOSTNAMEOPTS=alpine<enter>
DEVDOPTS=mdev<enter>
INTERFACESOPTS="auto lo<enter>
iface lo inet loopback<enter>
<enter>
auto eth0<enter>
iface eth0 inet dhcp<enter>
hostname alpine<enter>
"<enter>
DNSOPTS="-d example.com 8.8.8.8"<enter>
TIMEZONEOPTS=UTC<enter>
PROXYOPTS=none<enter>
APKREPOSOPTS=-1<enter>
USEROPTS="-a -u -g audio,video,netdev,dialout vagrant"<enter>
SSHDOPTS=openssh<enter>
NTPOPTS=busybox<enter>
DISKOPTS="-m sys ${var.install_dev}"<enter>
EOA<enter><wait>
setup-alpine -f answers<enter><wait10>
${var.root_password}<enter><wait1>
${var.root_password}<enter><wait20s>
y<enter><wait20s>
mount ${var.msys_dev} /mnt<enter><wait>
echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config<enter><wait>
cat /mnt/etc/apk/repositories<enter><wait>
umount /mnt<enter><wait1>
reboot<enter><wait1>
EOF
]
}
build {
sources = [
"source.virtualbox-iso.alpine"
]
provisioner "shell" {
inline = [
"echo 'vagrant:${var.vagrant_password}' | chpasswd",
"sed '/PermitRootLogin yes/d' -i /etc/ssh/sshd_config"
]
}
provisioner "shell" {
scripts = [
"x-apk-update.sh",
"x-only-virtualbox.sh",
"x-provision.sh",
"x-vmdiskclean.sh"
]
}
post-processor "shell-local" {
inline = [
"echo convert ${var.vm_name}.ova to ${var.vm_name}.box...",
"perl perl-ova2box.pl output-${var.vm_name}/${var.vm_name}.ova output-${var.vm_name}/${var.vm_name}.box"
]
}
}