1、制作根文件系统
Linux中就有制作根文件系统的工具,mke2fs.只需要找到一个目录,然后依次执行下面的命令就行
dd if=/dev/zero of=rootfs.ext2 bs=1024 count=2048
losetup /dev/loop1 rootfs.ext2
mke2fs -m 0 /dev/loop1 2048
mount -t ext2 /dev/loop1 ./rootfs/ #注意这里的rootfs在执行前应该创建出一个这样的文件夹
上面的命令中的loop1,执行的时候如果显示losetup: rootfs.ext2:设置回环设备失败: 设备或资源忙
,可以改成loop2,
还是不行的话,就改成loop3,以此类推。
然后进到刚刚创建的rootfs目录中,创建一个touch linuxrc
的文件。
卸载命令
umount /dev/loop1
losetup -d /dev/loop1
注意这里的loop1,要和上面的loop一样,上面用的loop2 ,这里就用loop2.
2、nfs方式挂载根文件系统
nfs是一种网络通讯协议,由服务器和客户端构成。在主机ubuntu的nfs服务器中导出我们制作的文件夹形式的rootfs目录,则在客户端中就可以去挂载这个文件夹形式的rootfs进而去启动系统。
安装nfs
sudo apt-get install nfs-kernel-server -y
然后我们要配置nfs,打开vi /etc/exports
,输入
/home/mengchao/flushbonding/rootfs/rootfs *(rw,sync,no_root_squash,no_subtree_check)
前面就是我们放的rootfs的位置,根据自己的位置决定,后面照着写就行了,在星号前面有一个空格。
依次执行下面的命令,自己检查命令是否执行成功
chmod 777 /home/mengchao/flushbonding/rootfs/rootfs
sudo exportfs -r
sudo showmount localhost -e
sudo /etc/init.d/nfs-kernel-server restart
注意第一个,文件夹是自己电脑的文件夹,不可复制粘贴。
待解决:未下载成功
3、配置内核和开发板支持nfs
make menuconfig中
配置Linux内核支持nfs
1、配置网络部分,主要是使能CONFIG_IP_PNP以在2中能够看到Root file system on NFS选项
Networking support
Networking options
TCP/IP networking
IP: kernel level autoconfiguration
[*] IP: DHCP support
[*] IP: BOOTP support
2、配置开启nfs服务
File systems --->
Network File Systems --->
<*> NFS client support
[*] NFS client support for NFS version 3
[*] NFS client support for the NFSv3 ACL protocol extension
[*] NFS client support for NFS version 4 (EXPERIMENTAL)
[*] NFS client support for NFSv4.1 (DEVELOPER ONLY)
[*] Root file system on NFS
3、在uboot中设置如下启动参数(IP根据实际使用更改)
setenv bootargs root=/dev/nfs rw nfsroot=192.168.0.111:/home/mengchao/flushbonding/rootfs/rootfs ip=192.168.0.88:192.168.0.111:192.168.0.1:255.255.255.0::enp2s0:off init=/linuxrc console=ttySAC2,115200
设置这句话的时候,因为太长,minicom就自动把后面的省略了,这个要注意一下,我就是因为这个倒腾了好几次才发现。可以自己手动输入,到屏幕末尾的时候,用一个连接符\
,然后回车继续输入后面的部分。
4、下载busybox
下载busybox,随便下载到一个地方,解压,进到源代码目录
第一步:make menuconfig,大概的配置项就这么几个
Busybox Settings--->
Build Options--->
[*]Build BusyBox as a static binary(no shared libs)
Busybox Library Tuning--->
[*]vi-style line editing commands
[*]Fancy shell prompts
Linux Module Utilities--->
[ ]Simplified modutils
[*]insmod
[*]rmmod
[*]lsmod
[*]modprobe
[*]depmod
Linux System Utilities--->[*]mdev
[*]Support /etc/mdev.conf
[*]Support subdirs/symlinks
[*]Support regular expressions substitutions when renaming dev
[*]Support command execution at device addition/removal
[*]Support loading of firmwares
第二步:make,一般来说不会有什么错误,有错误就要自己解决喽,我这里遇到一个error:
util-linux/lib.a(nsenter.o): In function `nsenter_main':
nsenter.c:(.text.nsenter_main+0x180): undefined reference to `setns'
collect2: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
Makefile:718: recipe for target 'busybox_unstripped' failed
make: *** [busybox_unstripped] Error 1
解决方法:make menuconfig在Linux System Utilities--->nsenter,去掉该选项,重新编译make
第三步:make install
执行成功后,我们安装到我们的nfs挂载的根文件系统中,方法如下:
我们的根文件系统目录:/home/mengchao/flushbonding/rootfs/rootfs
方法:make menuconfig
Busybox Settings —>
Installation Options (“make install” behavior) —> (./_install) Destination path for 'make install'
点进去,改成我们将要用作NFS挂载的目录
/home/mengchao/flushbonding/rootfs/rootfs
make install
此时就安装到了我们的根文件系统中去了,这里添加这几个文件或者文件夹
5、一些文件和文件夹的添加
不可缺少的文件夹dev、sys、proc、usr、etc、lib。
etc中要有inittab(才可以使用开发板中的控制台,必不可少啊)、profile(在shell前面添加用户名), init.d (文件夹), init.d 中要有rCS。
动态链接库/usr/local/arm/arm-2009q3/arm-none-linux-gnueabi/libc/lib
复制动态链接库到roots/lib目录下(自行创建)。复制时要注意参数用-rdf,主要目的就是符号链接复制过来还是符号链接。复制命令:cp lib/*so* /home/menghcao/flushbonding/rootfs/rootfs/lib/ -rdf
使用strip工具去掉库中符号信息
动态链接库so文件中包含了调试符号信息,这些符号信息在运行时是没用的(调试时用的),这些符号会占用一定空间。在传统的嵌入式系统中flash空间是有限的,为了节省空间常常把这些符号信息去掉。这样节省空间并且不影响运行。
去掉符号信息的命令:arm-linux-strip so
6、制作ext2格式的镜像并烧录启动
按照第一步重新做一个文件夹,暂时先不unmount,全部做好之后再卸载,然后把上面nfs中的那个根文件系统中的rootfs全部复制过来,然后unmount即可。
版权属于:孟超
本文链接:https://mengchao.xyz/index.php/archives/625/
转载时须注明出处及本声明