@@ -18,6 +18,75 @@ users:
18
18
{{- end}}
19
19
20
20
write_files :
21
+ - content : |
22
+ #!/bin/sh
23
+ # This script pretends that /bin/ash can be used as /bin/bash, so all following
24
+ # cloud-init scripts can use `#!/bin/bash` and `set -o pipefail`.
25
+ test -f /etc/alpine-release || exit 0
26
+
27
+ # Redirect bash to ash (built with CONFIG_ASH_BASH_COMPAT) and hope for the best :)
28
+ # It does support `set -o pipefail`, but not `[[`.
29
+ # /bin/bash can't be a symlink because /bin/ash is a symlink to /bin/busybox
30
+ cat >/bin/bash <<'EOF'
31
+ #!/bin/sh
32
+ exec /bin/ash "$@"
33
+ EOF
34
+ chmod +x /bin/bash
35
+ owner: root:root
36
+ path: /var/lib/cloud/scripts/per-boot/00-alpine-ash-as-bash.boot.sh
37
+ permissions: '0755'
38
+ - content : |
39
+ #!/bin/bash
40
+ set -eux -o pipefail
41
+
42
+ # Restrict the rest of this script to Alpine until it has been tested with other distros
43
+ test -f /etc/alpine-release || exit 0
44
+
45
+ # Data directories that should be persisted across reboots
46
+ DATADIRS="/home /usr/local /etc/containerd /var/lib/containerd"
47
+
48
+ # When running from RAM try to move persistent data to data-volume
49
+ # FIXME: the test for tmpfs mounts is probably Alpine-specific
50
+ if [ "$(awk '$2 == "/" {print $3}' /proc/mounts)" == "tmpfs" ]; then
51
+ mkdir -p /mnt/data
52
+ if [ -e /dev/disk/by-label/data-volume ]; then
53
+ mount -t ext4 /dev/disk/by-label/data-volume /mnt/data
54
+ else
55
+ # Find an unpartitioned disk and create data-volume
56
+ DISKS=$(lsblk --list --noheadings --output name,type | awk '$2 == "disk" {print $1}')
57
+ for DISK in ${DISKS}; do
58
+ IN_USE=false
59
+ # Looking for a disk that is not mounted or partitioned
60
+ for PART in $(awk '/^\/dev\// {gsub("/dev/", ""); print $1}' /proc/mounts); do
61
+ if [ "${DISK}" == "${PART}" -o -e /sys/block/${DISK}/${PART} ]; then
62
+ IN_USE=true
63
+ break
64
+ fi
65
+ done
66
+ if [ "${IN_USE}" == "false" ]; then
67
+ echo 'type=83' | sfdisk --label dos /dev/${DISK}
68
+ PART=$(lsblk --list /dev/${DISK} --noheadings --output name,type | awk '$2 == "part" {print $1}')
69
+ mkfs.ext4 -L data-volume /dev/${PART}
70
+ mount -t ext4 /dev/disk/by-label/data-volume /mnt/data
71
+ for DIR in ${DATADIRS}; do
72
+ DEST="/mnt/data$(dirname ${DIR})"
73
+ mkdir -p ${DIR} ${DEST}
74
+ mv ${DIR} ${DEST}
75
+ done
76
+ break
77
+ fi
78
+ done
79
+ fi
80
+ for DIR in ${DATADIRS}; do
81
+ if [ -d /mnt/data${DIR} ]; then
82
+ [ -e ${DIR} ] && rm -rf ${DIR}
83
+ ln -s /mnt/data${DIR} ${DIR}
84
+ fi
85
+ done
86
+ fi
87
+ owner: root:root
88
+ path: /var/lib/cloud/scripts/per-boot/05-persistent-data-volume.boot.sh
89
+ permissions: '0755'
21
90
- content : |
22
91
#!/sbin/openrc-run
23
92
supervisor=supervise-daemon
@@ -35,34 +104,24 @@ write_files:
35
104
path: /var/lib/lima-guestagent/lima-guestagent.openrc
36
105
permissions: '0755'
37
106
- content : |
38
- #!/bin/sh
39
- # This script prepares Alpine for lima; there is nothing in here for other distros
40
- test -f /etc/alpine-release || exit
41
-
42
- # Since we are on Alpine, we can now assume /bin/sh is /bin/ash
107
+ #!/bin/bash
43
108
set -eux -o pipefail
44
109
45
- # Redirect bash to ash (built with CONFIG_ASH_BASH_COMPAT) and hope for the best :)
46
- # (it does support `set -o pipefail`, but not `[[`)
47
- # /bin/bash can't be a symlink because /bin/ash is a symlink to /bin/busybox
48
- cat >/bin/bash <<'EOF'
49
- #!/bin/sh
50
- exec /bin/ash "$@"
51
- EOF
52
- chmod +x /bin/bash
110
+ # This script prepares Alpine for lima; there is nothing in here for other distros
111
+ test -f /etc/alpine-release || exit 0
53
112
54
113
# Configure apk repos
55
- branch =edge
114
+ BRANCH =edge
56
115
VERSION_ID=$(awk -F= '$1=="VERSION_ID" {print $2}' /etc/os-release)
57
- case $VERSION_ID in
58
- *_alpha*|*_beta*) branch =edge;;
59
- *.*.*) branch =v${VERSION_ID%.*};;
116
+ case ${ VERSION_ID} in
117
+ *_alpha*|*_beta*) BRANCH =edge;;
118
+ *.*.*) BRANCH =v${VERSION_ID%.*};;
60
119
esac
61
120
62
- for repo in main community; do
63
- url ="https://dl-cdn.alpinelinux.org/alpine/${branch }/${repo }"
64
- if ! grep -q "^${url }$" /etc/apk/repositories; then
65
- echo "${url }" >> /etc/apk/repositories
121
+ for REPO in main community; do
122
+ URL ="https://dl-cdn.alpinelinux.org/alpine/${BRANCH }/${REPO }"
123
+ if ! grep -q "^${URL }$" /etc/apk/repositories; then
124
+ echo "${URL }" >> /etc/apk/repositories
66
125
fi
67
126
done
68
127
@@ -85,7 +144,7 @@ write_files:
85
144
rc-update add acpid
86
145
rc-service acpid start
87
146
owner: root:root
88
- path: /var/lib/cloud/scripts/per-boot/00 -alpine-prep.boot.sh
147
+ path: /var/lib/cloud/scripts/per-boot/10 -alpine-prep.boot.sh
89
148
permissions: '0755'
90
149
- content : |
91
150
#!/bin/bash
@@ -159,7 +218,7 @@ write_files:
159
218
fi
160
219
owner: root:root
161
220
# We do not use per-once.
162
- path: /var/lib/cloud/scripts/per-boot/10 -base.boot.sh
221
+ path: /var/lib/cloud/scripts/per-boot/20 -base.boot.sh
163
222
permissions: '0755'
164
223
{{- if or .Mounts .Containerd.System .Containerd.User }}
165
224
- content : |
@@ -210,7 +269,7 @@ write_files:
210
269
fi
211
270
{{- end}}
212
271
owner: root:root
213
- path: /var/lib/cloud/scripts/per-boot/20 -install-packages.boot.sh
272
+ path: /var/lib/cloud/scripts/per-boot/30 -install-packages.boot.sh
214
273
permissions: '0755'
215
274
{{- end}}
216
275
{{- if or .Containerd.System .Containerd.User}}
@@ -274,7 +333,7 @@ write_files:
274
333
fi
275
334
{{- end}}
276
335
owner: root:root
277
- path: /var/lib/cloud/scripts/per-boot/30 -install-containerd.boot.sh
336
+ path: /var/lib/cloud/scripts/per-boot/40 -install-containerd.boot.sh
278
337
permissions: '0755'
279
338
{{- end}}
280
339
{{- if .Provision}}
@@ -291,7 +350,7 @@ write_files:
291
350
{{- end}}
292
351
{{- end}}
293
352
owner: root:root
294
- path: /var/lib/cloud/scripts/per-boot/40 -execute-provision-scripts.boot.sh
353
+ path: /var/lib/cloud/scripts/per-boot/50 -execute-provision-scripts.boot.sh
295
354
permissions: '0755'
296
355
{{- end}}
297
356
{{- range $i, $val := .Provision}}
0 commit comments