整个ROOT文件系统目录的制作

本文介绍如何从零开始构建一个嵌入式系统的rootfs文件系统,包括所需目录和文件的创建、节点文件的建立及配置文件的设置等关键步骤。

原帖地址:  http://lei43.spaces.live.com/blog/
1.建立root fs的文件系统所需的目录和文件。
[root@localhost /]$ mkdir /sspku2410
[root@localhost /]$ mkdir /sspku2410/root
[root@localhost sspku2410]$ tree root 5
root
|-- bin
|-- boot
|-- dev
|-- etc
|-- home
|-- lib
|   `-- modules
|-- makedir
|-- mnt
|   |-- data
|   |-- etc
|   |-- jffs2
|   |-- temp
|   `-- yaffs
|-- proc
|-- root
|-- sbin
|-- sys
|-- tmp
|-- usr
|   |-- bin
|   |-- lib
|   `-- sbin
`-- var
    |-- lib
    |-- lock
    |-- log
    |-- run
    `-- tmp
可以建立一个脚本文件:
[root@localhost sspku2410]$ vi makedir
#!/bin/sh
echo "making dir : bin dev etc lib proc sbin sys usr"
cd  root
mkdir bin dev etc lib proc sbin sys usr     #必备的8个目录
mkdir usr/bin usr/lib usr/sbin lib/modules

# Don't use mknod ,unless you run this Script as root !
# mknod -m 600 dev/console c 5 1
# mknod -m 666 dev/null c 1 3

echo "making dir : mnt tmp var"
mkdir mnt tmp var
chmod 1777 tmp
mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp
mkdir var/lib var/lock var/log var/run var/tmp
chmod 1777 var/tmp

echo "making dir : home root boot"
mkdir home root boot

echo "done"

运行脚本文件makedir

[root@localhost sspku2410]$ sh makedir
这样在root目录下就会生成以上列出的文件。

2.以root身份建立节点文件/dev/console, /dev/null
 mknod -m 600 dev/console c 5 1
 mknod -m 666 dev/null c 1 3
 
3. 建立配置文件如下:
[root@localhost etc]# more profile
#!/bin/sh
#/etc/profile:system-wide .profile file for the Bourne shells
echo
echo -n "Processing /etc/profile......"

# Set search library path
export LD_LIBRARY_PATH=/lib:/usr/lib
 
# set user path
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
 
#Set PS1
USER = "`id -un`"
LOGNAME=$USER
PS1='[/u@/h/W]/$'
PATH=$PATH
 
echo "Done!"
 
[root@localhost etc]# more init.d/rcS
#!/bin/sh
# set hostname, needed host file in /etc directory
#./etc/host
hostname `cat /etc/host`
 
# mount all filesystem defined in "fstab"
echo "#mount all......."
/bin/mount -a
 
#+yangdk
/bin/chmod 0666 /dev/null
 
echo "# starting mdev...."
/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
 
/usr/etc/init
 
echo "******************************************"
echo " fengqing linux-2.6.14.1 boot              "
echo " 2008-11-27               "
echo "                         "
echo "******************************************"
 
[root@localhost etc]# more
fstab     host       inittab    passwd     shadow    
group      init.d/    mdev.conf profile   
 
[root@localhost etc]# more fstab
proc    /proc   proc defaults 0 0
none    /tmp    ramfs   defaults 0 0
none    /var    ramfs   defaults 0 0
mdev    /dev    ramfs   defaults 0 0
sysfs   /sys    sysfs   defaults 0 0
 
[root@localhost etc]# more inittab
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
 
tty2::askfirst:-/bin/sh
 
::ctrlaltdel:/bin/umount -a -r
 
::shutdown:/bin umount -a -r
::shutdown:/sbin/swapoff -a
 
 
[root@localhost etc]# more ../usr/etc/init
#!/bin/sh
ifconfig eth0 192.168.1.103 up
ifconfig lo 127.0.0.1
 
4.建立文件/etc/mdev.conf,内容为空
[root@localhost etc]# vi mdev.conf
 
5.复制主机/etc/下面的文件passwd, group, shadow文件到/etc
[root@localhost etc]# cp /etc/group .
[root@localhost etc]# cp /etc/passwd .
[root@localhosts etc]# cp /etc/shadow .
ok,所需要的文件都已经建立ok了
 
[root@centos etc]# ls
fstab  group  host  init.d  inittab  mdev.conf  passwd  profile  shadow

 

原文中host文件不是必须的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值