Skip to content

Commit

Permalink
Create a mount script instead of editing /etc/fstab
Browse files Browse the repository at this point in the history
This enables support for mount points that include spaces. `/etc/fstab`
normally supports encoding special characters in filenames using octal
constants (like "\040` for a space), but that doesn't work on Alpine.

Signed-off-by: Jan Dubois <[email protected]>
(cherry picked from commit eb3d0b7)
  • Loading branch information
jandubois committed Mar 9, 2024
1 parent 68806de commit 3090e82
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lima-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ LIMA_CIDATA_GID=$(id -g "${LIMA_CIDATA_USER}")
chown -R "${LIMA_CIDATA_UID}:${LIMA_CIDATA_GID}" "${LIMA_CIDATA_SSHDIR}"
chmod 600 "${LIMA_CIDATA_SSHDIR}"/authorized_keys

# Add mounts to /etc/fstab
sed -i '/#LIMA-START/,/#LIMA-END/d' /etc/fstab
echo "#LIMA-START" >> /etc/fstab
awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' >> /etc/fstab
# Process mounts
MOUNT_SCRIPT=/etc/lima-mounts
echo "#!/bin/sh -eux" >"${MOUNT_SCRIPT}"
awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' >>"${MOUNT_SCRIPT}"
/^mounts:/ {
flag = 1
next
Expand All @@ -57,15 +57,17 @@ awk -f- "${LIMA_CIDATA_MNT}"/user-data <<'EOF' >> /etc/fstab
flag = 0
}
flag {
# Use a pattern unlikely to appear in a filename. "\0" unfortunately doesn't work.
FS = "<;><><;>"
sub(/^ *- \[/, "")
sub(/"?\] *$/, "")
gsub("\"?, \"?", "\t")
print $0
gsub("\"?, \"?", FS)
printf "mkdir -p \"%s\"\n", $2
printf "mount -t %s -o \"%s\" %s \"%s\"\n", $3, $4, $1, $2
}
EOF
echo "#LIMA-END" >> /etc/fstab
mkmntdirs
mount -a
chmod +x "${MOUNT_SCRIPT}"
"${MOUNT_SCRIPT}"

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

0 comments on commit 3090e82

Please sign in to comment.