安装 TFTP 服务:
sudo apt-get install tftpd-hpa创建 /tftpboot 目录并赋予权限:
mkdir /tftpboot sudo chmod 777 /tftpboot然后修改 TFTP 服务器的配置文件 /etc/default/tftpd-hpa,修改内容为:
# vi /etc/default/tftpd-hpa TFTP_USERNAME="tftp" TFTP_DIRECTORY="/tftpboot" #这个根据用户实际的 tftp 目录设置 TFTP_ADDRESS="0.0.0.0:69" TDTP_OPTIONS="-c -s -l"退出修改后重启 TFTP 服务器:
sudo service tftpd-hpa restart在 /tftpboot 目录中创建一个文件,测试 TFTP 服务是否可用:
firefly@Desktop:~$ cd /tftpboot/ firefly@Desktop:/tftpboot$ touch test firefly@Desktop:/tftpboot$ cd /tmp firefly@Desktop:/tmp$ tftp 127.0.0.1 tftp> get test tftp> q查看 /tmp 目录中的文件,如果看到了 test 文件表示 TFTP 服务器是可用的。
安装 NFS 服务器:
sudo apt-get install nfs-kernel-server 创建共享目录:
sudo mkdir /nfs sudo chmod 777 /nfs cd /nfs sudo mkdir rootfs sudo chmod 777 rootfs然后将制作好的根文件系统复制到 /nfs/rootfs 目录中。(根文件系统的制作可以参考:Ubuntu 根文件系统的制作)
接着配置 NFS,在 /etc/exports 中添加共享目录位置:
/nfs/rootfs *(rw,sync,no_root_squash,no_subtree_check)共享的目录根据用户实际情况设置,其中的”*”代表的是所有用户可访问。
重启 NFS 服务器:
sudo /etc/init.d/nfs-kernel-server restart本地挂载共享目录,测试 NFS 服务器是否可用:
sudo mount -t nfs 127.0.0.1:/nfs/rootfs/ /mnt在 /mnt 目录下查看到了与 /nfs/rootfs 一致的内容,则说明 NFS 服务器部署成功。然后可以解除挂载:
sudo umount /mnt如果要做到挂载网络根文件系统,需要在内核中做相关配置,并在 dts 中修改相关挂载根文件系统的配置。
首先进行内核配置,在内核目录中执行 make menuconfig,选择相关配置:
[*] Networking support ---> Networking options ---> [*] IP: kernel level autoconfiguration [*] IP: DHCP support [*] IP: BOOTP support [*] IP: RARP support File systems ---> [*] Network File Systems ---> [*] Root file system on NFS配置在 dts 文件中修改 chosen 节点下的 bootargs 参数,选择使用 NFS 挂载远程根文件系统,内容如下。修改kernel/arch/arm64//boot/dts/rockchip/rk3399-linux.dtsi
chosen { //支持mmc启动 //bootargs = "earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 console=ttyFIQ0 ro root=PARTLABEL=rootfs rootfstype=ext4 rootwait overlayroot=device:dev=PARTLABEL=userdata,fstype=ext4,mkfs=1 coherent_pool=1m systemd.gpt_auto=0 cgroup_enable=memory swapaccount=1"; //支持NFS启动 bootargs = "earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 console=ttyFIQ0 ro root=/dev/nfs rootfstype=ext4 rootwait overlayroot=device:dev=PARTLABEL=userdata,fstype=ext4,mkfs=1 coherent_pool=1m systemd.gpt_auto=0 cgroup_enable=memory swapaccount=1 nfsroot=192.168.3.32:/nfs/rootfs,v3 ip=192.168.3.101:192.168.3.32:192.168.3.1:255.255.255.0::eth0:off"; };#主要是修改 root 的值,root=/dev/nfs 表示通过 NFS 挂载网络根文件系统 编译内核:
make ARCH=arm64 rk3399-firefly.img -j12编译完成后,将编译好的内核文件 boot.img 和 rk3399-firefly.dtb 文件复制到 /tftpboot 目录中:
cp boot.img /tftpboot cp arch/arm64/boot/dts/rockchip/rk3399-firefly.dtb /tftpboot详细说明可以参考内核目录中的 kernel/Documentation/filesystems/nfs/nfsroot.txt
