From 753f883c35d0bd52002ce2d049a26bb1ae37c122 Mon Sep 17 00:00:00 2001 From: Atemu Date: Sat, 22 Oct 2022 23:55:04 +0200 Subject: [PATCH] stage-1: escape mount points and options mountFS adds these strings to fstab and then relies on `mount` parsing fstab. If they have spaces or tabs in them, that would break fstab and therefore not mount with the unhelpful error: No such file or directory. Co-authored-by: Lily Foster Co-authored-by: Luflosi --- nixos/modules/system/boot/stage-1-init.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index 994aa0e33cbf..4596c160a957 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -342,6 +342,14 @@ checkFS() { return 0 } +escapeFstab() { + local original="$1" + + # Replace space + local escaped="${original// /\\040}" + # Replace tab + echo "${escaped//$'\t'/\\011}" +} # Function for mounting a file system. mountFS() { @@ -569,7 +577,7 @@ while read -u 3 mountPoint; do continue fi - mountFS "$device" "$mountPoint" "$options" "$fsType" + mountFS "$device" "$(escapeFstab "$mountPoint")" "$(escapeFstab "$options")" "$fsType" done exec 3>&-