Skip to content

Commit a4b10ce

Browse files
authored
Merge pull request #124 from rancher-sandbox/mount-script
Create a mount script instead of editing /etc/fstab
2 parents 68806de + 3090e82 commit a4b10ce

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lima-init.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ LIMA_CIDATA_GID=$(id -g "${LIMA_CIDATA_USER}")
4545
chown -R "${LIMA_CIDATA_UID}:${LIMA_CIDATA_GID}" "${LIMA_CIDATA_SSHDIR}"
4646
chmod 600 "${LIMA_CIDATA_SSHDIR}"/authorized_keys
4747

48-
# Add mounts to /etc/fstab
49-
sed -i '/#LIMA-START/,/#LIMA-END/d' /etc/fstab
50-
echo "#LIMA-START" >> /etc/fstab
51-
awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' >> /etc/fstab
48+
# Process mounts
49+
MOUNT_SCRIPT=/etc/lima-mounts
50+
echo "#!/bin/sh -eux" >"${MOUNT_SCRIPT}"
51+
awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' >>"${MOUNT_SCRIPT}"
5252
/^mounts:/ {
5353
flag = 1
5454
next
@@ -57,15 +57,17 @@ awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' >> /etc/fstab
5757
flag = 0
5858
}
5959
flag {
60+
# Use a pattern unlikely to appear in a filename. "\0" unfortunately doesn't work.
61+
FS = "<;><><;>"
6062
sub(/^ *- \[/, "")
6163
sub(/"?\] *$/, "")
62-
gsub("\"?, \"?", "\t")
63-
print $0
64+
gsub("\"?, \"?", FS)
65+
printf "mkdir -p \"%s\"\n", $2
66+
printf "mount -t %s -o \"%s\" %s \"%s\"\n", $3, $4, $1, $2
6467
}
6568
EOF
66-
echo "#LIMA-END" >> /etc/fstab
67-
mkmntdirs
68-
mount -a
69+
chmod +x "${MOUNT_SCRIPT}"
70+
"${MOUNT_SCRIPT}"
6971

7072
# Rename network interfaces according to network-config setting
7173
mkdir -p /var/lib/lima-init

0 commit comments

Comments
 (0)