根文件系統的制作
[shaocongshuai@Centos-shaocongshuai fl2440]$ pwd
/home/shaocongshuai/fl2440
[shaocongshuai@Centos-shaocongshuai fl2440]$ mkdir rootfs
[shaocongshuai@Centos-shaocongshuai fl2440]$ cd rootfs/
[shaocongshuai@localhost rootfs]$ mkdir -p {apps,bin,data,dev,info,proc,root,sbin,sys,tmp,var,etc/{,init.d,dropbear},mnt/{,usb,sdc,nfs,dev},usr/{,bin,sbin,lib,share},lib/{,modules/{,3.0.2}}}
[shaocongshuai@localhost rootfs]$ tree -L 3
-l 如遇到性質為符號連接的目錄,直接列出該連接所指向的原始目錄。
顯示3級目錄和文件
.
├── apps
├── bin
├── data
├── dev
├── etc
│ ├── dropbear
│ └── init.d
├── info
├── lib
│ └── modules
│ └── 3.0.2
├── mnt
│ ├── dev
│ ├── nfs
│ ├── sdc
│ └── usb
├── proc
├── root
├── sbin
├── sys
├── tmp
├── usr
│ ├── bin
│ ├── lib
│ ├── sbin
│ └── share
└── var
27 directories, 0 files
上面的一些目錄,可以先不用關系它的用途,今後對文件系統進行擴展時在介紹。
一. Dev目錄下創建設備文件
因為內核掛載完文件系統後,init進程需要用到/dev/console和/dev/null這兩個設備文件來調用mdev構建dev,所以必須在制作文件系統時靜態創建這兩個設備文件,否則在系統啟動時將提示
Warning: unable to open an initial console:
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod -m 666 dev/null c 1 3
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod -m 666 dev/console c 5 1
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod -m 666 dev/ c ttyS0 4 64
在2.6以後的內核中,部分三星芯片(例如S3C24x0等)將串口終端設備節點命名為ttySACn
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod -m 666 dev/SAC0 c 4 64
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock0 b 31 0
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock1 b 31 1
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock2 b 31 2
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock3 b 31 3
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock4 b 31 4
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock5 b 31 5
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock6 b 31 6
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock7 b 31 7
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock8 b 31 8
[shaocongshuai@Centos-shaocongshuai rootfs]$ sudo mknod dev/mtdblock9 b 31 9
[shaocongshuai@Centos-shaocongshuai rootfs]$ ll dev/
total 0
crw-rw-rw- 1 root root 5, 1 Jul 24 03:27 console
brw-r--r-- 1 root root 31, 0 Jul 24 03:28 mtdblock0
brw-r--r-- 1 root root 31, 1 Jul 24 03:28 mtdblock1
brw-r--r-- 1 root root 31, 2 Jul 24 03:28 mtdblock2
brw-r--r-- 1 root root 31, 3 Jul 24 03:28 mtdblock3
brw-r--r-- 1 root root 31, 4 Jul 24 03:28 mtdblock4
brw-r--r-- 1 root root 31, 5 Jul 24 03:28 mtdblock5
brw-r--r-- 1 root root 31, 6 Jul 24 03:29 mtdblock6
brw-r--r-- 1 root root 31, 7 Jul 24 03:29 mtdblock7
brw-r--r-- 1 root root 31, 8 Jul 24 03:29 mtdblock8
brw-r--r-- 1 root root 31, 9 Jul 24 03:31 mtdblock9
crw-rw-rw- 1 root root 1, 3 Jul 24 03:27 null
crw-rw-rw- 1 root root 4, 64 Jul 24 03:27 ttyS0
crw-rw-rw- 1 root root 4, 64 Jul 24 03:27 ttySAC0
二、Var 目錄下創建符號鏈接文件
[shaocongshuai@Centos-shaocongshuai rootfs]$ ln -s /tmp var/lock
[shaocongshuai@Centos-shaocongshuai rootfs]$ ln -s /tmp var/log
[shaocongshuai@Centos-shaocongshuai rootfs]$ ln -s /tmp var/run
[shaocongshuai@Centos-shaocongshuai rootfs]$ ln -s /tmp var/tmp
[shaocongshuai@Centos-shaocongshuai rootfs]$ ll var/
total 0
lrwxrwxrwx 1 shaocongshuai shaocongshuai 4 Jul 24 03:32 lock -> /tmp
lrwxrwxrwx 1 shaocongshuai shaocongshuai 4 Jul 24 03:32 log -> /tmp
lrwxrwxrwx 1 shaocongshuai shaocongshuai 4 Jul 24 03:32 run -> /tmp
lrwxrwxrwx 1 shaocongshuai shaocongshuai 4 Jul 24 03:32 tmp -> /tmp
三、拷貝交叉編譯器中的動態庫到相應的目錄下
[shaocongshuai@Centos-shaocongshuai rootfs]$ cp -af /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-uclibcgnueabi/sysroot/usr/lib/*so* lib/
[shaocongshuai@Centos-shaocongshuai rootfs]$ cp -af /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-uclibcgnueabi/sysroot/lib/*so* lib/
[shaocongshuai@Centos-shaocongshuai rootfs]$ cp -af /opt/buildroot-2012.08/arm920t/usr/arm-unknown-linux-uclibcgnueabi/lib/*so* lib/
[shaocongshuai@Centos-shaocongshuai rootfs]$ cp -af /opt/buildroot-2012.08/arm920t/usr/lib/*so* lib/
[shaocongshuai@Centos-shaocongshuai rootfs]$ ls lib/
ld-uClibc-0.9.33.2.so libcrypt.so.0 libdl.so libgmp.so libltdl.so.7 libmpc.so.2 libmpfr.so.4.1.1 libnsl.so libpthread.so.0 libresolv.so librt.so.0 libutil.so.0
ld-uClibc.so.0 libc.so libdl.so.0 libgmp.so.10 libltdl.so.7.2.2 libmpc.so.2.0.0 libm.so libnsl.so.0 libresolv-0.9.33.2.so libresolv.so.0 libuClibc-0.9.33.2.so modules
libcrypt-0.9.33.2.so libc.so.0 libgcc_s.so libgmp.so.10.0.5 libm-0.9.33.2.so libmpfr.so libm.so.0 libpthread-0.9.33.2.so libresolv.a librt-0.9.33.2.so libutil-0.9.33.2.so
libcrypt.so libdl-0.9.33.2.so libgcc_s.so.1 libltdl.so libmpc.so libmpfr.so.4 libnsl-0.9.33.2.so libpthread.so libresolv_pic.a librt.so libutil.so
四、在etc/目錄下創建一些文件
創建inittab文件
[shaocongshuai@Centos-shaocongshuai rootfs]$ cd etc/
[shaocongshuai@Centos-shaocongshuai etc]$ ls
dropbear fstab group hostname hosts init.d inittab issue mdev.conf passwd profile protocols shadow TZ
[shaocongshuai@Centos-shaocongshuai etc]$ vim inittab
1 # /etc/inittab
2 #
3 # Copyright (C) 2016 shaocongshuai <
[email protected]>
4 #
5 # Note: BusyBox init doesn't support runlevels. The runlevels field is
6 # completely ignored by BusyBox init. If you want runlevels, use sysvinit.
7 #
8 # Format for each entry: <id>:<runlevels>:<action>:<process>
9 #
10 # id == tty to run on, or empty for /dev/console.
11 # If specified, then /dev/$id device must exist
12 # runlevels == ignored, busybox doesn't support it
13 # action == one of sysinit, respawn, askfirst, wait, and once
14 # process == program to run
15
16 # Startup the system
17 # mount all the file systems specified in /etc/fstab
18 ::sysinit:/bin/mount -a
19
20 #Use mdev as hotplug to auto mount USB storage or SD card
21 ::sysinit:/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
22
23 #Use mdev to auto generate the device node in /dev path
24 ::sysinit:/sbin/mdev -s
25
26 #make shm, pts support
27 ::sysinit:/bin/mkdir -p /dev/pts
28 ::sysinit:/bin/mkdir -p /dev/shm
29 ::sysinit:/bin/mount -t devpts devpts /dev/pts
30
31 #Mount our apps/info partition
32 null::wait:/bin/mount -o sync,noatime,ro -t jffs2 /dev/mtdblock6 /apps
33 null::wait:/bin/mount -o sync,noatime,ro -t jffs2 /dev/mtdblock7 /info
34
35 #Set hostname
36 null::sysinit:/bin/hostname -F /etc/hostname
37
38 #Enable console logon
39 null::respawn:/sbin/getty -L ttyS0 115200 vt100
40
41 # now run any rc scripts
42 null::wait:/etc/init.d/rcS
43
44 # system daemon
45 null::respawn:/sbin/syslogd -n
46 null::respawn:/sbin/klogd -n
47
48 # Stuff to do before rebooting
49 null::shutdown:/bin/umount /apps
50 null::shutdown:/bin/umount /info
51 null::shutdown:/bin/killall klogd
52 null::shutdown:/bin/killall syslogd
53 null::shutdown:/bin/umount -a -r
54 #null::shutdown:/sbin/swapoff -a
創建/etc/init.d/rcS腳本
[shaocongshuai@Centos-shaocongshuai etc]$ vim init.d/rcS
1 #!/bin/sh
2
3 # Copyright (C) 2016 shaocongshuai <
[email protected]>
4 # Start all init scripts in /etc/init.d
5 # executing them in numerical order.
6 #
7
8 for i in /etc/init.d/S??* ; do
9 $i
10 done
配置網卡的啟動腳本
[shaocongshuai@Centos-shaocongshuai etc]$ vim init.d/S01_network
1 #!/bin/sh
2
3 ifconfig eth0 192.168.1.99 netmask 255.255.255.0 up
創建支持/apps/etc目錄下的啟動腳本
[shaocongshuai@Centos-shaocongshuai etc]$ vim init.d/S99_rcsApp
1 #!/bin/sh
2
3 # Copyright (C) 2016 shaocongshuai <
[email protected]>
4 #
5 # Start all init scripts in /apps/etc/init.d
6 # executing them in numerical order.
7 #
8 if (test -d /apps/etc/init.d)
9 then
10 for i in /apps/etc/init.d/S??* ; do
11 $i
12 done
13 fi
修改init.d目錄下的文件權限
[shaocongshuai@Centos-shaocongshuai etc]$ chmod 777 init.d/*
[shaocongshuai@Centos-shaocongshuai etc]$ ll init.d/
total 16
-rwxrwxrwx 1 shaocongshuai shaocongshuai 230 Jul 24 03:45 rcS
-rwxrwxrwx 1 shaocongshuai shaocongshuai 63 Jul 24 03:47 S01_network
-rwxrwxrwx 1 shaocongshuai shaocongshuai 29 Jul 25 10:59 S04_dropbear
-rwxrwxrwx 1 shaocongshuai shaocongshuai 272 Jul 24 03:49 S99_rcsApp
創建fstab文件
[shaocongshuai@Centos-shaocongshuai etc]$ vim fstab
1 # /etc/fstab: static file system information.
2 # Copyright (C) 2016 shaocongshuai <[email protected]>
3 #
4 #<File system> <mount pt> <type> <options> <dump> <pass>
5 #devpts /dev/pts devpts defaults 0 0
6 #/dev/root / ext2 rw,noauto 0 1
7 proc /proc proc defaults 0 0
8 tmpfs /tmp tmpfs defaults 0 0
9 tmpfs /dev tmpfs defaults 0 0
10 sysfs /sys sysfs defaults 0 0
創建hostname,hosts,TZ文件
[shaocongshuai@Centos-shaocongshuai etc]$ echo "root" > hostname
[shaocongshuai@Centos-shaocongshuai etc]$ echo "127.0.0.1 localhost" >> hosts
[shaocongshuai@Centos-shaocongshuai etc]$ echo "MST7MDT" >> TZ
[shaocongshuai@Centos-shaocongshuai etc]$ echo "Copyright (C) 2016 shaocongshuai<
[email protected]>" >> issue
創建profile文件[shaocongshuai@Centos-shaocongshuai etc]$ vim profile
1 # ~/.bashrc: executed by bash(1) for non-login interactive shells.
2
3 export PATH=\
4 /bin:\
5 /sbin:\
6 /usr/bin:\
7 /usr/sbin:\
8 /apps/tools
9
10 export PS1='\w >: '
11
12 export USER=`id -un`
13 export LOGNAME=$USER
14 export HOSTNAME=`/bin/hostname`
15 export HISTSIZE=500
16 export HISTFILESIZE=500
17 export PAGER='/bin/more '
18 export EDITOR='/bin/vi'
19 export INPUTRC=/etc/inputrc
20 export network_cfg_dir=/apps/etc/network
21 export LD_LIBRARY_PATH=/lib:/usr/lib:/apps/lib
22 export network_cfg_dir=/apps/etc/network
23
24 ### Some aliases
25 alias vim='vi'
26 alias ll='ls -l'
27 alias l.='ls -d .*'
28 alias df='df -h'
創建指定一些協議所使用的端口號文件protocols
[shaocongshuai@Centos-shaocongshuai etc]$ vim protocols
1 # /etc/protocols:
2 # $Id: protocols,v 1.1.1.1 2001/09/12 19:03:24 andersee Exp $
3 #
4 # Internet (IP) protocols
5 #
6 # from: @(#)protocols 5.1 (Berkeley) 4/17/89
7 #
8 # Updated for NetBSD based on RFC 1340, Assigned Numbers (July 1992).
9
10 ip 0 IP # internet protocol, pseudo protocol number
11 icmp 1 ICMP # internet control message protocol
12 igmp 2 IGMP # Internet Group Management
13 ggp 3 GGP # gateway-gateway protocol
14 ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'')
15 st 5 ST # ST datagram mode
16 tcp 6 TCP # transmission control protocol
17 egp 8 EGP # exterior gateway protocol
18 pup 12 PUP # PARC universal packet protocol
19 udp 17 UDP # user datagram protocol
20 hmp 20 HMP # host monitoring protocol
21 xns-idp 22 XNS-IDP # Xerox NS IDP
22 rdp 27 RDP # "reliable datagram" protocol
23 iso-tp4 29 ISO-TP4 # ISO Transport Protocol class 4
24 xtp 36 XTP # Xpress Tranfer Protocol
25 ddp 37 DDP # Datagram Delivery Protocol
26 idpr-cmtp 39 IDPR-CMTP # IDPR Control Message Transport
27 rspf 73 RSPF #Radio Shortest Path First.
28 vmtp 81 VMTP # Versatile Message Transport
29 ospf 89 OSPFIGP # Open Shortest Path First IGP
30 ipip 94 IPIP # Yet Another IP encapsulation
31 encap 98 ENCAP # Yet Another IP encapsulation
創建mdev.conf文件
mdev會在/etc目錄下找mdev的配置文件: mdev.conf. 如果該文件不存在,那麼在執行mdev –s這個命令時,會提示找不到mdev.conf,這時我們可以建一個空的mdev.conf文件解決這個問題。下面創建使用mdev自動掛載u盤和SD卡的配置/etc/mdev.conf
[shaocongshuai@Centos-shaocongshuai etc]$ vim mdev.conf
1 sd[a-z][0-9] 0:0 0777 @(mount /dev/$MDEV /mnt/usb)
2 sd[a-z] 0:0 0777 $(umount /mnt/usb)
3 ub[a-z][0-9] 0:0 0777 @(mount /dev/$MDEV /mnt/usb)
4 ub[a-z] 0:0 0777 $(umount /mnt/usb)
5 mmcblk[0-9]p[0-9] 0:0 0777 @(mount /dev/$MDEV /mnt/sdc)
6 mmcblk[0-9] 0:0 0777 $(umount /mnt/sdc)
創建用戶組group文件
[shaocongshuai@Centos-shaocongshuai etc]$ vim group
1 root:x:0:root
它的格式如下:
groupname:password:gid:members
第一個字段為用戶組名稱
第二個字段為用戶組密碼,當為x時密碼是映射到/etc/gshadow中的,是非逆的第三個字段為GID,及組號,為正整數或0,0被付於了root用戶組;系統通常會預留一些較靠前的GID給系統虛擬用戶之用,每個系統預留的GID都不同,Fedora預留了500個,所以我們添加新用戶組時是從500開始的。GID的范圍由/etc/login.defs中的GID_MIN和GID_MAX決定第四個字段為用戶列表,每個用戶間用逗號分隔 這裡的password代表組口令,很少用到。它可使原先不在這個群組中的用戶可以通過newgrp命令暫時繼承該組的權限,使用
newgrp命令時會新開一個shell。口令的加密方式和passwd文件中的口令一樣,所以如果需設置組口令,要用passwd程序虛設一個用戶,再把該用戶password節中的加密口令到/etc/group文件中。members列代表組成員,我們可把需加入該組的用戶以逗號分隔添加到這裡即可。同一組的成員可繼承該組所擁有的權限。
創建用戶passwd文件
[shaocongshuai@Centos-shaocongshuai etc]$ vim passwd
1 root:x:0:0:root:/:/bin/sh
它的格式如下:
username:password:uid:gid:gecos:homedir:shell
第一個字段為登錄名
第二個字段為口令,一般被映射到shadow文件中
第三個字段為UID
第四個字段為GID
第五個字段為用戶名全稱,gecos是通用電子計算機操作系統的縮寫,是Bell實驗室中的一台大型主機。
第六個字段為用戶根目錄
第七個字段為用戶所用SHELL的類型
Unix系統最初是用明文保存密碼的,後來由於安全的考慮,采用crypt()算法加密密碼並存放在/etc/passwd文件。現在,由於計算機處理能力的提高,使密碼破解變得越來越容易。/etc/passwd文件是所有合法用戶都可訪問的,大家都可互相看到密碼的加密字符串,這給系統帶來很大的安全威脅。現代的Unix系統使用影子密碼系統,它把密碼從/etc/pa sswd文件中分離出來,真正的密碼保存在/etc/shadow文件中,shadow文件只能由超級用戶訪問。這樣入侵者就不能獲得加密密碼串,用於破解。使用shadow密碼文件後,/etc/passwd文件中所有帳戶的password域的內容為"x",如果password域的內容為"*",則該帳號被停用。使用passwd這個程序可修改用戶的密。
創建密碼映射shadow文件[shaocongshuai@Centos-shaocongshuai etc]$ vim shadow
root:($jGZIHmtT$y8ZXoPllK12/wl51kMw4e/:0:0:99999:7:::)
該文件我們可以在Linux系統上使用passwd命令修改root口令來獲取:
當然,在設置為嵌入式平台上的root口令後,最好把系統上的root命令恢復到原始密碼。
他的格式如下:
username:password:last_change:min_change:max_change:warm:failed_expire:expiration:reserved
第一字段:用戶名(也被稱為登錄名),在/etc/shadow中,用戶名和/etc/passwd 是相同的,這樣就把passwd 和shadow中用的用戶記錄聯系在一起;這個字段是非空的;
第二字段:密碼(已被加密),這個字段是非空的;
第三字段:上次修改口令的時間;這個時間是從1970年01月01日算起到最近一次修改口令的時間間隔(天數),您可以通過passwd 來修改用戶的密碼,然後查看/etc/shadow中此字段的變化;
第四字段:兩次修改口令間隔最少的天數;如果這個字段的值為空,帳號永久可用;
第五字段:兩次修改口令間隔最多的天數;如果這個字段的值為空,帳號永久可用;
第六字段:提前多少天警告用戶口令將過期;如果這個字段的值為空,帳號永久可用;
第七字段:在口令過期之後多少天禁用此用戶;如果這個字段的值為空,帳號永久可用;
第八字段:用戶過期日期;此字段指定了用戶作廢的天數(從1970年的1月1日開始的天數),如果這個字段的值為空,帳號永久可用;
第九字段:保留字段,目前為空,以備將來發展之用;
這裡我們設置為不用密碼登陸,將password格式的內容清空:
[shaocongshuai@Centos-shaocongshuai etc]$ vim shadow
1 root::0:0:99999:7:::
五、在文件系統中安裝busybox
[shaocongshuai@Centos-shaocongshuai opt]$ ls
buildroot-2012.08 busybox-1.20.2
[shaocongshuai@Centos-shaocongshuai opt]$ cd busybox-1.20.2/
[shaocongshuai@Centos-shaocongshuai busybox-1.20.2]$ vim Makefile
163
164 CROSS_COMPILE ?= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
165 # bbox: we may have CONFIG_CROSS_COMPILER_PREFIX in .config,
[shaocongshuai@Centos-shaocongshuai busybox-1.20.2]$ term=vt100
[shaocongshuai@Centos-shaocongshuai busybox-1.20.2]$ make menuconfig
Busybox Settings --->
General Configuration --->
[*] Don't use /usr
Installation Options ("make install" behavior) --->
What kind of applet links to install (as soft-links) --->
(/home/shaocongshuai/fl2440/rootfs) BusyBox installation prefix
#其它選項結合自己需求定制
[shaocongshuai@Centos-shaocongshuai busybox-1.20.2]$ sudo make
[shaocongshuai@Centos-shaocongshuai busybox-1.20.2]$ file busybox
busybox: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped
[shaocongshuai@Centos-shaocongshuai busybox-1.20.2]$ sudo make install
[shaocongshuai@localhost rootfs]$ ls
apps bin data dev etc info lib linuxrc mnt proc root sbin sys tmp usr var
多出了linuxrc文件!
六、
移植dropbear下載地址http://matt.ucc.asn.au/dropbear/releases/
編譯ARM版本的
[shaocongshuai@Centos-shaocongshuai dropbear-0.53.1]$ make distclean
[shaocongshuai@Centos-shaocongshuai dropbear-0.53.1]$ ./configure CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc --build=x86_64 --host=arm-linux --disable-zlib
[shaocongshuai@Centos-shaocongshuai dropbear-0.53.1]$ make[shaocongshuai@Centos-shaocongshuai dropbear-0.53.1]$ file dropbear
dropbear: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped
[shaocongshuai@Centos-shaocongshuai dropbear-0.53.1]$ file dbclient
dbclient: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped
[shaocongshuai@Centos-shaocongshuai dropbear-0.53.1]$ mv dbclient ssh
[shaocongshuai@Centos-shaocongshuai dropbear-0.53.1]$ /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-strip dropbear
[shaocongshuai@Centos-shaocongshuai dropbear-0.53.1]$ /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-strip ssh
[shaocongshuai@Centos-shaocongshuai dropbear-0.53.1]$ cp dropbear ssh /home/shaocongshuai/fl2440/rootfs/usr/sbin/
在文件系統中創建啟動腳本
[shaocongshuai@Centos-shaocongshuai rootfs]$ vim etc/init.d/S04_dropbear
1 #!/bin/sh
2 /usr/sbin/dropbear
[shaocongshuai@Centos-shaocongshuai rootfs]$ chmod 777 etc/init.d/S04_dropbear
以上我們已經成功的創建了一個根文件系統。下面我們開始對在嵌入式應用領域的多種文件系統的優缺點進行比較。
移植多種文件系統
下面我們開始制作和移植多種嵌入式領域所廣泛應用的文件系統initramfs、jffs2、和ubifs這些文件系統。
Initramfs的制作和移植
一、對根文件系統進行修改
由於制作initramfs文件系統啟動時會在根文件系統中執行第一個init程序,它對uboot傳過來的參數init=/linuxrc不予理睬,所以需要在上面制作的根文件系統裡的根目錄加入init程序,否則無法啟動。init程序和linuxrc程序一樣都是符號鏈接文件,它們都是指向/bin/busybox程序。
[shaocongshuai@Centos-shaocongshuai rootfs]$ ll
total 60
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 apps
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 25 11:03 bin
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 data
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:31 dev
drwxrwxr-x 4 shaocongshuai shaocongshuai 4096 Jul 25 11:55 etc
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 info
drwxrwxr-x 3 shaocongshuai shaocongshuai 4096 Jul 24 03:41 lib
lrwxrwxrwx 1 root root 11 Jul 25 11:03 linuxrc -> bin/busybox
drwxrwxr-x 6 shaocongshuai shaocongshuai 4096 Jul 24 03:15 mnt
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 proc
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 root
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 25 11:03 sbin
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 sys
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 tmp
drwxrwxr-x 6 shaocongshuai shaocongshuai 4096 Jul 24 03:15 usr
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:32 var
[shaocongshuai@Centos-shaocongshuai rootfs]$ ln -s bin/busybox init
[shaocongshuai@Centos-shaocongshuai rootfs]$ ll
total 60
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 apps
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 25 11:03 bin
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 data
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:31 dev
drwxrwxr-x 4 shaocongshuai shaocongshuai 4096 Jul 25 11:55 etc
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 info
lrwxrwxrwx 1 shaocongshuai shaocongshuai 11 Jul 25 11:04 init -> bin/busybox
drwxrwxr-x 3 shaocongshuai shaocongshuai 4096 Jul 24 03:41 lib
lrwxrwxrwx 1 root root 11 Jul 25 11:03 linuxrc -> bin/busybox
drwxrwxr-x 6 shaocongshuai shaocongshuai 4096 Jul 24 03:15 mnt
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 proc
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 root
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 25 11:03 sbin
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 sys
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:15 tmp
drwxrwxr-x 6 shaocongshuai shaocongshuai 4096 Jul 24 03:15 usr
drwxrwxr-x 2 shaocongshuai shaocongshuai 4096 Jul 24 03:32 var
二、添加內核對initramfs的支持
[shaocongshuai@Centos-shaocongshuai linux-3.0.2]$ make menuconfig
General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
(/home/shaocongshuai/fl2440/rootfs) Initramfs source file(s)
#輸入根文件系統的所在目錄
然後make編譯將linuxrom-s3c2440.bin上傳到tftp上
三、制作映像文件
因為文件系統和內核是集成在一起的,所以不需要制作文件系統映像
四、添加uboot對initramfs支持
Uboot源碼基本上不做修改。
下面對uboot進行修改。
[fl2440@shaocongshuai]# set bkr 'tftp 30008000 linuxrom-s3c2440.bin;nand erase 100000 f00000;nand write 30008000 100000 f00000'
[fl2440@shaocongshuai]# set bootargs 'console=ttyS0,115200 mem=64M init=/linuxrc rw loglevel=7'
[fl2440@shaocongshuai]# set bootcmd 'run bootcmd_initramdisk'
[fl2440@shaocongshuai]# set bootcmd_initramdisk 'nand read 30008000 100000 f00000;bootm 30008000'
[fl2440@shaocongshuai]# save
[fl2440@shaocongshuai]# run bkr
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:93:0a:5b
could not establish link
operating at 100M full duplex mode
......
15728640 bytes written: OK
[fl2440@shaocongshuai]# reset
resetting ...
U-Boot 2010.09 (Jan 26 2016 - 10:34:01)
DRAM: 64 MiB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
NAND read: device 0 offset 0x100000, size 0xf00000
15728640 bytes read: OK
## Booting kernel from Legacy Image at 30008000 ...
Image Name: Linux Kernel
Created: 2016-07-25 6:24:54 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4204248 Bytes = 4 MiB
Load Address: 30008000
Entry Point: 30008040
Verifying Checksum ... OK
......
Copyright (C) 2016 shaocongshuai<
[email protected]>
root login: root
~ >: ls
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr
這樣initramfs文件系統就自作成功