ループバックファイルを読み取り専用でマウントし、すべての書き込みをRAMにリダイレクトできますか?
ベストアンサー1
連合ファイルシステム階層を使用できます。オブ。
デモ:
ファイルシステムイメージの作成
# dd if=/dev/zero of=/tmp/image bs=1024 count=1024
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.0028428 s, 369 MB/s
# mke2fs /tmp/image
...
インストールして埋める
# mkdir /tmp/imgmnt
# mount -o loop /tmp/image /tmp/imgmnt
# echo hello > /tmp/imgmnt/hello.txt
# umount /tmp/imgmnt
読み取り専用でマウントしてください。
# mount -o loop,ro /tmp/image /tmp/imgmnt
# echo blah > /tmp/imgmnt/hello.txt
-su: /tmp/imgmnt/hello.txt: Read-only file system
小型RAMファイルシステム
# mkdir /tmp/rammnt
# mount -t tmpfs -o size=1M none /tmp/rammnt
両方とも結合
# mkdir /tmp/combined
# mount -t aufs -o br:/tmp/rammnt:/tmp/imgmnt=ro none /tmp/combined
このマウントオプションは(読み取り専用)の上に(読み取り - 書き込み)を重ねてbr
新しい「分岐」()を生成します。この「四半期」は。/tmp/rammnt
/tmp/imgmnt
/tmp/combined
(よりaufs(5)すべての詳細については、マニュアルページを参照してください。 )
これですべての作業が完了したので、次の結果が表示されます。
# ls /tmp/combined
hello.txt lost+found
# cat /tmp/combined/hello.txt
hello
# echo bye > /tmp/combined/hello.txt
# cat /tmp/combined/hello.txt
bye
# cat imgmnt/hello.txt
hello
# cat rammnt/hello.txt
bye
したがって、ファイルシステムへの書き込みを「停止」tmpfs
し、ループマウントイメージファイルに再度伝播しようとしません。
これを行うには、特定のディレクトリを作成する代わりに通常のディレクトリ(読み取り/書き込みファイルシステム)を使用するか、必要に応じて/dev/shm
ディレクトリを使用できます。tmpfs
一部のLiveCDディストリビューションでは、このテクノロジ(またはそのバリエーション)を使用しています。ウィキペディアオブ項目にはいくつかのリストがあります。