我的主机地址是192.168.1.100,虚拟机地址是192.168.1.101,开发板地址为192.168.1.102
1.设置eth0为静态IP地址, 开发板/etc/network/目录下对interfaces文件进行修改 。
vi /etc/network/interfaces
修改并为如下内容,执行 :wq 保存并退出,
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.102
netmask 255.255.255.0
gateway 192.168.1.1
2.执行/etc/init.d/S40network restart 重启网络服务。
3.ifconfig查看当前ip,确保三者处于同一网段,这时三者可以ping通。
但如果此时开发板联网不成功,执行udhcpc -i eth0,由路由器给开发板分配ip
然后ping www.baidu.com,此时发现可以上网了
3.执行busybox mount -t nfs -o nolock,vers=3 192.168.1.101:/home/book /mnt
就可将虚拟机的指定目录挂载到开发板的/mnt目录下
在这里我反复掉坑,
报错mount.nfs: access denied by server while mounting 192.168.1.101:/home/book/nfs_rootfs
执行systemctl status nfs-kernel-server,检查NFS服务的状态,发现输出日志显示具体错误:
● nfs-server.service - NFS server and services(红色点)
Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor prese
Active: failed (Result: exit-code)
于是我卸载了ubuntu的nfs服务,执行:
sudo apt-get remove --purge nfs-kernel-server
重新安装nfs服务,执行:
sudo apt-get install nfs-kernel-server
开启nfs服务,执行:
start nfs-kernel-server
显示:
● nfs-server.service - NFS server and services(绿色点)
Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor prese
Active: active (exited) since Thu 2023-12-07 14:13:15 UTC; 1min 37s ago
显示nfs可以正常工作
再次使用挂载命令
发现还是报错: mount.nfs: access denied by server while mounting
执行sudo systemctl status nfs-idmapd.service查看nfs-idmapd的状态
执行journalctl -xe | grep nfs-idmapd,用日志查看更为详细的报错
显示:
Dec 07 13:45:48 firefly systemd[1]: nfs-idmapd.service: Control process exited, code=exited status=1
Dec 07 13:45:48 firefly systemd[1]: nfs-idmapd.service: Failed with result 'exit-code'.
-- Subject: Unit nfs-idmapd.service has failed
-- Unit nfs-idmapd.service has failed.
-- Subject: Unit nfs-idmapd.service has begun start-up
-- Unit nfs-idmapd.service has begun starting up.
给Ubuntu也做卸载和重装nfs服务的操作
原来我没有重启nfs 服务,执行:
sudo /etc/init.d/nfs-kernel-server restart
关闭防火墙,执行:
sudo systemctl stop ufw
然后给虚拟机自己挂自己
执行:sudo mount -t nfs -o nolock,vers=3 127.0.0.1:/home/book /mnt
挂载成功!
回到开发板这端挂载
执行:mount -t nfs -o nolock,vers=3 192.168.1.101:/home/book没有报错
再执行:cd /mnt
可以看到/home/book里的内容啦!!!
4.执行df -h可查看挂载的情况
韦东山老师在讲挂载的时候没有报错,可能也是因为其他学生用了他所提供的自动安装 NFS,SAMBA,TFTP等的脚本,再次感谢韦老师,贴一下老师给的脚本,会自动创建一个book用户,也没关系的,可以在root用户下执行以上命令
https://weidongshan.coding.net/p/DevelopmentEnvConf/d/DevelopmentEnvConf/git/raw/master/Configuring_ubuntu.sh && sudo chmod +x Configuring_ubuntu.sh && sudo ./Configuring_ubuntu.sh
就不用一直给nfs服务debug了