Microsoft MVP성태의 닷넷 이야기
Windows: 257. Windows - Symbolic (hard/soft) Link 및 Junction 차이점 [링크 복사], [링크+제목 복사],
조회: 11310
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  82  [83]  84  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11896정성태5/15/201925112개발 환경 구성: 440. C#, C++ - double의 Infinity, NaN 표현 방식파일 다운로드1
11895정성태5/12/201922651.NET Framework: 832. ML.NET Model Builder - 회귀(Regression), 다중 분류(Multi-class classification) 예제파일 다운로드1
11894정성태5/10/201924594VS.NET IDE: 135. Visual Studio - ML.NET Model Builder 소개 [5]
11893정성태5/10/201920640오류 유형: 535. C# 6.0 이상의 문법을 컴파일 시 오류가 발생한다면?
11892정성태5/10/201920519웹: 38. HTTP Cookie의 expires 시간 형식(RFC7231)
11891정성태5/9/201923648.NET Framework: 831. (번역글) .NET Internals Cookbook Part 12 - Memory structure, attributes, handles
11890정성태5/8/201919341개발 환경 구성: 439. "Visual Studio Enterprise is required to execute the test." 메시지와 관련된 코드 기록
11889정성태5/8/201919407개발 환경 구성: 438. mstest, QTAgent의 로그 파일 설정 방법
11888정성태5/8/201937314.NET Framework: 830. C# - 비동기 호출을 취소하는 CancellationToken의 간단한 예제 코드 [1]파일 다운로드1
11887정성태5/8/201923106.NET Framework: 829. C# - yield 문을 사용할 수 있는 메서드의 조건
11886정성태5/7/201920176오류 유형: 534. mstest.exe 실행 시 "Visual Studio Enterprise is required to execute the test." 오류 [2]
11885정성태5/7/201917651오류 유형: 533. mstest.exe 실행 시 "File extension specified '.loadtest' is not a valid test extension." 오류 발생
11884정성태5/5/201922575.NET Framework: 828. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 두 번째 이야기
11883정성태5/3/201927562.NET Framework: 827. C# - 인터넷 시간 서버로부터 받은 시간을 윈도우에 적용하는 방법파일 다운로드1
11882정성태5/2/201924065.NET Framework: 826. (번역글) .NET Internals Cookbook Part 11 - Various C# riddles파일 다운로드1
11881정성태4/28/201924170오류 유형: 532. .NET Core 프로젝트로 마이그레이션 시 "CS0579 Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute" 오류 발생
11880정성태4/25/201919889오류 유형: 531. 이벤트 로그 오류 - Task Scheduling Error: m->NextScheduledSPRetry 1547, m->NextScheduledEvent 1547
11879정성태4/24/201928783.NET Framework: 825. (번역글) .NET Internals Cookbook Part 10 - Threads, Tasks, asynchronous code and others파일 다운로드2
11878정성태4/22/201924107.NET Framework: 824. (번역글) .NET Internals Cookbook Part 9 - Finalizers, queues, card tables and other GC stuff파일 다운로드1
11877정성태4/22/201924290.NET Framework: 823. (번역글) .NET Internals Cookbook Part 8 - C# gotchas파일 다운로드1
11876정성태4/21/201922520.NET Framework: 822. (번역글) .NET Internals Cookbook Part 7 - Word tearing, locking and others파일 다운로드1
11875정성태4/21/201924360오류 유형: 530. Visual Studo에서 .NET Core 프로젝트를 열 때 "One or more errors occurred." 오류 발생
11874정성태4/20/201924393.NET Framework: 821. (번역글) .NET Internals Cookbook Part 6 - Object internals파일 다운로드1
11873정성태4/19/201923082.NET Framework: 820. (번역글) .NET Internals Cookbook Part 5 - Methods, parameters, modifiers파일 다운로드1
11872정성태4/17/201923949.NET Framework: 819. (번역글) .NET Internals Cookbook Part 4 - Type members파일 다운로드1
11871정성태4/16/201921815.NET Framework: 818. (번역글) .NET Internals Cookbook Part 3 - Initialization tricks [3]파일 다운로드1
... 76  77  78  79  80  81  82  [83]  84  85  86  87  88  89  90  ...