本博客倡导开放源代码,在此公布之程序源代码如无特别声明均采用GNU通用公共 许可证(GPL)

乐在其中

分享学习Linux的乐趣

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  23 随笔 :: 0 文章 :: 401 评论 :: 0 Trackbacks
NFS(Network File System)是一种在Unix/Linux下广泛使用的网络文件系统。Linux的内核已经内置了对NFS客户端和服务器的支持。但是播放机的内核没有打开NFS服务器支持,因此我们需要自己编译相关的模块。另外我们还需要相应的辅助程序:portmapnfs-utils。其中nfs-utils要求C程序库包含对RPC的支持,然而播放机的uclibc没有打开RPC支持。下面我将介绍如何解决这些问题。

一、编译内核NFS服务器模块
仍然使用从华硕下载的内核源码,请参考:下载源代码(Download The Source Code)
内核源码目录下有一个名为config.develop.avhdd.mars.old的文件,我们以这个配置文件为基础重新配置内核:
$ cd linux-2.6.12
$ cp config.develop.avhdd.mars.old .config
$ make menuconfig

1. 关闭模块版本检查,使得我们编译的模块可以在原厂内核上加载。
配置菜单位置: Loadable module support  ---> [ ]  Module versioning support (EXPERIMENTAL)

2. 打开NFS服务器支持,选择把它编译成模块。
配置菜单位置:File systems  --->  Network File Systems  ---> [M]  NFS server support

3. 打开或关闭内核调试。这个一定要与你的播放机内核的实际配置保持一致,否则编译出的模块会无法加载。
Kernel hacking  --->  [?] Kernel debugging

然后执行make进行编译。编译完成后我们得到以下两个模块:
fs/exortfs/exportfs.ko
fs/nfsd/nfsd.ko

附件:
编译好的模块:
nfs-server-modules-debug.tar.bz2 (打开内核调试)
nfs-server-modules-nodebug.tar.bz2 (关闭内核调试)

二、打开uClibc对RPC的支持
NFS的通讯协议是基于ONC RPC(一种远程过程调用协议)的。nfs-utils工具调用了C函数库的RPC函数,因此要求uClibc必需提供这些函数。原厂固件中的uClibc关闭了RPC支持,我们只能用自己编译的支持RPC的uClibc来替换原厂的uClibc。
其实在编译Buildroot时就会自动编译uClibc,请参考:Buildroot - 让交叉编译更轻松。我们只需在配置buildroot时指定uClibc的配置文件,这个配置文件应该包括下面两项:
UCLIBC_HAS_RPC=y
UCLIBC_HAS_FULL_RPC
=y

对应的uClibc的配置菜单如下图:
screenshot

附件:
补丁:uClibc-0.9.28-patches.tar.bz2
配置文件:config-uClibc-0.9.28.bz2
编译好的uClibc:uClibc-0.9.28-binary.tar.bz2

三、编译辅助程序
为了方便链接上述的uClibc,请使用buildroot生成的工具链来编译portmap和nfs-utils。详细步骤请看:编译portmap和nfs-utils

附件:
编译好的portmap和nfs-utils:portmap_and_nfs-utils_binary.tar.bz2

四、更新固件
用以上三步编译产生的二进制文件制作新固件:
1. 内核模块放在如下路径:
lib/modules/2.6.12.6-VENUS/kernel/fs/exportfs/exportfs.ko
lib
/modules/2.6.12.6-VENUS/kernel/fs/nfsd/nfsd.ko

2. 用自己编译的uClibc替换原厂的uClibc,放在/lib下:
/lib/libm.so.0 -> libm-0.9.28.so
/lib/libresolv.so.0 -> libresolv-0.9.28.so
/lib/libpthread-0.9.28.so
/lib/libnsl.so.0 -> libnsl-0.9.28.so
/lib/ld-uClibc-0.9.28.so
/lib/libutil.so.0 -> libutil-0.9.28.so
/lib/libcrypt-0.9.28.so
/lib/libm-0.9.28.so
/lib/libutil-0.9.28.so
/lib/ld-uClibc.so.0 -> ld-uClibc-0.9.28.so
/lib/librt-0.9.28.so
/lib/libuClibc-0.9.28.so
/lib/libdl-0.9.28.so
/lib/libresolv-0.9.28.so
/lib/libcrypt.so.0 -> libcrypt-0.9.28.so
/lib/libdl.so.0 -> libdl-0.9.28.so
/lib/libnsl-0.9.28.so
/lib/libpthread.so.0 -> libpthread-0.9.28.so
/lib/libc.so.0 -> libuClibc-0.9.28.so
/lib/librt.so.0 -> librt-0.9.28
.so

