Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

uv warns it failed to hardlink files and copies them instead

Your error

Failed to hardlink files; falling back to full copy. This may lead to degraded performance.2 more lines it can show

Fix it fast

Most common cause, 1 of 3

A BuildKit cache mount keeps the uv cache apart from the image layer

Declare copy mode before the RUN step.

Fix
ENV UV_LINK_MODE=copy

RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --locked
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

uv prints Failed to hardlink files; falling back to full copy when its cache and the .venv sit on different filesystems. A Docker cache mount, a .venv volume beside a bind-mounted project, or a Windows project on another drive cause it. The install still succeeds. Set UV_LINK_MODE=copy, or move UV_CACHE_DIR beside the project. Applies to uv 0.13.

  • Applies to uv 0.13, Docker with BuildKit, Linux, macOS and Windows hosts
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Ask uv where its cache lives, then compare the mount behind that folder with the mount behind the environment. Two different Mounted on values confirm a filesystem split.

Run this first
uv cache dir
df "$(uv cache dir)" .venv

Then find the line you see in this list and open its fix:

  1. 1A BuildKit cache mount keeps the uv cache apart from the image layerThe warning appears during docker build, on a RUN line that starts with --mount=type=cache,target=/root/.cache/uv
  2. 2In a dev container, .venv sits on a volume while the cache stays in the containerThe warning shows up when uv sync runs inside a running container that was started with --volume .:/app --volume /app/.venv, or a compose file with similar volumes
  3. 3On Windows the project lives on a different drive from the cacheNo Docker involved; the project is on D: or a network drive while uv cache dir prints a path under C:\Users\<you>\AppData\Local\uv\cache

What does the error look like?

  • Failed to hardlink files; falling back to full copy. This may lead to degraded performance.
  • If the cache and target directories are on different filesystems, hardlinking may not be supported.
  • If this is intentional, set `export UV_LINK_MODE=copy` or use `--link-mode=copy` to suppress this warning.

Cause 1 of 3

A BuildKit cache mount keeps the uv cache apart from the image layer

You seeThe warning appears during docker build, on a RUN line that starts with --mount=type=cache,target=/root/.cache/uv

Check

During a Docker build, uv shows Failed to hardlink files because the cache mount is a separate filesystem from the layer where uv sync writes .venv. On Linux uv first tries a copy-on-write clone, then a hard link, and both fail across that boundary. uv's Docker guide pins the warning on exactly this split between cache and sync target.

Check
grep -n "mount=type=cache" Dockerfile

Fix

Declare copy mode before the RUN step. Files are copied from the mounted cache, so you keep the download savings and lose only the link speed-up, which this setup cannot use anyway.

Fix
ENV UV_LINK_MODE=copy

RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --locked

Verify

Rebuild without the layer cache. The uv step ends with its install summary and no hardlink warning.

Verify
docker build --no-cache --progress=plain . 2>&1 | grep -i hardlink || echo clean

Confirmed by docs.astral.sh

Did this fix it?

Cause 2 of 3

In a dev container, .venv sits on a volume while the cache stays in the container

You seeThe warning shows up when uv sync runs inside a running container that was started with --volume .:/app --volume /app/.venv, or a compose file with similar volumes

Check

uv's guide for developing in a container bind-mounts the project and keeps /app/.venv on an anonymous volume. That volume is its own filesystem, while the default cache under /root/.cache/uv belongs to the container's writable layer. Every sync inside the container then has to copy.

Check
docker exec <container> df /root/.cache/uv /app/.venv

Fix

Pass copy mode into the container with -e, or bake ENV UV_LINK_MODE=copy into the dev image. Pointing UV_CACHE_DIR at a folder on the same volume as the environment is the other option, and it lets links work again.

Fix
docker run --rm -e UV_LINK_MODE=copy \
  --volume .:/app --volume /app/.venv <image> uv sync

Verify

Run uv sync in the container again. It completes without the warning.

Verify
docker exec <container> uv sync

Confirmed by docs.astral.sh

Did this fix it?

Cause 3 of 3

On Windows the project lives on a different drive from the cache

You seeNo Docker involved; the project is on D: or a network drive while uv cache dir prints a path under C:\Users\<you>\AppData\Local\uv\cache

Check

uv's settings reference lists hardlink as the default link mode on Windows and %LOCALAPPDATA%\uv\cache as the default cache folder. A project kept on another drive therefore sits on another filesystem, and the hard link attempt falls back to copying.

Check
uv cache dir

Fix

Move the cache to the project's drive with UV_CACHE_DIR, then let uv rebuild the environment. If the cache must stay on C:, set UV_LINK_MODE to copy instead.

Fix
# PowerShell, for the current session
$env:UV_CACHE_DIR = "D:\uv-cache"
uv sync --reinstall

Verify

uv cache dir now prints the D: folder and uv sync finishes with no warning.

Verify
uv cache dir

Confirmed by docs.astral.sh

Did this fix it?

How do I stop it coming back?

  • Put ENV UV_LINK_MODE=copy at the top of every Dockerfile that uses a uv cache mount, next to the uv binary COPY line.
  • List .venv in .dockerignore; an environment made on your laptop is tied to its platform and should be rebuilt inside the image.
  • On Windows, keep the uv cache on the drive that holds your projects and set UV_CACHE_DIR in the user environment.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.