热门关键字:  ubuntu  分区  函数  Fedora  linux系统进程

制作ramdisk根文件系统大家说

来源: 作者: 时间:2008-02-16 Tag: 点击:

我也说:

内容有时间更新......

利用busybox制作ramdisk
(1)下载busybox,可以从
www.busybox.net上下载到最新版本。
(2)解压压缩文件,进入busybox目录。
(3)配置busybox,make menuconfig。
    ①Busybox Settings(busybox配置组)
      Busybox Settings --->
           General Configuration --->                                                    
           Build Options --->
              [*] Build BusyBox as a static binary (no shared libs)                              
              [ ] Build shared libbusybox                                                        
           Debugging Options --->                                                        
           Installation Options --->
              [*] Don't use /usr                                                                 
                  Applets links (as soft-links) --->                                            
              (./_install) BusyBox installation prefix                                                                                                
           Busybox Library Tuning --->

[*]代表必选项:
    [*] Build BusyBox as a static binary (no shared libs)表示应用静态库,
    在嵌入式工作时一般首选,它不应用动态库,可以节省空间,在创建的ramdisk
    的lib目录中可以加入动态库支持;
    [ ] Build shared libbusybox 表示应用动态库,这样会耗费空间。
    [*] Don't use /usr这个选项也一定要选,否则make install 后busybox将安装
    在原系统的/usr下,这将覆盖掉系统原有的命令.选择这个选项后,make install
    后会在busybox目录下生成一个叫_install的目录,里面有busybox和指向他的链接.

   
   ② --- Applets (命令配置组)
      Archival Utilities ---> 文档选项 例如:压缩文件tar、gzip等命令;                                                    
       Coreutils ---> 常用命令选项 一般/bin下的命令的选择点;
           [*]   Allow use of color to identify file types                                    
            [*]   Produce colored ls output by default
            这两个可选,在控制台将会根据文件的类型有颜色区分与提示;                                                                                                    
       Console Utilities ---> 控制台选项 例如:清屏命令clear等;                                                  
       Debian Utilities ---> Debian命令选项组;                                                        
       Editors ---> 文档编辑选项组,例如:vi编辑器;                                                                 
       Finding Utilities ---> 查找选项组;                                                       
       Init Utilities ---> 系统初始化选项;                                           
       Login/Password Management Utilities ---> 登录管理;                                     
       Linux Ext2 FS Progs ---> Ext2 文件系统选项 例如:longin、passwd;                                                     
       Linux Module Utilities ---> 模块选项,例如:lsmod、insmod;                                                 
       Linux System Utilities ---> 系统选项,例如:mount、dmesg;                                                 
       Miscellaneous Utilities ---> 其他命令选项;                                                 
       Networking Utilities ---> 网络功能选项,例如:ifconfig;                                                   
       Process Utilities ---> 进程选项;                                                      
       Shells ---> Shell选项;
              Choose your default shell (msh) ---> 选择默认的shell
                                        ( ) ash                                 
                                             ( ) hush                                
                                             (X) msh                                 
                                             ( ) none                                                                             
       System Logging Utilities ---> 系统日志选项;                                                
       Runit Utilities ---> 即刻运行选项;
       ipsvd utilities ---> ip服务进程;
    ③保存与载入配置文件选项组
      Load an Alternate Configuration File                                            
      Save Configuration to an Alternate File
     
(4)配置busybox后保存配置,然后修改Makefile文件,在文件中找到这一行
CROSS_COMPILE   ?=,这一行用于指定交叉编译器的位置与类型,修改为系统中
交叉编译器的绝对路径;例如本系统在交叉编译器/eldk/usr/bin/中,
   CROSS_COMPILE   ?=/eldk/usr/bin/ppc_8xx-

(5)如果有ulibc,跳过这一步。
修改busybox目录下面applets/applets.c,注释掉下面的内容:
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
#warning Static linking against glibc produces buggy executables
#warning (glibc does not cope well with ld --gc-sections).
   #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
   #warning Note that glibc is unsuitable for static linking anyway.
   #warning If you still want to do it, remove -Wl,--gc-sections
   #warning from scripts/trylink and remove this warning.
   #error Aborting compilation.
   #endif
   这些内容用于提示你用ulibc以减少空间消耗,而不是用glibc。