3. portman,nfs-utils及脚本
/etc/init.d/S60nfs
/sbin/portmap
/usr/sbin/exportfs
/usr/sbin/rpc.mountd     
/usr/sbin/rpc.nfsd
/usr/sbin/rpc.statd


参考:
1. 下载源代码(Download The Source Code)
2. 重新编译uClibc
3. 编译portmap和nfs-utils
4. Buildroot - 让交叉编译更轻松
posted on 2010-11-04 15:30 gouzhuang 阅读(7289) 评论(24)  编辑 收藏 引用 所属分类: 嵌入式Linux

评论

# re: 搭建NFS服务器(Setup NFS Server) 2010-11-09 00:43 nfs-setup
hello-

Thank you for your hard work and great tutorials.

I am having trouble getting the nfs mount to work.

Can you share your media player's:
/etc/exports
and how you have setup your ubuntu pc to mount the share?

Thanks

in Chinese from translate.google:
你好,

感谢你们的辛勤工作和伟大的教程。

我遇到麻烦NFS挂载工作。

你能分享您的媒体播放器的:
/ etc / exports中
以及您如何设置您的Ubuntu电脑装入分享?

谢谢  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2010-11-09 03:54 kernel-module-compiling
when I try to compile / make the asus oplay kernel using the buildroot (built as described in your tutorial) I get a lot of errors and the compilation fails.
当我尝试编译/使华硕oplay内核使用buildroot(内置在您的教程中介绍)我得到了很多错误和编译失败。

user111@acer-1810t:~/asus-oplay-kernel/linux-2.6.12$ PATH=/home/user111/buildroot-2009.11/output/staging/usr/bin:$PATH make
CHK include/linux/version.h
CC scripts/mod/empty.o
HOSTCC scripts/mod/mk_elfconfig
MKELF scripts/mod/elfconfig.h
HOSTCC scripts/mod/file2alias.o
HOSTCC scripts/mod/modpost.o
HOSTCC scripts/mod/sumversion.o
scripts/mod/sumversion.c: In function ‘parse_file’:
scripts/mod/sumversion.c:260: warning: pointer targets in passing argument 1 of ‘grab_file’ differ in signedness


....(cut out a lot of errors | 切出了很多错误)....


/usr/include/stdlib.h:184: note: expected ‘const char * __restrict__’ but argument is of type ‘unsigned char *’
CC arch/mips/kernel/offset.s
arch/mips/kernel/offset.c: In function 'output_mm_defines':
arch/mips/kernel/offset.c:227: error: invalid 'asm': invalid use of '%x'
arch/mips/kernel/offset.c:228: error: invalid 'asm': invalid use of '%x'
arch/mips/kernel/offset.c:229: error: invalid 'asm': invalid use of '%x'
make[1]: *** [arch/mips/kernel/offset.s] Error 1
make: *** [arch/mips/kernel/offset.s] Error 2

Do you have any ideas what I might be doing wrong?
你有什么想法我可能是做错了什么?  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2010-11-09 10:52 gouzhuang
@nfs-setup
suppose your PC is on network 192.168.1.0/24, put the following line in /etc/exports
/tmp/usbmounts/sda1 192.168.1.0/24(rw,sync,no_subtree_check)

or you can run the following on command line:

# exportfs -o rw,sync,no_subtree_check 192.168.1.0/24:/tmp/usbmounts/sda1

Mount nfs on you ubuntu PC:
# mount -t nfs -o udp <ip of you player>:/tmp/usbmounts/sda1 /mnt
  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2010-11-09 10:57 gouzhuang
@kernel-module-compiling
You are using the wrong compiler. To compile kernel, you have to use the compiler for kernel: mipsel-linux-sdelinux 6.03.01-1, which was install at /usr/bin/mipsel-linux-gcc

The buildroot compiler should be used to compile application only.  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2010-11-29 23:59 nfs-setup
@gouzhuang
Still can't get nfs-server offerings to mount.

I get:
Unknown error 521

When I try to mount using ubuntu 10.10

Does the compiled nfsserver module require an older nfs client to work?

That is, if the nfsserver is version 3, does the nfs client have to be version 3 as well?

Thank you for your hard work,
nfs-setup  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2010-11-30 09:08 gouzhuang
@nfs-setup
Please check if portmap, rpc.statd, rpc.mountd, rpc.nfsd is running on your player.

If all the above daemons are running, then what is the output of 'exportfs -v'?

