打造小型Linux操作系统.docx
《打造小型Linux操作系统.docx》由会员分享,可在线阅读,更多相关《打造小型Linux操作系统.docx(8页珍藏版)》请在冰点文库上搜索。
打造小型Linux操作系统
一、对linux内核进行配置和编译
1.下载linux-2.6.18.8内核至/usr/src
2.解压并makemenuconfig;make;makemodules_installinstall
3.得到一个bzImage文件,备份,后面要用
(bzImage所在位置:
/usr/src/linux-2.6.18.8/arch/i386/boot)
二、编译busybox
1.下载busybox(存放的位置没有太大关系)
2.对busybox进行配置
#tarxvfzbusybox-1.7.2.tar.gz//解开busybox
#cdbusybox-1.7.2
#makemenuconfig//配置busybox
下面是必需要编译进busybox的功能选项:
GeneralConfiguration
Showverboseappletusagemessages
RuntimeSUID/SGIDconfigurationvia/etc/busybox.conf
BuildOptions
BuildBusyBoxasastaticbinary(nosharedlibs)
原因:
这个选项的作用是把busybox编译成静态链接的可执行文件,运行时才能独立于其它函数库,否则需要其它库文件才能运行
InstallationOptions
Don'tuse/usr
原因:
这个选项也一定要选,否则makeinstall后busybox将安装在原系统的/usr下,这将覆盖掉系统原有的命令。
选择这个选项后,makeinstall后会在busybox目录下生成一个叫_install的目录,里面有busybox和指向他的链接。
其它选项为默认选项。
配置好后退出并保存.
#make//编译busybox
#makeinstall//安装busybox
编译好后在busybox目录下生成子目录_install,里面的内容是:
drwxr-xr-x2rootroot4096Nov3009:
04bin
lrwxrwxrwx1rootroot11Nov3009:
04linuxrc->bin/busybox
drwxr-xr-x2rootroot4096Nov3009:
04sbin
drwxr-xr-x4rootroot4096Nov3008:
55usr
三、制作文件系统
1.建一个目录rootfs用来装文件系统(在/目录下)
2.#mkdiretcusrvartmpprochomerootdev//建立文件目录
注:
其中etc,proc和dev是一定要建的,bin和sbin可以拷贝busybox生成的,其他的可以象征性的建几个就可以了.
3.拷贝busybox下的_install文件夹到rootfs下
#cp-R/busybox-1.7.2/_install/*/rootfs/
4.在dev文件夹下建立设备文件名:
#vi/rootfs/dev
其配置文件直接从原系统的/dev目录下拷贝过来。
(一定要带-r参数)
#cp–r/dev/*/rootfd/dev
5.建立etc目录下的配置文件
busybox.confgroupinittabmotdpasswdresolv.confshadow-fstabinit.dissuemtabprofileshadow
其中init.d是一个目录,从busybox-1.7.2源代码目录下拷贝过来.
#cp-Rbusybox-1.7.2/examples/bootfloppy/etc/init.d/rootfs/etc/
把init.d拷过来后要更改其中的文件rcS:
确保这个文件是可执行的,否则请改成可执行的:
#chmodu+xrcS
rcS的内容是:
#!
/bin/sh
mount-oremount,rw/
/bin/mount-a
>/etc/mtab
echo
echo
echo
echo
echo-en"\t\tWelcomtoZmlLinux\\033][0;39m\n"
hostnameZmlLinux
busybox.conf是一个空文件
其他文件的内容如下:
fstab
/dev/fd0/ext2defaults00
none/procprocdefaults00
/dev/cdrom/mnt/cdromudf,iso9660noauto,owner,kudzu,ro00
/dev/fd0/mnt/floppyautonoauto,owner,kudzu00
group
root:
0:
root
inittab
:
:
sysinit:
/etc/init.d/rcS
:
:
askfirst:
/bin/sh
tty2:
:
respawn:
/bin/getty38400tty2
tty3:
:
respawn:
/bin/getty38400tty3
tty4:
:
respawn:
/bin/getty38400tty4
#Stufftodowhenrestartingtheinitprocess
:
:
restart:
/bin/init
#Stufftodobeforerebooting
:
:
ctrlaltdel:
/bin/reboot
:
:
shutdown:
/bin/umount-a-r
:
:
shutdown:
/bin/swapoff-a
issue
ZmlLinuxrelease0.1
motd(空文件)
mtab(空文件)
passwd
root:
:
0:
0:
root:
/root:
/bin/ash
profile
#/etc/profile:
system-wide.profilefilefortheBourneshells
echo
echo
exportPS1="[\u@\h\w]\$"
echo"Done"
aliasll='ls-l'
aliasdu='du-h'
aliasdf='df-h'
aliasrm='rm-i'
echo
resolv.conf
nameserver192.168.1.12
shadow
root1$$adltAB9Sr/MSKqylIvSJT/:
12705:
0:
99999:
7:
:
:
shadow-
root1$DWU.tenP$B7ANiXoGoiZMwJR6Ih8810:
12705:
0:
99999:
7:
:
:
四、制作img映象文件
把上面的文件系统做成img映像文件,以便内核把它载入ram中
linux下有很多ram,我用ram1,首先把ram1格式化成ext2文件系统
[root@localhost/]#mkfs.ext2–m0/dev/ram1
mke2fs1.35(28-Feb-2004)
Filesystemlabel=
OStype:
Linux
Blocksize=1024(log=0)
Fragmentsize=1024(log=0)
4096inodes,16384blocks
0blocks(0.00%)reservedforthesuperuser
Firstdatablock=1
Maximumfilesystemblocks=16777216
2blockgroups
8192blockspergroup,8192fragmentspergroup
2048inodespergroup
Superblockbackupsstoredonblocks:
8193
Writinginodetables:
done
Writingsuperblocksandfilesystemaccountinginformation:
done
Thisfilesystemwillbeautomaticallycheckedevery32mountsor
180days,whichevercomesfirst.Usetune2fs-cor-itooverride.
将ram1挂装到文件系统中:
先建立一个挂装点:
#mkdir/mnt/ram
挂上ram1:
#mount/dev/ram1/mnt/ram
将先前做好的rootfs根文件系统拷贝到ram1上.
#cp–R/rootfs/*/mnt/ram
拷贝好根文件系统后卸载ram1:
#umount/dev/ram1
再用dd把这个ram1以映象方式取出来:
[root@localhost/]#ddif=/dev/ram1of=initrd.img
读入了8192+0个块输出了8192+0个块
把生成的initrd.img和前面得到的bzImage文件一起拷到/boot即可
五、利用grub启动
[root@localhost/]#vi/boot/grub/grub.conf
将grub.conf改写为:
#grub.confgeneratedbyanaconda
#
#Notethatyoudonothavetorerungrubaftermakingchangestothisfile
#NOTICE:
Youhavea/bootpartition.Thismeansthat
#allkernelandinitrdpathsarerelativeto/boot/,eg.
#root(hd0,0)
#kernel/vmlinuz-versionroroot=/dev/sda3
#initrd/initrd-version.img
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
titleRedHatEnterpriseLinuxAS(2.6.18.8)
root(hd0,0)
kernel/vmlinuz-2.6.18.8roroot=LABEL=/rhgbquiet
initrd/initrd-2.6.18.8.img
titleRedHatEnterpriseLinuxAS(2.6.9-55.ELsmp)
root(hd0,0)
kernel/vmlinuz-2.6.9-55.ELsmproroot=LABEL=/rhgbquiet
initrd/initrd-2.6.9-55.ELsmp.img
titleRedHatEnterpriseLinuxAS-up(2.6.9-55.EL)
root(hd0,0)
kernel/vmlinuz-2.6.9-55.ELroroot=LABEL=/rhgbquiet
initrd/initrd-2.6.9-55.EL.img
titleZML
root(hd0,0)
kernel/bzImageroroot=LABEL=/rhgbquiet
initrd/initrd.img
titleZML就是做出的小型操作系统
~