https://smart888.taobao.com/ 立观智能监控
分类: LINUX
2009-03-10 23:30:20
2、建立根文件系统目录
#mkdir rootfs
#cd rootfs
#mkdir dev proc etc lib mnt mnt/etc mnt/etc/init.d tmp var usr
#touch linuxrc //建立linuxrc文件
#touch mnt/etc/inittab //建立inittab文件
#touch mnt/etc/init.d/rcS //建立rcS脚本文件
将上面编译bosybox生成的_install目录下的bin和sbin两个目录cp到我们刚才建立的rootfs目录下面,注意这里不需要busybox生成的linuxrc文件。
在linux
因此我们还需要在rootfs/dev下面建立一些设备文件!我在busybox/example下面找到一个工具mkdev.sh可以自动帮助我们完成这个工作,我们需要的只是在这个文件里面稍微修改一下即可!
#!/bin/sh
#
# makedev.sh - creates device files for a busybox boot floppy image
#make by zj , so_zhou@qq.com
# we do our work in the dev/ directory
if [ -z "$1" ]; then
echo "usage: `basename $0` path/to/dev/dir"
exit 1
fi
cd $1
# miscellaneous one-of-a-kind stuff
mknod console c 5 1
mknod full c 1 7
mknod kmem c 1 2
mknod mem c 1 1
mknod null c 1 3
mknod port c 1 4
mknod random c 1 8
mknod urandom c 1 9
mknod zero c 1 5
mknod mtdblock0 b 31 0
mknod mtdblock1 b 31 1
mknod mtdblock2 b 31 2
mknod mtdblock3 b 31 3
mknod mtdblock4 b 31 4
mknod mtd0 c 90 0
mknod mtd1 c 90 1
mknod mtd2 c 90 2
mknod mtd3 c 90 3
mknod mtd4 c 90 4
mknod cua0 5 64
for i in `seq 0 9`; do
mknod cua$i c 5 $i+64
done
for i in `seq 0 9`; do
mknod tty$i c 4 $i
done
mknod ttySAC0 c 4 64
mknod tty c 5 0
mknod ttyp0 c 3 0
# virtual console screen devs
for i in `seq 0 9`; do
mknod vcs$i b 7 $i
done
ln -s vcs0 vcs
# virtual console screen w/ attributes devs
for i in `seq 0 9`; do
mknod vcsa$i b 7 $i
done
ln -s vcsa0 vcsa
其实还有很多设备文件都是不需要的,我也没有去一个一个的式样,还是那句话,我现在的目标只是让我的系统能够进入shell。
接下来我们要将前面创建的几个文件(linuxrc inittab fstab rcS)完善一下
#vi linuxrc
输入下面的内容(可根据自己的需要修改)
#!/bin/sh
echo "mount /etc as ramfs"
/bin/mount -n -t ramfs ramfs /etc
echo "done"
echo "cp mnt/etc/* /etc"
/bin/cp -a /mnt/etc/* /etc
echo "done"
echo "re-create the /etc/mtab entries"
# re-create the /etc/mtab entries
/bin/mount -f -t cramfs -o remount,ro /dev/mtdblock3 /
#/bin/mount -f -t ramfs ramfs /etc
#echo "mount ramfs /etc ...... done"
#/sbin/insmod -f /lib/yaffs.o
/bin/mount -t yaffs /dev/mtdblock4 /usr
echo "mount yaffs mtdblock4 .................done"
#mount some fike system
echo "-------mount /devshm as tmpfs"
/bin/mount -n -t tmpfs tmpfs /dev/shm
echo "-----------mount /proc as proc"
/bin/mount -n -t proc none /proc
echo "-----mount /sys as sysfs"
/bin/mount -n -t sysfs none /sys
/bin/cat /etc/motd
echo "exec sbin/init"
exec /sbin/init
#vi mnt/etc/inittab
::sysinit:/etc/init.d/rcS
::askfirst:-/bin/sh
::restart:sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/mount -a -r
::shutdown:/sbin/swapoff -a
#vi mnt/etc/fstab
none /proc proc defaults 0 0
none /dev/pts devpts mode=0622 0 0
tmpfs /dev/shm tmpfs defaults 0 0
#vi mnt/etc/init.d/rcS
#! /bin/sh
echo "Starting system"
hostname zj
/bin/mount -a
在这三个文件中我都加了一些echo “…….”语句,这样我就可以知道我的系统运行到什么地方了,如果出错,也能查出错在什么地方,^_^
3、生成cramfs
#mkcramfs rootfs root.cramfs
生成文件系统镜像,下载运行:
……前面略……
NET: Registered protocol family 1
VFS: Mounted root (cramfs filesystem) readonly.
Freeing init memory: 108K
mount /etc as ramfs
done
cp mnt/etc/* /etc
done
re-create the /etc/mtab entries
yaffs: dev is 32505860 name is "mtdblock4"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.4, "mtdblock4"
mount yaffs mtdblock4 .................done
-------mount /devshm as tmpfs
-----------mount /proc as proc
-----mount /sys as sysfs
Welcome to my
| | |_|
| |
| | | | nnnnnnnn |u| |u| \ \/ /
| | | | nn nn |u| |u| \/\/
| | | | nn nn |u| |u| /\/\
| | | | nn nn |u|u|u|u|u| / /\ \
make by ZJ zo_zhou@qq.com
exec sbin/init
command='/etc/init.d/rcS' action='1' terminal='/dev/console'
command='-/bin/sh' action='4' terminal='/dev/console' //这个红色部分不知道
command='sbin/init' action='128' terminal='/dev/console' //是什么意思,还有点
command='/sbin/reboot' action='32' terminal='/dev/console' //不明白,希望能和大家
command='/bin/mount -a -r' action='64' terminal='/dev/console' //一起讨论一下,
command='/sbin/swapoff -a' action='64' terminal='/dev/console' //so_zhou@qq.com
Starting system
Please press Enter to activate this console.
BusyBox v
Enter 'help' for a list of built-in commands.
#
现在 shell终于出现了,整整花了我两天时间不断的实验,终于成功了!^_^
经过我的实验之后,发现一个问题,有一部分命令无效,不知道是我的busybox编译有问题还是其他的什么有问题,总之现在我的系统算是运行起来了,
下一步我需要做的就是完善我的嵌入式linux系统了!^-^