基于busybox制作mini2440根文件系统及使用nfs挂载

时间:2021-01-01 12:45:22
 

常见的文件系统有yaffs2, jffs2,他们是适用于根文件系统镜像存在于NAND Flash上的情况。而传统的Linux EXT2/EXT3文件系统格式适用于传统的block设备,比如SD卡或者硬盘。
cramfs同时适用于以上两种情况。其不管采用哪种格式,内核都必须支持它,这是根文件系统正确挂载的前提条件。其内核支持它是指:在对内核进行编译的时候必须加入对相应文件系统的支持。

基于busybox制作mini2440根文件系统及使用nfs挂载

由于在内核没有加入对yaffs2的支持,因此在最后根据mkyaffs2image制作yaffs2类型的根文件系统,在加载之前,必须要对linux内核进行打yaffs2的补丁。将yaffs文件系统编译进内核。之后在启动linux内核时候才能识别yaffs2文件系统。

我在自己的mini2440开发板上面通过nfs来加载制作好的"根文件系统",这里的"根文件系统"指的是:没有经过像mkyaffs2image工具转化的原始的类linux目录结构的文件。其文件包括Linux启动时所必须的目录和关键性的文件。nfs便于加载及验证我们制作的文件系统的正确性。其加载时文件系统不用读写flash。

*******************************第一步:下载busybox并编译********************************

下载busybox-1.19.2.tar.bz2

http://www.busybox.net/downloads/

解压并进入目录
# tar jxvf busybox-1.19.2.tar.bz2
# cd busybox-1.19.2修改Makefile
# gedit Makefile &
把 164 行修改为:
CROSS_COMPILE = arm-linux-
把 190 行修改为:
ARCH = arm

配置
# make menuconfig 或者make xconfig(为图形化界面)

在Busybox Settings->Build Options之下选择Build BusyBox as a static binary (no shared libs) (STATIC)以静态的方式来编译busybox。

其他的比如安装目录及常用命令我没有设置,采用的是默认值。如果有需要再添加。
编译
# make

安装
# make install

在busybox-1.19.2目录下可以找到_install子目录,其中就是编译好的命令。

[busybox-1.19.2]$ll

total 12
drwxr-xr-x 2 root root 4096 Feb  9 14:43 bin
lrwxrwxrwx 1 root root   11 Feb  9 14:43 linuxrc -> bin/busybox
drwxr-xr-x 2 root root 4096 Feb  9 14:43 sbin
drwxr-xr-x 4 root root 4096 Feb  9 14:43 usr

并将以上文件copy到/mini2440/rootfs目录下面

 *******************第二步:建立所需的目录及文件*************************

1: 建立目录

使用以下脚本

[root@centos /mini2440]$cat mkDir.sh //具有执行权限
#!/bin/sh
echo "------Create rootfs directons start...--------"
mkdir /mini2440/rootfs
cd /mini2440/rootfs
echo "--------Create root,dev....----------"
mkdir root dev etc boot tmp var sys proc lib mnt home usr
mkdir etc/init.d etc/rc.d etc/sysconfig
mkdir usr/sbin usr/bin usr/lib usr/modules
echo "make node in dev/console dev/null"
mknod -m 600 dev/console c 5 1
mknod -m 600 dev/null c 1 3
mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp
mkdir var/lib var/lock var/run var/tmp
chmod 777 tmp
chmod 777 var/tmp
echo "-------make direction done---------"

上面shell中建立的目录有的没有使用。执行问脚本目录结构如下:

[root@centos /mini2440/rootfs]$ls
boot  dev  etc  home  lib  mnt  proc  root  sys  tmp  usr  var
[root@centos /mini2440/rootfs]$tree
.
|-- boot
|-- dev
|   |-- console
|   `-- null
|-- etc
|   |-- init.d
|   |-- rc.d
|   `-- sysconfig
|-- home
|-- lib
|-- mnt
|   |-- data
|   |-- etc
|   |-- jffs2
|   |-- temp
|   `-- yaffs
|-- proc
|-- root
|-- sys
|-- tmp
|-- usr
|   |-- bin
|   |-- lib
|   |-- modules
|   `-- sbin
`-- var
    |-- lib
    |-- lock
    |-- run
    `-- tmp

