无法写入文件到 NFS目录

来源:互联网 发布:想学游戏编程 编辑:程序博客网 时间:2024/05/01 05:09

在qemu的网络和主机能通信后,就可以使用nfs来从虚拟机访问主机了,方法是在虚拟机内执行命令:

mount -t nfs -o nolock 192.168.1.100:/home/charles /mnt
但是,后面发现i一个问题,无法在 /mnt目录下写入新文件,或者删除i一个文件,总是提示不允许。

经过排查,发现主机的nfs 配置有问题, /etc/exports 缺少了一个选项 no_root_squash.

添加上后就行了:

$ cat /etc/exports # /etc/exports: the access control list for filesystems which may be exported#to NFS clients.  See exports(5).## Example for NFSv2 and NFSv3:# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)## Example for NFSv4:# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)#/home/charles*(rw,sync,no_subtree_check,no_root_squash)
然后重新 export:

 sudo exportfs  -rv