-
Notifications
You must be signed in to change notification settings - Fork 11
/
custom-config.fcc
132 lines (116 loc) · 3.79 KB
/
custom-config.fcc
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
variant: fcos
version: 1.1.0
storage:
files:
- path: /etc/systemd/network/99-default.link
mode: 420
contents:
inline: |
[Link]
NamePolicy=mac
MACAddressPolicy=persistent
- path: /etc/NetworkManager/conf.d/10-dhcp-config.conf
mode: 420
contents:
inline: |
[main]
no-auto-default=*
dhcp=dhclient
- path: /usr/local/bin/capture-macs
mode: 0755
contents:
inline: |
#!/usr/bin/env bash
set -ex
echo "Processing MAC addresses"
cmdline=( $(</proc/cmdline) )
karg() {
local name="$1" value="${2:-}"
for arg in "${cmdline[@]}"; do
if [[ "${arg%%=*}" == "${name}" ]]; then
value="${arg#*=}"
fi
done
echo "${value}"
}
# Wait for device nodes
udevadm settle
macs="$(karg macAddressList)"
if [[ -z $macs ]]; then
echo "No MAC addresses specified."
exit 1
fi
export PRIMARY_MAC=$(echo $macs | awk -F, '{print $1}')
export SECONDARY_MAC=$(echo $macs | awk -F, '{print $2}')
mount "/dev/disk/by-label/boot" /boot
echo -e "PRIMARY_MAC=${PRIMARY_MAC}\nSECONDARY_MAC=${SECONDARY_MAC}" > /boot/mac_addresses
- path: /usr/local/bin/create-datastore
mode: 0755
contents:
inline: |
#!/bin/bash
LABEL=datastore
OFFSET=120G
set -euo pipefail
cmdline=( $(</proc/cmdline) )
karg() {
local name="$1" value="${2:-}"
for arg in "${cmdline[@]}"; do
if [[ "${arg%%=*}" == "${name}" ]]; then
value="${arg#*=}"
fi
done
echo "${value}"
}
# Get install device
device="$(karg coreos.inst.install_dev)"
if [[ -z $device ]]; then
echo "Install device not specified."
exit 1
fi
# Append /dev/ if missing
device="/dev/${device##/dev/}"
# Wait for device nodes
udevadm settle
# Check for partitions other than the system ones
if lsblk --pairs --output NAME,TYPE,PARTLABEL "${device}" |\
awk '/TYPE="part"/ && !/PARTLABEL="(boot|EFI-SYSTEM|BIOS-BOOT|root|luks_root)"/ {print; exit 1}'
then
echo "Creating data partition \"${LABEL}\""
# Relocate second GPT header to end of disk and create partition
sgdisk --move-second-header \
--new=0:+"${OFFSET}":0 --change-name=0:"${LABEL}" \
"${device}"
# Wait for device node
udevadm settle
else
echo "Found existing data partition; not creating a new one"
fi
systemd:
units:
- name: capture-macs.service
enabled: true
contents: |
[Unit]
Description=Capture MAC address from kargs
After=create-datastore.service
Before=coreos-installer.target
ConditionKernelCommandLine=custom-config
[Service]
Type=oneshot
ExecStart=/usr/local/bin/capture-macs
[Install]
RequiredBy=coreos-installer.target
- name: create-datastore.service
enabled: true
contents: |
[Unit]
Description=Create data partition if one doesn't already exist
After=coreos-installer.service
Before=coreos-installer.target
ConditionKernelCommandLine=custom-config
[Service]
Type=oneshot
ExecStart=/usr/local/bin/create-datastore
[Install]
WantedBy=coreos-installer.target