您的位置:首页 > 运维架构 > Linux

嵌入式Linux中tftp和nfs的笔记

2017-05-16 14:55 337 查看

一、tftp

我用的ubuntu14.04已经安装好tftp服务,这里记录下网上的安装方法:

1、服务器安装tftp,

apt-get install tftpd-hpa, tftp-hpa

我没有安装xinetd,能够成功从服务器下载文件到开发板。

2、配置TFTP服务器:

# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/root/hi3518/tftpboot"  #服务器端的tftp目录
TFTP_ADDRESS="0.0.0.0:69"
#TFTP_OPTIONS="--secure"
TFTP_OPTIONS="-l -c -s"


3、重启tftp服务service tftpd-hpa restart

看看服务是否开启

netstat -a | grep tftp

显示结果为

udp 0 0 :tftp :*

表明服务已经开启,就表明tftp配置成功了。

4、在服务器端测试tftp:

tftp

get “filename”

但我这步没有成功。

下面是在开发板上测试tftp

“需要注意的的是设置开发板的serverip与服务器的ip设置一样”

“关闭防火墙”

“开发板在编译内核时应该把tftp选中,编译进内核中”

1、在开发板进入Linux系统后,busybox中的tftp命令为:

# tftp
BusyBox v1.16.1 (2015-04-01 19:35:12 HKT) multi-call binary.
Usage: tftp [OPTIONS] HOST [PORT]
Transfer a file from/to tftp server
Options:
-l FILE Local FILE (本地文件)
-r FILE Remote FILE (远程服务器上tftp目录下的文件)
-g      Get file  (下载文件)
-p      Put file  (上传文件到服务器)
-b SIZE Transfer blocks of SIZE octets
#


2、下载文件到当前目录tftp -g -r

# ls
hello    hello.c  world.c
# rm hello
# ls
hello.c  world.c
# rm hello.c
# rm world.c
# ls
# tftp -g -r hello.c 192.168.1.105
hello.c              100% |**************************|   512  --:--:-- ETA
# cat hello.c
#include<stdio.h>
main(){
printf("hello\r\n");
}
# tftp -g -r hello 192.168.1.105
hello                100% |*************************|  5120  --:--:-- ETA
# ./hello
-sh: ./hello: Permission denied
# ls -l hello
-rw-r--r--    1 root     root          4681 Jan  1 00:13 hello
# chmod 777 hello
# ./hello
hello
#


3、uboot中也带有tftp服务,其命令格式与busybox中的不一样

在uboot命令下tftp下载服务器文件到ram中的确定的地址

mw.b 82000000 ff 100000 (擦除一定空间大小)

tftp 0x82000000 (下载文件到此地址中)

这样可方便的下载编译好的内核和文件系统,如果在Windows系统下用tftp需要tftpd32软件,把在Linux系统中编译好的文件复制到Windows下,比较麻烦。

二、nfs

1、服务器端nfs的配置,网上很多

配置文件:etc目录下的exports文件,最后面添加下面一句:

/root/hi3518/nfs *(insecure,rw,sync,no_root_squash)

前面的目录自己设置,*表示所有ip都可以访问这个目录,若要指定Ip可以这样写

/root/hi3518/nfs 192.168.1.*(insecure,rw,sync,no_root_squash)

开启nfs

/etc/init.d/portmap start //用service portmap stasrt也可以

/etc/init.d/nfs start 或者service nfs start也可以

nfs挂载有两种,一是把服务器端的完整的文件系统作为开发板的跟文件系统挂载,

参考嵌入式linux之NFS启动根文件系统

二是把服务器nfs目录挂载在开发板上的一个目录上。

linux nfs配置

# ls
nfs   tftp
# cd nfs
# cd ..
# mount -t nfs -o nolock 192.168.1.105:/root/hi3518/nfs nfs
# cd nfs
# ls
hello        hello.c      ircut        ko           redled       sample_venc
# cd ..
# ls
nfs   tftp
# umount -t nfs 192.168.1.105:/root/hi3518/nfs
umount: can't umount 192.168.1.105:/root/hi3518/nfs: No such file or directory
# ls
nfs   tftp
# cd nfs
# ls
#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: