我们知道一个linux的启动过程,包括BIOS的加电自检POST,拷贝MBR的信息(启动BootLoader),加载内核,挂载根文件安系统这几大步,在嵌入式系统的移植方面我们也要自己动手制作内核映像,根文件系统等。今天境就带大家讲讲使用busybox制作嵌入式可以移植的根文件系统。
需要的材料:
1,busybox(busybox-1.14.2)
        下载一个版本的busybox。下载地址。
        busybox是主要用来提供一些bash shell命令的工具。
2,配置文件 
        重点配置文件是在境的上一篇文章提到的几个文件。linux启动过程中的几个重要文件的详解
3,设备文件(文中会教你如何添加)
4,必要的库文件(选用)
所以今天我要的做的就是由busybox等组成的rootfs。
制作过程:
第一步:编译busybox获得shell工具。
1,在用户主目录下建立一个用于我们实验的一个目录(~/exp/mkrootfs),并转至该目录;
@ubuntu:~$ mkdir -p ~/exp/mkrootfs
@ubuntu:~$ cd ~/exp/mkrootfs
2,将刚才的下载的busybox解压至此,并转至;
@ubuntu:~/exp/mkrootfs$ tar xvjf busybox-1.14.2.tar.bz2
@ubuntu:~/exp/mkrootfs$ cd busybox-1.14.2/
3,修改makefile文件来修改我们的arch和gcc编译工具;没有安装交叉编译工具的筒子请看快速安装ubuntu交叉编译工具。
@ubuntu:~/exp/mkrootfs$vim Makefile
修改164行:ROSS_COMPILE ?=/usr/bin/arm-linux-gnueabi-
修改190行:ARCH ?= arm
4,make menuconfig

@ubuntu:~/exp/mkrootfs$ make menuconfig
如果遇到像境这样的问题:请查看文章最后面。
 5,优化我们的配置选项,在做make menuconfig之前最好,全屏打开你的terminal,这样才还显示类似编译内核一样的配置框,如下:
主要也是根据个人口味来选择优化配置,境选择如下:
   Busybox Settings  --->下的
    General Configuration  --->                 
    Build Options  --->        
    Debugging Options  --->       
    Installation Options  --->          
    Busybox Library Tuning  ---> 
这几项都稍微看下,决定对你的有需要的就选山;比如补全命令,查看历史命令等有用的都选上。
6,编译安装我们的busybox
@ubuntu:~/exp/mkrootfs$make
@ubuntu:~/exp/mkrootfs$make install
这样我们可以得到我们的一个编译结果@ubuntu:~/exp/mkrootfs/busybox-1.14.2/_install$下的bin,sbin,linuxrc等。
第二步:完成第一步也就说明我们已经完成了一半任务,现在制作我们的根文件系统正式拉开帷幕:
1,建立一个根文件系统目录。可以利用下面这个脚本快速建立一些默认的文件系统框架。
@ubuntu:~/exp/rootfs$vim helprootfs.sh

#!/bin/sh
echo "------Create rootfs directons......"
mkdir rootfs
cd rootfs
echo "--------Create root,dev......"
mkdir root dev etc bin sbin mnt sys proc lib home tmp var usr
mkdir usr/sbin usr/bin usr/lib usr/modules
mkdir mnt/usb mnt/nfs mnt/etc mnt/etc/init.d
mkdir lib/modules
chmod 1777 tmp
cd ..
echo "-------make direction done---------"

