linux怎么进入自己添加的软盘,制作可以放入软盘的linux系统(笔记)

制作可以放入软盘的linux系统(笔记)

发布时间:2006-09-20 16:14:48来源:红联作者:wuhu911

前言:小型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

#

###########################################################################

一、制作一个小的文件系统和内核

首先是内核,根据你的需要配置内核,为了减小它的尺寸,没有用的模块请选择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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值