為了在播放機上實現NFS服務器的功能,我們已經在uClibc中打開了完整RPC支持,并且在新編譯的內核中打開了NFS服務器支持。此外還有兩個軟件包也是提供NFS服務所必需的:portmap和nfs-utils。portmap為RPC程序提供端口映射服務,nfs-utils則是使用內核NFS服務器的支持程序。
編譯portmap
1. 下載portmap_5beta:?ftp://ftp.porcupine.org/pub/security/portmap_5beta.tar.gz
2. 打這個補丁:?portmap_5beta.patch.zip?(補丁來自buildroot-2009.11,我只是把多個補丁合并成一個)
3. $?make CC=mipsel-linux-gcc
4.?$ mipsel-linux-strip portmap
編譯nfs-utils
1. 下載nfs-utils-1.1.1: http://nchc.dl.sourceforge.net/project/nfs/nfs-utils/1.1.1/nfs-utils-1.1.1.tar.gz
2. 打這個補丁:?nfs-utils-1.1.1-uclibc.patch.zip?(在網上找到的,來源記不清了,我稍加了修改)
3. 運行配置腳本:
1?./configure?--build=i686-linux?--host=mipsel-linux?--disable-nfsv4?--disable-gss?--disable-uuid?--disable-mount?--without-tcp-wrappers?--with-gnu-ld?CC=mipsel-linux-gcc?CPP=mipsel-linux-cpp?AR=mipsel-linux-ar?STRIP=mipsel-linux-strip?RANLIB=mipsel-linux-ranlib?LD=mipsel-linux-ld
4.?$ make5. 安裝到/home/user/dist/nfs-utils目錄
1?$?make?DESTDIR=/home/user/dist/nfs-utils?install-strip
在制作固件時,我們只需要幾個編譯好的程序:portmap, rpc.statd, rpc.nfsd, rpc.mountd, exportfs。其中portmap?放到/sbin下,其余的放到/usr/sbin下。
此外還需要一個NFS服務啟動腳本S60nfs,放在/etc/init.d目錄下。下載腳本S60nfs.zip?(來自buildroot,我把portmap的啟動加進去了)
?1?#!/bin/sh????????????????????????????????
?2?#????????????????????????????????????????
?3?#?nfs???????????This?shell?script?takes?care?of?starting?and?stopping
?4?#???????????????the?NFS?services.?Stolen?from?RedHat?FC5.????????????
?5?
?6?[?-x?/sbin/portmap?]?||?exit?0
?7?[?-x?/usr/sbin/rpc.statd?]?||?exit?0
?8?[?-x?/usr/sbin/rpc.nfsd?]?||?exit?0?
?9?[?-x?/usr/sbin/rpc.mountd?]?||?exit?0
10?[?-x?/usr/sbin/exportfs?]?||?exit?0??
11?
12?#?Don't?fail?if?/etc/exports?doesn't?exist;?create?a?bare-bones?version?and?continue.
13?[?-r?/etc/exports?]?||?\?????????????????????????????????????????????????????????????
14?????{?touch?/etc/exports?&&?chmod?u+rw,g+r,o+r?/etc/exports?;?}?||?\?????????????????
15?????{?echo?"/etc/exports?does?not?exist"?;?exit?0?;?}????????????????????????????????
16??????????????????????????????????????????????????????????????????????????????????????
17?#?The?/var/lib/nfs?directory?is?actually?on?a?tmpfs?filesystem.??????????????????????
18?mkdir?-p?/var/lib/nfs/sm?????????????????????????????????????????????????????????????
19?mkdir?-p?/var/lib/nfs/sm.bak?????????????????????????????????????????????????????????
20?touch?/var/lib/nfs/etab??????????????????????????????????????????????????????????????
21?touch?/var/lib/nfs/rmtab?????????????????????????????????????????????????????????????
22?touch?/var/lib/nfs/state?????????????????????????????????????????????????????????????
23?touch?/var/lib/nfs/xtab??????????????????????????????????????????????????????????????
24?
25?start()?{
26?????????#?Start?daemons.
27?????????echo?-n?"Starting?port?mapper:?"
28?????????portmap?????????????????????????
29?????????echo?"done"?????????????????????
30?
31?????????echo?-n?"Starting?NFS?statd:?"
32?????????rpc.statd?????????????????????
33?????????touch?/var/lock/subsys/nfslock
34?????????echo?"done"???????????????????
35?
36?????????echo?-n?"Starting?NFS?services:?"
37?????????/usr/sbin/exportfs?-r????????????
38?????????rpc.statd????????????????????????
39?????????echo?"done"??????????????????????
40?
41?????????echo?-n?"Starting?NFS?daemon:?"
42?????????rpc.nfsd?2?????????????????????
43?????????echo?"done"????????????????????
44?
45?????????echo?-n?"Starting?NFS?mountd:?"
46?????????rpc.mountd?????????????????????
47?????????echo?"done"????????????????????
48?????????touch?/var/lock/subsys/nfs?????
49?}??????????????????????????????????????
50?
51?stop()?{
52?????????#?Stop?daemons.
53?????????echo?-n?"Shutting?down?NFS?mountd:?"
54?????????killall?-q?rpc.mountd???????????????
55?????????echo?"done"?????????????????????????
56?
57?????????echo?"Shutting?down?NFS?daemon:?"
58?????????kill?-9?`pidof?nfsd`?2>/dev/null?
59?????????echo?"done"??????????????????????
60?
61?????????echo?-n?"Shutting?down?NFS?services:?"
62?????????/usr/sbin/exportfs?-au????????????????
63?????????rm?-f?/var/lock/subsys/nfs????????????
64?????????killall?-q?rpc.statd??????????????????
65?????????echo?"done"
66?
67?????????echo?-n?"Stopping?NFS?statd:?"
68?????????killall?-q?rpc.statd
69?????????echo?"done"
70?????????rm?-f?/var/lock/subsys/nfslock
71?
72?????????echo?-n?"Stopping?port?mapper:?"
73?????????killall?-q?portmap
74?????????echo?"done"
75?}
76?
77?#?See?how?we?were?called.
78?case?"$1"?in
79???start)
80?????????start
81?????????;;
82???stop)
83?????????stop
84?????????;;
85???restart)
86?????????stop
87?????????start
88?????????;;
89???reload)
90?????????/usr/sbin/exportfs?-r
91?????????touch?/var/lock/subsys/nfs
92?????????;;
93???*)
94?????????echo?"Usage:?nfs?{start|stop|reload}"
95?????????exit?1
96?esac
97?
98?exit?0
?2?#????????????????????????????????????????
?3?#?nfs???????????This?shell?script?takes?care?of?starting?and?stopping
?4?#???????????????the?NFS?services.?Stolen?from?RedHat?FC5.????????????
?5?
?6?[?-x?/sbin/portmap?]?||?exit?0
?7?[?-x?/usr/sbin/rpc.statd?]?||?exit?0
?8?[?-x?/usr/sbin/rpc.nfsd?]?||?exit?0?
?9?[?-x?/usr/sbin/rpc.mountd?]?||?exit?0
10?[?-x?/usr/sbin/exportfs?]?||?exit?0??
11?
12?#?Don't?fail?if?/etc/exports?doesn't?exist;?create?a?bare-bones?version?and?continue.
13?[?-r?/etc/exports?]?||?\?????????????????????????????????????????????????????????????
14?????{?touch?/etc/exports?&&?chmod?u+rw,g+r,o+r?/etc/exports?;?}?||?\?????????????????
15?????{?echo?"/etc/exports?does?not?exist"?;?exit?0?;?}????????????????????????????????
16??????????????????????????????????????????????????????????????????????????????????????
17?#?The?/var/lib/nfs?directory?is?actually?on?a?tmpfs?filesystem.??????????????????????
18?mkdir?-p?/var/lib/nfs/sm?????????????????????????????????????????????????????????????
19?mkdir?-p?/var/lib/nfs/sm.bak?????????????????????????????????????????????????????????
20?touch?/var/lib/nfs/etab??????????????????????????????????????????????????????????????
21?touch?/var/lib/nfs/rmtab?????????????????????????????????????????????????????????????
22?touch?/var/lib/nfs/state?????????????????????????????????????????????????????????????
23?touch?/var/lib/nfs/xtab??????????????????????????????????????????????????????????????
24?
25?start()?{
26?????????#?Start?daemons.
27?????????echo?-n?"Starting?port?mapper:?"
28?????????portmap?????????????????????????
29?????????echo?"done"?????????????????????
30?
31?????????echo?-n?"Starting?NFS?statd:?"
32?????????rpc.statd?????????????????????
33?????????touch?/var/lock/subsys/nfslock
34?????????echo?"done"???????????????????
35?
36?????????echo?-n?"Starting?NFS?services:?"
37?????????/usr/sbin/exportfs?-r????????????
38?????????rpc.statd????????????????????????
39?????????echo?"done"??????????????????????
40?
41?????????echo?-n?"Starting?NFS?daemon:?"
42?????????rpc.nfsd?2?????????????????????
43?????????echo?"done"????????????????????
44?
45?????????echo?-n?"Starting?NFS?mountd:?"
46?????????rpc.mountd?????????????????????
47?????????echo?"done"????????????????????
48?????????touch?/var/lock/subsys/nfs?????
49?}??????????????????????????????????????
50?
51?stop()?{
52?????????#?Stop?daemons.
53?????????echo?-n?"Shutting?down?NFS?mountd:?"
54?????????killall?-q?rpc.mountd???????????????
55?????????echo?"done"?????????????????????????
56?
57?????????echo?"Shutting?down?NFS?daemon:?"
58?????????kill?-9?`pidof?nfsd`?2>/dev/null?
59?????????echo?"done"??????????????????????
60?
61?????????echo?-n?"Shutting?down?NFS?services:?"
62?????????/usr/sbin/exportfs?-au????????????????
63?????????rm?-f?/var/lock/subsys/nfs????????????
64?????????killall?-q?rpc.statd??????????????????
65?????????echo?"done"
66?
67?????????echo?-n?"Stopping?NFS?statd:?"
68?????????killall?-q?rpc.statd
69?????????echo?"done"
70?????????rm?-f?/var/lock/subsys/nfslock
71?
72?????????echo?-n?"Stopping?port?mapper:?"
73?????????killall?-q?portmap
74?????????echo?"done"
75?}
76?
77?#?See?how?we?were?called.
78?case?"$1"?in
79???start)
80?????????start
81?????????;;
82???stop)
83?????????stop
84?????????;;
85???restart)
86?????????stop
87?????????start
88?????????;;
89???reload)
90?????????/usr/sbin/exportfs?-r
91?????????touch?/var/lock/subsys/nfs
92?????????;;
93???*)
94?????????echo?"Usage:?nfs?{start|stop|reload}"
95?????????exit?1
96?esac
97?
98?exit?0