Microsoft MVP성태의 닷넷 이야기
Windows: 257. Windows - Symbolic (hard/soft) Link 및 Junction 차이점 [링크 복사], [링크+제목 복사],
조회: 3485
글쓴 사람
정성태 (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)
13697정성태7/26/2024386닷넷: 2283. C# - async 메서드에서의 lock/Monitor.Enter/Exit 잠금 처리파일 다운로드1
13696정성태7/26/2024297오류 유형: 920. dotnet publish - error NETSDK1047: Assets file '...\obj\project.assets.json' doesn't have a target for '...'
13695정성태7/25/2024327닷넷: 2282. C# - Lock / Wait 상태에서도 STA COM 메서드 호출 처리파일 다운로드1
13694정성태7/25/2024306닷넷: 2281. C# - ASP.NET Core Web App의 Request 용량 상한값 (Kestrel, IIS)
13693정성태7/24/2024457개발 환경 구성: 717. Visual Studio - C# 프로젝트에서 레지스트리에 등록하지 않은 COM 개체 참조 및 사용 방법파일 다운로드1
13692정성태7/24/2024458디버깅 기술: 199. Windbg - 리눅스에서 뜬 닷넷 응용 프로그램 덤프 파일에 포함된 DLL의 Export Directory 탐색
13691정성태7/23/2024521디버깅 기술: 198. Windbg - 스레드의 Win32 Message Queue 정보 조회
13690정성태7/23/2024533오류 유형: 919. Visual C++ 리눅스 프로젝트 - error : ‘u8’ was not declared in this scope
13689정성태7/22/2024526디버깅 기술: 197. Windbg - PE 포맷의 Export Directory 탐색
13688정성태7/21/2024661닷넷: 2280. C# - Lock / Wait 상태에서도 일부 Win32 메시지 처리파일 다운로드1
13687정성태7/19/2024675닷넷: 2279. C# - PostThreadMessage로 보낸 메시지를 Windows Forms에서 수신하는 방법파일 다운로드1
13686정성태7/19/2024625오류 유형: 918. Visual Studio - ATL Simple Object 추가 시 error C2065: 'IDR_...': undeclared identifier
13685정성태7/19/2024693스크립트: 66. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법 - 두 번째 이야기
13684정성태7/19/2024865닷넷: 2278. C# - 문자열 보간식 사례
13683정성태7/18/2024874오류 유형: 917. ClrMD - Linux 환경의 .NET 5 덤프 분석 시 hang 현상
13682정성태7/18/2024944닷넷: 2277. WPF - 스레드에 종속되는 DependencyObject파일 다운로드1
13681정성태7/17/20241014닷넷: 2276. C# 13 - (2) 메서드 그룹의 자연 타입 개선 (메서드 추론 개선)파일 다운로드1
13680정성태7/16/20241030닷넷: 2275. C# - Method Group, Natural Type, function_type파일 다운로드1
13679정성태7/16/20241040Linux: 75. Linux - C++ (getaddrinfo 등을 담고 있는) libnss 정적 링크
13678정성태7/15/2024897VS.NET IDE: 191. Visual Studio 2022 - .NET 5 프로젝트를 Docker Support로 실행했을 때 오류
13677정성태7/15/20241032오류 유형: 916. MSBuild - CheckEolTargetFramework (warning NETSDK1138)
13676정성태7/14/2024996Linux: 75. gdb에서 glibc의 함수에 Breakpoint 걸기
13675정성태7/13/2024987C/C++: 166. C/C++ - DLL에서 template 함수를 export하는 방법파일 다운로드1
13674정성태7/13/20241042오류 유형: 915. Unhandled Exception: Microsoft.Diagnostics.NETCore.Client.ServerNotAvailableException: Unable to connect to Process
13673정성태7/11/20241065닷넷: 2274. C# 13 - (1) 신규 이스케이프 시퀀스 '\e'파일 다운로드1
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...