forked from coreos/fedora-coreos-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coreos-boot-mount-generator
executable file
·73 lines (58 loc) · 2.08 KB
/
coreos-boot-mount-generator
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
#!/bin/bash
set -euo pipefail
# Generators don't have logging right now
# https://github.com/systemd/systemd/issues/15638
exec 1>/dev/kmsg; exec 2>&1
UNIT_DIR="${1:-/tmp}"
add_wants() {
local name="$1"; shift
local wants_dir="${UNIT_DIR}/local-fs.target.wants"
mkdir -p "${wants_dir}"
ln -sf "../${name}" "${wants_dir}/${name}"
}
# If there's already an /etc/fstab entries for /boot, then this is is a non-FCOS
# system, likely RHCOS pre-4.3 (which still used Anaconda). In that case, we
# don't want to overwrite what the systemd-fstab-generator will do.
if findmnt --fstab /boot &>/dev/null; then
exit 0
fi
mk_mount() {
local unit_name="${1}.mount"; shift
local label="${1}"; shift
local mount_pt="/${1:-$label}"
local path="/dev/disk/by-label/${label}"
eval $(udevadm info --query property --export "${path}")
local device="dev-disk-by\x2dlabel-${label//-\x2d}"
if [ "${DM_NAME:-x}" != "x" ]; then
device="dev-mapper-${DM_NAME}"
path="/dev/mapper/${DM_NAME}"
fi
echo "coreos-boot-mount-generator: using ${device} for ${label} mount to ${mount_pt}"
cat > "${UNIT_DIR}/${unit_name}" <<EOF
# Automatically created by coreos-boot-mount-generator
[Unit]
Description=CoreOS Dynamic Mount for ${path}
Documentation=https://github.com/coreos/fedora-coreos-config
Before=local-fs.target
After=${device}.device
Requires=${device}.device
Requires=systemd-fsck@${device}.service
After=systemd-fsck@${device}.service
[Mount]
What=${path}
Where=${mount_pt}
EOF
add_wants "${unit_name}"
}
# Don't create mount units for /boot or /boot/efi on live systems.
# ConditionPathExists won't work here because conditions don't affect
# the dependency on the underlying device unit.
if [ ! -f /run/ostree-live ]; then
mk_mount boot boot
# Only mount the EFI System Partition on machines where it exists,
# which are 1) machines actually booted through EFI, and 2) x86_64
# when booted through BIOS.
if [ "$(uname -m)" = "x86_64" -o -d /sys/firmware/efi ]; then
mk_mount boot-EFI-SYSTEM EFI-SYSTEM "boot/EFI-SYSTEM"
fi
fi