Microsoft MVP성태의 닷넷 이야기
Windows: 257. Windows - Symbolic (hard/soft) Link 및 Junction 차이점 [링크 복사], [링크+제목 복사],
조회: 13191
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

Windows - Symbolic (hard/soft) Link 및 Junction 차이점

윈도우에 내장한 mklink를 이용하면 특정 디렉터리에 대한 Symbolic Link 및 Junction을 연결할 수 있습니다.

예를 들어 볼까요? ^^ 우선 기존에 사용하던 디렉터리를 가정해 "C:\temp\testdir1"을 만듭니다.

c:\temp> mkdir testdir1

// 실습을 위해 임의 파일도 하나 만듭니다.
c:\temp>echo "TEST" > c:\temp\testdir1\test.txt

이제 우리가 원하는 것은 해당 디렉터리에 대해 "C:\temp\testdir2"라는 새로운 이름을 만들어 연결하는 것입니다. (이때 "C:\temp\testdir2" 경로는 존재하지 않아야 합니다.)

c:\temp> mklink /J "testdir2" "testdir1"

c:\temp> dir
 Volume in drive C has no label.
 Volume Serial Number is 015B-B1A4

 Directory of c:\temp

2024-02-17  오후 02:38    <DIR>          .
2024-02-17  오후 02:31    <DIR>          testdir1
2024-02-17  오후 02:35    <JUNCTION>     testdir2 [c:\temp\testdir1]
               0 File(s)              0 bytes
               3 Dir(s)  340,979,662,848 bytes free

보는 바와 같이 새롭게 명명한 "testdir2"로 "JUCTION" 항목이 하나 추가되고, 탐색기에서 살펴보면 "폴더" 아이콘에 "화살표"가 하나 추가된 것으로 그것이 JUNCTION임을 알 수 있습니다.

junction_dir_1.png

이후부터는 testdir2 경로를 마치 testdir1을 다루듯이 사용할 수 있습니다.

// testdir2의 파일을 나열하도록 명령하면 그것과 연결된 testdir1의 파일을 나열

c:\temp> dir .\testdir2 /b
test.txt

그렇다면 삭제는 어떻게 할까요? 왠지 걱정이 드는 것은, 저렇게 연결되었다는 점에서 혹시 testdir2를 삭제하면 원본인 testdir1도 통째로 날아가는 것은 아닐까요? ^^

재미있게도, 삭제만큼은 연결 기능을 하지 않아 그냥 안전하게 rd 명령어로 제거할 수 있습니다.

// testdir2 junction만 삭제

c:\temp> rd testdir2

// 기존에 연결되었던 디렉터리는 그대로 존재

c:\temp> dir /b
testdir1

물론, rd 명령어가 아닌 "윈도우 탐색기"에서 해당 항목을 삭제해도 됩니다.




Junction에 대해 봤으니, 이제 mklink의 "/D" 옵션으로 연결할 수 있는 symbolic link에 대해서도 살펴보겠습니다. 일례로, C:\Users 디렉터리에서 dir /a 명령을 내려보면,

c:\Users> dir /a
 Volume in drive C has no label.
 Volume Serial Number is 015B-B1A4

 Directory of c:\Users

2024-02-17  오후 11:18    <DIR>          .
2024-02-17  오후 11:28    <DIR>          ..
2022-05-07  오후 02:41    <SYMLINKD>     All Users [C:\ProgramData]
2022-09-27  오후 06:48    <DIR>          Default
2022-05-07  오후 02:41    <JUNCTION>     Default User [C:\Users\Default]
...[생략]...

Junction 외에도 SYMLINKD로 표시되는 항목이 있습니다. 윈도우 탐색기에서는 아이콘이 동일하므로 구분이 안 되는데요, 대신 속성창을 띄워보면 Symolic Link의 경우에는 "Shortcut" 탭이 하나 더 있는 걸로 알아낼 수는 있습니다.

기본적인 수준에서의 동작은 Junction과 (삭제까지도) 다른 점이 없습니다.




그런데, 도대체 그 둘 간의 차이가 뭘까요? 이에 대해 검색해 보면 다음의 글을 찾을 수 있습니다.

Pete Hinchley: Junctions and Symbolic Links
; https://hinchley.net/articles/junctions-and-symbolic-links

가장 뚜렷한 기능상의 차이점은, Junction은 로컬 PC 내에서만 연결을 할 수 있는 반면 Symbolic Link는 원격으로 연결도 가능하다고 합니다. 또한, 연결 결과가 대상에서 이뤄지느냐 로컬에서 이뤄지느냐로 나뉩니다.

가령, 다음과 같이 Junction으로 연결된 상태인 경우,

mklink /J c:\alias c:\target

만약 원격에서 위와 같이 Junction으로 연결된 "\\remote\c$\alias"로 요청을 하면 자동으로 "\\remote\c$\target"에 대한 결과로 이어집니다. 하지만, 만약 Symbolic Link로 연결했다면,

mklink /D c:\alias c:\target

원격에서 "\\remote\c$\alias"로 요청을 한 경우, 서버는 "c:\target" 정보를 클라이언트에 보내게 되고, 결국 (서버 측의 "\\remote\c$\target"이 아닌) 요청한 측의 "c:\target" 디렉터리를 접근하려고 시도하게 됩니다.

참고로, Junction은 (Windows 2000부터 적용한) NTFS 3.0부터 지원한다고 합니다.




