Files
llm-wiki/raw/articles/redhat-virtiofs-host-vm-file-sharing-2026.md
2026-06-30 22:22:00 +09:00

81 lines
4.7 KiB
Markdown

---
source_url: https://docs.redhat.com/ja/documentation/red_hat_enterprise_linux/9/html/configuring_and_managing_virtualization/sharing-files-between-the-host-and-its-virtual-machines-using-virtio-fs_sharing-files-between-the-host-and-its-virtual-machines
ingested: 2026-06-29
sha256: a73f36816cdc611785eb66c3f51d414d4ee7a015acb485f2e0e039e88bd58719
discovered_from:
platform: discord
channel_id: '1477793137064935675'
channel_name: "tw"
message_id: '1521164340986777651'
author_id: '890908900520505354'
posted_at: 2026-06-29T14:44:00.758000000Z
message_excerpt: "https://docs.redhat.com/ja/documentation/red_hat_enterprise_linux/9/html/configuring_and_managing_virtualization/sharing-files-between-the-host-and-its-virtual-machines-using-virtio-fs_sharing-files-between-the-host-and-"
---
## 20.2. virtiofs を使用してホストと仮想マシン間でファイルを共有する
---
virtiofs を使用すると、ホストと仮想マシン (VM) の間で、ローカルファイルシステムの構造と同じように機能するディレクトリーツリーとしてファイルを共有できます。
### 20.2.1. virtiofs を使用してホストと仮想マシン間でファイルを共有する
RHEL 9 をハイパーバイザーとして使用する場合は、 `virtiofs` 機能を使用して、ホストシステムとその仮想マシン間でファイルを効率的に共有できます。
**前提条件**
- 仮想化は、RHEL 9 ホストで [インストールされ、有効](https://docs.redhat.com/ja/documentation/red_hat_enterprise_linux/9/html/configuring_and_managing_virtualization/assembly_enabling-virtualization-in-rhel-9_configuring-and-managing-virtualization "第2章 仮想化の有効化") になります。
- 仮想マシンと共有するディレクトリーがある。既存のディレクトリーを共有しない場合は、 *shared-files* などの新しいディレクトリーを作成します。
```plaintext
# mkdir /root/shared-files
```
- データを共有する仮想マシンは、ゲストオペレーティングシステムとして Linux ディストリビューションを使用します。
**手順**
1. 仮想マシンと共有するホストの各ディレクトリーを、仮想マシンの XML 設定の virtiofs ファイルシステムとして設定します。
1. 目的の仮想マシンの XML 設定を開きます。
```plaintext
# virsh edit vm-name
```
2. 仮想マシンの XML 設定の `<devices>` に、以下のようなエントリーを追加します。
```plaintext
<filesystem type='mount' accessmode='passthrough'>
<driver type='virtiofs'/>
<binary path='/usr/libexec/virtiofsd' xattr='on'/>
<source dir='/root/shared-files'/>
<target dir='host-file-share'/>
</filesystem>
```
この例では、ホストの `/root/shared-files` ディレクトリーを、仮想マシンの `host-file-share` として表示するように設定します。
2. 仮想マシンの共有メモリーを設定します。そのためには、共有メモリーバッキングを XML 設定の `<domain>` セクションに追加します。
```plaintext
<domain>
[...]
<memoryBacking>
<access mode='shared'/>
</memoryBacking>
[...]
</domain>
```
3. 仮想マシンを起動します。
```plaintext
# virsh start vm-name
```
4. ゲストオペレーティングシステムにファイルシステムをマウントします。以下の例では、Linux ゲストオペレーティングシステムで事前に設定した `host-file-share` ディレクトリーをマウントします。
```plaintext
# mount -t virtiofs host-file-share /mnt
```
**検証**
- 共有ディレクトリーが仮想マシンからアクセス可能になり、ディレクトリーに保存されているファイルを開けるようになりました。
**既知の問題と制限**
- `noatime` 、 `strictatime` など、アクセス時間に関連するファイルシステムのマウントオプションは virtiofs では機能しない可能性が高く、Red Hat はその使用を推奨しません。
**トラブルシューティング**
- `virtiofs` がユースケースに最適でない場合、またはシステムでサポートされていない場合は、代わりに [NFS](https://docs.redhat.com/ja/documentation/red_hat_enterprise_linux/9/html/configuring_and_managing_virtualization/sharing-files-between-the-host-and-its-virtual-machines_configuring-and-managing-virtualization#sharing-files-between-the-host-and-its-virtual-machines-using-NFS_sharing-files-between-the-host-and-its-virtual-machines "20.1. NFS を使用してホストとその仮想マシン間でファイルを共有する") を使用できます。