環境
- debian10(buster)
nfs serverを立てる
nfs-serverのinstall
# apt-get -y install nfs-kernel-server
nfsの設定
公開するディレクトリを設定する
nfsのテストでHostOSからmountする場合、127.0.0.1でアクセスする。192.168.1.0/24だけであると、127.0.0.1と一致しないためmount失敗してしまう
/etc/exports
/home/data 192.168.1.0/24(rw,sync,fsid=0,no_subtree_check,crossmnt,no_root_squash) 127.0.0.1(rw,sync,fsid=0,no_subtree_check,crossmnt,no_root_squash)
nfsv4のみを有効にする
/etc/defaults/nfs-kernel-server
s/RPCMOUNTDOPTS=\" --manage-gids"/RPCMOUNTDOPTS=\" --manage-gids --no-nfs-version 2 --no-nfs-version 3\"/
nfs serverの再起動
# systemctl restart nfs-kernel-server
mount pointの作成
virshはstorage poolを/var/lib/libvirt/images
に保存する(デフォルト)
nfs(netfs)のstorage poolを使用する場合、nfs mount pointのデクレクトリ(e.g. /var/lib/libvirt/images/nfs-pool)を作成しておく
# mkdir /var/lib/libvirt/images/nfs-pool
nfs mountの動作確認
# exportfs
/home/data 127.0.0.1
/home/data 192.168.16.0/24
# apt-get -y install nfs-utils
# mount -t nfs example.com:/ /var/lib/libvirt/images/nfs-pool
# df -h
# touch /var/lib/libvirt/images/nfs-pool/aaa
# rm /var/lib/libvirt/images/nfs-pool/aaa
# umount /var/lib/libvirt/images/nfs-pool
storage-poolの作成
まずpool-create-asでxmlファイルを作成しないでpoolの作成ができるかどうか確認する
成功した場合HostOS起動時に自動mountにしたいためautostartを設定する。
そのためにはxmlファイルが必要である。
そこでpool-define-as --print-xml
を使ってxmlファイルを生成する。
storage-pool作成の確認
# virsh pool-create-as nfs-pool netfs \
--source-host=example.com \
--source-path=/ \
--target=/var/lib/libvirt/images/nfs-pool
storage-poolの削除
# virsh pool-destroy nfs-pool
xmlファイルの生成
# virsh pool-create-as nfs-pool netfs \
--source-host=example.com \
--source-path=/ \
--target=/var/lib/libvirt/images/nfs-pool \
--print-xml > /etc/libvirt/storage/nfs-pool.xml
# cat /etc/libvirt/storage/nfs-pool.xml
<pool type='netfs'>
<name>nfs-pool</name>
<uuid>abcd-efgh-4b16-aa0f-63f8bfa291c7</uuid>
<capacity unit='bytes'>0</capacity>
<allocation unit='bytes'>0</allocation>
<available unit='bytes'>0</available>
<source>
<host name='example.com'/>
<dir path='/'/>
<format type='auto'/>
</source>
<target>
<path>/var/lib/libvirt/images/nfs-pool</path>
</target>
</pool>
storage-poolのdefine
# virsh pool-define etc/libvirt/storage/nfs-pool.xml
autostart
# virsh pool-autostart nfs-pool
pool作成
# virsh pool-create etc/libvirt/storage/nfs-pool.xml
確認
# virsh pool-list
Name State Autostart
---------------------------------
default active yes
nfs-pool active yes