您的位置:首页 > 运维架构 > Linux

制作自已的Linux操作系统ISO

2014-08-17 20:16 281 查看
本文参考自:http://hi.baidu.com/websfx/item/f6a7b2177ddf9325f7625cdb,非常感谢..

本文没有重新编译Linux kernel.内核文件取自Centos5.6系统光盘.

本文使用GRUB完成引导.

本机环境Centos 5.6,版本有点低,因为当时工作要求必须用Centos5.6,没有其它版本的虚拟机了,将就一下吧.

一、目录结构

#mkdir jieos

#cd jieos

#mkdir rootfs

#mkdir iso

jieos #工作目录

    | ---- [rootfs] #存放用于生成initrd.img的原目录

                | -----  [bin] [dev] [etc] [home] linuxrc [mnt] [proc] [root] [sbin] [tmp] [usr] [var]

    | ---- [iso] #存放用于生成iso文件的原目录

              |  ----- [boot]

                             | --- [grub]

                             | --- initrd.img

                             | --- vmlinuz

二、编译busybox

在网上找了一个低版本的busybox 1.0.tar.gz ,先解压

编译配置,另外有一个命令 make menuconfig 应该是图形,可惜本人这用这个报错,只能有make config,功能是一样的;

#make config

下面列出几个注意的应选项:

General Configuration

Show verbose applet usage messages 

Runtime SUID/SGID configuration via /etc/busybox.conf

Build Options

Build BusyBox as a static binary (no shared libs) 

Installation Options

Don't use /usr

其它的一些linux基本命令如果是你认识并认为有用的,可以选上,我在编译时有因为某些命令编译时缺少需要用的包,导致编译失败.把对应的功能关掉就好了.

#make 

#make install

install完成后会在busybox 目录中生成_install 目录,其中包括 [bin] [sbin]两个目录和linuxrc一个链接文件,注意linuxrc链接文件同样很重要.

二、建立文件系统

#cp -R busybox-1.0/_install/* jieos/rootfs/

#cd jieos/rootfs

#mkdir etc usr var tmp proc home root dev    //建立文件目录

如下:

drwxr-xr-x 2 root   root   4096 08-17 18:10 bin

drwxrwxr-x 2 root   root   4096 08-17 18:52 dev

drwxrwxr-x 3 root   root   4096 08-17 18:55 etc

drwxrwxr-x 2 root   root   4096 08-16 21:43 home

lrwxrwxrwx 1 root   root     11 08-17 18:10 linuxrc -> bin/busybox

drwxr-xr-x 3 root   root   4096 08-17 18:51 mnt

drwxrwxr-x 2 root   root   4096 08-16 21:43 proc

drwxrwxr-x 2 root   root   4096 08-16 21:43 root

drwxr-xr-x 2 root   root   4096 08-17 18:10 sbin

drwxrwxr-x 2 root   root   4096 08-16 21:43 tmp

drwxrwxr-x 2 root   root   4096 08-16 21:43 usr

drwxrwxr-x 2 root   root   4096 08-16 21:43 var

在dev文件夹下建立设备文件名:

#cd rootfs/dev

为了方便直接从原系统的/dev目录下拷贝过来.一定要加-R参数

#cp -a /dev/console ./

#cp -a /dev/null ./

#cp -a /dev/ramdisk ./

#cp -a /dev/ram0 ./

#cp -a /dev/tty1 ./

#cp -a /dev/tty2 ./

#cp -a /dev/zero ./

其它的根据情况另加.

建立etc目录下文件 busybox.conf group inittab motd passwd resolv.conf fstab issue mtab profile shadow shadow- 

#cd etc

#>busybox.conf

#>group

#>inittab

#>motd

#>passwd

#>resolv.conf

#>issue

#>mtab

#>profile

#>shadow

#>shadow-

创建init.d目录

#mkdir init.d

#cp -R busybox-1.0/examples/bootfloppy/etc/init.d/*    rootfs/etc/init.d/

把init.d拷过来后要更改其中的文件rcS: 

请确保这个文件是可执行的:

#chmod u+x rcS

#vim init.d/rcS

#! /bin/ash
/bin/mount -o remount,rw /
/bin/mount -a

echo
echo
echo
echo
echo -en "\t\tWelcom to jieos Linux.."
echo
echo

#vim group
root:0:root

#vim inittab
::sysinit:/etc/init.d/rcS

::askfirst:/bin/sh
tty2::respawn:/bin/getty 38400 tty2
tty3::respawn:/bin/getty 38400 tty3
tty4::respawn:/bin/getty 38400 tty4

# Stuff to do when restarting the init process
::restart:/bin/init

# Stuff to do before rebooting
::ctrlaltdel:/bin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/bin/swapoff -a

issue
Baby Linux release 0.1

三、生成initrc.img

#mkfs.ext2 /dev/ram1

#mount -o loop /dev/ram1 /mnt/ram

#cp -R rootfs/* /mnt/ram

#umount /mnt/ram

#dd if=/dev/ram1 of=iso/boot/initrd.img

#mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o jieos.iso iso

OK,结束jieos.iso已生成,可以引导试下,不过还需要进一步完善。

四、总结问题:

kernel panic - not syncing : No init found.Try passing init=option to kernel

解决:busybox 缺少_install目录中生成的linuxrc

could not run /etc/init.d/rcs no such file or directory

解决:busybox 默认使用ash,在/etc/init.d/rcS第一行:

#! /bin/sh 应改为 #! /bin/ash

花费了一个下午的时间找这个问题,终于搞定呀..
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: