製作自已的Linux操作系統ISO

本文參考自: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
花費了一個下午的時間找這個問題,終於搞定呀..


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章