-
由于开发板挂载 ubuntu18.04系统下的 nfs根文件系统会失败,因为从Ubuntu17.04开始,nfs默认只支持协议3和协议4,而kernel中默认支持协议2,所以才会出现挂载失败的情况。所以要根据情况修改nfs配置文件:
~$ sudo vi /etc/default/nfs-kernel-server
,
在文件末尾加入一句:RPCNFSDOPTS="--nfs-version 2,3,4 --debug --syslog"
,
输入命令重启NFS服务:
~$sudo /etc/init.d/nfs-kernel-server restart
[ ok ] Restartubg nfs-kernel-server (via systemctl): nfs-kernel-service.
-
打开busybox官网地址
https://busybox.net/
下载当前最新稳定版 BusyBox 1.31.1 -
配置并编译busybox
3.1 修改Makefile,添加编译器。注:这里使用的是编译器的绝对路径。
164 CROSS_COMPILE ?= /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
3.2 指定目标CPU架构
190 #ARCH ?= $(SUBARCH)
191 ARCH ?= arm
3.3 使用make defconfig
命令进行配置
glen@ubuntu:~/linux/imx6ull/busybox/glen_busybox$ make defconfig
scripts/kconfig/conf -d Config.in
*
* Busybox Configuration
*
......
Linux kernel printk buffer support (FEATURE_KMSG_SYSLOG) [Y/n/?] (NEW) y
执行完之后会产生.config文件如:-rw-r--r-- 1 glen glen 28195 1月 15 22:59 .config
3.4 更改busybox源文件以支持中文显示
更改busybox/libbb/printable_string.c文件中的printable_string2函数
12 const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str)
13 {
14 char *dst;
15 const char *s;
16
17 s = str;
18 while (1) {
19 unsigned char c = *s;
20 if (c == '\0') {
21 /* 99+% of inputs do not need conversion */
22 if (stats) {
23 stats->byte_count = (s - str);
24 stats->unicode_count = (s - str);
25 stats->unicode_width = (s - str);
26 }
27 return str;
28 }
29 if (c < ' ')
30 break;
31 /* if (c >= 0x7f)
32 break; */
33 s++;
34 }
35
36 #if ENABLE_UNICODE_SUPPORT
37 dst = unicode_conv_to_printable(stats, str);
38 #else
39 {
40 char *d = dst = xstrdup(str);
41 while (1) {
42 unsigned char c = *d;
43 if (c == '\0')
44 break;
45 /* if (c < ' ' || c >= 0x7f)
46 *d = '?'; */
47 if (c < ' ')
48 *d = '?';
49 d++;
50 }
51 if (stats) {
52 stats->byte_count = (d - dst);
53 stats->unicode_count = (d - dst);
54 stats->unicode_width = (d - dst);
55 }
56 }
57 #endif
58 return auto_string(dst);
59 }
更改busybox/libbb/unicode.c文件中的unicode_conv_to_printable2函数
1003 static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags)
1004 {
1005 char *dst;
1006 unsigned dst_len;
1007 unsigned uni_count;
1008 unsigned uni_width;
1009
1010 if (unicode_status != UNICODE_ON) {
1011 char *d;
1012 if (flags & UNI_FLAG_PAD) {
1013 d = dst = xmalloc(width + 1);
1014 while ((int)--width >= 0) {
1015 unsigned char c = *src;
1016 if (c == '\0') {
1017 do
1018 *d++ = ' ';
1019 while ((int)--width >= 0);
1020 break;
1021 }
1022 /* *d++ = (c >= ' ' && c < 0x7f) ? c : '?'; */
1023 *d++ = (c >= ' ') ? c : '?';
1024 src++;
1025 }
1026 *d = '\0';
1027 } else {
1028 d = dst = xstrndup(src, width);
1029 while (*d) {
1030 unsigned char c = *d;
1031 /* if (c < ' ' || c >= 0x7f)
1032 *d = '?'; */
1033 if (c < ' ')
1034 *d = '?';
1035 d++;
1036 }
1037 }
1038 if (stats) {
1039 stats->byte_count = (d - dst);
1040 stats->unicode_count = (d - dst);
1041 stats->unicode_width = (d - dst);
1042 }
1043 return dst;
......
3.5 使用make menuconfig
命令进行图形化配置
1)Settings —> [ ] Build static binary (no shared libs) 这里不选中,即不使用静态编译
2)Settings —> [*] vi-style line editing commands 这里选中
3)Linux Module Utilities —> [ ] Simplified modutils 这里不选中
4)Linux System Utilities —>
[*] mdev(17kb)
[*] Support /etc/mdev.conf
[*] Support subdirs/symlinks [*] Support regular expressions substitutions when renaming device
[*] Support command execution at device addition/removal
[*] Support loading of firmware
[*] Support daemon mode
[*] mesg (1.4 kb)
这几项均选中
5)Settings —> [*] Check $LC_ALL, $LC_CTYPE and $LANG environment variables
3.6 编译busybox
输入命令:make install CONFIG_PREFIX=/home/glen/linux/nfs/rootfs
,产生下面的提示编译完成
/home/glen/linux/nfs/rootfs//usr/sbin/ubirsvol -> ../../bin/busybox
/home/glen/linux/nfs/rootfs//usr/sbin/ubiupdatevol -> ../../bin/busybox
/home/glen/linux/nfs/rootfs//usr/sbin/udhcpd -> ../../bin/busybox
--------------------------------------------------
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------
- 向根文件系统添加lib库
4.1 把/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linuxgnueabihf/libc/lib
路径下的库文件拷贝到./nfs/rootfs/lib/
目录
glen@ubuntu:/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib$ cp *so* *.a /home/glen/linux/nfs/rootfs/lib -d
glen@ubuntu:~/linux/nfs/rootfs/lib$ rm ld-linux-armhf.so.3
glen@ubuntu:/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib$ cp ld-linux-armhf.so.3 /home/glen/linux/nfs/rootfs/lib
4.2 把/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/lib
路径下的库文件拷贝到./nfs/rootfs/lib/
目录
glen@ubuntu:/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib$ cp *so* *.a /home/glen/linux/nfs/rootfs/lib -d
4.3 把/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/ usr/lib
路径下的库文件拷贝到./nfs/rootfs/usr/lib/
目录
glen@ubuntu:/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib$ cp *so* *.a /home/glen/linux/nfs/rootfs/usr/lib -d
检查一下文件拷贝情况,
glen@ubuntu:~/linux/nfs/rootfs$ du ./lib ./usr/lib -sh
57M ./lib
67M ./usr/lib
4.4 创建其它文件夹: dev proc mnt sys tmp root
glen@ubuntu:~/linux/nfs/rootfs$ mkdir dev proc mnt sys tmp root
glen@ubuntu:~/linux/nfs/rootfs$ ls
bin dev lib linuxrc mnt proc root sbin sys tmp usr
- 根文件系统测试
5.1 设置uboot的bootargs环境变量
=> setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs rw nfsroot=192.168.1.55:/home/glen/linux/nfs/rootfs ip=192.168.1.50:192.168.1.55:192.168.1.1:255.255.255.0::eth0:off'
=> saveenv
Saving Environment to MMC...
Writing to MMC(0)... done
5.2 linux启动测试,重启开发板,在终端打印出以下提示,说明根文件系统制作成功同时linux正常启动
......
mmcblk1boot1: mmc1:0001 8GTF4R partition 2 4.00 MiB
mmcblk1rpmb: mmc1:0001 8GTF4R partition 3 512 KiB
mmcblk1: p1 p2
fec 20b4000.ethernet eth0: Link is Up - 100Mbps/Full - flow control off
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
IP-Config: Complete:
device=eth0, hwaddr=00:04:99:00:d3:33, ipaddr=192.168.1.50, mask=255.255.255.0, gw=192.168.1.1
host=192.168.1.50, domain=, nis-domain=(none)
bootserver=192.168.1.55, rootserver=192.168.1.55, rootpath=
can-3v3: disabling
ALSA device list:
No soundcards found.
VFS: Mounted root (nfs filesystem) on device 0:15.
devtmpfs: mounted
Freeing unused kernel memory: 404K (8090f000 - 80974000)
can't run '/etc/init.d/rcS': No such file or directory
Please press Enter to activate this console.
/ #
5.3 完善根文件系统
5.3.1 创建/etc/init.d/rcS文件
从5.2小节试验的终端提示可以看出缺少rcS文件,这里我们就直接创建rcS文件(在终端直接操作即可——先创建目录/etc/init.d/
,再创建rcS文件),并编辑以下内容:
#!/bin/sh #这是一个shell脚本
PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib:/usr/lib
export PATH LD_LIBRARY_PATH runlevel
mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/kernel/hotplug
mdev -s
5.3.2 创建/etc/fstab文件(fstab在Linux开机以后自动配置哪些需要自动挂载的分区),编辑以下内容:
#<file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
5.3.3 创建/etc/inittab文件,编辑以下内容:
1 #etc/inittab
2 ::sysinit:/etc/init.d/rcS
3 console::askfirst:-/bin/sh
4 ::restart:/sbin/init
5 ::ctrlaltdel:/sbin/reboot
6 ::shutdown:/bin/umount -a -r
7 ::shutdown:/sbin/swapoff -a