12.2. transient-ro による動的マウントポイントの作成


root ユーザーは、bootc の root.transient-ro 機能を使用することで、デフォルトでは read-only であるルートファイルシステムの上に一時的なオーバーレイを構築し、動的なトップレベルのマウントポイントを作成して、必要に応じてファイルシステムを read-write として再マウントすることができます。

root.transient-ro 機能を使用する場合は、アプリケーションがホストディレクトリーに適切にアクセスし、read-only ファイルシステム上に必要なマウントポイントを作成できるように、以下のように考慮すべき点がいくつかあります。

  • アプリケーションは、ホストの絶対パスに一致するホストディレクトリーをバインドマウントする必要があります。
  • macOS の /Users など、プラットフォーム固有のマウントポイントが必要です。
  • デプロイ後、アプリケーションの起動前に動的マウントポイントを作成します。
  • ファイルシステムは、通常のプロセスに対しては read-only のまま維持されます。

前提条件

  • container-tools メタパッケージがインストールされている。

手順

  1. transient-root-example.service サービスを作成し、read および write 権限を持つディレクトリーを作成します。次の例では、/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.target
  2. ContainerFile に次の設定を追加します。

    # 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
  3. コンテナービルドプロセス中に 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 イメージを再生成する必要があります。

  4. 一時的なルートファイルシステムを使用して bootc イメージをビルドします。

    $ podman build --cap-add SYS_ADMIN -t transient-root-ro:test .

    これにより、ビルド中の ostree 操作において bootc が必要とする SYS_ADMIN ケーパビリティーが追加されます。

検証

  1. ビルドしたイメージで transient-ro = true 設定ファイルが正しく設定されていることを確認します。

    $ sudo podman run --rm transient-root-ro:test cat /usr/lib/ostree/prepare-root.conf

    以下のような出力が表示されます。

    [root]
    transient-ro = true
  2. 稼働中のシステムで、実行時の機能を検証します。

    1. イメージを起動します。
    2. /etc/afs テストディレクトリーを作成します。

      $ sudo mkdir -p /etc/afs
    3. サービスを再起動し、動的マウントポイントの作成をトリガーします。

      $ systemctl restart transient-root-example.service

      サービスにより、ルートが read-write として再マウントされ、/afs ディレクトリーが作成されます。

  3. systemd サービスなしで機能をテストするために、実行中のシステムで root としてテストディレクトリーを作成します。

    $ sudo export LIBMOUNT_FORCE_MOUNT2=always
    $ sudo unshare -m -- /bin/sh -c 'mount -o remount,rw / && mkdir /transient-test'
  4. ディレクトリーが作成されたかどうかを検証します。

    $ sudo ls -d /transient-test /transient-test
  5. ルートファイルシステムへの書き込みを試行して、他のプロセスにとっては read-only ステータスであることを検証します。

    $ touch /another-test-file
    touch: cannot touch '/another-test-file': Read-only file system
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

Red Hat ドキュメントについて

Legal Notice

Theme

© 2026 Red Hat
トップに戻る