红联Linux门户
Linux帮助

自己做个迷你型linux

发布时间:2006-04-25 01:17:29来源:红联作者:uu
作者:cexoyq

hda1----新装的RH9
hdc1----64M的硬盘,生成的小型linux就装在这个盘上,还未分区格式化。
环境:ms的虚拟机5.1版。

先重新编译内核,把不需要的全部去掉,这样模块也只有几M了。编译后生成了
内核:vmlinuz-2.4.20-8custom
initrd:initrd-2.4.20-8custom.img(这个没用到,在GRUB中使用它反而不能启动了,提示要加init内核参数。)
可加载模块:/lib/modules/2.4.20-8custom

fdisk /dev/hdc 分区,并激活,保存后退出。
mkext2fs /dev/hdc1
mkdir /mnt/hd2
mount /dev/hdc1 /mnt/hd2
mkdir /mnt/hd2/boot/grub -p
cp /boot/vmlinuz.2.4.20-8custom /mnt/hd2/boot/ -a
cp /boot/initrd.2.4.20-8custom /mnt/hd2/boot/ -a
cp /boot/grub/stage? /mnt/hd2/boot/grub/ -a
cp /boot/grub/grub.conf /mnt/hd2/boot/grub/ -a
cp /boot/grub/e2fs_stage1_5 /mnt/hd2/boot/grub/ -a
然后运行:grub
root (hdc1,0)
setup (hdc)
quit
这样,小硬盘就能启动了(不过进不了系统,内核启动完后就死了)。但是记得要配置一下grub.conf,改成:
default=1
timeout=10
title linux
root (hd0,0)
kernel /boot/vmlinuz-2.4.20-8custom ro root=/dev/hda1
不能够加入initrd,要不然会出错的,不清楚原因。有谁知道的可以告诉我吗?cexoyq1020@163.com,谢谢了。

制作文件系统
建立目录:/home,/mnt,/proc,/lib,/sbin,/bin,/root,/etc,/dev
需要的文件:/dev
/dev/console
系统控制台设备,非常重要。
/dev/fd0
第一个软驱
/dev/hda
/dev/hda[1-8]
IDE硬盘及分区
/dev/initctl
实际上是一个FIFO设备,跟init有关(切换运行级别时用于新init与原init通信)
/dev/initrd
Initial RAM disk
/dev/input
(目录)Input core(包括游戏杆、鼠标等)
/dev/kmem
内核虚拟内存
/dev/loop[0-7]
Loopback设备
/dev/mem
访问物理内存
/dev/null
NULL设备
/dev/psaux
PS/2鼠标
/dev/ptmx
UNIX98 PTY master
/dev/pts
(目录)UNIX98 PTY slaves
/dev/ptyp[0-7]
伪终端主设备(远程登录使用)
/dev/ram[0-7]
/dev/ramdisk
/dev/ram
RAM Disk设备。至少/dev/ram0是应用initrd机制所必须的。
/dev/ramdisk链接到/dev/ram0,是为了兼容老版本内核而保留的。
/dev/ram链接到/dev/ram1。
/dev/random
随机数发生器
/dev/sda
/dev/sda[1-8]
SCSI磁盘及分区设备
/dev/shm
共享内存设备
/dev/systty
指向系统tty设备的符号链接,一般是tty0。
/dev/tty
当前TTY设备
/dev/tty[0-7]
虚控制台(Virtual console)
/dev/ttyp[0-7]
伪终端从设备
/dev/ttyS0
/dev/ttyS1
串口(COM1和COM2)
/dev/urandom
速度更快、安全性较差的随机数发生器
/dev/zero
零设备,只能读0出来
需要的文件:/etc
etc/default
(目录)某个命令(比如useradd)的缺省设置(man useradd(8))
/etc/ld.so.cache
由ldconfig命令根据/etc/ld.so.conf文件产生
/etc/ld.so.conf
库文件路径配置文件,ldconfig命令根据该配置文件生成/etc/ld.so.cache
/etc/localtime
本地时间、时区设置
/etc/login.defs
全局缺省设置
/etc/fstab
文件系统列表(man fstab(5))
/etc/group
组文件(man group(5))
/etc/hosts
列出主机名和IP地址(man hosts(5))
/etc/init.d
符号链接到/etc/rc.d/init.d
/etc/initlog.conf
Initlog日志配置文件(man initlog(8))
/etc/inittab
Init配置文件(man inittab(5))
/etc/ioctl.save
该文件包含了用于单用户模式的串口和终端参数,因为这些参数是由getty设置的,
而在单用户模式时没有运行getty,所以用该文件保存参数。单用户模式对系统安全
是个威胁,我们应该禁止使用单用户模式,因此这个文件实际上并没有必要复制过
来。
/etc/issue
登录信息和标识文件(man issue(5))
/etc/modules.conf
模块的配置文件(man modules.conf(5))
/etc/mtab
已经挂载的文件系统列表(man mount(8))
/etc/nsswitch.conf
Name Service Switch的配置文件(配置名称服务数据源和查询的顺序)(man nss
witch.conf(5))
/etc/pam.d
放置PAM配置文件的目录(有关PAM请参考5.5节)
/etc/passwd
用户口令文件(man passwd(5))
/etc/profile
系统环境变量和登录配置文件
/etc/rc.d
放置启动脚本的目录
/etc/services
列出可用的网络服务及其端口(man services(5))
/etc/termcap
终端(terminal)功能数据库(man termcap(5))
另外,跟网络参数有关的文件也要一一拷贝过来。要不然就得手动配置网络参数了。

需要的文件:/lib
用“ldd 命令名称” 来取得命令所需要的LIB库,然后拷贝过来(要建立相应的目录)。

/bin和/sbin:根据自己的需要拷贝相应的文件。我把iptables,tc等拷贝过去。

需要的文件:/lib/modules
整个拷贝重新编译内核后的整个"2.4.20-8custom"目录,因为经过了裁剪,所以我的只有5M,不大可以完全使用。这个很重要,网络的驱动,
iptables,tc等都靠它了。

下载busybox并编译安装。http://www.busybox.net/downloads
下载最新版的busybox-1.1.2.tar.bz2到/root
解压后进入busybox-1.1.2
make menuconfig -----选自己需要的命令,也可以从源RH9中拷贝,不过那样就要拷LIB,麻烦。记得要选静态编译,还有init.
make
makeinstall
完成后在目录下生成“_install”目录,把所有目录及文件拷贝到小硬盘中。

重新配置/etc/inittab,/etc/fstab,/etc/rc.d/rc.sysinit
/etc/inittab
::sysinit:/etc/rc.d/rc.sysinit
::askfirst:-/bin/sh
tty2::askfirst:-/bin/sh
tty3::askfirst:-/bin/sh
tty4::askfirst:-/bin/sh
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a

/etc/fstab
proc /proc proc defaults 0 0

/etc/rc.d/rc.sysinit
#!/bin/sh
mount -a
添加自己的启动脚本。

然后关机,在虚拟机中把小硬盘设置成第一个硬盘,也就是(hd0,0)
就可以看到你的mini-linux在跑了。

问题:
做出来的系统每次启动后,网卡驱动是加载了(因为我编译在内核中),但是用"ifconfig eth0"却看不到它的配置信息,可能是未配置,
而所有的配置文件/etc/都已经拷贝了。只能用"ifconfig eth0 10.0.0.103"配置一下才能使用网络。

在grub中不能使用initrd参数。出错提示要加init内核参数,而加了init参数也不行。去掉initrd 就可以启动了。很是奇怪。
请教高手指点.
文章评论

共有 0 条评论