- NTFS junction point
-
An NTFS junction point is a feature of the NTFS file system that provides the ability to create a symbolic link to a directory which then functions as an alias of that directory. This has many benefits over a Windows shell shortcut (.lnk) file, such as allowing access to files within the directory via Windows Explorer, the Command Prompt, etc.
Junction points can only link to directories on a local volume; junction points to remote shares are unsupported.[1]
Junction points are a type of NTFS reparse point; they were introduced with NTFS 3.0, the default file system for Windows 2000 (Windows NT 5.0). The Windows 2000 and Windows 2003 Resource Kits include a program called linkd,[2] to create junction points; Mark Russinovich of Winternals released a tool called junction[3] which provided more complete functionality. Windows XP includes
fsutil reparsepoint
. Windows NT 6.0 and later operating systems include an mklink command-line utility for creating junction points.Contents
Warning
- Microsoft strongly recommends:[4]
- Use NTFS ACLs to protect junction points from inadvertent deletion.
- Use NTFS ACLs to protect files and directories targeted by junction points from inadvertent deletion or other file system operations.
- Never delete a junction point using Explorer, a del /s command, or other file system utilities that walk recursively into directory trees. These utilities will affect the target directory and all subdirectories. Instead, use the utilities described below to delete junction points.
- Use caution when applying ACLs or changing file compression in a directory tree that includes NTFS Junction Points.
- Do not create namespace cycles with NTFS or DFS junction points.
- Place all junction points at a secure location in a namespace where they can be tested safely, and other users will not mistakenly delete them or walk through them.
- Obscure: There are issues relating to junction points on Windows 2000 domain controllers & certain Active Directory files.[5]
Examples of use
Program redirection
By setting a junction point that points to a directory containing a particular version of a piece of software, it may be possible to add another version of the software and redirect the junction point to point to the version desired.
Avoiding manual file synchronization
Sometimes you may require that two directories have exactly the same contents. If a separate directory is created for this, the two directories must also be kept in sync. Using an NTFS junction instead of a second directory can avoid this.
Saving disk space
Since the contents of a junction do not take up any space (they simply point to the original files in the original directory) if you need to have multiple points of entry to a large directory, junction points will serve that purpose well. Do not confuse junction points with a copy of something as it simply points to the original. If directories need to be modified separately a junction cannot be used as it does not provide a distinct copy of the directory or files within.
Circumventing pre-defined paths
Since reinstalling Windows (or installing a new version) often requires deleting the contents of the C: drive, it is advantageous to create multiple partitions so only one partition needs to be deleted during the installation. However, some programs don't let the user choose the installation directory, or install some of their files to the C: drive even when they are installed to a different drive. By creating a junction point, the program can be tricked into installing to a different directory.
Obtaining a list of junction points
A list of all the junctions present on a disk volume can be obtained from an elevated Command Prompt as Admin by executing "dir /aL /s C:\", where "C:" is the volume to scan.
Observed effects
Windows 2000/XP/2003
Windows Explorer
- Deleting a junction point using Windows Explorer will delete the targeted files immediately if using shift-delete.
- If the junction point is sent to the Recycle Bin, the targeted files will look safe, but will be deleted when the Recycle Bin is emptied.
- Moving the junction point to a different location on the same drive only moves the junction point. However, moving it to another drive turns the junction point into a regular directory and moves all files there (leaving the original targeted directory empty). Undoing the move puts the junction directory and its contents back on the original drive, but the original targeted directory is still empty (that is, the junction is not recreated).
- While walking through the directory with Windows Explorer, use shift-delete to delete directories; however, files can be deleted normally. Disabling the recycle bin for the drive hosting the junction point will allow regular deletion of folders.
Command Prompt (cmd.exe)
- The dir command in Windows 2000 or later recognizes junction points, displaying
<JUNCTION>
instead of<DIR>
in directory listings (use dir with the/A
or/AL
command-line switch). - Any commands that would normally affect files inside a normal directory will act the same here. Thus the command
del myjunction
should not be used — this will just delete all the files in the targeted directory. - The commands rmdir and move work fine with junctions, with the caveat that
move
won't let the junction move to another volume (as opposed to Windows Explorer, as mentioned above.) - The rmdir command is safe in that it only deletes the junction point, not the targeted files.
- Whilst walking through the directory with the command line interface, files can be deleted, but unlike explorer, directories can also be deleted (using
rmdir /s dirname
for example.) - Using the
linkd
command with the/d
switch is a safe way to delete junction points. - Windows XP and above,
fsutil reparsepoint delete
safely deletes junction points. - The command
attrib myjunction
appended with -s -h -a -r will not work on a junction.
General
- An infinite loop in the file structure can be created by placing a junction point in the directory it targets. This can confuse some tools which scan entire directory trees but do not check for junctions, such as Antivirus tools, which end up recursing until they crash or create a path name longer than 255 characters which causes a Windows API error and stops the recursion. Windows Vista and Windows 7 have an example of this in "
C:\Users\%USERNAME%\AppData\Local\Application Data
". Here "Application Data
" is a junction that points to "C:\Users\%USERNAME%\AppData\Local\
" for compatibility with legacy applications. - ACL inheritance is by design based on volumes and not working across junctions.
Windows Vista/7
Windows in common
Junction points are useless on removable media, even when they redirect to itself. The reason is that the target destination is converted to an absolute path (including drive letter) and stored on the destination point. On another computer the drive will be normally mapped on a different drive which results in void links. To avoid this misbehavior you must use symbolic links to directories, which is restricted on Windows Vista/7 to administrators.
Windows Explorer
- Junction points are indicated with a shortcut overlay.
- Deleting a junction point using Explorer is now safe.
- A junction point can be restored from the recycle bin.
Symbolic link
Main article: NTFS symbolic linkWindows Vista supports a new symbolic link capability that replaces junction points in Windows 2000 and Windows XP. They are designed to aid in migration and application compatibility with UNIX operating systems.[6]
Unlike a junction point, a symbolic link can also point to a file or remote SMB network path. Additionally, the NTFS symbolic link implementation provides full support for cross-filesystem links. However, the functionality enabling cross-host symbolic links requires that the remote system also support them, which effectively limits their support to Windows Vista and later Windows operating systems.
References
- ^ Sysinternals Junction documentation
- ^ Microsoft Knowledge Base, 2007-02-20, How to create and manipulate NTFS junction points, http://support.microsoft.com/kb/205524/en-us
- ^ Mark Russinovich, 2010-09-08, Junction, http://technet.microsoft.com/en-us/sysinternals/bb896768
- ^ "How to create and manipulate NTFS junction points". Microsoft. http://support.microsoft.com/kb/205524. Retrieved 2007-08-08.
- ^ Neohapsis.
- ^ "Symbolic Links". MSDN. http://msdn2.microsoft.com/en-us/library/aa365680.aspx. Retrieved 2007-07-20.
External links
- Microsoft Knowledge Base Article – 'How to Create and Manipulate NTFS Junction Points'
- Junction command line utility from Microsoft TechNet
- Codeproject Article – discussion on the source code of a junction point utility, aimed at programmers
- PC Mag Article about adding any directory to the start menu (allowing a preview within the startmenu as a submenu).
- Link Shell Extension - free software to work with junctions, hard links, symbolic links and more complex features like Hardlink Clones and Symboliclink Clones.
- GetFoldersize - free software to list all junctions, hard links and symbolic links on your hard drive.
Categories:- Disk file systems
- Windows disk file systems
- Microsoft strongly recommends:[4]
Wikimedia Foundation. 2010.