简单根文件系统构建记录

开发环境简介
开发板正点原子MINI
操作系统Linux-Mint 20.2
交叉编译链gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf
BusyBox版本busybox-1.34.1
BusyBox配置
BusyBox下载

​ BusyBox官网地址:https://busybox.net

​ busybox-1.34.1下载地址:https://busybox.net/downloads/busybox-1.34.1.tar.bz2

​ 解压即可

tar -jxvf busybox-1.34.1.tar.bz2
BusyBox配置选项

​ 提供三种配置选项:

1. defconfig:默认配置
2. allyesconfig:全选配置,使能busybox中的所有选项
3. allnoconfig:最小配置

一般使用默认配置:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- defconfig

同样支持图形化配置:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
编译脚本
vim build_custom_rootfs.sh

内容如下:

#! /bin/sh

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- 

// 指定输出地址
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- install CONFIG_PREFIX=<OUTPUT_PATH>

编译成功打印:

  DOC     busybox.pod
  DOC     BusyBox.txt
  DOC     busybox.1
  DOC     BusyBox.html

安装成功打印:

--------------------------------------------------
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------

此时,rootfs还不完善。

完善rootfs
  • 创建需要的文件夹

    mkdir dev etc proc mnt sys tmp root var opt lib 
    
  • 添加动态库(从交叉编译器中获取)

    将交叉编译器根目录 arm-linux-gnueabihs/libarm-linux-gnueabihs/libc/lib 中的所有.so文件和.a文件拷贝到 rootfs/lib 文件中

    cp *so* *.a <rootfs_path>/lib -d
    

    在 rootfs/usr/ 目录下新建 /lib 文件夹,将将交叉编译器根目录 arm-linux-gnueabihs/libc/usrlib 中的所有.so文件和.a文件拷贝进去

    cp *so* *.a <rootfs_path>/lib -d
    

    此时,根文件系统基本完整。

NFS挂载根文件系统
安装NFS服务
sudo apt install nfs-kernel-server  rpcbind
配置NFS
  • 新建 nfs 文件夹作为工作目录

    mkdir <nfs_path>
    chmod 777 <nfs_path>
    
  • 修改配置文件(路径一定不要弄错,()里的内容不要有空格)

    sudo vim /etc/exports
    
    <nfs_path> *(rw,sync,no_root_squash)
    
  • 重启服务

    sudo /etc/init.d/nfs-kernel-server restart
    
启动配置
设置uboot环境变量
setenv serverip 192.168.0.101   // 设置服务器IP 
setenv nfsroot '/home/hugh/Network/nfs/rootfs'  // 设置rootfs路径
saveenv // 保存环境

直接设置bootargs会失败,可能是uboot或者kernel移植时没配置好,启动内核时如下语句判断是否正确。

[    0.000000] Kernel command line: console=ttymxc0,115200 root=/dev/nfs ip=dhcp nfsroot=192.168.0.101:/home/hugh/Network/nfs/rootfs,v3,tcp
错误处理
  1. arm-linux-gnueabihs/libc/lib中复制的ld-linux-armhf.so.3不能是链接文件,需要重新替换
[   13.355364] VFS: Mounted root (nfs filesystem) readonly on device 0:16.
[   13.365994] devtmpfs: mounted
[   13.371928] Freeing unused kernel memory: 1024K
[   13.394700] Run /sbin/init as init process
[   13.683530] request_module: kmod_concurrent_max (0) close to 0 (max_modprobes: 50), for module binfmt-464c, throttling...
[   18.724509] request_module: modprobe binfmt-464c cannot be processed, kmod busy with 50 threads for more than 5 seconds now
[   18.761697] Starting init: /sbin/init exists but couldn't execute it (error -8)
[   18.781427] Run /etc/init as init process
[   18.840029] Run /bin/init as init process
[   18.854243] Run /bin/sh as init process
[   19.074661] request_module: kmod_concurrent_max (0) close to 0 (max_modprobes: 50), for module binfmt-464c, throttling...
[   24.084527] request_module: modprobe binfmt-464c cannot be processed, kmod busy with 50 threads for more than 5 seconds now
[   24.121461] Starting init: /bin/sh exists but couldn't execute it (error -8)
[   24.140938] Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.
[   24.155241] ---[ end Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance. ]---

​ 先删除rootfs/lib下的ld-linux-armhf.so.3文件,回到交叉编译链的库文件中重新拷贝,不要带-d参数

cp ld-linux-armhf.so.3  <rootfs_path>/lib/
完善

​ Kernel挂载根文件系统后,运行的第一个程序是根目录下的linuxrc,其实质是一个指向/bin/busybox的链接,即系统启动后运行的第一个程序是busybox本身。linux先执行/etc/inittab,然后调用/etc/init.d/rcS,最后执行/etc/profile/。因此,我们需要先把文件创建出来。

# /etc/init.d/rcS 开机启动脚本
echo Hello Linux
ls
# /etc/fstab Linux 开机以后自动配置需要自动挂载的分区。
proc    /proc   proc    defaults    0   0
tmpfs   /tmp    tmpfs   defaults    0   0
sysfs   /sys    sysfs   defaults    0   0
# /etc/inittab

::sysinit:/etc/init.d/rcS
# console::askfirst:-/bin/sh
console::respawn:-/bin/sh
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/unmount -a -r
::shutdown:/sbin/swapoff -a
# /etc/profile 全局环境变量相关

PATH=/sbin:/bin:/usr/sbin:/usr/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib:/usr/lib
USER=root
LOGNAME=$USER
HOSTNAME=`/bin/hostname`
HOME=/root
PS1="[$USER@$HOSTNAME\W]\#"
export USER LOGNAME HOSTNAME HOME PS1 PATH LD_LIBRARY_PATH

​ 1. 失能Please press Enter to activate this console.

​ 在/etc/inittab,将::askfirst:-/bin/sh改为::respawn:-/bin/sh

​ 2. 设置hostname

​ 在/etc/init.d/rcS加入/bin/hostname

​ 3. 设置user

​ 在/etc/profile 设置USER=root

启动结果
[    7.305811] Run /sbin/init as init process
Hello Linux
total 44
drwxrwxr-x    2 1000     1000          4096 Oct 17  2021 bin
drwxr-xr-x    5 0        0             2880 Jan  1  1970 dev
drwxrwxr-x    3 1000     1000          4096 Oct 17  2021 etc
-rwxrwxr-x    1 1000     1000           143 Oct 17  2021 init
drwxrwxr-x    2 1000     1000          4096 Oct 17  2021 lib
lrwxrwxrwx    1 1000     1000            11 Oct 17  2021 linuxrc -> bin/busybox
drwxrwxr-x    2 1000     1000          4096 Oct 17  2021 mnt
drwxrwxr-x    2 1000     1000          4096 Oct 17  2021 proc
drwxrwxr-x    2 1000     1000          4096 Oct 17  2021 root
drwxrwxr-x    2 1000     1000          4096 Oct 17  2021 sbin
drwxrwxr-x    2 1000     1000          4096 Oct 17  2021 sys
drwxrwxr-x    2 1000     1000          4096 Oct 17  2021 tmp
drwxrwxr-x    5 1000     1000          4096 Oct 17  2021 usr
[root@hugh]#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值