保存退出。
更改可执行权限
@ubuntu:~/exp$ chmod +x helprootfs.sh 
@ubuntu:~/exp$ ./helprootfs.sh 
------Create rootfs directons......
--------Create root,dev......
-------make direction done---------
并将刚才我们编译的busybox生成的_install目录下的文件拷贝至此:
@ubuntu:~/exp/rootfs$ cp ../mkrootfs/busybox-1.14.2/_install/* -a ./
这样就建好了一个根文件系统的大致框架。
2、创建设备文件
mdev 是通过 init 进程来启动的,在使用 mdev 构造 /dev 目录之前,init 至少要用到设备文件/dev/console、 /dev/null ,所以需要事先建立这两个设备文件:
@ubuntu:~/exp/rootfs$ cd dev/
@ubuntu:~/exp/rootfs/dev$ sudo mknod -m 660 console c 204 64
@ubuntu:~/exp/rootfs/dev$ sudo mknod -m 660 null c 1 3
@ubuntu:~/exp/rootfs/dev$ ls -l
total 0
crw-rw---- 1 root root 204, 64 2011-04-04 10:16 console
crw-rw---- 1 root root   1,  3 2011-04-04 10:16 null
3,准备一些配置文件和系统启动时所需的文件,这些文件的作用可以查看:(看好所在的目录)
(1)在mnt/etc下添加mdev。conf;
@ubuntu:~/exp/rootfs/mnt/etc$ touch mdev.conf
(2)在rootfs下添加linurc,rootfs下不要busybox下的linuxrs;
@ubuntu:~/exp/rootfs$ vim linuxrc
将下面内容写进去:

#!/bin/sh
echo "Processing /linuxrc"
echo "mount /etc as ramfs"
/bin/mount -n -t ramfs ramfs /etc      
/bin/cp -a /mnt/etc/* /etc
echo "re-create the /etc/mtab entries"
/bin/mount -f -t cramfs -o remount,ro /dev/bon/3 /
/bin/mount -f -t ramfs ramfs /etc
echo "start init"
exec /sbin/init

(3)在mnt/etc/init.d下添加rcS;
@ubuntu:~/exp/rootfs$ cd mnt/etc/init.d/
@ubuntu:~/exp/rootfs/mnt/etc/init.d$ vim rcS
将下面内容写进去

#!/bin/sh
echo "Processing /etc/init.d/rcS"
echo "mount -a"
mount -a #mount上fstab文件中所有文件系统
exec /etc/rc.local

(4)在mnt/etc下添加rc.local文件;
@ubuntu:~/exp/rootfs/mnt/etc$ vim rc.local
添加下面的内容:

#!/bin/sh
echo "Processing /etc/rc.local"
echo "get hostname"
/bin/hostname -F /etc/hostname
echo "Starting mdev"
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
echo "ifconfig eth0 192.168.1.21"
ifconfig eth0 192.168.1.21
echo "**************************************************"
echo "*                                                *"
echo "*        Linux ubuntu 2.6.32-30-generic          *"
echo "*                                                *"
echo "*           arm-linux-gnueabi-gcc 4.4.5          *"
echo "*                                                *"
echo "*                 2011-04-04                     *"
echo "*                                                *"
echo "**************************************************"

(5)在mnt/etc下添加profile文件:
@ubuntu:~/exp/rootfs/mnt/etc$ vim profile
添加下面内容:

#/etc/profile
echo "Processing /etc/profile"
echo "set user path"
PATH=/bin:/sbin:/usr/bin:/usr/sbin
echo "set search library path"
LD_LIBRARY_PATH=/lib:/usr/lib
echo "set PS1"
HOSTNAME=`/bin/hostname`
PS1='\u@\h:\w\$ ' #设置命令提示符为ubuntu风格
export PATH LD_LIBRARY_PATH HOSTNAME PS1

(6)改变权限;
@ubuntu:~/exp/rootfs$ chmod 775 linuxrc mnt/etc/init.d/rcS mnt/etc/rc.local mnt/etc/profile
(7)在mnt/etc下添加inittab文件:
@ubuntu:~/exp/rootfs/mnt/etc$ vim inittab
添加下面内容:

#/etc/inittab
::sysinit:/etc/init.d/rcS
console::askfirst:-/bin/sh    
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r

(8)在mnt/etc下添加fstab文件:
@ubuntu:~/exp/rootfs/mnt/etc$ vim fstab
添加下面内容:

#/etc/fstab: static file system information.
#<File system> <mount pt>     <type>   <options>         <dump> <pass>
proc  /proc proc  defaults 0 0
sysfs /sys  sysfs defaults 0 0
mdev  /dev  ramfs defaults 0 0
none  /tmp  ramfs defaults 0 0

(9)在/etc下添加passwd文件:
@ubuntu:~/exp/rootfs/etc$ vim passwd
添加下面内容:

#username:password:User ID:Group ID:comment:home directory:shell
root:x:0:0:root:/root:/bin/sh

(10)lib库文件复制到rootfs/lib目录下(根据需要复制)此处暂且不写了。
第三步:生成CramFS文件系统镜像文件myrootfs.img
1,下载CramFS制作工具,地址
2,解压编译(位子随便,最好在有别于rootf这个目录)
@ubuntu:~/tools$ tar xvzf cramfs-1.1.tar.gz
@ubuntu:~/tools$ make 
这样就生成了我们需要的工具拉,你可以将cramfsck和mkcramfs添加到你的bin下,也可以不。
3,最后一步制作我们的镜像;
@ubuntu:~/exp$ ~/tools/cramfs-1.1/mkcramfs rootfs/ myrootfs.img
Directory data: 6424 bytes
Everything: 572 kilobytes
Super block: 76 bytes
CRC: 1245ce56
warning: gids truncated to 8 bits (this may be a security concern)
4,goodluck!如果遇到你的CramFS没有办法make,可以在互联网上搜到解决方法,其他请跟贴。

make menuconfig时候出错处理

HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/split-include
scripts/basic/split-include.c: In function ‘main’:
scripts/basic/split-include.c:133: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
HOSTCC scripts/basic/docproc
HOSTCC scripts/kconfig/conf.o
scripts/kconfig/conf.c: In function ‘conf_askvalue’:
scripts/kconfig/conf.c:104: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
scripts/kconfig/conf.c: In function ‘conf_choice’:
scripts/kconfig/conf.c:359: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result
HOSTCC scripts/kconfig/kxgettext.o
HOSTCC scripts/kconfig/mconf.o
scripts/kconfig/mconf.c: In function ‘exec_conf’:
scripts/kconfig/mconf.c:470: warning: ignoring return value of ‘pipe’, declared with attribute warn_unused_result
scripts/kconfig/mconf.c: In function ‘show_textbox’:
scripts/kconfig/mconf.c:836: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/mconf
HOSTCC scripts/kconfig/lxdialog/checklist.o
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:31:20: error: curses.h: 没有那个文件或目录
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:128: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘use_colors’
scripts/kconfig/lxdialog/dialog.h:129: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘use_shadow’
scripts/kconfig/lxdialog/dialog.h:131: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘attributes’
scripts/kconfig/lxdialog/dialog.h:143: error: expected ‘)’ before ‘*’ token
scripts/kconfig/lxdialog/dialog.h:146: error: expected ‘)’ before ‘*’ token
scripts/kconfig/lxdialog/dialog.h:147: error: expected ‘)’ before ‘*’ token
scripts/kconfig/lxdialog/dialog.h:148: error: expected ‘)’ before ‘*’ token
scripts/kconfig/lxdialog/dialog.h:149: error: expected ‘)’ before ‘*’ token
scripts/kconfig/lxdialog/dialog.h:151: error: expected ‘)’ before ‘*’ token
scripts/kconfig/lxdialog/checklist.c:31: error: expected ‘)’ before ‘*’ token
scripts/kconfig/lxdialog/checklist.c:59: error: expected ‘)’ before ‘*’ token
scripts/kconfig/lxdialog/checklist.c:95: error: expected ‘)’ before ‘*’ token
scripts/kconfig/lxdialog/checklist.c: In function ‘dialog_checklist’:
scripts/kconfig/lxdialog/checklist.c:117: error: ‘WINDOW’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:117: error: (Each undeclared identifier is reported only once
scripts/kconfig/lxdialog/checklist.c:117: error: for each function it appears in.)
scripts/kconfig/lxdialog/checklist.c:117: error: ‘dialog’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:117: error: ‘list’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:117: warning: left-hand operand of comma expression has no effect
scripts/kconfig/lxdialog/checklist.c:121: warning: implicit declaration of function ‘endwin’
scripts/kconfig/lxdialog/checklist.c:122: warning: implicit declaration of function ‘fprintf’
scripts/kconfig/lxdialog/checklist.c:122: warning: incompatible implicit declaration of built-in function ‘fprintf’
scripts/kconfig/lxdialog/checklist.c:122: error: ‘stderr’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:140: error: ‘COLS’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:141: error: ‘LINES’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:143: warning: implicit declaration of function ‘draw_shadow’
scripts/kconfig/lxdialog/checklist.c:143: error: ‘stdscr’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:145: warning: implicit declaration of function ‘newwin’
scripts/kconfig/lxdialog/checklist.c:146: warning: implicit declaration of function ‘keypad’
scripts/kconfig/lxdialog/checklist.c:146: error: ‘TRUE’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:148: warning: implicit declaration of function ‘draw_box’
scripts/kconfig/lxdialog/checklist.c:148: error: ‘attributes’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:149: warning: implicit declaration of function ‘wattrset’
scripts/kconfig/lxdialog/checklist.c:150: warning: implicit declaration of function ‘mvwaddch’
scripts/kconfig/lxdialog/checklist.c:152: warning: implicit declaration of function ‘waddch’
scripts/kconfig/lxdialog/checklist.c:156: warning: implicit declaration of function ‘print_title’
scripts/kconfig/lxdialog/checklist.c:159: warning: implicit declaration of function ‘print_autowrap’
scripts/kconfig/lxdialog/checklist.c:166: warning: implicit declaration of function ‘subwin’
scripts/kconfig/lxdialog/checklist.c:190: warning: implicit declaration of function ‘print_item’
scripts/kconfig/lxdialog/checklist.c:194: warning: implicit declaration of function ‘print_arrows’
scripts/kconfig/lxdialog/checklist.c:197: warning: implicit declaration of function ‘print_buttons’
scripts/kconfig/lxdialog/checklist.c:199: warning: implicit declaration of function ‘wnoutrefresh’
scripts/kconfig/lxdialog/checklist.c:201: warning: implicit declaration of function ‘doupdate’
scripts/kconfig/lxdialog/checklist.c:204: warning: implicit declaration of function ‘wgetch’
scripts/kconfig/lxdialog/checklist.c:211: error: ‘KEY_UP’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:211: error: ‘KEY_DOWN’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:221: error: ‘FALSE’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:222: warning: implicit declaration of function ‘scrollok’
scripts/kconfig/lxdialog/checklist.c:223: warning: implicit declaration of function ‘wscrl’
scripts/kconfig/lxdialog/checklist.c:232: warning: implicit declaration of function ‘wrefresh’
scripts/kconfig/lxdialog/checklist.c:282: warning: incompatible implicit declaration of built-in function ‘fprintf’
scripts/kconfig/lxdialog/checklist.c:283: warning: implicit declaration of function ‘delwin’
scripts/kconfig/lxdialog/checklist.c:287: error: ‘KEY_LEFT’ undeclared (first use in this function)
scripts/kconfig/lxdialog/checklist.c:288: error: ‘KEY_RIGHT’ undeclared (first use in this function)
make[2]: *** [scripts/kconfig/lxdialog/checklist.o] 错误 1
make[1]: *** [menuconfig] 错误 2
make: *** [menuconfig] 错误 2
@ubuntu:~/exp/mkrootfs$
解决办法:ubuntu系统中缺少一个套件 ncurses devel ,把此套件安装下即可
@ubuntu:~/exp/mkrootfs$ sudo apt-get install libncurses5-dev

http://www.ourunix.org/post/63.html

转载于:https://www.cnblogs.com/cainiaoaixuexi/archive/2013/06/13/3133891.html

使用busybox制作根文件系统(rootfs)相关推荐

  1. 嵌入式Linux利用busybox制作根文件系统

    本文介绍如何利用busybox制作一个最小根文件系统,系统包含ls.cd.ifconfig等基本指令,文件系统采用动态加载的方式. 1.去busybox官网下载源码   官网地址:busybox官网 ...

  2. 使用BusyBox制作根文件系统的理论分析

    以下内容源于朱有鹏嵌入式课程的学习,如有侵权,请告知删除. 一.inittab文件介绍 #first:run the system script file ::sysinit:/etc/init.d/ ...

  3. [架构之路-30]:目标系统 - 系统软件 - Linux OS根文件系统rootfs的概念、组成、制作以及用busybox制作根文件系统

    目录 前言: 第1章 什么是根文件系统 1.1 什么是文件 1.2 什么是文件系统 1.3 文件系统组织文件的方式:树形结构 1.4 统一的虚拟文件系统 1.5 物理存储介质与物理文件系统类型 1.5 ...

  4. 使用BusyBox制作根文件系统的操作步骤

    参考博客http://www.cnblogs.com/Charles-Zhang-Blog/p/3419301.html 一.构建根文件系统该有的目录 即在/rootfs/目录下创建该有的空目录: 一 ...

  5. busybox制作根文件系统

    一.分配空间 制作64M的镜像文件,命名为myrootfs.ext3 sudo dd if=/dev/zero of=myrootfs.ext3 bs=1M count=64 用ext3格式化上一步的 ...

  6. Linux 利用busybox制作根文件系统

    busybox版本:1.17.3 官网下载路径:https://busybox.net/downloads/ 网盘下载路径:https://pan.baidu.com/s/1nvrEa73 密码:7y ...

  7. 使用Busybox制作根文件系统

    使用Busybox手工制作 Busybox本身包含了很了Linux命令,但是要编译其他程序的话需要手工下载.编译,如果它需要某些依赖库,你还需要手工下载.编译这些依赖库. 如果想做一个极简的文件系统, ...

  8. 根文件系统rootfs制作——使用buildroot工具(重制版)

    根文件系统rootfs制作--使用buildroot工具(重制版) 0.前言 一.rootfs配置 1.下载buildroot源码 2.开始配置 Target options配置如下: Toolcha ...

  9. 基于Linux的Buildroot 制作根文件系统(rootfs)

    基于Linux的Buildroot 制作根文件系统(rootfs) 1.需要条件 2.安装交叉编译链 3.下载Buildroot代码包 4.开始buildroot 制作根文件系统 5.配置文件系统 m ...

最新文章

  1. mysql 存储过程 格式化_转 mysql 存储过程初探
  2. ie下面出现Notice: Undefined index: HTTP_REFERER 的解决办法
  3. 我什么时候应该使用结构而不是类?
  4. linux给普通用户sudo权限
  5. 利用python脚本(re)抓取美空mm图片
  6. android 定位 广播,android - 如何触发广播接收器在GPS开启/关闭? - SO中文参考 - www.soinside.com...
  7. java敏感异常是什么_java中的异常是什么?
  8. Android中ScrollView嵌套WebView
  9. 报错,Field cardTypeService in cn.yihuazt.cols.controller.CardTypeController required a bean of type ‘c
  10. 金秋该有的样子,平面设计师秋季海报值得借鉴的PSD分层模板
  11. Javascript脚本 : eval()函数
  12. HDU 3065 病毒侵袭持续中(AC自动机 模板)题解
  13. 论文阅读-主干网络(2022)-ConvNext:下一代卷积网络
  14. 设计模式-第七篇之门面模式
  15. 苹果Mac电脑的复制粘贴不能用了
  16. mapbox/minemap 首屏固定比例尺为1:20
  17. Axial Attention 和 Criss-Cross Attention及其代码实现
  18. 计算机二级考试场次是随机的,计算机二级考试知多少
  19. Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo 解决方法
  20. [ 电脑维修那些事 ] 一招教你自己解决电脑蓝屏

热门文章

  1. 手机发包工具_【发包工具】http多线程发包工具
  2. 伤感网络验证系统_网络攻防演练中弱密码安全治理的几点建议
  3. 原始套接字AF_PACKET用法尝试
  4. 的write方法有哪些参数_Python笔记13:文件操作三件套:read,write,seek
  5. Socket 与 WebSocket
  6. FlashDevelop打包IOS应用教程
  7. 【java学习之路】(java SE篇)013.lambda表达式
  8. mysql事务控制(xa分布式事务)和锁定语句_MySQL的SQL语句 -事务性语句和锁定语句(7)- XA 事务...
  9. android++日历示例,Android开发之日历CalendarView用法示例
  10. MapReduce进程