12.2. transient-ro를 사용하여 동적 마운트 지점 생성
루트 사용자는 bootc 기능을 사용하여 기본적으로 root.transient-ro읽기 전용 인 루트 파일 시스템 상단에 일시적인 오버레이를 빌드하고 동적 최상위 마운트 지점을 생성하고 필요한 경우 파일 시스템을 읽기-쓰기 로 다시 마운트할 수 있습니다.
root.transient-ro 기능을 사용하는 경우 애플리케이션이 호스트 디렉터리에 올바르게 액세스하고 읽기 전용 파일 시스템에서 필요한 마운트 지점을 생성할 수 있도록 하려면 다음과 같은 몇 가지 고려 사항이 적용됩니다.
- 애플리케이션은 호스트의 절대 경로와 일치하는 호스트 디렉터리를 바인딩 마운트해야 합니다.
-
macOS의
/Users와 같은 플랫폼별 마운트 지점이 필요합니다. - 배포 후 애플리케이션을 시작하기 전에 동적 마운트 지점 생성.
-
파일 시스템은 일반 프로세스에 대해
읽기 전용으로 유지됩니다.
사전 요구 사항
-
container-toolsmeta-package가 설치되어 있습니다.
프로세스
transient-root-example.service서비스를 생성하여읽기및쓰기권한이 있는 디렉터리를 생성합니다. 다음 예제에는/etc/afs가 있습니다.[Unit] Description=Transient Root Example - Dynamic Mount Point Creation After=local-fs.target ConditionPathExists=/etc/afs DefaultDependencies=no [Service] Type=oneshot RemainAfterExit=yes MountFlags=slave # LIBMOUNT_FORCE_MOUNT2=always is required for mount command compatibility # See: https://github.com/util-linux/util-linux/issues/3171 Environment=LIBMOUNT_FORCE_MOUNT2=always ExecStart=/usr/bin/bash -c "echo 'Transient root example: Detected /etc/afs, remounting root as read-write'; mount -o remount,rw /; mkdir -p /afs; echo 'Created /afs directory for AFS mount point'" [Install] WantedBy=multi-user.targetContainerFile에 다음 구성을 추가합니다.
# Copy the systemd service unit that demonstrates dynamic mount point creation # The service will: # 1. Check for existence of /etc/afs (ConditionPathExists) # 2. Use MountFlags=slave for proper mount propagation # 3. Set LIBMOUNT_FORCE_MOUNT2=always for mount command compatibility # 4. Remount root as read-write and create /afs directory when triggered COPY transient-root-example.service /usr/lib/systemd/system/ # Enable the service to start automatically on boot RUN systemctl enable transient-root-example.service컨테이너 빌드 프로세스 중에
transient-ro옵션을 활성화하려면 이미지 내부의/usr/lib/ostree/prepare-root.conf파일에 다음 구성을 생성합니다.RUN echo -e '[root]\ntransient=true' > /usr/lib/ostree/prepare-root.conf && \ set -x; kver=$(cd /usr/lib/modules && echo *); dracut -vf /usr/lib/modules/$kver/initramfs.img $kver참고파일 시스템 구성을 변경할 때 initramfs 이미지를 다시 생성해야 합니다.
일시적인 루트 파일 시스템을 사용하여 bootc 이미지를 빌드합니다.
$ podman build --cap-add SYS_ADMIN -t transient-root-ro:test .그러면 빌드 중
ostree작업에 필요한SYS_ADMIN기능이 추가되었습니다.
검증
transient-ro = true구성 파일이 빌드된 이미지에 올바르게 설정되어 있는지 확인합니다.$ sudo podman run --rm transient-root-ro:test cat /usr/lib/ostree/prepare-root.conf다음과 유사한 출력이 표시됩니다.
[root] transient-ro = true실행 중인 시스템에서 런타임 기능을 확인합니다.
- 이미지를 부팅합니다.
/etc/afs테스트 디렉토리를 만듭니다.$ sudo mkdir -p /etc/afs서비스를 다시 시작하여 동적 마운트 지점 생성을 트리거합니다.
$ systemctl restart transient-root-example.service서비스는 root를
읽기-쓰기로 다시 마운트하고/afs디렉터리를 생성합니다.
systemd서비스 없이 기능을 테스트하려면 실행 중인 시스템에서 root로 테스트 디렉토리를 생성합니다.$ sudo export LIBMOUNT_FORCE_MOUNT2=always $ sudo unshare -m -- /bin/sh -c 'mount -o remount,rw / && mkdir /transient-test'디렉터리가 생성되었는지 확인합니다.
$ sudo ls -d /transient-test /transient-testroot 파일 시스템에 쓰기를 시도하여 다른 프로세스에 대한
읽기 전용상태를 확인합니다.$ touch /another-test-file touch: cannot touch '/another-test-file': Read-only file system