安装 NFS server
mystery@lcw:~$ sudo apt-get install nfs-kernel-server
编辑/etc/exports,添加目标系统的根文件系统映射目录,假如目标系统的根文件系统最后映射到/home/mystery/nfs_files,则/etc/exports内容如下
/home/mystery/nfs_files *(subtree_check,rw,no_root_squash,async)
解释如下:
- /home/mystery/nfs_files:映射目录
- *:允许所以的主机挂载
- subtree_check:子目录权限检查
- rw:可读写
- no_root_squash:无root权限
- async:同步文件
重启服务
mystery@lcw:~$ sudo /etc/init.d/nfs-kernel-server restart * Stopping NFS kernel daemon ...done. * Unexporting directories for NFS kernel daemon... ...done. * Exporting directories for NFS kernel daemon... exportfs: Failed to stat /home/mystery/nfs_files: No such file or directory ...done. * Starting NFS kernel daemon ...done. mystery@lcw:~$ sudo exportfs /home/mystery/nfs_files <world> mystery@lcw:~$
最好每修改过 /etc/exports 后都执行一次
测试NFS
首先建立一个nfs测试的挂载点
mystery@lcw:~$ sudo mkdir /mnt/nfs mystery@lcw:~$ ls /mnt/nfs/ mystery@lcw:~$
挂载NFS
mystery@lcw:~$ sudo mount 192.168.7.233:/home/mystery/nfs_files /mnt/nfs/ -t nfs mystery@lcw:~$
测试下
mystery@lcw:~$ cd /mnt/nfs/ mystery@lcw:/mnt/nfs$ ls mystery@lcw:/mnt/nfs$ touch test mystery@lcw:/mnt/nfs$ ls test mystery@lcw:/mnt/nfs$ ls /home/mystery/nfs_files/ test mystery@lcw:/mnt/nfs$
OK,卸载
mystery@lcw:/mnt/nfs$ cd .. mystery@lcw:/mnt$ sudo umount ./nfs/ mystery@lcw:/mnt$ cd nfs/ mystery@lcw:/mnt/nfs$ ls mystery@lcw:/mnt/nfs$