컨테이너: UFS(Union File System)

Seongho Jang·2023년 7월 13일
0

1. UFS(Union File system)

Unionfs is a filesystem service for Linux, FreeBSD and NetBSD which implements
a union mount for other file systems. It allows files and directories of
separate file systems, known as branches, to be transparently overlaid,
forming a single coherent file system. Contents of directories which have the
same path within the merged branches will be seen together in a single merged
directory, within the new, virtual filesystem(UnionFs, wikipedia).

  • 즉, 여러 file system으로 나뉘어져 있는 directories를 하나의 합쳐진 directory로 만드는 virtual file system.

  • overlayfs와 aufs가 존재

1) AUFS(Advanced Multi Layered Unification Filesystem)

  • linux kernel main stream에는 포함되어 있지 않음, 따라서 별도의 설치 이후 이용

Docker originally used aufs for container filesystem layers. It is still available as one of the storage backends but is deprecated in favour of the overlay2 backend which uses OverlayFS(aufs, wikipedia).

#aufs 설치
$ apt-get install aufs-tools
#aufs 사용
#device는 보통 none: 두 directory를 mount할 것이기 때문
$ sudo mount -t aufs -o br={branch_path1}:{branch_path2}:.. udba={option} {{device} {unify_path}
  • 권한을 설정하지 않은 경우, 첫번째 브랜치는 쓰기 가능으로 열리고, 나머지 브랜치는 읽기 전용으로 열림

  • CoW(Copy-on-Write)방식을 사용하므로, RO(Read Only)으로 열린 branch_path2이후의 브랜치는 파일이 변경되지 않고, RW(Read Write)로 열린 brach_path1에 복사하여 변경본이 저장됨

  • udba(User's Direct Branch Access): 추가옵션으로 브랜치에서 발생하는 파일 생성/변경을 동기화 하는 방법을 변경할 수 있음

    • udba=none: 가장 빠른 동작방식, 하지만 변경 데이터가 바로 동기화되지 않을 수 있음
    • udba=reval: 변경사항이 있을 시 바로 변경하도록 하는 옵션
    • udba=notify: inotify를 이용 브랜치 directory의 변경사항을 알림, aufs성능에 영향
$ sudo mount -t aufs -o br=/l_rw=rw:/l_01=ro+wh:/l_02=ro+wh:/l_03=ro+wh none /mnt
  • 이 경우 l_rw는 RW로 나머지는 RO와 WH(WhiteOut)으로 열림

(1) Read, Write

layerfilefile
/mntfile01file02
/l_rwfile02
l_01file01
l_02file02
l_03file01
  • 해당 상황에서는 file01은 l_01, l_03에 존재, file02는 l_02에 존재함

  • /mnt는 현재보이는 파일이고, /ㅣ_rw는 변경된 파일이 저장되는 곳, 나머지는 unify한 RO layer.

  • file01과 같이 겹치는 경우에는 위와 같이 l_01의 파일만이 보임

  • file02는 변경사항이 있는 경우인데, 이때 AUFS는 변경된 파일의 일부가 아닌 전체를 l_rw에 복사함

  • mnt에서는 변경된 파일만이 보이지만, l_02의 원본파일도 유지됨.

(2) Remove

layerfilefile
/mnt(file01)
/l_rw.wh.file01
l_01file01.wh.file02
l_02file02
l_03file01
  • file01을 삭제한 경우 l_rw에 .wh파일을 생성해 아래 layer의 파일을 읽지 못하게 함

  • 이렇게 해서 l_01, l_02의 file01은 유지

  • l_01에 file02에 대한 .wh파일이 존재함, 이때 권한으로 wh을 주었기 때문에 file02는 가려짐

  • .wh..wh..opq라는 whiteout파일이 존재하는데, 이 때는 해당 폴더의 모든 파일을 mnt에서 볼 수 없음.

정리

  • RO layer는 변경이 불가능하므로 Base Image Layer로 다른 컨테이너와 공유하여 사용이 가능

  • Docker Snapshot수행시 RW layer폴더만 복사하여 이미지로 보관하고, 해당 Layer를 다른 컨테이너의 RO layer로 이용도 가능함.

2) Overlay File System

In computing, OverlayFS is a union mount filesystem implementation for Linux. It combines multiple different underlying mount points into one, resulting in single directory structure that contains underlying files and sub-directories from all sources. Common applications overlay a read/write partition over a read-only partition, such as with LiveCDs and IoT devices with limited flash memory write cycles(OverlayFs, wikipedia).

$ mount -t overlay overlay -o lowerdir={path1}:..:{path_n}, upper={upper_path},workdir={work_path} {merge_path}
  • 리눅스 커널에 기본적으로 내장되어 있다고 함

  • workdir는 upperdir와 같은 file system으로 빈 directory로 준비(어떤 필요인지는 아직 못찾음)

  • 방식은 위의 AUFS와 비슷(CoW, White-out)

  • 주로 이걸 사용하는듯

AUFS 관련 참고1

AUFS 관련 참고2

0개의 댓글