From 3090e82d40ed22d37d58e743f6ab21731550c063 Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Tue, 6 Jun 2023 15:16:25 -0700 Subject: [PATCH] Create a mount script instead of editing /etc/fstab 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 (cherry picked from commit eb3d0b78d88db15c365e8f80b4be66b1cb302f3d) --- lima-init.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lima-init.sh b/lima-init.sh index c7b6714..1489da8 100755 --- a/lima-init.sh +++ b/lima-init.sh @@ -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 @@ -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