今日、私はArchLinuxのvagrantボックスを備えた新しい仮想マシンを作成しました。 vagrant up
でArchLinux仮想マシンを起動しました コマンドが起動しませんでした。 VMを起動しようとするたびに、NFS共有フォルダーをマウントするときにvagrantupがハングします。 5分以上待った後、コマンドは次のエラーで終了しました:
[...] ==> default: Mounting NFS shared folders… ==> default: Pruning invalid NFS exports. Administrator privileges will be required… [sudo] password for sk: ==> default: Removing domain… The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! mount -o vers=3,udp 192.168.122.1:/home/sk/vagrant/archlinux /vagrant Stdout from the command: Stderr from the command: mount.nfs: Connection refused

ご覧のとおり、vagrant up
NFS共有フォルダのマウントでコマンドが失敗します。私のKVMホストは最新のFedora34エディションです。 Ubuntu仮想マシンでこの問題が発生したことはありません。このエラーは、ArchLinux仮想マシンを起動したときにのみ発生しました。 「NFS共有フォルダーのマウント」中にVagrantマシンがスタックした場合は、以下の回避策を使用できます。
LinuxでNFS共有フォルダーをマウントするとVagrantupがハングします
これはおそらく、ファイアウォールが原因である可能性が高くなります。私の場合、それは確かにファイアウォールの問題です。 VagrantでのNFS共有フォルダーのマウントの問題を修正するには、ファイアウォールを介して次のサービスを許可する必要がありました。
- nfs、
- マウント済み
- rpc-bind。
また、ポート2049
を開きました 両方のtcp
およびudp
。
1.次のコマンドを1つずつ実行して、前述のサービスとポート2049を許可します。
$ sudo firewall-cmd --permanent --zone=libvirt --add-service=nfs3
$ sudo firewall-cmd --permanent --zone=libvirt --add-service=nfs
$ sudo firewall-cmd --permanent --zone=libvirt --add-service=mountd
$ sudo firewall-cmd --permanent --zone=libvirt --add-service=rpc-bind
$ sudo firewall-cmd --permanent --zone=libvirt --add-port=2049/tcp
$ sudo firewall-cmd --permanent --zone=libvirt --add-port=2049/udp
2.ファイアウォールルールをリロードして、変更を有効にします。
$ sudo firewall-cmd --reload
3.コマンドを使用して許可されたサービスのリストを表示します:
$ firewall-cmd --list-all
出力例:
FedoraWorkstation (active)
target: default
icmp-block-inversion: no
interfaces: wlp9s0
sources:
services: dhcpv6-client mdns mountd nfs rpc-bind samba-client ssh
ports: 1025-65535/udp 1025-65535/tcp
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
これにより、ホストとVagrant仮想マシン間のNFSが有効になり、libvirt
が有効になります。 ホストシステムからのnfsマウントを使用するためにホストされたVagrantVM。
4. nfsサービスと関連するポートを許可した後、VagrantVMを起動しようとしました。今回、私は別の問題に遭遇しました:
[...] mount.nfs: requested NFS version or transport protocol is not supported
5.このエラーを修正するには、/etc/nfs.conf
を編集します ホストシステムのファイル:
$ sudo vi /etc/nfs.conf
6.次の2行のコメントを解除します。
[nfsd] udp=y
ファイルを保存して閉じます。
7. nfsサービスを再起動します:
$ sudo systemctl restart nfs-server.service
8.最後に、ホストシステムを再起動します。
$ sudo reboot
それでおしまい。これで、Vagrantマシンを問題なく起動できるようになります。
Vagrantの使用法に関する完全なガイドを掲載しました。 Vagrantの使用方法については、次のリンクを確認してください。
- Vagrantチュートリアル–LinuxでVagrantを使い始める