嵌入式linux搭建nfs服务器(portmap+nfs-utils)
使用portmap+nfs-utils的工具在hi3531d的linux系统上搭建nfs服务器,使用VM虚拟机中的ubuntu作为客户端挂载,进行文件的读写。
使用portmap+nfs-utils的工具在hi3531d的linux系统上搭建nfs服务器,使用VM虚拟机中的ubuntu作为客户端挂载,进行文件的读写。
1.首先对linux内核进行修改,让linux内核支持nfs服务器的功能,修改方式是在内核目录arch/arm/configs目录下的hi3531d_defconfig文件添加如下图所示,再进行内核编译,并将内核下载板卡上。
2.Portmap和nfs-utils的下载,其中portmap的下载地址为:https://fossies.org/linux/misc/portmap-6.0.tar.bz2;
nfs-utils的下载地址为: Index of /pub/linux/utils/nfs-utils/1.3.3/
3.portmap的解压、修改与编译
4.nfs-utils的解压、修改与编译
./configure --build=arm-hisiv500-linux --host=arm-linux --disable-nfsv4 --disable-gss --disable-uuid --disable-mount --disable-tirpc --disable-ipv6 --without-tcp-wrappers CC=arm-hisiv500-linux-gcc
5.将编译后的文件安装到/home/alinx/work/hi3531d_BK2010/nfs-utils目录下,如下图流程
make DESTDIR=/home/alinx/work/hi3531d_BK2010/nfs-utils install -strip
6.进入安装目录nfs-utils/sbin的文件如下图所示:
7.将编译好的portmap、 rpc.statd、 rpc.nfsd、rpc.mountd和exportfs文件拷贝到hi3531d板卡上。其中 portmap 放到 /sbin下,其余的放到 /usr/sbin下。注意以上5个文件拷贝到hi3531d板卡上,使用chmod +x 给每个文件赋予执行权限。
8.在hi3531d板卡的/etc/init.d目录下新建S60nfs脚本文件,添加如下内容:
#!/bin/sh
#
# nfs This shell script takes care of starting and stopping
# the NFS services. Stolen from RedHat FC5.
[ -x /sbin/portmap ] || exit 0
[ -x /usr/sbin/rpc.statd ] || exit 0
[ -x /usr/sbin/rpc.nfsd ] || exit 0
[ -x /usr/sbin/rpc.mountd ] || exit 0
[ -x /usr/sbin/exportfs ] || exit 0
# Don't fail if /etc/exports doesn't exist; create a bare-bones version and continue.
[ -r /etc/exports ] || \
{ touch /etc/exports && chmod u+rw,g+r,o+r /etc/exports ; } || \
{ echo "/etc/exports does not exist" ; exit 0 ; }
# The /var/lib/nfs directory is actually on a tmpfs filesystem.
mkdir -p /var/lib/nfs/sm
mkdir -p /var/lib/nfs/sm.bak
touch /var/lib/nfs/etab
touch /var/lib/nfs/rmtab
touch /var/lib/nfs/state
touch /var/lib/nfs/xtab
start() {
# Start daemons.
echo -n "Starting port mapper: "
portmap
echo "done"
echo -n "Starting NFS statd: "
rpc.statd
touch /var/lock/subsys/nfslock
echo "done"
echo -n "Starting NFS services: "
/usr/sbin/exportfs -r
rpc.statd
echo "done"
echo -n "Starting NFS daemon: "
rpc.nfsd 2
echo "done"
echo -n "Starting NFS mountd: "
rpc.mountd
echo "done"
touch /var/lock/subsys/nfs
}
stop() {
# Stop daemons.
echo -n "Shutting down NFS mountd: "
killall -q rpc.mountd
echo "done"
echo "Shutting down NFS daemon: "
kill -9 `pidof nfsd` 2>/dev/null
echo "done"
echo -n "Shutting down NFS services: "
/usr/sbin/exportfs -au
rm -f /var/lock/subsys/nfs
killall -q rpc.statd
echo "done"
echo -n "Stopping NFS statd: "
killall -q rpc.statd
echo "done"
rm -f /var/lock/subsys/nfslock
echo -n "Stopping port mapper: "
killall -q portmap
echo "done"
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
/usr/sbin/exportfs -r
touch /var/lock/subsys/nfs
;;
*)
echo "Usage: nfs {start|stop|reload}"
exit 1
esac
exit 0
9.在hi3531d板卡的/etc目录下,添加exports文件,如下图所示:
10.在hi3531d板卡的/etc目录下,在servers文件中添加nfsd的支持,如下图所示:
11.在hi3531d板卡的linux系统中开启nfs的服务,如下图所示:
/etc/init.d/S60nfs restart
更多推荐
所有评论(0)