On you ubuntu PC, run 'showmount -e <your player ip>', does it output anything?

nfs client does not have to be version 3, it can detect the server version and use the correct one.  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-23 17:29 ygao2004
我用你所编译好的nfs文件去替换,
rpc.nfsd 没有运行,
运行S60nfs,出现
mount: Mounting nfsd on /proc/fs/nfsd failed: No such device  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-23 22:14 gouzhuang
@ygao2004
你加载了nfs内核模块了吗?  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-23 22:30 ygao2004
@gouzhuang
insmod nfsd.ko
insmod exports.ko
dmesg 未有错误.
ubuntu: sudo mount -t nfs -o nolock 192.168.1.103:/tmp/hdd/root /tmp/good

rpcinfo
showmount
看起来都正常.

现在则出现:mount.nfs: mount to NFS server '192.168.1.103' failed: System Error: Connection refused
  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-23 22:39 gouzhuang
@ygao2004
播放机上exportfs -v显示什么?  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-23 22:44 ygao2004
@gouzhuang
/tmp/hdd/root/opt/etc/init.d # exportfs -v
/tmp/hdd/root 192.168.1.*(rw,async,wdelay,no_root_squash,no_subtree_check)  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-23 22:50 gouzhuang
@ygao2004
请用192.168.1.0/24替换192.168.1.*  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-23 22:54 ygao2004
@gouzhuang
/tmp/hdd/root/opt/etc/init.d # exportfs -v
/tmp/hdd/root 192.168.1.0/24(rw,async,wdelay,no_root_squash,no_subtree_check)

/tmp/hdd/root/opt/etc/init.d # ./S60nfs reload

ubuntu@ubuntu:/tmp$ sudo mount -t nfs -o nolock 192.168.1.103:/tmp/hdd/root /tmp/good
mount.nfs: mount to NFS server '192.168.1.103' failed: System Error: Connection refused
u  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-23 23:19 gouzhuang
@ygao2004
不要执行./S60nfs reload,它会重置共享的文件系统。  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-24 08:17 ygao2004
@gouzhuang
exportfs: No versions for exported symbols. Tainting kernel.
Installing knfsd (copyright (C) 1996 okir@monad.swb.de).

本地自行mount,也没办法.
~ # mount -t nfs -o nolock192.168.1.103:/tmp/hdd/root /tmp/good
mount: 192.168.1.103:/tmp/hdd/root is write-protected, mounting read-only
mount: Mounting 192.168.1.103:/tmp/hdd/root on /tmp/good failed: Permission denied  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-24 08:25 gouzhuang
@ygao2004
有点乱,请重新描述你的问题。请按顺序列出你的操作及输出信息,并指明操作是在播放机上还是在PC上。  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-24 08:37 ygao2004
@gouzhuang
我无法在系统下 kernel/fs/等自起动装载,
只能手动insmod,
而且只能在播放机起动后
insmod exports.ko
然后 insmod nfsd.ko
最后 S60nfs
发现 rpc.nfsd没起动
就手动起动,rpc.nfsd

这时在ubuntu上 showmout rpcinfo 的输出与正常无区别

但是不能mount,无论在播放器上,还是ubuntu上

我有一扫描程序,对nfs 端口对2049的扫描非常慢,提示
connection error.
  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-24 08:40 ygao2004
对nfs tcp 2049非常慢,但nfs udp 2049显示正常.
  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-24 19:23 gouzhuang
@ygao2004
试一下给mount命令加上 -o udp 参数。如果还是不行,我也没办法了。  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-24 19:59 ygao2004
@gouzhuang
不试了,我想也不会行的.  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-03-31 07:58 ygao2004
Xtreamer Linux Kernel, based on official 2.6.12
http://code.google.com/p/xtreamerdev/  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-09-13 18:48 uragan
Hello,
where can I find this manual in english?
Thanks!  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-09-15 21:26 John
请教一个问题,
我在锋哲V6T上已经 mount 一个NFS服务器上的共享文件夹,挂载到 /tmp/ramfiles/... 下的一个文件夹,但是怎么样才能用遥控器通过视频界面来播放它呢??
能告诉我吗?感激不尽。  回复  更多评论
  

# re: 搭建NFS服务器(Setup NFS Server) 2011-09-16 14:23 gouzhuang
@John
简单的方法是:如果你的硬盘是ext3文件系统,可以在硬盘目录下建一个符号连接:ln -s /tmp/ramfiles /tmp/usbmounts/sda1

假设硬盘的挂载点是/tmp/usbmounts/sda1  回复  更多评论
  

只有注册用户登录后才能发表评论。