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

비밀번호

댓글 작성자
 




... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12401정성태11/5/202010838VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할 [1]
12400정성태11/5/20207775오류 유형: 679. Visual Studio - "Source Not Found" 창에 "Decompile source code" 링크가 없는 경우
12399정성태11/5/202011456.NET Framework: 961. C# 9.0 - (10) 대상으로 형식화된 조건식(Target-typed conditional expressions)파일 다운로드1
12398정성태11/4/202010002오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/202010183.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/20208451VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/20209800오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/20208188오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
12393정성태11/3/20208688오류 유형: 675. Visual Studio - 닷넷 응용 프로그램 디버깅 시 Disassembly 창에서 BP 설정할 때 "Error while processing breakpoint." 오류
12392정성태11/2/202012800.NET Framework: 959. C# 9.0 - (9) 레코드(Records) [4]파일 다운로드1
12390정성태11/1/202011054디버깅 기술: 173. windbg - System.Configuration.ConfigurationErrorsException 예외 분석 방법
12389정성태11/1/202010783.NET Framework: 958. C# 9.0 - (8) 정적 익명 함수 (static anonymous functions)파일 다운로드1
12388정성태10/29/202010248오류 유형: 674. 어느 순간부터 닷넷 응용 프로그램 실행 시 System.Configuration.ConfigurationErrorsException 예외가 발생한다면?
12387정성태10/28/202011033.NET Framework: 957. C# - static 필드의 정보가 GC Heap에 저장될까요? [3]파일 다운로드1
12386정성태10/28/202011264Linux: 34. 사용자 정보를 함께 출력하는 리눅스의 ps 명령어 사용 방법
12385정성태10/28/20209078오류 유형: 673. openssl - req: No value provided for Subject Attribute CN, skipped
12384정성태10/27/202010298오류 유형: 672. AllowPartiallyTrustedCallers 특성이 적용된 어셈블리의 struct 멤버 메서드를 재정의하면 System.Security.VerificationException 예외 발생
12383정성태10/27/202011183.NET Framework: 956. C# 9.0 - (7) 패턴 일치 개선 사항(Pattern matching enhancements) [3]파일 다운로드1
12382정성태10/26/20208903오류 유형: 671. dotnet build - The local source '...' doesn't exist
12381정성태10/26/202010583VC++: 137. C++ stl map의 사용자 정의 타입을 key로 사용하는 방법 [1]파일 다운로드1
12380정성태10/26/20207973오류 유형: 670. Visual Studio - Squash_FailureCommitsReset
12379정성태10/21/202011000.NET Framework: 955. .NET 메서드의 Signature 바이트 코드 분석 [1]파일 다운로드2
12378정성태10/15/202010404.NET Framework: 954. C# - x86/x64 환경에 따라 달라지는 P/Invoke 함수의 export 이름파일 다운로드1
12377정성태10/15/202011712디버깅 기술: 172. windbg - 파일 열기 시점에 bp를 걸어 파일명 알아내는 방법(Managed/Unmanaged)
12376정성태10/15/20208406오류 유형: 669. windbg - sos의 name2ee 명령어 실행 시 "Failed to request module list." 오류
12375정성태10/15/20209794Windows: 177. 윈도우 탐색기에서 띄우는 cmd.exe 창의 디렉터리 구분 문자가 'Yen(&#0165;)' 기호로 나오는 경우 [1]
... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...