配置TFTP

Uboot启动内核镜像,除了在SD卡、Nand等raw分区中启动外,还可以通过tftp从远端服务器获取镜像。
下面是配置tftp的过程

安装TFTP客户端、服务程序和xinetd

1
2
sudo apt-get install tftp-hpa tftpd-hpa
sudo apt-get install xinetd

文件配置

配置/etc/xinetd.conf

若没有,则创建,然后修改,下同

1
2
3
4
5
6
7
8
9
10
# Simple configuration file for xinetd
##
Some defaults, and include /etc/xinetd.d/
defaults
{#
Please note that you need a log_type line to be able to use log_on_success
# and log_on_failure. The default is the following :
# log_type = SYSLOG daemon info
}
includedir /etc/xinetd.d

配置/etc/default/tftpd-hpa

将内容改为

1
2
3
4
5
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-l -c -s"

配置/etc/xinetd.d/tftp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
service tftp
{
socket_type = dgram
wait = yes
disable = no
user = root
protocol = udp
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
#log_on_success += PID HOST DURATION
#log_on_failure += HOST
per_source = 11
cps =100 2
flags =IPv4
}

修改权限

创建一个服务器存放文件的文件夹并设置最高权限

1
2
sudo mkdir /tftpboot
sudo chmod 777 /tftpboot

重启服务

每次修改完配置文件都需要重启服务

1
2
3
sudo service tftpd-hpa restart
sudo /etc/init.d/xinetd reload
sudo /etc/init.d/xinetd restart

本地测试

  1. 在/tftpboot 中新建一个文件file
  2. 进入另一个文件夹中
    进入本地tftp命令行下

    1
    2
    sudo tftp localhost
    // 可输入help查看命令和命令作用
  3. 1
    2
    3
    get file // 下载文件到当前文件夹
    put file // 上传文件到tftp服务器
    q // 退出tftp命令行

非本地

  1. 关闭防火墙(sudo ufw disable)或 卸载防火墙(sudo apt -get remove iptables)
  2. sudo tftp 目标ip地址
要是觉得不错,就鼓励一下吧!