28 directories, 2 files:

2:修改与添加系统初始化脚本 都在 /mini2440/rootfs目录下面进行

(1)etc/inittab 系统init进程配置文件,并更改权限 chmod +x inittab
::sysinit:/etc/init.d/rcS
::askfirst:-/bin/sh #没有这就不行,就不能打开console控制台。
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a

(2)etc/init.d/rcS系统启动加载项文件,并更改权限chmod +x etc/init.d/rcS

#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel
mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts #用于telnet登录时使用

echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
mkdir -p /var/lock
/bin/hostname -F /etc/sysconfig/HOSTNAME

(3)etc/fstab 系统挂载文件系统列表文件

#device mount-point type option dump fsck order
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
mdev /dev ramfs defaults 0 0
none /var ramfs defaults 0 0
none /tmp ramfs defaults 0 0

(4)etc/profile用户环境配置文件

# Ash profile
# vim: syntax= sh
# No core file by defaults
# ulimit - S - c 0> / dev/ null 2> & 1

USER="id -un"
LOGNAME=$USER
PS1="[\u@\h \w]#"  #\w 目录将显示全路径
PATH=$PATH
HOSTNAME= '/bin/hostname'
alias cls="clear"
export USER LOGNAME PS1 PATH 
 (5)/etc/passwd shadow 用户文件以及密码
把主机的passwd shadow 文件拷贝到/etc下

# cp /etc/passwd  /mini2440/rootfs/etc
# cp /etc/group /mini2440/rootfs/etc
# cp /etc/shadow /mini2440/rootfs/etc

(6)etc/sysconfig/HOSTNAME的内容为你自己的名字即可,内容为"mini2440"
        gedit /etc/sysconfig/HOSTNAME  然后键入 mini2440

 

***********************第三步:以nfs方式加载测试********************************

测试之前必须确保nfs服务已经开启,uboot中的bootargs参数已经设置成功。

bootcmd=nfs 0x30008000 192.168.1.149:/opt/FriendlyARM/uImage;bootm
bootargs=noinitrd root=/dev/nfs proto=tcp,nolock,nfsvers=3, rw nfsroot=192.168.1.149:/mini2440/rootfs ip=192.168.1.144:192.168.1.149::255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M

在reboot的时候

[@mini2440 /etc]#reboot
[@mini2440 /etc]#umount: mdev busy - remounted read-only
是由于在reboot的时候执行了 /etc/inittab中的::shutdown:/bin/umount -a -r 需要重新挂载设备所致,可以去掉此行。

有待改进:使用mkyaffs2image制作成为最终的根文件系统,烧写到flash中,启动的时候从flash中读取内容。后面会做这一实验。
最终rootfs中的目录结构如下:

