abiosoft/colima · error

error creating directory '%s': %w

Error message

error creating directory '%s': %w

What it means

limaVM.Write first creates the target's parent directory with `sudo mkdir -p <dir>` inside the guest before piping bytes via `cat > file`. This error wraps a failure of that mkdir step: sudo unavailable, read-only mount for that path, invalid directory name (e.g. paths with characters the guest shell mishandles), or SSH execution failure. The subsequent file write gets a different (unwrapped) error path.

Source

Thrown at environment/vm/lima/file.go:28

	"strings"
	"time"

	"github.com/abiosoft/colima/environment"
)

func (l limaVM) Read(fileName string) (string, error) {
	s, err := l.RunOutput("sudo", "cat", fileName)
	if err != nil {
		return "", fmt.Errorf("cannot read file '%s': %w", fileName, err)
	}
	return s, err
}

func (l *limaVM) Write(fileName string, body []byte) error {
	var stdin = bytes.NewReader(body)
	dir := filepath.Dir(fileName)
	if err := l.RunQuiet("sudo", "mkdir", "-p", dir); err != nil {
		return fmt.Errorf("error creating directory '%s': %w", dir, err)
	}
	return l.RunWith(stdin, nil, "sudo", "sh", "-c", "cat > "+fileName)
}

func (l *limaVM) Stat(fileName string) (os.FileInfo, error) {
	return newFileInfo(l, fileName)
}

var _ os.FileInfo = (*fileInfo)(nil)

type fileInfo struct {
	isDir   bool
	modTime time.Time
	mode    fs.FileMode
	name    string
	size    int64
}

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Validate the target directory makes sense (absolute, not under a read-only mount) before writing.
  2. Verify guest health: `colima ssh -- sudo mkdir -p <dir>` manually to see the raw failure.
  3. Retry after stop/start for transient states.
  4. Recreate the VM if the guest userspace is corrupted.
Defensive patterns

Strategy: validation

Validate before calling

// sanity-check target before write
if !filepath.IsAbs(fileName) { return fmt.Errorf("guest path must be absolute: %s", fileName) }
if isReadOnlyGuestMount(filepath.Dir(fileName)) { return fmt.Errorf("refusing write to read-only dir: %s", filepath.Dir(fileName)) }

Prevention

When it happens

Trigger: Writing guest files into paths under read-only mounts (e.g. /proc-style or bind-mounted read-only volumes); guest still booting; malformed absolute paths (empty dir, trailing slashes on root); concurrent guest operations breaking sudo.

Common situations: Certificate and config deployment during start; custom scripts writing to unusual guest locations; broken guests after forced shutdowns.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/1795261ce7e0f9ab. Report an issue: GitHub.