(6)编译安装:
[guo@localhost busybox]$ make
[guo@localhost busybox]$ make install
编译安装后会在busybox目录下生成_install目录,它包括bin、sbin、linuxrc:
[guo@localhost _install]$ ls
bin linuxrc sbin

(7)建立ramdisk文件系统
[guo@localhost ~]$ dd if=/dev/zero of=rootfs bs=1M count=5
用dd命令建立了一个名为rootfs的ramdisk基本文件;
[guo@localhost ~]$ mke2fs -m 0 -N 3500 rootfs
在rootfs上面建立ext2文件系统。
[guo@localhost ~]$ mount -o loop rootfs /mnt/ramdisk
把rootfs文件系统挂载到/mnt/ramdisk目录下面(可随意指定一个目录);
[guo@localhost busybox]$ cp -dpR ./_install/* /mnt/ramdisk
把busybox目录下面_install目录下面的所有文件拷贝到/mnt/ramdisk下面;
[guo@localhost ~]$ cd /mnt/ramdisk
转到/mnt/ramdisk目录进行操作;
[guo@localhost ~]$ mkdir dev proc etc mnt usr lib
建立基本文件目录;

下面拷贝各要目录的内容:
①dev目录
   直接从本机/dev目录下面拷贝所需内容即可;
   以下是我认为需要的设备名:
console hda12 hda6     mouse ptyp6 ptypf ram15 ram9   tty15 ttyp3 ttypc   ttyS13 ttyS7
fb       hda13 hda7     null   ptyp7 ram    ram16 rtc    tty16 ttyp4 ttypd   ttyS14 ttyS8
fb0      hda14 hda8     psaux ptyp8 ram0   ram2   tty0   tty6   ttyp5 ttype   ttyS15 ttyS9
fd0      hda15 hda9     ptyp0 ptyp9 ram1   ram3   tty1   tty7   ttyp6 ttypf   ttyS16 zero
full     hda16 initctl ptyp1 ptypa ram10 ram4   tty10 tty8   ttyp7 ttyS0   ttyS2   tty5
hda      hda2   kmem     ptyp2 ptypb ram11 ram5   tty11 tty9   ttyp8 ttyS1   ttyS3   tty4
hda1     hda3   loop0    ptyp3 ptypc ram12 ram6   tty12 ttyp0 ttyp9 ttyS10 ttyS4   tty3
hda10    hda4   loop1    ptyp4 ptypd ram13 ram7   tty13 ttyp1 ttypa ttyS11 ttyS5   tty2
hda11    hda5   mem      ptyp5 ptype ram14 ram8   tty14 ttyp2 ttypb ttyS12 ttyS6   tty

②etc目录
   以下是我认为需要的设备名:
busybox.conf    inetd.conf inittab mtab           profile      xinetd.d
fstab           init.d      motd     nsswitch.conf xinetd.conf

可能根据busybox的配置不同会有不同要求,但有些是必须的:
inittab、init.d、fstab、profile。其中init.d、fstab、profile可从这里拷贝:
[guo@localhost busybox]$ cp -R examples/bootflopyp/etc/init.d /mnt/ramdisk/etc

(8)卸载
   umount /mnt/ramdisk
  
(9)生成压缩文件
[guo@localhost ~]# gzip -v9 rootfs
rootfs: 65.1% -- replaced with rootfs.gz

(10)在开发板上测试
①[guo@localhost ~]# /eldk/usr/bin/mkimage -A PPC -O linux -T ramdisk -C gzip -n dog_en -d rootfs.gz /tftpboot/rootfs
   利用该命令在/tftpboot下面生成映像文件
②在开发板上跑程序
APC2004=>tftp 下载内存地址 映像文件
APC2004=>bootm 内核地址     ramdisk地址

(11)小结
根据需求不同则配置busybox的情况不同,所以系统所需选择的设备文件、
命令文件也不同。
/bin:linux必需命令目录;
/sbin:系统常用命令目录;
/dev:设备文件目录;
/etc:系统启动与运行所需文件目录;
/proc:proc文件系统mount目录;
/mnt:用户mount目录;
/lib:库文件存放处;
/usr:其他工具与用户程序的存放处。  


最新评论共有 4 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册