huozhenhua的个人博客分享 http://blog.sciencenet.cn/u/huozhenhua

博文

LFS:Busybox编译、建立文件系统

已有 13271 次阅读 2011-9-7 22:36 |个人分类:Linux from scratch|系统分类:科研笔记|关键词:学者

系统:Fedora 15
$普通用户
#超级用户

1.下载Busybox源代码  http://www.busybox.net/
    当前版本:busybox-1.19.2.tar.bz2
2. 解压缩 $  tar xvf busybox-1.19.2.tar.bz2
3. 配置代码$  make menuconfig
Busybox Settings  ---> Build Options  ---> [*] Build BusyBox as a static binary (no shared libs)   
静态编译
can not found lcrypt
can not found lm
缺少glibc-static
# yum install glibc-static
重新编译
出错如下
In file included from miscutils/ubi_tools.c:63:0:
/usr/include/mtd/ubi-user.h:412:3: error: conflicting types for ‘__packed’
/usr/include/mtd/ubi-user.h:313:3: note: previous declaration of ‘__packed’ was here
make[1]: *** [miscutils/ubi_tools.o] Error 1
make: *** [miscutils] Error 2

重新配置 make menuconfig
Miscellaneous Utilities  --->删掉所有和ubi相关选项
linux-2.6.27后,内核加入了一种新型的Flash文件系统UBI(Unsorted Block Images)
新东西,不稳定,还是不用了,哈哈!
接着出错:
==========
networking/lib.a(nslookup.o): In function `print_host':
nslookup.c:(.text.print_host+0x42): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(ipcalc.o): In function `ipcalc_main':
ipcalc.c:(.text.ipcalc_main+0x229): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
util-linux/lib.a(mount.o): In function `nfsmount':
mount.c:(.text.nfsmount+0xd1): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(inetd.o): In function `reread_config_file':
inetd.c:(.text.reread_config_file+0x6f9): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(netstat.o): In function `ip_port_str':
netstat.c:(.text.ip_port_str+0x3d): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(inetd.o): In function `reread_config_file':
inetd.c:(.text.reread_config_file+0x675): warning: Using 'getrpcbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(inetd.o): In function `unregister_rpc':
inetd.c:(.text.unregister_rpc+0x17): undefined reference to `pmap_unset'
networking/lib.a(inetd.o): In function `register_rpc':
inetd.c:(.text.register_rpc+0x4e): undefined reference to `pmap_unset'
inetd.c:(.text.register_rpc+0x75): undefined reference to `pmap_set'
networking/lib.a(inetd.o): In function `prepare_socket_fd':
inetd.c:(.text.prepare_socket_fd+0x8a): undefined reference to `bindresvport'
util-linux/lib.a(mount.o): In function `nfsmount':
mount.c:(.text.nfsmount+0x825): undefined reference to `pmap_getmaps'
mount.c:(.text.nfsmount+0x996): undefined reference to `clntudp_create'
mount.c:(.text.nfsmount+0x9fe): undefined reference to `clnttcp_create'
mount.c:(.text.nfsmount+0xa26): undefined reference to `clnt_spcreateerror'
mount.c:(.text.nfsmount+0xa35): undefined reference to `authunix_create_default'
mount.c:(.text.nfsmount+0xabe): undefined reference to `clnt_sperror'
mount.c:(.text.nfsmount+0xae6): undefined reference to `clnt_sperror'
mount.c:(.text.nfsmount+0xc97): undefined reference to `bindresvport'
mount.c:(.text.nfsmount+0xced): undefined reference to `pmap_getport'
util-linux/lib.a(mount.o): In function `xdr_fhstatus':
mount.c:(.text.xdr_fhstatus+0x15): undefined reference to `xdr_u_int'
mount.c:(.text.xdr_fhstatus+0x3b): undefined reference to `xdr_opaque'
util-linux/lib.a(mount.o): In function `xdr_dirpath':
mount.c:(.text.xdr_dirpath+0x1b): undefined reference to `xdr_string'
util-linux/lib.a(mount.o): In function `xdr_mountres3':
mount.c:(.text.xdr_mountres3+0x15): undefined reference to `xdr_enum'
mount.c:(.text.xdr_mountres3+0x40): undefined reference to `xdr_bytes'
mount.c:(.text.xdr_mountres3+0x4e): undefined reference to `xdr_int'
mount.c:(.text.xdr_mountres3+0x74): undefined reference to `xdr_array'
collect2: ld returned 1 exit status
make: *** [busybox_unstripped] Error 1


 重新配置 $ make menuconfig
 Linux System Utilities  --->  [ ]   Support mounting NFS file systems 网络文件系统
 Networking Utilities  ---> [ ] inetd (Internet 超级服务器 )
版本较高,默认支持功能较多,去掉编译不过的功能,如上。

编译成功!!!!哈哈呵呵!!!!

4、$ make install
默认安装在本目录下的_install中

5. $ cd _install
$ ls
bin  linuxrc  sbin  usr

6、$  mkdir proc sys etc dev mnt (创建四个空目录,linux内核需要)
 $ cd dev
 # mknod console c 5 1 (创建一个控制台字符设备文件)
 # mknod null c  1 3 (创建一个0设备文件)

 # cp -r /dev/sda9 dev (根目录分区)

7、$ cd etc (整个etc可以copy busybox 的example)
     $ vim fstab
 输入如下:
#device          mount-point            type           options          dump            fsck
proc               /proc                     proc            defaults         0                 0
sysfs             /sys                       sysfs          defaults         0                 0

$ mkdir init.d
$vim init.d/rcS 输入以下内容:
#!/bin/sh
mount -a

$ chmod +x init.d/rcS (rcS文件加上可执行权限)

$ vim inittab (输入如下内容)

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

8、返回安装目录,$ rm linuxrc
 $ ln -sv bin/busybox init
`init' -> `bin/busybox

(如整个etc可以copy busybox 的example)可写一init脚本并 chmod u+x init

”#!/bin/sh
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mdev -s
mount /dev/sda9 /mnt (注意:为了简单,我们直接把分区写死在init脚本中了)
exec switch_root /mnt /sbin/init   

转自http://linux.chinaunix.net/techdoc/system/2008/12/22/1054305.shtml
9、创建initrd镜像
$ find . | cpio --quiet -H newc -o | gzip -9 -n > ../initrd.gz
initrd.gz: 文件系统镜像文件





https://m.sciencenet.cn/blog-623402-483960.html

上一篇:访问量600纪念
下一篇:LFS: linux 引导文件系统

1 刘洋

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-3 04:17

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部