[root@centos /mini2440/rootfs]$tree
.
|-- bin
|   |-- addgroup -> busybox
|   |-- adduser -> busybox
|   |-- ash -> busybox
|   |-- base64 -> busybox
|   |-- busybox
|   |-- cat -> busybox
|   |-- catv -> busybox
|   |-- chattr -> busybox
|   |-- chgrp -> busybox
|   |-- chmod -> busybox
|   |-- chown -> busybox
|   |-- cp -> busybox
|   |-- cpio -> busybox
|   |-- cttyhack -> busybox
|   |-- date -> busybox
|   |-- dd -> busybox
|   |-- delgroup -> busybox
|   |-- deluser -> busybox
|   |-- df -> busybox
|   |-- dmesg -> busybox
|   |-- dnsdomainname -> busybox
|   |-- dumpkmap -> busybox
|   |-- echo -> busybox
|   |-- ed -> busybox
|   |-- egrep -> busybox
|   |-- false -> busybox
|   |-- fdflush -> busybox
|   |-- fgrep -> busybox
|   |-- fsync -> busybox
|   |-- getopt -> busybox
|   |-- grep -> busybox
|   |-- gunzip -> busybox
|   |-- gzip -> busybox
|   |-- hostname -> busybox
|   |-- hush -> busybox
|   |-- ionice -> busybox
|   |-- iostat -> busybox
|   |-- ip -> busybox
|   |-- ipaddr -> busybox
|   |-- ipcalc -> busybox
|   |-- iplink -> busybox
|   |-- iproute -> busybox
|   |-- iprule -> busybox
|   |-- iptunnel -> busybox
|   |-- kill -> busybox
|   |-- linux32 -> busybox
|   |-- linux64 -> busybox
|   |-- ln -> busybox
|   |-- login -> busybox
|   |-- ls -> busybox
|   |-- lsattr -> busybox
|   |-- lzop -> busybox
|   |-- makemime -> busybox
|   |-- mkdir -> busybox
|   |-- mknod -> busybox
|   |-- mktemp -> busybox
|   |-- more -> busybox
|   |-- mount -> busybox
|   |-- mountpoint -> busybox
|   |-- mpstat -> busybox
|   |-- mt -> busybox
|   |-- mv -> busybox
|   |-- netstat -> busybox
|   |-- nice -> busybox
|   |-- pidof -> busybox
|   |-- ping -> busybox
|   |-- ping6 -> busybox
|   |-- pipe_progress -> busybox
|   |-- powertop -> busybox
|   |-- printenv -> busybox
|   |-- ps -> busybox
|   |-- pwd -> busybox
|   |-- reformime -> busybox
|   |-- rev -> busybox
|   |-- rm -> busybox
|   |-- rmdir -> busybox
|   |-- rpm -> busybox
|   |-- run-parts -> busybox
|   |-- scriptreplay -> busybox
|   |-- sed -> busybox
|   |-- setarch -> busybox
|   |-- setserial -> busybox
|   |-- sh -> busybox
|   |-- sleep -> busybox
|   |-- stat -> busybox
|   |-- stty -> busybox
|   |-- su -> busybox
|   |-- sync -> busybox
|   |-- tar -> busybox
|   |-- touch -> busybox
|   |-- true -> busybox
|   |-- umount -> busybox
|   |-- uname -> busybox
|   |-- usleep -> busybox
|   |-- vi -> busybox
|   |-- watch -> busybox
|   `-- zcat -> busybox
|-- boot
|-- dev
|   |-- console
|   |-- null
|   `-- pts
|-- etc
|   |-- fstab
|   |-- fstab~
|   |-- init.d
|   |   |-- rcS
|   |   `-- rcS~
|   |-- inittab
|   |-- inittab~
|   |-- profile
|   |-- rc.d
|   `-- sysconfig
|       |-- HOSTNAME
|       `-- HOSTNAME~
|-- home
|-- lib
|-- linuxrc -> bin/busybox
|-- mnt
|   |-- data
|   |-- etc
|   |-- jffs2
|   |-- temp
|   `-- yaffs
|-- proc
|-- root
|-- sbin
|   |-- acpid -> ../bin/busybox
|   |-- adjtimex -> ../bin/busybox
|   |-- arp -> ../bin/busybox
|   |-- blkid -> ../bin/busybox
|   |-- blockdev -> ../bin/busybox
|   |-- bootchartd -> ../bin/busybox
|   |-- depmod -> ../bin/busybox
|   |-- devmem -> ../bin/busybox
|   |-- fbsplash -> ../bin/busybox
|   |-- fdisk -> ../bin/busybox
|   |-- findfs -> ../bin/busybox
|   |-- freeramdisk -> ../bin/busybox
|   |-- fsck -> ../bin/busybox
|   |-- fsck.minix -> ../bin/busybox
|   |-- getty -> ../bin/busybox
|   |-- halt -> ../bin/busybox
|   |-- hdparm -> ../bin/busybox
|   |-- hwclock -> ../bin/busybox
|   |-- ifconfig -> ../bin/busybox
|   |-- ifdown -> ../bin/busybox
|   |-- ifenslave -> ../bin/busybox
|   |-- ifup -> ../bin/busybox
|   |-- init -> ../bin/busybox
|   |-- insmod -> ../bin/busybox
|   |-- klogd -> ../bin/busybox
|   |-- loadkmap -> ../bin/busybox
|   |-- logread -> ../bin/busybox
|   |-- losetup -> ../bin/busybox
|   |-- lsmod -> ../bin/busybox
|   |-- makedevs -> ../bin/busybox
|   |-- man -> ../bin/busybox
|   |-- mdev -> ../bin/busybox
|   |-- mkdosfs -> ../bin/busybox
|   |-- mke2fs -> ../bin/busybox
|   |-- mkfs.ext2 -> ../bin/busybox
|   |-- mkfs.minix -> ../bin/busybox
|   |-- mkfs.vfat -> ../bin/busybox
|   |-- mkswap -> ../bin/busybox
|   |-- modinfo -> ../bin/busybox
|   |-- modprobe -> ../bin/busybox
|   |-- nameif -> ../bin/busybox
|   |-- pivot_root -> ../bin/busybox
|   |-- poweroff -> ../bin/busybox
|   |-- raidautorun -> ../bin/busybox
|   |-- reboot -> ../bin/busybox
|   |-- rmmod -> ../bin/busybox
|   |-- route -> ../bin/busybox
|   |-- runlevel -> ../bin/busybox
|   |-- setconsole -> ../bin/busybox
|   |-- slattach -> ../bin/busybox
|   |-- start-stop-daemon -> ../bin/busybox
|   |-- sulogin -> ../bin/busybox
|   |-- swapoff -> ../bin/busybox
|   |-- swapon -> ../bin/busybox
|   |-- switch_root -> ../bin/busybox
|   |-- sysctl -> ../bin/busybox
|   |-- syslogd -> ../bin/busybox
|   |-- tunctl -> ../bin/busybox
|   |-- udhcpc -> ../bin/busybox
|   |-- vconfig -> ../bin/busybox
|   |-- watchdog -> ../bin/busybox
|   `-- zcip -> ../bin/busybox
|-- sys
|-- tmp
|-- usr
|   |-- bin
|   |   |-- [ -> ../../bin/busybox
|   |   |-- [[ -> ../../bin/busybox
|   |   |-- add-shell -> ../../bin/busybox
|   |   |-- arping -> ../../bin/busybox
|   |   |-- awk -> ../../bin/busybox
|   |   |-- basename -> ../../bin/busybox
|   |   |-- beep -> ../../bin/busybox
|   |   |-- bunzip2 -> ../../bin/busybox
|   |   |-- bzcat -> ../../bin/busybox
|   |   |-- bzip2 -> ../../bin/busybox
|   |   |-- cal -> ../../bin/busybox
|   |   |-- chat -> ../../bin/busybox
|   |   |-- chpst -> ../../bin/busybox
|   |   |-- chrt -> ../../bin/busybox
|   |   |-- chvt -> ../../bin/busybox
|   |   |-- cksum -> ../../bin/busybox
|   |   |-- clear -> ../../bin/busybox
|   |   |-- cmp -> ../../bin/busybox
|   |   |-- comm -> ../../bin/busybox
|   |   |-- crontab -> ../../bin/busybox
|   |   |-- cryptpw -> ../../bin/busybox
|   |   |-- cut -> ../../bin/busybox
|   |   |-- dc -> ../../bin/busybox
|   |   |-- deallocvt -> ../../bin/busybox
|   |   |-- diff -> ../../bin/busybox
|   |   |-- dirname -> ../../bin/busybox
|   |   |-- dos2unix -> ../../bin/busybox
|   |   |-- du -> ../../bin/busybox
|   |   |-- dumpleases -> ../../bin/busybox
|   |   |-- eject -> ../../bin/busybox
|   |   |-- env -> ../../bin/busybox
|   |   |-- envdir -> ../../bin/busybox
|   |   |-- envuidgid -> ../../bin/busybox
|   |   |-- ether-wake -> ../../bin/busybox
|   |   |-- expand -> ../../bin/busybox
|   |   |-- expr -> ../../bin/busybox
|   |   |-- fdformat -> ../../bin/busybox
|   |   |-- fgconsole -> ../../bin/busybox
|   |   |-- find -> ../../bin/busybox
|   |   |-- flock -> ../../bin/busybox
|   |   |-- fold -> ../../bin/busybox
|   |   |-- free -> ../../bin/busybox
|   |   |-- ftpget -> ../../bin/busybox
|   |   |-- ftpput -> ../../bin/busybox
|   |   |-- fuser -> ../../bin/busybox
|   |   |-- groups -> ../../bin/busybox
|   |   |-- hd -> ../../bin/busybox
|   |   |-- head -> ../../bin/busybox
|   |   |-- hexdump -> ../../bin/busybox
|   |   |-- hostid -> ../../bin/busybox
|   |   |-- id -> ../../bin/busybox
|   |   |-- ifplugd -> ../../bin/busybox
|   |   |-- install -> ../../bin/busybox
|   |   |-- ipcrm -> ../../bin/busybox
|   |   |-- ipcs -> ../../bin/busybox
|   |   |-- kbd_mode -> ../../bin/busybox
|   |   |-- killall -> ../../bin/busybox
|   |   |-- killall5 -> ../../bin/busybox
|   |   |-- last -> ../../bin/busybox
|   |   |-- less -> ../../bin/busybox
|   |   |-- logger -> ../../bin/busybox
|   |   |-- logname -> ../../bin/busybox
|   |   |-- lpq -> ../../bin/busybox
|   |   |-- lpr -> ../../bin/busybox
|   |   |-- lspci -> ../../bin/busybox
|   |   |-- lsusb -> ../../bin/busybox
|   |   |-- lzcat -> ../../bin/busybox
|   |   |-- lzma -> ../../bin/busybox
|   |   |-- lzopcat -> ../../bin/busybox
|   |   |-- md5sum -> ../../bin/busybox
|   |   |-- mesg -> ../../bin/busybox
|   |   |-- microcom -> ../../bin/busybox
|   |   |-- mkfifo -> ../../bin/busybox
|   |   |-- mkpasswd -> ../../bin/busybox
|   |   |-- nc -> ../../bin/busybox
|   |   |-- nmeter -> ../../bin/busybox
|   |   |-- nohup -> ../../bin/busybox
|   |   |-- nslookup -> ../../bin/busybox
|   |   |-- od -> ../../bin/busybox
|   |   |-- openvt -> ../../bin/busybox
|   |   |-- passwd -> ../../bin/busybox
|   |   |-- patch -> ../../bin/busybox
|   |   |-- pgrep -> ../../bin/busybox
|   |   |-- pkill -> ../../bin/busybox
|   |   |-- pmap -> ../../bin/busybox
|   |   |-- printf -> ../../bin/busybox
|   |   |-- pscan -> ../../bin/busybox
|   |   |-- pstree -> ../../bin/busybox
|   |   |-- pwdx -> ../../bin/busybox
|   |   |-- readahead -> ../../bin/busybox
|   |   |-- readlink -> ../../bin/busybox
|   |   |-- realpath -> ../../bin/busybox
|   |   |-- remove-shell -> ../../bin/busybox
|   |   |-- renice -> ../../bin/busybox
|   |   |-- reset -> ../../bin/busybox
|   |   |-- resize -> ../../bin/busybox
|   |   |-- rpm2cpio -> ../../bin/busybox
|   |   |-- rtcwake -> ../../bin/busybox
|   |   |-- runsv -> ../../bin/busybox
|   |   |-- runsvdir -> ../../bin/busybox
|   |   |-- rx -> ../../bin/busybox
|   |   |-- script -> ../../bin/busybox
|   |   |-- seq -> ../../bin/busybox
|   |   |-- setkeycodes -> ../../bin/busybox
|   |   |-- setsid -> ../../bin/busybox
|   |   |-- setuidgid -> ../../bin/busybox
|   |   |-- sha1sum -> ../../bin/busybox
|   |   |-- sha256sum -> ../../bin/busybox
|   |   |-- sha512sum -> ../../bin/busybox
|   |   |-- showkey -> ../../bin/busybox
|   |   |-- smemcap -> ../../bin/busybox
|   |   |-- softlimit -> ../../bin/busybox
|   |   |-- sort -> ../../bin/busybox
|   |   |-- split -> ../../bin/busybox
|   |   |-- strings -> ../../bin/busybox
|   |   |-- sum -> ../../bin/busybox
|   |   |-- sv -> ../../bin/busybox
|   |   |-- tac -> ../../bin/busybox
|   |   |-- tail -> ../../bin/busybox
|   |   |-- tcpsvd -> ../../bin/busybox
|   |   |-- tee -> ../../bin/busybox
|   |   |-- telnet -> ../../bin/busybox
|   |   |-- test -> ../../bin/busybox
|   |   |-- tftp -> ../../bin/busybox
|   |   |-- tftpd -> ../../bin/busybox
|   |   |-- time -> ../../bin/busybox
|   |   |-- timeout -> ../../bin/busybox
|   |   |-- top -> ../../bin/busybox
|   |   |-- tr -> ../../bin/busybox
|   |   |-- traceroute -> ../../bin/busybox
|   |   |-- traceroute6 -> ../../bin/busybox
|   |   |-- tty -> ../../bin/busybox
|   |   |-- ttysize -> ../../bin/busybox
|   |   |-- udpsvd -> ../../bin/busybox
|   |   |-- unexpand -> ../../bin/busybox
|   |   |-- uniq -> ../../bin/busybox
|   |   |-- unix2dos -> ../../bin/busybox
|   |   |-- unlzma -> ../../bin/busybox
|   |   |-- unlzop -> ../../bin/busybox
|   |   |-- unxz -> ../../bin/busybox
|   |   |-- unzip -> ../../bin/busybox
|   |   |-- uptime -> ../../bin/busybox
|   |   |-- users -> ../../bin/busybox
|   |   |-- uudecode -> ../../bin/busybox
|   |   |-- uuencode -> ../../bin/busybox
|   |   |-- vlock -> ../../bin/busybox
|   |   |-- volname -> ../../bin/busybox
|   |   |-- wall -> ../../bin/busybox
|   |   |-- wc -> ../../bin/busybox
|   |   |-- wget -> ../../bin/busybox
|   |   |-- which -> ../../bin/busybox
|   |   |-- who -> ../../bin/busybox
|   |   |-- whoami -> ../../bin/busybox
|   |   |-- whois -> ../../bin/busybox
|   |   |-- xargs -> ../../bin/busybox
|   |   |-- xz -> ../../bin/busybox
|   |   |-- xzcat -> ../../bin/busybox
|   |   `-- yes -> ../../bin/busybox
|   |-- lib
|   |-- modules
|   `-- sbin
|       |-- brctl -> ../../bin/busybox
|       |-- chpasswd -> ../../bin/busybox
|       |-- chroot -> ../../bin/busybox
|       |-- crond -> ../../bin/busybox
|       |-- dhcprelay -> ../../bin/busybox
|       |-- dnsd -> ../../bin/busybox
|       |-- fakeidentd -> ../../bin/busybox
|       |-- fbset -> ../../bin/busybox
|       |-- ftpd -> ../../bin/busybox
|       |-- httpd -> ../../bin/busybox
|       |-- inetd -> ../../bin/busybox
|       |-- loadfont -> ../../bin/busybox
|       |-- lpd -> ../../bin/busybox
|       |-- nbd-client -> ../../bin/busybox
|       |-- ntpd -> ../../bin/busybox
|       |-- popmaildir -> ../../bin/busybox
|       |-- rdate -> ../../bin/busybox
|       |-- rdev -> ../../bin/busybox
|       |-- readprofile -> ../../bin/busybox
|       |-- sendmail -> ../../bin/busybox
|       |-- setfont -> ../../bin/busybox
|       |-- setlogcons -> ../../bin/busybox
|       |-- svlogd -> ../../bin/busybox
|       |-- telnetd -> ../../bin/busybox
|       |-- ubiattach -> ../../bin/busybox
|       |-- ubidetach -> ../../bin/busybox
|       |-- ubimkvol -> ../../bin/busybox
|       |-- ubirmvol -> ../../bin/busybox
|       |-- ubirsvol -> ../../bin/busybox
|       |-- ubiupdatevol -> ../../bin/busybox
|       `-- udhcpd -> ../../bin/busybox
`-- var
    |-- lib
    |-- lock
    |-- run
    |   `-- utmp
    `-- tmp

31 directories, 361 files