Chinaunix首页 | 论坛 | 博客
  • 博客访问: 196814
  • 博文数量: 60
  • 博客积分: 3269
  • 博客等级: 中校
  • 技术积分: 648
  • 用 户 组: 普通用户
  • 注册时间: 2005-09-21 10:48
文章存档

2012年(6)

2011年(6)

2010年(30)

2009年(8)

2007年(6)

2005年(4)

我的朋友

分类: LINUX

2005-11-01 16:17:44

前言:小型linux
在设计产品的过程中制作了各种各样的linux应用系统,回想起来这个在早期用于学习和实践的软盘系统制作过程一直让我时刻惦记,也是他带我进入嵌入式linux的世界。
这是制作笔记,放到这里但愿不会丢失。

###########################################################################
#
#    This file and those BASH files that the file about write by Leadgenius
#    on 2002.04.01
#    Test on linux k2.2.10 and passed
#    LG 2002
#
###########################################################################

http://leadgenius.cublog.cn/

一、制作一个小的文件系统和内核
首先是内核,根据你的需要配置内核,为了减小它的尺寸,没有用的模块请选择n。想要装入一张软盘的话它最好在400k以内,所以,对于高版本的内核代码实现起来比较困难(我认为)。文件系统比较复杂,简单如下:
1> 先建立一个目录rootfs作为将来小文件系统的根目录,并在其中建立需要的系统目录,这些子目录都是大家“ls /”是经常见到的
   mkdir rootfs # 建根目录
   mkdir rootfs/dev 。。。

2> 准备/拷贝必要的/dev下的设备文件,要使用-dpR 或者 -a参数
   eg. cp -dpR -f /dev/hd* rootfs/dev

3> 准备一些启动配置文件和shell文件
   eg. inittab rootfs/etc # 我使用busybox中的init
   我尝试将ash或者bash改名放到 rootfs/bin中也能直接进入shell
   对于其他启动控制文件的作用我不细说了。

4> 准备必要的可执行程序
   这会有些问题,选择静态程序或者动态的elf程序,取决于实际的情况。
   我选择了busybox这个软件,它包括了很多常用的shell工具,然后选择静态编译方式,效果很好,选择只有200k左右。
 
5> 当然,我也使用过动态的程序,不过要在rootfs/lib中备齐所要的函数库
   使用ldd命令可以列出一个动态程序所需要的函数库
   这里有一个方法可以减小函数库的尺寸objcopy
   eg. objcopy --strip-debug rootfs/lib/libtermcap.so.2

# ###############################################
# 制作ext2文件系统映像
# LG 2002
# ###############################################

二、压缩文件系统数据,制作系统映像
   以下的代码屡试不爽,好像现在还是有很多人在问那些系统映像是怎么做的!仔细看一下。
   mkdir /mnt/loop 2>/dev/null
   # 说清楚打算建立的虚拟存储器的大小,这里是4M
   dd if=/dev/zero of=/tmp/loop_tmp bs=1k count=4096>/dev/null
   losetup /dev/loop0 /tmp/loop_tmp
   mke2fs -m 0 /dev/loop0 2>/dev/null
   mount /dev/loop0 /mnt/loop -t ext2
   cp -a rootfs/* /mnt/loop
   umount /mnt/loop
   rmdir /mnt/loop 2>/dev/null
   losetup -d /dev/loop0
   dd if=/tmp/loop_tmp|gzip -9>rootfs.gz
   rm -f /tmp/loop_tmp

   所以说,当一个文件系统映像被获得,揭开其秘密是很容易的
   gunzip rootfs.gz => rootfs
   losetup /dev/loop0 rootfs #建立loop设备与文件的联系
   mount /dev/loop0 /mnt/loop -t ext2
   ls /mnt/loop/*
   OK!

三、将内核和文件系统写入软盘
看不懂我写的英文,只好自己去man了。
1> Find the linux boot core file and copied      eg. "vmlinuz" file
   找到编译好的内核,BIN格式文件。
2> Make the root system in DIR rootfs            use "mkrootfs"
3> Creat root system ramdisk ZIP file rootfs.gz  use "mkrootgz"
   2、3步就是一、二中的过程
4> Check files's size, "vmlinuz" and "rootfs.gz",determin to make one disk or two disks
   根据内核和文件系统映像的尺寸决定放入几张软盘。
5> Use ls -s can know the "vmlinuz" file's size  eg. 439
   用 ls -s 获得内核文件占用存储尺寸
6> Set linux core boot ramdisk BYTE
   in the byte
 bits  0-10:ramdisk start offset < 1024
 bits 11-13:not used (set 0)
 bits    14:flag to make core load ramdisk (set 1)
 bits    15:flag to prompt before load ramdisk
  (set 0 : root infomation in the same disk)
  (set 1 : root infomation in the other disk)

   the byte can be changed with command "rdev"

   the CORESIZE = vmlinuz size + 1 = 439 + 1 = 440
   the OFFSET = CORESIZE + 2(14) = CORESIZE + 16384       (in one disk)
   the OFFSET = 2(14) + 2(15) = 49152                     (in two disks)

   rdev vmlinuz /dev/fd0
   rdev -r vmlinuz OFFSET
   内核中的固定位置有一些记录设置的地方,具体的可以看一下内核代码main.c or setup.c
7> Make ALL in ONE disk
   dd if=vmlinuz of=/dev/fd0 bs=1k
   dd if=rootfs.gz of=/dev/fd0 bs=1k seek=CORESIZE
8> Make two boot disks
   dd if=vmlinuz of=/dev/fd0 bs=1k
   dd if=rootfs.gz of=/dev/fd0 bs=1k

Thank you for your accress
(END)

阅读(1031) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~