마지막으로, Symbolic Link는 유형에 따라 "hard-link"와 "soft-link"로 나뉘는데, hard-link는 원본에 참조 카운트를 유지하는 방법으로 구현하기 때문에 실제 파일을 삭제하려면 원본 및 hard-link를 모두 삭제해야 한다는 특징이 있습니다. 반면, soft-link (및 junction)은 일종의 shortcut처럼 동작하기 때문에 원본을 삭제하면 soft-link와 junction은 더 이상 가리킬 곳이 없는 상태로 존재만 하게 됩니다. 이 외에도 hard-link는 다음과 같은 차이점을 가지고 있습니다.

  • 오직 파일 연결만 가능하고,
  • 연결 대상의 파일이 hard-link를 생성하는 시점에 반드시 존재해야 하고,
  • 같은 볼륨 내에서만 생성 가능 (즉, C:\ 드라이브의 파일을 D:\ 드라이브에서 연결할 수 없음)

그리고 Symbolic link의 연결은 fsutil을 이용해 제어하는 것이 가능합니다.

C:\Windows\System32> fsutil behavior set symlinkevaluation /?
Usage: fsutil behavior set symlinkEvaluation {L2L|L2R|R2L|R2R}:{0|1} [...]

Controls the class of symbolic links that can be traversed when opening files.

 Values: L2L:{0|1} - Controls local-to-local symbolic link evaluation   (default ENABLED)
         L2R:{0|1} - Controls local-to-remote symbolic link evaluation  (default ENABLED)
         R2L:{0|1} - Controls remote-to-local symbolic link evaluation  (default DISABLED)
         R2R:{0|1} - Controls remote-to-remote symbolic link evaluation (default DISABLED)

 Eg:  fsutil behavior set symlinkEvaluation L2L:1 L2R:0
      - Enables local-to-local symbolic link evaluation
      - Disables local-to-remote symbolic link evaluation
      - Does not change the evaluation state of remote-to-remote or remote-to-local links.

This operation takes effect immediately (no reboot required)

보는 바와 같이, Local 내에서의 연결과 Local에서 Remote로의 연결은 기본적으로 활성화돼 있어 fsutil로 변경할 필요 없이 곧바로 생성할 수 있습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 2/18/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
14000정성태8/18/2025253오류 유형: 979. ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory
13999정성태8/15/2025790닷넷: 2355. C# 14 - (8) null 조건부 연산자 개선 - 대입문에도 사용 가능파일 다운로드1
13998정성태8/14/2025830닷넷: 2354. C# 14 - (7) 확장 메서드에 정적 메서드와 속성 지원을 위한 전용 구문 추가파일 다운로드1
13997정성태8/14/2025996Linux: 120. docker 컨테이너로 매핑된 볼륨에 컨테이너 측의 사용자 ID를 유지하면서 복사하는 방법
13996정성태8/13/2025585오류 유형: 978. Unable to find the requested .Net Framework Data Provider.
13995정성태8/13/2025632개발 환경 구성: 754. Visual C++ - 리눅스 빌드를 위한 Ubuntu 18 docker 컨테이너 설정
13994정성태8/12/2025643오류 유형: 977. SQL Server - User, group, or role '...' already exists in the current database. (Microsoft SQL Server, Error: 15023)
13993정성태8/11/2025976오류 유형: 976. Microsoft.ML.OnnxRuntimeGenAI 패키지 사용 시 "cublasLt64_12.dll" which is missing. (Error 126: "The specified module could not be found.") 오류
13992정성태8/11/20251162닷넷: 2353. C# - Foundry Local을 이용한 gpt-oss-20b 모델 사용파일 다운로드1
13991정성태8/9/20251085오류 유형: 975. winget - Foundry Local 패키지 업데이트가 안 되는 문제
13990정성태8/8/2025833Windows: 283. Time zone 설정이 없는 Windows Server 2025
13989정성태8/8/20251224닷넷: 2352. C# - Windows S-mode 환경인지 체크하는 방법파일 다운로드1
13988정성태8/8/20251365오류 유형: 974. 비주얼 스튜디오 업데이트 시 잠김 파일 경고 - Visual Studio Standard Collector Service 150 (VSStandardCollectorService150)
13987정성태8/7/20251030닷넷: 2351. C# 14 - (6) event와 생성자에도 partial 메서드 적용파일 다운로드1
13986정성태8/6/20251115닷넷: 2350. C# 14 - (5) 람다 매개 변수에 접근자가 있는 경우에도 타입 생략 가능파일 다운로드1
13985정성태8/6/20251473오류 유형: 973. "wsl --install" 명령어 수행 시 "The server name or address could not be resolved"
13984정성태8/6/20251246Windows: 282. 윈도우 운영체제에 추가된 ssh 서버(Win32-OpenSSH)
13983정성태8/4/20251336오류 유형: 972. Microsoft.Data.SqlClient 6.1.0 버전부터 .NET 8 이상만 지원
13982정성태8/2/20251754개발 환경 구성: 753. CentOS 7 컨테이너 내에서 openssh 서버 호스팅
13981정성태8/1/20251408오류 유형: 971. CentOS 7에서 yum 사용 시 "Could not resolve host: mirrorlist.centos.org; Unknown error"
13980정성태7/31/20251581Linux: 119. eBPF - BPF_PROG_TYPE_CGROUP_SOCK 유형에서 정상 동작하지 않는 BPF_CORE_READ (2)
13979정성태7/30/20251881Linux: 118. eBPF - BPF_PROG_TYPE_CGROUP_SOCK 유형에서 정상 동작하지 않는 BPF_CORE_READ
13978정성태7/29/20251705오류 유형: 970. 파일 복사 시 "Data error (cyclic redundancy check). (0x80070017)" 에러
13977정성태7/28/20252021닷넷: 2349. C# 14 - (4) 문자열 리터럴을 utf-8 인코딩으로 저장파일 다운로드1
13976정성태7/25/20251867닷넷: 2348. C# - 카카오 카나나 모델 + Microsoft.ML.OnnxRuntimeGenAI 예제파일 다운로드1
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...