注意
- 服务器端与客户端系统的版本号需为Ubuntu20.04
- 执行用户需要为sudo权限
- 服务器端nfs目录权限必须为nobody:nogroup
服务端配置:
在服务器192.168.60.142上配置 NFS 共享:
1.安装 NFS 服务器:
|---|------------------------------------------------|
| 1 | sudo
apt-get ``install
nfs-kernel-server
|
- 编辑 /etc/exports 文件,添加共享目录,本次以/data/nfsroot目录作为共享缓存目录:
|---|-----------------------------------------------------------------------------------------------|
| 1 | /aosp/pvt1/nfsdata
*(rw,``sync``,no_subtree_check,all_squash,anonuid=65534,anongid=65534)
|
- 赋权
|-------|----------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 | mkdir
-p ``/aosp/pvt1/nfsdata
sudo
chown
-R nobody:nogroup ``/aosp/pvt1/nfsdata
sudo
chmod
-R 777 ``/aosp/pvt1/nfsdata
|
- 重新启动 NFS 服务:
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 | # 重新导出所有共享目录
sudo
exportfs -a
# 重新启动 NFS 服务,使新配置生效
sudo
systemctl restart nfs-kernel-server
# 确保 NFS 服务在系统启动时自动运行
sudo
systemctl ``enable
nfs-kernel-server
|
客户端配置
在客户端(编译机)挂载 NFS 共享:
1.安装 NFS 客户端:
|---|--------------------------------------------|
| 1 | sudo
apt-get -y ``install
nfs-common
|
2.创建挂载点并挂载 NFS 共享:
|-----|--------------------------------------------------------------------------------------------------------------------------|
| 1 2 | sudo
mkdir
-p ``/aosp/pvt1/``.nfsroot
sudo
mount
192.168.60.142:``/aosp/pvt1/nfsdata
/aosp/pvt1/``.nfsroot
|
3.配置 Yocto 使用 NFS 共享的 sstate 缓存:
编辑 local.conf 文件,设置 SSTATE_DIR :
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 | # 编译命令可能不同,具体以实际版本的编译命令为准
export
TEMPLATECONF=${PWD}``/meta/meta-mediatek-mt8678/conf/templates/auto8678p1_64_hyp
source
meta``/poky/oe-init-build-env
# 如需要使用共享缓存则执行下行sed命令,如不使用则不执行,注意:需要替换相关项目的名称,本次按mt8678_yocto举例
sed
-i ``'s#^SSTATE_DIR ?=.*#SSTATE_DIR ?= "/aosp/pvt1/.nfsroot/mt8678_yocto/auto8678p1_64_hyp/sstate-cache"#'
conf``/local``.conf
time
bitbake mtk-core-image-auto8678-hyp 2>&1| ``tee
build.log
|
- 配置开机自动挂载
4.1 在 /etc/systemd/system/mount-nfs.service中写入以下内容(如没有则新建此文件):
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit]
Description=Mount NFS Share
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c "sleep 10 && /usr/bin/mount 192.168.60.142:/aosp/pvt1/nfsdata /aosp/pvt1/.nfsroot"
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
|
这里添加了一个 sleep 10 命令来确保挂载命令在网络完全启动后执行。
4.2 保存并退出文件,然后重新加载 systemd 配置:
|---|----------------------------------|
| 1 | sudo
systemctl daemon-reload
|
4.3 确保服务已启用:
|---|---------------------------------------------------|
| 1 | sudo
systemctl ``enable
mount``-nfs.service
|
4.4 重启系统:
|---|-----------------|
| 1 | sudo
reboot
|
4.5 验证挂载
重启后再次检查挂载:
|---|------------------------------|
| 1 | df
-h | ``grep
nfsroot
|
如下图则表示挂载成功:

4.6 查看日志
如果挂载仍然未成功,查看服务的状态和日志以获取更多信息:
|-----|----------------------------------------------------------------------------------------------|
| 1 2 | sudo
systemctl status ``mount``-nfs.service
sudo
journalctl -u ``mount``-nfs.service
|
参考文档:
Network File System (NFS) | Ubuntu
Yocto: sharing the sstate cache and download directories - Bootlin's blog