ln: failed to create hard link | No such file or directory

Abstract: Resolve ln hard link failures across different filesystems by verifying mount points and using symbolic links instead.

Created: 2026-09-02 by

The "ln: failed to create hard link | No such file or directory" error in Linux typically occurs because the source and destination paths reside on different filesystems. Hard links are physical pointers to the same inode, which is impossible across distinct storage boundaries like local disks and network shares. This guide explains how to verify filesystem boundaries and implement symbolic links as a reliable alternative.

Understanding Hard Link Limitations

To resolve this issue effectively, you must first understand why the ln command fails. A hard link creates a new directory entry that points directly to the same inode (data structure) on the disk as the original file. Because an inode exists only within a single filesystem, the kernel cannot create a hard link if the target location is on a different filesystem than the source. This limitation is not a bug but a fundamental constraint of the POSIX standard for file systems. When you attempt to link a file from your local ext4 partition to a mounted Samba share, the system recognizes two separate filesystem contexts. The operation fails immediately because there is no mechanism to duplicate the inode reference across these boundaries. Many users misinterpret the "No such file or directory" message as a permission problem or a missing path, but it is actually the kernel’s way of stating that the requested cross-filesystem operation is unsupported.

Distinguishing Between Filesystems

Before troubleshooting further, confirm whether your source and destination are indeed on different filesystems. You can use the df command to identify the mount point for each path. If the device identifiers differ, you have confirmed the cross-filesystem barrier. For example, running df /path/to/source might show /dev/sda1, while df /path/to/destination shows a CIFS or NFS mount. This discrepancy is the root cause of the error.

Troubleshooting Network Share Issues

Since the context involves Samba, it is crucial to address the specific behaviors of network file systems. Network protocols like SMB/CIFS often map remote files into the local namespace via FUSE or kernel mounts. These implementations do not support hard links in the traditional sense. Even if the file appears to exist locally, the underlying protocol does not allow the creation of additional directory entries pointing to the same remote inode. If you are working with a Samba share, check the configuration on the server side. While some older configurations might have attempted to emulate hard links, modern standards discourage this due to consistency risks. However, the client-side behavior is the primary constraint here. The client cannot force the server to accept a hard link request if the protocol semantics do not support it. Therefore, relying on hard links for network files is generally discouraged. For more information on managing network connectivity issues that might complicate your file operations, see our guide on Troubleshooting Network-Shared Hard Drive Connection Issues with Samba. Understanding the stability of your connection helps ensure that symbolic links function reliably without interruption.

Implementing Symbolic Links as an Alternative

The most robust solution to bypass the hard link limitation is to use symbolic links (symlinks). Unlike hard links, symbolic links are special files that contain a text string specifying the path to another file. They do not require the source and destination to be on the same filesystem. The operating system handles the resolution of the symlink at runtime, allowing it to traverse local and network boundaries seamlessly. To create a symbolic link, use the -s flag with the ln command. The syntax remains similar: ln -s /path/to/source /path/to/link. This approach works regardless of whether the source is on a local disk, a USB drive, or a Samba share. It is important to note that symbolic links can become broken if the source file is moved or deleted. Always verify that the source path is stable before creating symlinks in production environments. When dealing with complex network setups, ensure that your permissions are correctly configured. Incorrect permissions can sometimes manifest as access errors that look like file-not-found issues. Review our article on Accessing Samba Shared Files Over Internet to ensure that your user accounts have the necessary read and write privileges on both the source and destination paths.

Verifying Symlink Functionality

After creating a symbolic link, verify its integrity using the ls -l command. Symlinks are displayed with an arrow (->) indicating the target path. You can also use the file command to confirm that the entry is identified as a symbolic link rather than a regular file. If the symlink points to a valid resource, commands like cat or cp will operate on the target file transparently. In scenarios where you need to execute scripts located on network shares, remember that execution permissions must be granted on the actual file, not just the symlink. Check the execution rights on the source file to avoid "Permission denied" errors after linking. For deeper insights into how mounted files are processed by the system, refer to On Which Computer Are Mounted Files Executed?. This knowledge helps prevent unexpected behavior when running applications that rely on linked resources.

Conclusion

The "ln: failed to create hard link" error is a clear indicator of a cross-filesystem operation. By recognizing the limitations of hard links and adopting symbolic links, you can maintain seamless file access across local and network environments. Always validate your filesystem boundaries and ensure proper permissions to avoid similar pitfalls in the future.

Frequently Asked Questions

Can I enable hard links on a Samba share?

Generally, no. Samba supports hard links if the underlying Unix filesystem allows them and the client requests them correctly, but it is not recommended for cross-OS compatibility. Windows clients often struggle with Samba hard links, leading to data inconsistency. Using symbolic links is the safer and more universal approach.

Why does ln say "No such file" when the file clearly exists?

This misleading error message usually indicates that the source and destination are on different filesystems. The kernel aborts the operation before checking file existence because hard links cannot span filesystem boundaries. It is a structural limitation, not a missing file issue.

What happens if I delete the source file of a hard link?

If you delete one name (directory entry) of a hard-linked file, the data remains accessible through any other hard links pointing to the same inode. The data is only removed when the last hard link is deleted. This differs from symbolic links, where deleting the source breaks the link entirely.

How do I fix broken symbolic links?

Broken symlinks appear grayed out in many file managers and show "No such file" when accessed. To fix them, you must recreate the link pointing to the current location of the target file. Use rm to remove the broken link and then ln -s to create a new one with the correct path.

Are there performance differences between hard and symbolic links?

Hard links offer slightly better performance for accessing files because they bypass the extra indirection step required by symbolic links. However, for network files, the latency of the network protocol dominates any minor overhead from symlinks. The convenience of cross-filesystem support makes symbolic links preferable in most mixed-environment setups.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More