Skip to content

Renaming directory created during Docker build fails with EXDEV (overlay2, btrfs, redirect_dir=N) #2338

@gerardo-navarro

Description

@gerardo-navarro

Describe the bug

Renaming a directory that was created during docker build (i.e., a directory in an overlay2 lower layer) inside an OrbStack container fails with EXDEV (Invalid cross-device link) at runtime. This does not occur with Docker Desktop, causing OrbStack to not be fully drop-in compatible for builds or apps expecting to rename such directories. The error seems related to kernel overlay2 settings and btrfs as the backing filesystem.

Impact: Any application that calls rename() on a directory created during image build will fail at runtime. As a real-world example, GitLab's scripts/regenerate-schema renames db/migrate/ temporarily and fails on OrbStack but works on Docker Desktop.

To Reproduce

  1. Create the following Dockerfile:
FROM debian:bookworm-slim
RUN mkdir -p /test/mydir && touch /test/mydir/file.txt
CMD ["bash", "-c", "mv /test/mydir /test/mydir__ && echo 'rename OK' && mv /test/mydir__ /test/mydir"]
  1. Run:
docker build -t exdev-test .
docker run --rm exdev-test

Expected: "rename OK"
Actual: mv: cannot move '/test/mydir' to '/test/mydir__': Invalid cross-device link

Alternatively, this fails in Ruby as well:

File.rename("/test/mydir", "/test/mydir__")
# => Errno::EXDEV: Invalid cross-device link

Environment:

  • OrbStack kernel: 6.17.8-orbstack-00308-g8f9c941121b1
  • Host: macOS (Apple Silicon)
  • Overlay parameters: redirect_dir = N, metacopy = N, redirect_always_follow = Y
  • Backing filesystem: btrfs

Expected behavior

Directories created during image build should be able to be renamed at runtime in containers running under OrbStack, matching behavior of Docker Desktop (using the same overlay2 kernel settings, but with ext4 backing FS), so that tools and scripts remain compatible.

Diagnostic report (REQUIRED)

No response

Screenshots and additional context (optional)

Analysis:

OrbStack's kernel overlay2 module has redirect_dir=N. The Linux kernel cannot rename directories that reside in a lower overlay layer and returns EXDEV unless the redirect_dir feature is enabled. While Docker Desktop also has redirect_dir=N, it does not show this error—possibly due to its use of ext4 (vs btrfs on OrbStack) as the backing filesystem or a difference in how its LinuxKit kernel handles this case.

References:

Possible fix:

  • Enable redirect_dir=on in OrbStack's kernel config (aware of diff driver tradeoff)
  • Or replicate the workaround/behavior from Docker Desktop's kernel

Metadata

Metadata

Assignees

No one assigned

    Labels

    t/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions