- UID
- 852722
|
1.1.17.9. 创建指定一些协议所使用的端口号文件protocols[lingyun@localhost etc]$ vim protocols
# /etc/protocols:
# $Id: protocols,v 1.1.1.1 2001/09/12 19:03:24 andersee Exp $
#
# Internet (IP) protocols
#
# from: @(#)protocols 5.1 (Berkeley) 4/17/89
#
# Updated for NetBSD based on RFC 1340, Assigned Numbers (July 1992).
ip 0 IP # internet protocol, pseudo protocol number
icmp 1 ICMP # internet control message protocol
igmp 2 IGMP # Internet Group Management
ggp 3 GGP # gateway-gateway protocol
ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'')
st 5 ST # ST datagram mode
tcp 6 TCP # transmission control protocol
egp 8 EGP # exterior gateway protocol
pup 12 PUP # PARC universal packet protocol
udp 17 UDP # user datagram protocol
hmp 20 HMP # host monitoring protocol
xns-idp 22 XNS-IDP # Xerox NS IDP
rdp 27 RDP # "reliable datagram" protocol
iso-tp4 29 ISO-TP4 # ISO Transport Protocol class 4
xtp 36 XTP # Xpress Tranfer Protocol
ddp 37 DDP # Datagram Delivery Protocol
idpr-cmtp 39 IDPR-CMTP # IDPR Control Message Transport
rspf 73 RSPF #Radio Shortest Path First.
vmtp 81 VMTP # Versatile Message Transport
ospf 89 OSPFIGP # Open Shortest Path First IGP
ipip 94 IPIP # Yet Another IP encapsulation
encap 98 ENCAP # Yet Another IP encapsulation
1.1.17.10. 创建mdev.conf文件mdev会在/etc目录下找mdev的配置文件: mdev.conf. 如果该文件不存在,那么在执行mdev –s这个命令时,
会提示找不到mdev.conf,这时我们可以建一个空的mdev.conf文件解决这个问题。下面创建使用mdev自动挂载u盘和SD卡的配置/etc/mdev.conf
[lingyun@localhost etc]$ vim mdev.conf
sd[a-z][0-9] 0:0 0777 @(mount /dev/$MDEV /mnt/usb)
sd[a-z] 0:0 0777 $(umount /mnt/usb)
ub[a-z][0-9] 0:0 0777 @(mount /dev/$MDEV /mnt/usb)
ub[a-z] 0:0 0777 $(umount /mnt/usb)
mmcblk[0-9]p[0-9] 0:0 0777 @(mount /dev/$MDEV /mnt/sdc)
mmcblk[0-9] 0:0 0777 $(umount /mnt/sdc)
1.1.17.11. 创建用户组group文件[lingyun@localhost etc]$ vim group
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列代表组成员,我们可把需加入该组的用户以逗号分隔添加到这里即可。同一组的成员可继承该组所拥有的权限。
1.1.17.12. 创建用户passwd文件[lingyun@localhost etc]$ vim passwd
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这个程序可修改用户的密。
1.1.17.13. 创建密码映射shadow文件[lingyun@localhost etc]$ vim shadow
root$jGZIHmtT$y8ZXoPllK12/wl51kMw4e/:0:0:99999:7::# 显示的是加密后的字符串
该文件我们可以在Linux系统上使用passwd命令修改root口令来获取:
[lingyun@localhost ~]$ passwd root
Changing password for user root.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[lingyun@localhost ~]$ cat /etc/shadow | grep root
root1$jGZIHmtT$y8ZXoPllK12/wl51kMw4e/:0:0:99999:7:::
当然,在设置为嵌入式平台上的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格式的内容清空:
[lingyun@localhost rootfs]$ vim etc/shadow
root::0:0:99999:7:::
1.1.18. 在文件系统中安装busybox[lingyun@localhost opt]$ sudo tar xjf ~/fulinux/systools/busybox-1.20.2.tar.bz2
[lingyun@localhost opt]$ cd busybox-1.20.2/
[lingyun@localhost busybox-1.20.2]$ vim Makefile
#修改CROSS_COMPILER为:
CROSS_COMPILE ?= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
[lingyun@localhost busybox-1.20.2]$ ls ../rootfs
apps bin data dev etc info lib mnt proc root sbin sys tmp usr var
[lingyun@localhost busybox-1.20.2]$ vt100
[lingyun@localhost busybox-1.20.2]$ sudo 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) --->
(../rootfs) BusyBox installation prefix
#其他选项结合和自己的需求定制
[lingyun@localhost busybox-1.20.2]$ sudo make
#编译过程略
[lingyun@localhost busybox-1.20.2]$ file busybox
busybox: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped
[lingyun@localhost busybox-1.20.2]$ sudo make install
....
../rootfs/sbin/udhcpc -> ../bin/busybox
../rootfs/sbin/udhcpd -> ../bin/busybox
../rootfs/sbin/vconfig -> ../bin/busybox
../rootfs/sbin/zcip -> ../bin/busybox
--------------------------------------------------
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------
[lingyun@localhost busybox-1.20.2]$
[lingyun@localhost busybox-1.20.2]$ ls ../rootfs
apps bin data dev etc info lib linuxrc mnt proc root sbin sys tmp usr var
1.1.19. 移植dropbear1.1.19.1. 首先编译生成PC版的,在制作密钥时用到[lingyun@localhost ~]$ wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.53.1.tar.bz2
[lingyun@localhost ~]$ tar -xjf dropbear-0.53.1.tar.bz2
[lingyun@localhost ~]$ cd dropbear-0.53.1
[lingyun@localhost dropbear-0.53.1]$ ./configure && make
生成的文件:
dropbear: ssh2 server
dropbearkey: 密钥生成器
dropbearconvert: 可以转换openssh的密钥
dbclient: ssh2 client
[lingyun@localhost dropbear-0.53.1]$ ./dropbearkey -t rsa -f /opt/rootfs/etc/dropbear/dropbear_rsa_host_key
Will output 1024 bit rsa secret key to '/opt/rootfs/etc/dropbear/dropbear_rsa_host_key'
Generating key, this may take a while...
Public key portion is:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgwChXpm6ogojmWy7GTZloJDdSIFq7pd49P3dh2I8Ap/7Cr9KRWlfQb0rchkFv1h62736FyX28S1jo7HpES9Rjp7MinG66pyzFjOfrsruzkeheo7YBrk8GPeSdEm65O3gPlJzReyMY3r020fwVIGaMf7+bPBuMsYY1g+8OcgeEygYCExz lingyun@localhost.localdomain
Fingerprint: md5 ed:a6:c9:6d:6e:85:f6:10:b2:3c:49:90:52:be:9b:19
[lingyun@localhost dropbear-0.53.1]$ ./dropbearkey -t dss -f /opt/rootfs/etc/dropbear/dropbear_dss_host_key
Will output 1024 bit dss secret key to '/opt/rootfs/etc/dropbear/dropbear_dss_host_key'
Generating key, this may take a while...
Public key portion is:
ssh-dss AAAAB3NzaC1kc3MAAACBAOa5XsTcByi4cdnhJ44Uro/athrTzv68+yeizFejzQM+K1e4ung/2SfAIZW/ms41HSSMhO6Siv/oOGz3cPnw8NKkWHWTP6pQmyZlvl2zNdrbDwiPGQ17rb5THoVDbXwn54c/aMR27mj+DBJ4+SDpL08wfs6k2JaelQIpBYWbFJ+rAAAAFQCgrFTR2dqbRdrk+lhaxnU7L8ADiQAAAIEAwUThj2irqMRCuItsKN+hYKmydUAtAL47ys+GBYMxKH36cLBovm19+2gaBTKsdBJbBs7j/7/xrFLPypAQmN3MukeSQvIUGQ0qzqPEcwtOdDtqOzi2//f4Cb3JUQd+JVXYj0lYGjRMZGuGzUlk6zoVoY8SEdGpQgRtI5Zi/M1H5YEAAACAMYxm7p6mBeA/SD5uESAgfPgF87h0ZIdC2cONVG0Ay/TJvOJC2ioNyQEL+UinNEV5+cA4tv5huA8zryp/jBgHVtxUQu168KlzSzo8397Rsy5Lhg7zgRGZYhLNEBzypHQjX8bpEve76GgHSbZ+9aj+zznpvAmKwonqZNLic2/HTMc= lingyun@localhost.localdomain
Fingerprint: md5 96:f3:31:04:8b:a6:1b:a5:cc:37:e5:08:9c:18:98:cd
[lingyun@localhost dropbear-0.53.1]$
[lingyun@localhost dropbear-0.53.1]$ chmod 666 /opt/rootfs/etc/dropbear/dropbear_*
[lingyun@localhost dropbear-0.53.1]$
1.1.19.2. 编译ARM版本的[lingyun@localhost dropbear-0.53.1]$ make distclean
[lingyun@localhost dropbear-0.53.1]$ ./configure CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc --build=i686 --host=arm-linux --disable-zlib
[lingyun@localhost dropbear-0.53.1]$ make
[lingyun@localhost dropbear-0.53.1]$ file dropbear
dropbear: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[lingyun@localhost dropbear-0.53.1]$ file dbclient
dbclient: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[lingyun@localhost dropbear-0.53.1]$ mv dbclient ssh
[lingyun@localhost dropbear-0.53.1]$ arm-linux-strip dropbear
[lingyun@localhost dropbear-0.53.1]$ arm-linux-strip ssh
[lingyun@localhost dropbear-0.53.1]$ cp dropbear ssh /opt/rootfs/usr/sbin/
1.1.20. 在文件系统中创建启动脚本[lingyun@localhost rootfs]$ vim etc/init.d/S04_dropbear
#!/bin/sh
/usr/sbin/dropbear
[lingyun@localhost rootfs]$ chmod 777 etc/init.d/S04_dropbear
[lingyun@localhost rootfs]$ ls
apps bin data dev etc info lib linuxrc mnt proc root sbin sys tmp usr var
[lingyun@localhost rootfs]$ OK
* 在开发板中移植上面制作的根文件系统后的截图如下所示:
以上我们已经成功的创建了一个根文件系统。下面我们开始对在嵌入式应用领域的多种文件系统的优缺点进行比较。
4. 制作和移植多种文件系统下面我们开始制作和移植多种嵌入式领域所广泛应用的文件系统initramfs、nfs、ramdisk、cramfs、jffs2、yaff2和ubifs这些文件系统。
4.1. [url=]Initramfs[/url]的制作和移植4.1.1. 对根文件系统进行修改由于制作initramfs文件系统启动时会在根文件系统中执行第一个init程序,它对uboot传过来的参数init=/linuxrc不予理睬,所以需要在上面制作的根文件系统里的根目录加入init程序,否则无法启动。init程序和linuxrc程序一样都是符号链接文件,它们都是指向/bin/busybox程序。
[lingyun@localhost rootfs]$ ll
total 60
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 apps
drwxr-xr-x 2 lingyun trainning 4096 Apr 26 15:16 bin
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 data
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:51 dev
drwxr-xr-x 4 lingyun trainning 4096 Apr 26 14:16 etc
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 info
drwxr-xr-x 3 lingyun trainning 4096 Apr 25 21:17 lib
lrwxrwxrwx 1 root root 11 Apr 26 15:16 linuxrc -> bin/busybox
drwxr-xr-x 6 lingyun trainning 4096 Apr 25 20:15 mnt
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 proc
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 root
drwxr-xr-x 2 lingyun trainning 4096 Apr 26 15:16 sbin
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 sys
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 tmp
drwxr-xr-x 6 lingyun trainning 4096 Apr 25 20:15 usr
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:57 var
[lingyun@localhost rootfs]$ ln -s bin/busybox init
[lingyun@localhost rootfs]$ ll
total 60
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 apps
drwxr-xr-x 2 lingyun trainning 4096 Apr 26 15:16 bin
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 data
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:51 dev
drwxr-xr-x 4 lingyun trainning 4096 Apr 26 14:16 etc
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 info
lrwxrwxrwx 1 lingyun trainning 11 Apr 27 21:19 init -> bin/busybox
drwxr-xr-x 3 lingyun trainning 4096 Apr 25 21:17 lib
lrwxrwxrwx 1 root root 11 Apr 26 15:16 linuxrc -> bin/busybox
drwxr-xr-x 6 lingyun trainning 4096 Apr 25 20:15 mnt
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 proc
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 root
drwxr-xr-x 2 lingyun trainning 4096 Apr 26 15:16 sbin
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 sys
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:15 tmp
drwxr-xr-x 6 lingyun trainning 4096 Apr 25 20:15 usr
drwxr-xr-x 2 lingyun trainning 4096 Apr 25 20:57 var
[lingyun@localhost rootfs]$
4.1.2. 添加内核对initramfs的支持[lingyun@localhost kernel]$ ls
build.sh linux-3.0 linux-3.0.tar.bz2 patch
[lingyun@localhost kernel]$ cd linux-3.0
[lingyun@localhost linux-3.0]$ vt100
[lingyun@localhost linux-3.0]$ make menuconfig
。 。 。 。 。 。
General setup --->
Initial RAM filesystem and RAM disk (initramfs/initrd) support
(/opt/rootfs) Initramfs source file(s) #输入根文件系统的所在目录
。 。 。 。 。 。
[lingyun@localhost linux-3.0]$ ls
arch crypto fs Kbuild linuxrom-s3c2440.bin modules.builtin README security usr
block Documentation include Kconfig MAINTAINERS modules.order REPORTING-BUGS sound virt
COPYING drivers init kernel Makefile Module.symvers samples System.map vmlinux
CREDITS firmware ipc lib mm net scripts tools vmlinux.o
[lingyun@localhost linux-3.0]$ du -h linuxrom-s3c2440.bin
6.9M /tftp/linuxrom-s3c2440.bin
[lingyun@localhost linux-3.0]$ mv linuxrom-s3c2440.bin /tftp/
4.1.3. 制作映像文件因为文件系统和内核是集成在一起的,所以不需要制作文件系统映像
4.1.4. 添加uboot对initramfs支持Uboot源码基本上不做修改。
下面对uboot进行修改。
[ s3c2440@fulinux ]# pri
bbl=nand erase 0 100000;tftp 30008000 u-boot-$cpu.bin;nand write 30008000 0 $filesize
norbbl=erase bank 1;tftp 30008000 u-boot-$cpu.bin;cp.b 30008000 0 $filesize
bkr=tftp 30008000 uImage-$cpu.gz;nand erase 100000 400000;nand write 30008000 100000 $filesize
bootcmd_rootfs=nand read 30008000 100000 400000;bootm 30008000
tpb=tftp 30008000 uImage-$cpu.gz;tftp 30800000 ramdisk-$cpu.gz;bootm 30008000
mtdids=nand0=nand0
mtdparts=mtdparts=nand0:1M@0x0(u-boot),5M@0x100000(kernel),10M@0x600000(ramdisk),10M@0x1000000(cramfs),20M@0x1a00000(yaffs2),20M@0x2e00000(ubifs),-(users)
bootdelay=1
baudrate=115200
ethaddr=08:00:3e:26:0a:6b
ethact=dm9000
bcramfs=tftp 30800000 rootfs.cramfs;nand erase f00000 600000;nand write 30800000 f00000 600000
bjffs2=tftp 30008000 rootfs.jffs2;nand erase 1e00000 1400000;nand write.jffs2 30008000 1e00000 1400000
bootargs_jffs2=noinitrd root=/dev/mtdblock4 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200
bootargs_cramfs=noinitrd root=/dev/mtdblock3 rootfstype=cramfs init=/linuxrc console=ttyS0,115200
bootargs_ubifs=console=ttyS0,115200 mem=64M ubi.mtd=6 root=ubi0:rootfs rootwait rootfstype=ubifs rw
bubifs=tftp 30008000 ubifs-$cpu.img;nand erase 6e00000 900000;nand write 30008000 6e00000 900000
cpu=arm920t
brdfs=tftp 30008000 ramdisk.gz;nand erase 500000 a00000;nand write 30008000 500000 500000
bootcmd_ramdisk=nand read 30008000 100000 400000;nand read 30800000 500000 500000;bootm 30008000
bootargs_ramdisk=console=ttyS0,115200 mem=64M initrd=0x30800000,16M root=/dev/ram0 rw loglevel=7
ip=192.168.1.111:192.168.1.3:192.168.1.1:255.255.255.0:localhost.com:eth0ff
bootargs_nfs=noinitrd console=ttyS0,115200 init=/linuxrc mem=64M loglevel=7 root=/dev/nfs rw nfsroot=192.168.1.3:/opt/rootfs ip=192.168.1.111:192.168.1.3:192.168.1.1:255.255.255.0:localhost.com:eth0ff
bootargs=noinitrd root=/dev/mtdblock3 rootfstype=cramfs init=/linuxrc console=ttyS0,115200
filesize=4DF000
fileaddr=30800000
netmask=255.255.255.0
ipaddr=192.168.1.111
serverip=192.168.1.3
bootcmd=run bootcmd_rootfs
stdin=serial
stdout=serial
stderr=serial
Environment size: 2064/131068 bytes
[ s3c2440@fulinux ]#
[ s3c2440@fulinux ]# set bkr 'tftp 30008000 linuxrom-s3c2440.bin;nand erase 100000 800000;nand write 30008000 100000 800000'
[ s3c2440@fulinux ]# set bootargs 'console=ttyS0,115200 mem=64M init=/linuxrc rw loglevel=7'
[ s3c2440@fulinux ]# set bootcmd 'run bootcmd_initramdisk'
[ s3c2440@fulinux ]# save
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x60000 -- 100% complete.
Writing to Nand... Done
[ s3c2440@fulinux ]# run bkr
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:6b
could not establish link
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.3; our IP address is 192.168.1.111
Filename 'linuxrom-s3c2440.bin'.
Load address: 0x30008000
Loading: T T #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
###################################
done
Bytes transferred = 7187832 (6dad78 hex)
NAND erase: device 0 offset 0x100000, size 0x800000
Erasing at 0x8e0000 -- 100% complete.
OK
NAND write: device 0 offset 0x100000, size 0x800000
8388608 bytes written: OK |
|