OpenBMC v2.8 启用 NFS 客户端支持
尝试在 OpenBMC 上调试程序时如果要上传带符号信息的可执行文件,那么会发现 flash 空间远远不够,因此使用 NFS 是很自然的选择,不过在 OpenBMC v2.8 上启用 NFS 客户端支持也不是那么简单的事情。
nfs-utils
linux 的 nfs 客户端需要 linux 内核模块和用户态程序配合,其中用户态程序由 nfs-utils 提供:
$ vi local.conf
IMAGE_INSTALL_append = "nfs-utils"
rpc
root@romulus:~# showmount -e 10.0.1.105
clnt_create: RPC: Unknown host
root@romulus:~# rpcinfo -p 10.0.1.105
10.0.1.105: RPC: Unknown host
该错误的原因是缺少 /etc/services
文件:
root@romulus:~# scp runsisi@192.168.1.60:/etc/services /etc
root@romulus:~# ls -l /etc/services
-rw-r--r-- 1 root root 299330 Dec 26 02:10 /etc/services
root@romulus:~# mount -v -t nfs -o nfsvers=2 10.0.1.105:/home/runsisi/bmc /media/
mount.nfs: timeout set for Tue Dec 26 01:58:41 2023
mount.nfs: trying text-based options 'nfsvers=2,addr=10.0.1.105'
mount.nfs: prog 100003, trying vers=2, prot=6
mount.nfs: trying 10.0.1.105 prog 100003 vers 2 prot TCP port 2049
mount.nfs: prog 100005, trying vers=1, prot=17
mount.nfs: trying 10.0.1.105 prog 100005 vers 1 prot UDP port 20048
mount.nfs: Protocol not supported
该错误的原因是缺少 /etc/protocols
文件:
root@romulus:~# scp runsisi@192.168.1.60:/etc/protocols /etc
root@romulus:~# ls -l /etc/protocols
-rw-r--r-- 1 root root 3198 Dec 26 02:16 /etc/protocols
kernel nfs client
root@romulus:~# mount -v -t nfs -o nfsvers=2 10.0.1.105:/home/runsisi/bmc /media/
mount.nfs: timeout set for Tue Dec 26 02:20:02 2023
mount.nfs: trying text-based options 'nfsvers=2,addr=10.0.1.105'
mount.nfs: prog 100003, trying vers=2, prot=6
mount.nfs: trying 10.0.1.105 prog 100003 vers 2 prot TCP port 2049
mount.nfs: prog 100005, trying vers=1, prot=17
mount.nfs: trying 10.0.1.105 prog 100005 vers 1 prot UDP port 20048
mount.nfs: mount(2): No such device
mount.nfs: No such device
该错误定位如下:
root@romulus:~# strace mount.nfs -o nfsvers=2 10.0.1.105:/home/runsisi/bmc /media/
mount("10.0.1.105:/home/runsisi/bmc", "/media", "nfs", 0, "addr=10.0.1.105,vers=2,proto=tcp"...) = -1 ENODEV (No such device)
write(2, "mount.nfs: No such device\n", 26mount.nfs: No such device
) = 26
root@romulus:~# zcat /proc/config.gz | grep NFS
# CONFIG_USB_FUNCTIONFS is not set
CONFIG_KERNFS=y
显然,内核没有启用 NFS 客户端支持:
// linux/fs/namespace.c
do_new_mount
type = get_fs_type(fstype);
if (!type)
return -ENODEV;
// linux/fs/nfs/super.c
register_nfs_fs
register_filesystem(&nfs_fs_type);
register_nfs4_fs();
// linux/fs/nfs/fs_context.c
struct file_system_type nfs_fs_type = {
.owner = THIS_MODULE,
.name = "nfs",
.init_fs_context = nfs_init_fs_context,
.parameters = nfs_fs_parameters,
.kill_sb = nfs_kill_super,
.fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
};
MODULE_ALIAS_FS("nfs");
EXPORT_SYMBOL_GPL(nfs_fs_type);
#if IS_ENABLED(CONFIG_NFS_V4)
struct file_system_type nfs4_fs_type = {
.owner = THIS_MODULE,
.name = "nfs4",
.init_fs_context = nfs_init_fs_context,
.parameters = nfs_fs_parameters,
.kill_sb = nfs_kill_super,
.fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
};
MODULE_ALIAS_FS("nfs4");
MODULE_ALIAS("nfs4");
EXPORT_SYMBOL_GPL(nfs4_fs_type);
#endif /* CONFIG_NFS_V4 */
ENODEV filesystemtype not configured in the kernel.
MountNotes
http://linux-nfs.org/wiki/index.php/MountNotes
kernel nfs config
修改内核选项:
❯ devtool modify linux-aspeed
❯ bitbake -c menuconfig virtual/kernel
注意使能 NFS v2 需要显式选择 CONFIG_NFS_V2
,内核的帮助文档在 NFS v2 支持上的文档应该具有误导性。
mount
root@romulus:~# mount.nfs -v -o nfsvers=2 10.0.1.105:/home/runsisi/bmc /media/
mount.nfs: timeout set for Wed Dec 27 01:11:37 2023
mount.nfs: trying text-based options 'nfsvers=2,addr=10.0.1.105'
mount.nfs: prog 100003, trying vers=2, prot=6
mount.nfs: trying 10.0.1.105 prog 100003 vers 2 prot TCP port 2049
mount.nfs: prog 100005, trying vers=1, prot=17
mount.nfs: trying 10.0.1.105 prog 100005 vers 1 prot UDP port 20048
mount.nfs: mount(2): Permission denied
mount.nfs: access denied by server while mounting 10.0.1.105:/home/runsisi/bmc
该错误需要在 NFS 服务端增加 insecure
选项:
❯ sudo vi /etc/exports
/home/runsisi/bmc *(rw,sync,no_root_squash,no_subtree_check,insecure)
❯ sudo exportfs -rav
Mount failed with mount: mount.nfs: access denied by server while mounting error
https://access.redhat.com/solutions/3773891
最终成功 mount 的结果如下:
root@romulus:~# mount -v -t nfs -o nfsvers=2 10.0.1.105:/home/runsisi/bmc /media/
mount.nfs: timeout set for Wed Dec 27 01:43:18 2023
mount.nfs: trying text-based options 'nfsvers=2,addr=10.0.1.105'
mount.nfs: prog 100003, trying vers=2, prot=6
mount.nfs: trying 10.0.1.105 prog 100003 vers 2 prot TCP port 2049
mount.nfs: prog 100005, trying vers=1, prot=17
mount.nfs: trying 10.0.1.105 prog 100005 vers 1 prot UDP port 20048
root@romulus:/media# df -h
Filesystem Size Used Available Use% Mounted on
dev 80.9M 0 80.9M 0% /dev
tmpfs 113.9M 11.7M 102.3M 10% /run
/dev/mtdblock4 18.9M 18.9M 0 100% /run/initramfs/ro
/dev/mtdblock5 32.0M 1.0M 31.0M 3% /run/initramfs/rw
cow 32.0M 1.0M 31.0M 3% /
tmpfs 113.9M 8.0K 113.9M 0% /dev/shm
tmpfs 113.9M 0 113.9M 0% /sys/fs/cgroup
tmpfs 113.9M 0 113.9M 0% /tmp
tmpfs 113.9M 8.0K 113.9M 0% /var/volatile
10.0.1.105:/home/runsisi/bmc
221.8G 112.7G 109.0G 51% /media
最后修改于 2024-01-03