lima-vm/lima · error

failed to write raw digest file: %w

Error message

failed to write raw digest file: %w

What it means

The computed raw digest is first written to imgconv/raw.digest.tmp, then renamed to raw.digest for atomicity. If os.WriteFile cannot create/write the tmp file, this error is returned. A failing write here almost always means the cache directory is unwritable or the disk is full.

Source

Thrown at pkg/downloader/downloader.go:516

	}
	if err := os.Rename(rawPathTmp, rawImgConvPath); err != nil {
		return "", "", fmt.Errorf("failed to replace original with raw image: %w", err)
	}

	algo := digest.Canonical
	if originalDigest != "" {
		algo = originalDigest.Algorithm()
	}
	rawDigest, err := calculateFileDigest(rawImgConvPath, algo)
	if err != nil {
		return "", "", fmt.Errorf("failed to calculate digest of raw image: %w", err)
	}

	rawDigestPath := filepath.Join(imgConvPath, "raw.digest")
	rawDigestPathTmp := rawDigestPath + ".tmp"
	defer os.Remove(rawDigestPathTmp)
	if err := os.WriteFile(rawDigestPathTmp, []byte(rawDigest.String()), 0o644); err != nil {
		return "", "", fmt.Errorf("failed to write raw digest file: %w", err)
	}
	if err := os.Remove(rawDigestPath); err != nil && !errors.Is(err, os.ErrNotExist) {
		return "", "", fmt.Errorf("failed to remove stale raw digest file %q: %w", rawDigestPath, err)
	}
	if err := os.Rename(rawDigestPathTmp, rawDigestPath); err != nil {
		return "", "", fmt.Errorf("failed to rename raw digest file: %w", err)
	}

	return rawImgConvPath, rawDigest, nil
}

func calculateFileDigest(path string, algo digest.Algorithm) (digest.Digest, error) {
	f, err := os.Open(path)
	if err != nil {
		return "", err
	}
	defer f.Close()

View on GitHub (pinned to dd909d0973)

Solutions

  1. Free disk space on the cache volume (df -h) — raw conversion can consume large amounts
  2. Fix ownership/permissions of the cache directory so the running user can write (chown -R)
  3. Delete the affected cache entry and retry the download from scratch
  4. Point LIMA_HOME/cache at a volume with sufficient free space

Example fix

// before
# df -h ~/.lima/_cache  -> 100% used
// after
$ df -h ~/.lima/_cache  # ensure free space, or:
$ limactl rm <instance> && rm -rf ~/.lima/_cache/download/by-url-sha256/<hash>
Defensive patterns

Strategy: validation

Validate before calling

// ensure enough free space before downloading/converting large images
var st unix.Statfs_t
if err := unix.Statfs(cacheDir, &st); err == nil {
    avail := int64(st.Bavail) * st.Bsize
    if avail < 20<<30 { return fmt.Errorf("only %d bytes free in cache volume", avail) }
}

Try / catch

if err != nil && strings.Contains(err.Error(), "failed to write raw digest file") {
    // check ENOSPC vs EACCES and act accordingly
    return fmt.Errorf("cache volume full or unwritable; free space or fix perms: %w", err)
}

Prevention

When it happens

Trigger: os.WriteFile(rawDigestPathTmp, ..., 0o644) fails with ENOSPC (disk full), EACCES (imgconv dir not writable by current user), or ENOENT (imgconv dir deleted mid-run).

Common situations: Host cache volume out of space after writing a large raw image; cache dir owned by root while lima runs unprivileged; another process wiped imgconv during conversion.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/65539c7ee6a74951. Report an issue: GitHub.