Skip to content

cidata: fix virtiofs mounts with a space in the path#5145

Open
ekalinin wants to merge 1 commit into
lima-vm:masterfrom
ekalinin:fix/virtiofs-mount-path-with-spaces
Open

cidata: fix virtiofs mounts with a space in the path#5145
ekalinin wants to merge 1 commit into
lima-vm:masterfrom
ekalinin:fix/virtiofs-mount-path-with-spaces

Conversation

@ekalinin

@ekalinin ekalinin commented Jun 22, 2026

Copy link
Copy Markdown

Problem

A vz + virtiofs mount whose host path contains a space (e.g. /Volumes/External HD, /tmp/lima space test) is never mounted in the guest, and no error is reported — the mount silently does not appear. External drives on macOS commonly contain spaces, so this affects a common setup. Surfaced downstream in Colima (abiosoft/colima#1471).

Root cause

cloud-init's cc_mounts writes each mount into /etc/fstab with a bare "\t".join(fields) and does not octal-escape the mount point (canonical/cloud-init#3603). A space/tab in the path produces an unparsable fstab line that mount(8) silently skips because of the nofail option, so the mount never appears:

lima-9661e8fd74e6c9ad /tmp/lima space test    virtiofs        rw,nofail,comment=cloudconfig   0       0

(findmnt --verify reports parse error at line N -- ignored.)

Fix

cc_mounts already creates the mount-point directory from the unescaped value, so only the fstab line needs repair. The escape/decode logic lives in two small, self-tested helper scripts under pkg/cidata/cidata.TEMPLATE.d/util/, following the compare_version.sh convention:

  • util/escape_fstab.sh — octal-escapes the mount-point field of cloud-config virtiofs entries read on stdin. Parsing with -F'\t' isolates the field reliably and makes the pass idempotent (an already-escaped path has no literal space/tab), so it is also forward-compatible with a fixed cloud-init.
  • util/unescape_fstab.sh — the inverse decode, used by the SELinux remount in 05-lima-mounts.sh and (replacing an identical inline sed) by 04-persistent-data-volume.sh.

boot.Linux/05-lima-mounts.sh now repairs the fstab via escape_fstab.sh, runs mount -t virtiofs -a, and decodes via unescape_fstab.sh before the SELinux remount. Both helpers are unit-tested via an embedded SELFTEST block (SELFTEST=1 ./util/escape_fstab.sh), like compare_version.sh; .ls-lint.yml carries the snake_case exceptions.

No Go/template changes. The fix is scoped to vz + virtiofs; it complements, but does not depend on, the upstream cloud-init fix canonical/cloud-init#6911 (distros will ship that only years from now).

Verified

Built limactl and booted a vz + virtiofs instance mounting /tmp/lima space test:

  • findmnt --verify0 parse errors (was parse error at line 4)
  • mount present; test file reads/writes round-trip host ↔ guest
  • idempotent across reboot — a single \040-escaped fstab line, no duplicate
  • no-space mounts unaffected; no literal \040 directory created
  • SELFTEST=1 passes for both helpers, and escape → unescape round-trips

Fixes: #5136
Link: abiosoft/colima#1471

@ekalinin ekalinin force-pushed the fix/virtiofs-mount-path-with-spaces branch 3 times, most recently from 4927b53 to 2a59527 Compare June 23, 2026 16:14
Comment thread hack/test-templates.sh
Comment thread pkg/cidata/cidata.TEMPLATE.d/boot.Linux/05-lima-mounts.sh
Comment thread pkg/cidata/cidata.TEMPLATE.d/boot.Linux/05-lima-mounts.sh Outdated
@ekalinin ekalinin force-pushed the fix/virtiofs-mount-path-with-spaces branch 2 times, most recently from b3ffef4 to ef7158e Compare June 23, 2026 19:07
Comment thread pkg/cidata/cidata.TEMPLATE.d/util/escape-fstab.sh Outdated
Comment thread pkg/cidata/cidata.TEMPLATE.d/boot.Linux/05-lima-mounts.sh Outdated
Comment thread pkg/cidata/cidata.TEMPLATE.d/util/escape-fstab.sh Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a vz + virtiofs mount failure when the host path contains whitespace by repairing cloud-init–generated /etc/fstab entries and ensuring mount points are correctly (un)escaped when remounting under SELinux. It also factors out fstab unescaping into a reusable utility script.

Changes:

  • Add util/escape_fstab.sh to octal-escape the mount-point field for affected cloud-config virtiofs fstab entries, and trigger a mount -t virtiofs -a pass for vz+virtiofs.
  • Add util/unescape_fstab.sh and use it where mount points must be decoded before being passed to mount(8).
  • Update .ls-lint.yml ignores for the new util scripts.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/cidata/cidata.TEMPLATE.d/util/unescape_fstab.sh New helper to decode fstab/proc-style octal escapes, with selftest.
pkg/cidata/cidata.TEMPLATE.d/util/escape_fstab.sh New helper to rewrite fstab so virtiofs mount points with whitespace are parseable.
pkg/cidata/cidata.TEMPLATE.d/boot.Linux/05-lima-mounts.sh Repairs fstab and remounts virtiofs; decodes escaped mount points for SELinux remount path.
pkg/cidata/cidata.TEMPLATE.d/boot.Linux/04-persistent-data-volume.sh Reuses unescape_fstab.sh for mount-point decoding from /proc/mounts.
.ls-lint.yml Adds ignores for the newly introduced util scripts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/cidata/cidata.TEMPLATE.d/util/escape_fstab.sh
@ekalinin ekalinin force-pushed the fix/virtiofs-mount-path-with-spaces branch 2 times, most recently from 0a2b97d to decc82e Compare June 25, 2026 20:04
@ekalinin

Copy link
Copy Markdown
Author

@AkihiroSuda thanks for the reviews! I think everything is addressed now:

  • the awk/sed are split into self-tested util/escape_fstab.sh and util/unescape_fstab.sh, following the compare_version.sh convention (SELFTEST=1 ./… runs the unit tests)
  • issue references are full URLs
  • the unescape helper also de-duplicates the identical snippet in 04-persistent-data-volume.sh

All review threads are resolved and CI is green. Whenever you have a moment, could you take another look? 🙏

@AkihiroSuda AkihiroSuda added this to the v2.2.0 milestone Jun 29, 2026
@AkihiroSuda

Copy link
Copy Markdown
Member

Please squash the commits

@ekalinin ekalinin force-pushed the fix/virtiofs-mount-path-with-spaces branch 3 times, most recently from 6695408 to d4242b7 Compare June 29, 2026 15:24
A vz + virtiofs mount whose host path contains a space (e.g.
"/Volumes/External HD") was never mounted in the guest, and no error was
reported. cloud-init's cc_mounts writes each mount into /etc/fstab with a bare
"\t".join(fields) and does not octal-escape the mount point, so a space/tab in
the path makes an unparsable line that mount(8) silently skips via nofail.
cc_mounts already creates the directory from the unescaped value, so only the
fstab line needs repair.

Add two self-tested helpers under cidata.TEMPLATE.d/util/ (compare_version.sh
convention):
- escape_fstab.sh: octal-escapes the mount-point field of cloud-config virtiofs
  entries; -F'\t' isolates the field and makes the pass idempotent.
- unescape_fstab.sh: the inverse decode, used by the SELinux remount in
  05-lima-mounts.sh and (replacing an identical inline sed) by
  04-persistent-data-volume.sh.

boot.Linux/05-lima-mounts.sh repairs the fstab via escape_fstab.sh, runs
mount -t virtiofs -a, and decodes via unescape_fstab.sh before the SELinux
remount. No Go/template changes; scoped to vz + virtiofs. Complements, but does
not depend on, the upstream cloud-init fix.

Fixes: lima-vm#5136
Link: abiosoft/colima#1471

Signed-off-by: Eugene Kalinin <e.v.kalinin@gmail.com>
@ekalinin ekalinin force-pushed the fix/virtiofs-mount-path-with-spaces branch from d4242b7 to 36195f4 Compare June 29, 2026 15:26
@ekalinin

Copy link
Copy Markdown
Author

@AkihiroSuda sorry to bother you again, could you help me with this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mounts with a space in the path silently fail to mount (unescaped fstab entry)

3 participants