lima-vm/lima · error

failed to find data slice in attached disk

Error message

failed to find data slice in attached disk

What it means

After attaching the disk image, patchWriteGuestFiles expects the attach result to expose a Data volume device. If the attach result is nil or its Data field is empty, the code cannot locate the data slice device path and returns this error instead of proceeding to mount.

Source

Thrown at pkg/guestpatch/macos/macos_darwin.go:58

// LaunchDaemon plist, init script, and setup markers via a noowners
// mount, then fixes file ownership by patching APFS inode records
// directly on the raw disk image. No sudo required.
func Patch(ctx context.Context, disk string) error {
	if err := patchWriteGuestFiles(ctx, disk); err != nil {
		return err
	}
	return patchFixOwnership(ctx, disk)
}

// patchWriteGuestFiles attaches the disk image, mounts the Data
// volume with noowners, writes guest files, then detaches.
func patchWriteGuestFiles(ctx context.Context, disk string) error {
	attached, err := attachImageWithRetry(ctx, disk, 3)
	if err != nil {
		return fmt.Errorf("failed to attach disk: %w", err)
	}
	if attached == nil || attached.Data == "" {
		return errors.New("failed to find data slice in attached disk")
	}
	dataDevPath := "/dev/" + attached.Data
	defer func() {
		// Detaching the data slice is enough to detach the whole ASIF.
		if err := asifutil.DetachASIF(dataDevPath); err != nil {
			logrus.WithError(err).Warnf("failed to detach %#q (%#q)", dataDevPath, disk)
		}
	}()

	instDir := filepath.Dir(disk)
	mnt := filepath.Join(instDir, filenames.MntDir)
	if err := os.MkdirAll(mnt, 0o755); err != nil {
		return fmt.Errorf("failed to create mount point %#q: %w", mnt, err)
	}
	defer func() {
		if err := os.Remove(mnt); err != nil {
			logrus.WithError(err).Warnf("failed to remove mount point %#q", mnt)
		}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Inspect the disk image's partition layout and confirm a data/cidata volume exists.
  2. Recreate or repair the instance disk so it contains the expected data slice.
  3. Upgrade/verify the attach code path returns the full slice mapping (all volumes).
  4. Recreate the instance if its disk predates the current image format.

Example fix

// before: attaching a legacy disk without a data slice
attached, _ := attachImageWithRetry(ctx, disk, 3) // attached.Data == ""
// after: validate image before patch
if err := verifyDataSlicePresent(disk); err != nil {
	return fmt.Errorf("disk %s has no data slice; recreate instance: %w", disk, err)
}
Defensive patterns

Strategy: validation

Validate before calling

// check the attach result for a usable data slice before mounting
if attached == nil || attached.Data == "" {
	return fmt.Errorf("no data slice on %s; recreate the instance disk", disk)
}

Try / catch

if err := patchWriteGuestFiles(ctx, disk); err != nil {
	if strings.Contains(err.Error(), "failed to find data slice") {
		log.Errorf("disk %s lacks a data volume; recreate or upgrade the instance", disk)
		return errSkipPatch
	}
	return err
}

Prevention

When it happens

Trigger: Patch -> patchWriteGuestFiles when attachImageWithRetry succeeds but returns no Data slice — e.g. an image without a data partition (cidata missing), a partial/legacy image layout, or the ASIF enumeration failing to map the data slice.

Common situations: Instance image created by an older Lima version without the expected data slice; disk image truncated or rebuilt without the cidata volume; macOS framework returning a result with no data volume mapping.

Related errors


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