SlideShare uma empresa Scribd logo
1 de 10
Baixar para ler offline
IT 运维专家网                                                                       http://www.linuxtone.org


                                          利用 CentOS 快速构建自己的发行版
                                作者:                   NetSeek          http://www.linuxtone.org
                                日期:                  2009-4-10              版本号:V1


【背景】
我的朋友不少是个人网站站长并且网站运营的都很不错。但是每次业务扩容装Linux系统都让他们很头痛。
有的IDC技术不会装Linux系统,或者有的就是装一次系统收取一定的费用。为此一个朋友向我提出能不能
做一个精简一点的CentOS发行版,并且针对LinuxTone论坛里的<<构建高性能的LEMP第三版>做个版本并
且集成初始化优化脚本。为此我建立了LTOS这个发行版。以下是具体的制作过程和朋友们一起分享!希望
能共同进步并且支持http://www.linuxtone.org的发展!


一.制作 LTOS 具体过程
  光盘结构介绍
  * isolinux 目录存放光盘启动时的安装界面信息
  * images     目录包括了必要的启动映像文件
  * CentOS      目录存放安装软件包及信息
  * .discinfo 文件是安装价质的识别信息
  * lemp.tar.gz 文件存放系统初始化及其相关程序安装脚本.
  》》环境说明:CentOS 5.3-i386 Vmware Workstation 上完成制作工作.



1.安装制作发行版所需的基本软件包
 # yum -y install anaconda-runtime createrepo yum-utils anaconda anaconda-help busybox-anaconda mkisofs


2.制作 ltos 源文件夹
# mkdir /ltos
# mkdir /mnt/cdrom
# mount -t iso9660 -o loop /dev/cdrom /mnt/cdrom/ 挂载光盘镜像
 或者挂载 ISO 文件到/mnt/cdrom
# mount -t iso9660 -o loop centos.xxx.iso /mnt/cdrom             将 CentOS 的 ISO 文件挂载到/mnt/cdrom 目录
# cd /mnt/cdrom
# tar -cf - . | ( cd /ltos ; tar -xvpf - )   //将/mnt/cdrom 里的文件利用 tar 全部拷贝到/ltsos 这个目录下.
#cd /ltos    //进入此目录删除一些无关的文件,仍后进入后面的工作.

[root@server ltos]# ls -al
total 88
drwxr-xr-x      6 root root     4096 Apr 11 21:00 .
drwxr-xr-x 27 root root        4096 Apr 12 05:26 ..
drwxr-xr-x      2 root root 36864 Apr         8 16:06 CentOS
-rw-r--r--    1 root root        97 Apr      8 16:43 .discinfo
drwxr-xr-x      4 root root     4096 Mar 21 23:04 images
drwxr-xr-x      2 root root     4096 Apr 12 00:00 isolinux
-rw-r--r--    1 root root 14371 Apr 11 23:16 lemp.tar.gz         //这个软件包是我们后面要建立的,读者可以分析一下
后面的 ks.cfg 脚本就可以明白他的用途.
drwxr-xr-x      2 root root     4096 Apr 11 21:00 repodata

IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
IT 运维专家网                                                                               http://www.linuxtone.org


-r--r--r--   1 root root   7048 Mar 21 23:05 TRANS.TBL




3.定制 package.list 软件包清单
如安装一个 CentOS5.3 的系统,根据自己的需求选择软件包;如果想你的系统很小,建议选择最少的包。安
装完成以后,在系统里会产生日志。日文文件存放在/root/install.log。
# cat install.log | grep Installing | sed 's/Installing //g'|sed 's/^[0-9]+://g' > packages.list


#mkdir /ltos/CentOS 建立存放 rpm 包的目录.


创建自动提取相关 rpm 脚本:
#vi cprpms.sh
#!/bin/bash
DEBUG=0
LT_CD=/mnt/cdrom
ALL_RPMS_DIR=/mnt/cdrom/CentOS #挂载光盘存放的目录
LT_RPMS_DIR=/ltos/CentOS                        #存放 RPM 包的目录
packages_list=/root/packages.list
number_of_packages=`cat $packages_list | wc -l`
i=1
while [ $i -le $number_of_packages ] ; do
line=`head -n $i $packages_list | tail -n -1`
name=`echo $line | awk '{print $1}'`
version=`echo $line | awk '{print $3}' | cut -f 2 -d :`
if [ $DEBUG -eq "1" ] ; then
echo $i: $line
echo $name
echo $version
fi
if [ $DEBUG -eq "1" ] ; then
ls $ALL_RPMS_DIR/$name-$version*
if [ $? -ne 0 ] ; then
echo "cp $ALL_RPMS_DIR/$name-$version* "
fi
else
echo "cp $ALL_RPMS_DIR/$name-$version* $LT_RPMS_DIR/"
cp $ALL_RPMS_DIR/$name-$version* $LT_RPMS_DIR/
# in case the copy failed
if [ $? -ne 0 ] ; then
echo "cp $ALL_RPMS_DIR/$name-$version* "
cp $ALL_RPMS_DIR/$name* $LT_RPMS_DIR/
fi
fi
i=`expr $i + 1`

IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
IT 运维专家网                                                              http://www.linuxtone.org


done
执行以上脚本将定制 ltos 必要的 rpm 复制到/ltos/CentOS 目录


返回到/ltos 目录下,执行 createrepo 程序生成 repodata 下的 comps.xml 文件
#cd /ltos
#createrepo -g repodata/comps.xml .




4.配置 kickstart 脚本
 通过 CentOS5.3 定制安装系统以后,会在系统里产生一个 kickstart 安装脚本(/root/anaconda-ks.cfg)
 # cp anaconda-ks.cfg /ltos/isolinux/ks.cfg


# vi /ltos/isolinux/ks.cfg 并修改脚本如下:
# Kickstart file automatically generated by anaconda.
# Install CentOS instead of Upgrade
install
text


#install from cd-rom
cdrom
lang en_US.UTF-8
keyboard us


# Skip the X Configuration
skipx


network --device eth0 --bootproto dhcp --hostname ltos.linuxtone.org
rootpw --iscrypted $1$jPZf0P0r$JRe7pd.5wq9k.VZEMOgdq/


# Setup the firewall with SSH, HTTP/S, Syslog, Webmin, and Netflow enabled
firewall --enabled --port=22:tcp --port=69:udp --port=80:tcp --port=443:tcp


authconfig --enableshadow --enablemd5
# Disable SELinux
selinux --disabled


timezone --utc Asia/Shanghai


# Clear the Bootloader and load it to the Master Boot Record
bootloader --location=mbr
zerombr yes


# Set the Mouse

IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
IT 运维专家网                                            http://www.linuxtone.org


mouse generic3ps/2


# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --initlabel
part /boot --fstype ext3 --size=100 --asprimary
part / --fstype ext3 --size=25000
part swap --size=4096
part /data --fstype ext3 --size=1 --grow




#--- Reboot the host after installation is done
reboot


%packages
@development-libs
@editors
@system-tools
@text-internet
@legacy-network-server
@dialup
@core
@base
@mail-server
@development-tools
audit
net-snmp-utils
sysstat
iptraf
dstat
tftp
lynx
device-mapper-multipath
imake
-zsh
-vnc
-zisofs-tools
-xdelta
-openldap-clients
-samba-client
-fetchmail
-dovecot


IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
IT 运维专家网                                                               http://www.linuxtone.org


-spamassassin


#
#    ------- Begin LEMP Install ---------
#


%post --nochroot


# Mount CDROM
mkdir -p /mnt/cdrom
mount -r -t iso9660 /tmp/cdrom /mnt/cdrom


# Copy our tar file and extract it
cp /mnt/cdrom/lemp.tar.gz /mnt/sysimage/tmp/lemp.tar.gz > /dev/null
cd /mnt/sysimage/tmp/
tar -zxvf lemp.tar.gz > /dev/null




# Move the contents of the tar into their new locations


cp -R /mnt/sysimage/tmp/boot/* /mnt/sysimage/boot/ > /dev/null 2>/dev/null
cp -R /mnt/sysimage/tmp/etc/* /mnt/sysimage/etc/ > /dev/null 2>/dev/null


# Unmount CDROM
umount /mnt/cdrom




%post


#vim syntax on
sed -i "8 s/^/alias vi='vim'/" /root/.bashrc 2>/dev/null
echo 'syntax on' > /root/.vimrc 2>/dev/null


# Disable IPv6 until Cacti at least supports it
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off


#init_ssh
ssh_cf="/etc/ssh/sshd_config"
sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf
sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf
#client
sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf


IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
IT 运维专家网                                                                          http://www.linuxtone.org




# Remove the ISO File translation files
find / -name TRANS.TBL -exec rm {} ; /dev/null 2>/dev/null




# Remove some unneeded services
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
|             === Welcome to Tunoff services ===                                     |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
for i in `ls /etc/rc3.d/S*`
do
                   CURSRV=`echo $i|cut -c 15-`


echo $CURSRV
case $CURSRV in
             crond | irqbalance | microcode_ctl | network | random | sendmail | sshd | syslog | local | mysqld )
       echo "Base services, Skip!"
       ;;
       *)
             echo "change $CURSRV to off"
             chkconfig --level 235 $CURSRV off
             service $CURSRV stop
       ;;
esac
done


# file descriptors
ulimit -HSn 65535


echo -ne "
* soft nofile 65536
* hard nofile 65536
" >>/etc/security/limits.conf
.
5.让系统从 kickstart 配置启动
# vi /ltos/ isolinux/ isolinux.cfg
default auto
prompt 1
timeout 600
display boot.msg


IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
IT 运维专家网                                                                 http://www.linuxtone.org


F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label auto
kernel vmlinuz
append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img
label ks
kernel vmlinuz
append ks initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest
append -


二.个性化定制你的系统(问答形式)

1.如何定制安装开机画面:
启动画面用的是一种比较奇怪的格式 lss16,它限制图片使用 16 种颜色,除去前景和背景色只能有 14 种颜
色。我们需要 ppmtolss16 giftopnm 等程序,系统一般默认都安装了。
一般用 gimp 生成一个 index 模式的 gif 图形,颜色限制为 14, 然后通过如下的办法进行转:


安装 yum -y install syslinux
giftopnm < splash.gif | ppmtolss16 > splash.lss
另外你还需要修改 isolinux/boot.msg 文件,做一些个性化的提示.


?如何生成高质量的图。
先用 photoshop 打开任何一张图片,然后在文件的下拉菜单里,保存的时候选择“保存为 WEB 和设备使用格
式“,再然后选择 gif 再选择 16 色保存就 OK.
仍后利用 giftopnm < splash.gif | ppmtolss16 > splash.lss 转换即可.


2.如何生成 GRUP 的 xpm 文件?
(1) 将备一张 640 x 480 16 色图片,档案类型为 JPG 的格式
(2)convert grub.gif -colors 14 -geometry 640x480! splash.xpm && gzip -9 splash.xpm
(3) 直接替换/boot/grup/splash.xpm.gz 文件即可.




IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
IT 运维专家网                                                                       http://www.linuxtone.org


? 利用上面方法生成的图片可能无法显示,或者质量不高,如何生成高质量的 grub 图片呢.
利用文中后面我提供的 ltospackl.tar.gz 里面的 grubtool.exe 即可在 windows 平台将 jpg,bmp 图生成为.xpm.gz
格式的文件,直接替换/boot/grup 下的文件即可.


2.如何去掉安装过程中的 CentOS 字样?
在安装光盘里面有两个.buildstamp 文件,一个位于 stage2.img 中,一个位于 initrd.img 中,
安装光盘运行时读取的是 initrd.img 中的那个.buildstamp 文件,所以只要把 initrd.img 文件改了就可以了。
如何解压 initr.dimg 文件:
2.6 内核中的 initrd.img 采用 cpio 压缩,不再是 2.4 内核使用的 ext2 格式,无法使用 mount -o loop 挂载。需
要使用 gunzip 解压缩,然后再使用
利用 cpio 给 img 解包
# cd /ltos/isolinux/
# cp   initrd.img      /tmp/initrd.img.gz
# cd /tmp
# gunzip initrd.img.gz
# mkdir initrd
# mv initrd.img initrd
# cd initrd
# cpio -ivmd < initrd.img
仍后修改.buildstamp 文件,将 CentOS 改为 LTOS 即可.
如何制作 initrd.img 文件:
#假设当前目录位于准备好的 initrd 文件系统的根目录下
# find . | cpio -c -o > ../initrd.img
# gzip ../initrd.img
# mv initrd.img.gz initrd.img
# cp initrd.img /ltos/isolinux/
仍后将 initrd.img 复制到/ltos/isolinux/


3. 如何替换安装以后的 grub ?
在安装光盘里的 ks.cfg 文件里写好替换 splash.xpm.gz 文件即可.


4. 如何去掉启动过程中的"CentOS release 5 (Final)"
在安装光盘里的 ks.cfg 文件里写好脚本,直接替换/etc/redhat-release 即可.


三.打包生成 ISO 文件发布
# cd /ltos
# declare -x discinfo=`head -1 .discinfo`
# createrepo -u "media://$discinfo" -g repodata/comps.xml .


生成 ISO 文件
#mkisofs -R -J -T -r -l -d -allow-multidot -allow-leading-dots -no-bak -o /tmp/ltos-0.1-i386.iso 
-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table .
Md5



IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
IT 运维专家网                                                         http://www.linuxtone.org


/usr/lib/anaconda-runtime/implantisomd5 /tmp/ltos-0.1-i386.iso


相关脚本及制作工具下载:
http://www.linuxtone.org/project/ltos/ltospack.tar.gz   //相关脚本及工具下载.


四.安装光盘效果演示图
   启动安装光盘




    Grub 界面




IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
IT 运维专家网                                                     http://www.linuxtone.org


系统登陆界面演示




五.参考文档(并对以下文章作者表示感谢和致敬!                             )
 1. http://lingxiang.tang.googlepages.com/createalesssizecentos5
 2. http://sipx-wiki.calivia.com/index.php/A_Kickstart_CD_for_sipX_on_CentOS
 3. http://linux.chinaunix.net/ebook/doc/2009/04/02/1095757.shtml
 4. http://www.ibm.com/developerworks/cn/linux/l-k26initrd/




IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!

Mais conteúdo relacionado

Mais procurados

CentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 ZendCentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 Zend
wensheng wei
 
Lamp安全全攻略
Lamp安全全攻略Lamp安全全攻略
Lamp安全全攻略
Da Zhao
 
Unixtoolbox zh cn
Unixtoolbox zh cnUnixtoolbox zh cn
Unixtoolbox zh cn
xdboy2006
 
尚观Linux研究室 linux驱动程序全解析
尚观Linux研究室   linux驱动程序全解析尚观Linux研究室   linux驱动程序全解析
尚观Linux研究室 linux驱动程序全解析
hangejnu
 
20121111 linux intro
20121111 linux intro20121111 linux intro
20121111 linux intro
Chang Mt
 
基于PXE实现部署Linux服务器
基于PXE实现部署Linux服务器基于PXE实现部署Linux服务器
基于PXE实现部署Linux服务器
ekoing
 
VMware Rhel5 Oracle10g Rac
VMware Rhel5 Oracle10g RacVMware Rhel5 Oracle10g Rac
VMware Rhel5 Oracle10g Rac
guest77e407
 
20030623 linuxbasic and-security
20030623 linuxbasic and-security20030623 linuxbasic and-security
20030623 linuxbasic and-security
建融 黃
 
Centos下安装apache + subversion
Centos下安装apache + subversionCentos下安装apache + subversion
Centos下安装apache + subversion
Yiwei Ma
 
Linux必学的60个命令
Linux必学的60个命令Linux必学的60个命令
Linux必学的60个命令
yiditushe
 
Hadoop平台搭建
Hadoop平台搭建Hadoop平台搭建
Hadoop平台搭建
Liyang Tang
 
Linux1文字介面操作
Linux1文字介面操作Linux1文字介面操作
Linux1文字介面操作
jiannrong
 

Mais procurados (20)

Ruby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for MacRuby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for Mac
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for Ubuntu
 
unixtoolbox_zh_CN
unixtoolbox_zh_CNunixtoolbox_zh_CN
unixtoolbox_zh_CN
 
CentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 ZendCentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 Zend
 
Lamp安全全攻略
Lamp安全全攻略Lamp安全全攻略
Lamp安全全攻略
 
Unixtoolbox zh cn
Unixtoolbox zh cnUnixtoolbox zh cn
Unixtoolbox zh cn
 
尚观Linux研究室 linux驱动程序全解析
尚观Linux研究室   linux驱动程序全解析尚观Linux研究室   linux驱动程序全解析
尚观Linux研究室 linux驱动程序全解析
 
20121111 linux intro
20121111 linux intro20121111 linux intro
20121111 linux intro
 
Free Bsd7.2 Install V1.6
Free Bsd7.2 Install V1.6Free Bsd7.2 Install V1.6
Free Bsd7.2 Install V1.6
 
基于PXE实现部署Linux服务器
基于PXE实现部署Linux服务器基于PXE实现部署Linux服务器
基于PXE实现部署Linux服务器
 
VMware Rhel5 Oracle10g Rac
VMware Rhel5 Oracle10g RacVMware Rhel5 Oracle10g Rac
VMware Rhel5 Oracle10g Rac
 
Linux基础
Linux基础Linux基础
Linux基础
 
20030623 linuxbasic and-security
20030623 linuxbasic and-security20030623 linuxbasic and-security
20030623 linuxbasic and-security
 
Centos下安装apache + subversion
Centos下安装apache + subversionCentos下安装apache + subversion
Centos下安装apache + subversion
 
Linux必学的60个命令
Linux必学的60个命令Linux必学的60个命令
Linux必学的60个命令
 
Hadoop平台搭建
Hadoop平台搭建Hadoop平台搭建
Hadoop平台搭建
 
pfSsense
pfSsensepfSsense
pfSsense
 
Linux1文字介面操作
Linux1文字介面操作Linux1文字介面操作
Linux1文字介面操作
 
網路組-Ubuntu介紹
網路組-Ubuntu介紹網路組-Ubuntu介紹
網路組-Ubuntu介紹
 
[精彩回顾]Linux新手教程
[精彩回顾]Linux新手教程[精彩回顾]Linux新手教程
[精彩回顾]Linux新手教程
 

Destaque (9)

EmfStoreTutorial
EmfStoreTutorialEmfStoreTutorial
EmfStoreTutorial
 
Love Medicine Critical Reasoning Response
Love Medicine Critical Reasoning ResponseLove Medicine Critical Reasoning Response
Love Medicine Critical Reasoning Response
 
Power of blogging in business
Power of blogging in businessPower of blogging in business
Power of blogging in business
 
Building business u is with emf forms
Building business u is with emf formsBuilding business u is with emf forms
Building business u is with emf forms
 
EMFStore Demo EclipseCon2012
EMFStore Demo EclipseCon2012EMFStore Demo EclipseCon2012
EMFStore Demo EclipseCon2012
 
Democamp Munich 2013: Are you still manually coding UIs?
Democamp Munich 2013: Are you still manually coding UIs?Democamp Munich 2013: Are you still manually coding UIs?
Democamp Munich 2013: Are you still manually coding UIs?
 
What´s (new with) EMFStore?
What´s (new with) EMFStore?What´s (new with) EMFStore?
What´s (new with) EMFStore?
 
EMF Dos and Don’ts EclipseCon Europe 2013
EMF Dos and Don’ts EclipseCon Europe 2013EMF Dos and Don’ts EclipseCon Europe 2013
EMF Dos and Don’ts EclipseCon Europe 2013
 
How to Distribute, Store and Version Models with EMFStore
How to Distribute, Store and Version Models with EMFStoreHow to Distribute, Store and Version Models with EMFStore
How to Distribute, Store and Version Models with EMFStore
 

Semelhante a 利用Cent Os快速构建自己的发行版

unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版
Jie Bao
 
Kick start无人值守批量安装linux
Kick start无人值守批量安装linuxKick start无人值守批量安装linux
Kick start无人值守批量安装linux
Yiwei Ma
 
Install Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 LInstall Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 L
heima911
 
Openshift by mtchang
Openshift by mtchangOpenshift by mtchang
Openshift by mtchang
Chang Mt
 
Proxmox: 建立自己的虛擬主機
Proxmox: 建立自己的虛擬主機Proxmox: 建立自己的虛擬主機
Proxmox: 建立自己的虛擬主機
維泰 蔡
 
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
acqua young
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结
Yiwei Ma
 

Semelhante a 利用Cent Os快速构建自己的发行版 (18)

unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版
 
Kick start无人值守批量安装linux
Kick start无人值守批量安装linuxKick start无人值守批量安装linux
Kick start无人值守批量安装linux
 
Open Street Map安裝指引 (Ubuntu 12.04)
Open Street Map安裝指引 (Ubuntu 12.04)Open Street Map安裝指引 (Ubuntu 12.04)
Open Street Map安裝指引 (Ubuntu 12.04)
 
Aix操作系统培训文档
Aix操作系统培训文档Aix操作系统培训文档
Aix操作系统培训文档
 
Install Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 LInstall Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 L
 
Asm+aix
Asm+aixAsm+aix
Asm+aix
 
LinuxGuide4F2E
LinuxGuide4F2ELinuxGuide4F2E
LinuxGuide4F2E
 
Rootkit 101
Rootkit 101Rootkit 101
Rootkit 101
 
8, lamp
8, lamp8, lamp
8, lamp
 
5, system admin
5, system admin5, system admin
5, system admin
 
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
[Modern Web 2016] 讓你的 PHP 開發流程再次潮起來
 
Oracle10g Rac Configuration For Linux X86
Oracle10g Rac Configuration For Linux X86Oracle10g Rac Configuration For Linux X86
Oracle10g Rac Configuration For Linux X86
 
StackOps step by-step guide
StackOps step by-step guideStackOps step by-step guide
StackOps step by-step guide
 
Openshift by mtchang
Openshift by mtchangOpenshift by mtchang
Openshift by mtchang
 
Proxmox: 建立自己的虛擬主機
Proxmox: 建立自己的虛擬主機Proxmox: 建立自己的虛擬主機
Proxmox: 建立自己的虛擬主機
 
Bigdata 大資料分析實務 (進階上機課程)
Bigdata 大資料分析實務 (進階上機課程)Bigdata 大資料分析實務 (進階上機課程)
Bigdata 大資料分析實務 (進階上機課程)
 
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结
 

利用Cent Os快速构建自己的发行版

  • 1. IT 运维专家网 http://www.linuxtone.org 利用 CentOS 快速构建自己的发行版 作者: NetSeek http://www.linuxtone.org 日期: 2009-4-10 版本号:V1 【背景】 我的朋友不少是个人网站站长并且网站运营的都很不错。但是每次业务扩容装Linux系统都让他们很头痛。 有的IDC技术不会装Linux系统,或者有的就是装一次系统收取一定的费用。为此一个朋友向我提出能不能 做一个精简一点的CentOS发行版,并且针对LinuxTone论坛里的<<构建高性能的LEMP第三版>做个版本并 且集成初始化优化脚本。为此我建立了LTOS这个发行版。以下是具体的制作过程和朋友们一起分享!希望 能共同进步并且支持http://www.linuxtone.org的发展! 一.制作 LTOS 具体过程 光盘结构介绍 * isolinux 目录存放光盘启动时的安装界面信息 * images 目录包括了必要的启动映像文件 * CentOS 目录存放安装软件包及信息 * .discinfo 文件是安装价质的识别信息 * lemp.tar.gz 文件存放系统初始化及其相关程序安装脚本. 》》环境说明:CentOS 5.3-i386 Vmware Workstation 上完成制作工作. 1.安装制作发行版所需的基本软件包 # yum -y install anaconda-runtime createrepo yum-utils anaconda anaconda-help busybox-anaconda mkisofs 2.制作 ltos 源文件夹 # mkdir /ltos # mkdir /mnt/cdrom # mount -t iso9660 -o loop /dev/cdrom /mnt/cdrom/ 挂载光盘镜像 或者挂载 ISO 文件到/mnt/cdrom # mount -t iso9660 -o loop centos.xxx.iso /mnt/cdrom 将 CentOS 的 ISO 文件挂载到/mnt/cdrom 目录 # cd /mnt/cdrom # tar -cf - . | ( cd /ltos ; tar -xvpf - ) //将/mnt/cdrom 里的文件利用 tar 全部拷贝到/ltsos 这个目录下. #cd /ltos //进入此目录删除一些无关的文件,仍后进入后面的工作. [root@server ltos]# ls -al total 88 drwxr-xr-x 6 root root 4096 Apr 11 21:00 . drwxr-xr-x 27 root root 4096 Apr 12 05:26 .. drwxr-xr-x 2 root root 36864 Apr 8 16:06 CentOS -rw-r--r-- 1 root root 97 Apr 8 16:43 .discinfo drwxr-xr-x 4 root root 4096 Mar 21 23:04 images drwxr-xr-x 2 root root 4096 Apr 12 00:00 isolinux -rw-r--r-- 1 root root 14371 Apr 11 23:16 lemp.tar.gz //这个软件包是我们后面要建立的,读者可以分析一下 后面的 ks.cfg 脚本就可以明白他的用途. drwxr-xr-x 2 root root 4096 Apr 11 21:00 repodata IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
  • 2. IT 运维专家网 http://www.linuxtone.org -r--r--r-- 1 root root 7048 Mar 21 23:05 TRANS.TBL 3.定制 package.list 软件包清单 如安装一个 CentOS5.3 的系统,根据自己的需求选择软件包;如果想你的系统很小,建议选择最少的包。安 装完成以后,在系统里会产生日志。日文文件存放在/root/install.log。 # cat install.log | grep Installing | sed 's/Installing //g'|sed 's/^[0-9]+://g' > packages.list #mkdir /ltos/CentOS 建立存放 rpm 包的目录. 创建自动提取相关 rpm 脚本: #vi cprpms.sh #!/bin/bash DEBUG=0 LT_CD=/mnt/cdrom ALL_RPMS_DIR=/mnt/cdrom/CentOS #挂载光盘存放的目录 LT_RPMS_DIR=/ltos/CentOS #存放 RPM 包的目录 packages_list=/root/packages.list number_of_packages=`cat $packages_list | wc -l` i=1 while [ $i -le $number_of_packages ] ; do line=`head -n $i $packages_list | tail -n -1` name=`echo $line | awk '{print $1}'` version=`echo $line | awk '{print $3}' | cut -f 2 -d :` if [ $DEBUG -eq "1" ] ; then echo $i: $line echo $name echo $version fi if [ $DEBUG -eq "1" ] ; then ls $ALL_RPMS_DIR/$name-$version* if [ $? -ne 0 ] ; then echo "cp $ALL_RPMS_DIR/$name-$version* " fi else echo "cp $ALL_RPMS_DIR/$name-$version* $LT_RPMS_DIR/" cp $ALL_RPMS_DIR/$name-$version* $LT_RPMS_DIR/ # in case the copy failed if [ $? -ne 0 ] ; then echo "cp $ALL_RPMS_DIR/$name-$version* " cp $ALL_RPMS_DIR/$name* $LT_RPMS_DIR/ fi fi i=`expr $i + 1` IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
  • 3. IT 运维专家网 http://www.linuxtone.org done 执行以上脚本将定制 ltos 必要的 rpm 复制到/ltos/CentOS 目录 返回到/ltos 目录下,执行 createrepo 程序生成 repodata 下的 comps.xml 文件 #cd /ltos #createrepo -g repodata/comps.xml . 4.配置 kickstart 脚本 通过 CentOS5.3 定制安装系统以后,会在系统里产生一个 kickstart 安装脚本(/root/anaconda-ks.cfg) # cp anaconda-ks.cfg /ltos/isolinux/ks.cfg # vi /ltos/isolinux/ks.cfg 并修改脚本如下: # Kickstart file automatically generated by anaconda. # Install CentOS instead of Upgrade install text #install from cd-rom cdrom lang en_US.UTF-8 keyboard us # Skip the X Configuration skipx network --device eth0 --bootproto dhcp --hostname ltos.linuxtone.org rootpw --iscrypted $1$jPZf0P0r$JRe7pd.5wq9k.VZEMOgdq/ # Setup the firewall with SSH, HTTP/S, Syslog, Webmin, and Netflow enabled firewall --enabled --port=22:tcp --port=69:udp --port=80:tcp --port=443:tcp authconfig --enableshadow --enablemd5 # Disable SELinux selinux --disabled timezone --utc Asia/Shanghai # Clear the Bootloader and load it to the Master Boot Record bootloader --location=mbr zerombr yes # Set the Mouse IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
  • 4. IT 运维专家网 http://www.linuxtone.org mouse generic3ps/2 # The following is the partition information you requested # Note that any partitions you deleted are not expressed # here so unless you clear all partitions first, this is # not guaranteed to work clearpart --all --initlabel part /boot --fstype ext3 --size=100 --asprimary part / --fstype ext3 --size=25000 part swap --size=4096 part /data --fstype ext3 --size=1 --grow #--- Reboot the host after installation is done reboot %packages @development-libs @editors @system-tools @text-internet @legacy-network-server @dialup @core @base @mail-server @development-tools audit net-snmp-utils sysstat iptraf dstat tftp lynx device-mapper-multipath imake -zsh -vnc -zisofs-tools -xdelta -openldap-clients -samba-client -fetchmail -dovecot IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
  • 5. IT 运维专家网 http://www.linuxtone.org -spamassassin # # ------- Begin LEMP Install --------- # %post --nochroot # Mount CDROM mkdir -p /mnt/cdrom mount -r -t iso9660 /tmp/cdrom /mnt/cdrom # Copy our tar file and extract it cp /mnt/cdrom/lemp.tar.gz /mnt/sysimage/tmp/lemp.tar.gz > /dev/null cd /mnt/sysimage/tmp/ tar -zxvf lemp.tar.gz > /dev/null # Move the contents of the tar into their new locations cp -R /mnt/sysimage/tmp/boot/* /mnt/sysimage/boot/ > /dev/null 2>/dev/null cp -R /mnt/sysimage/tmp/etc/* /mnt/sysimage/etc/ > /dev/null 2>/dev/null # Unmount CDROM umount /mnt/cdrom %post #vim syntax on sed -i "8 s/^/alias vi='vim'/" /root/.bashrc 2>/dev/null echo 'syntax on' > /root/.vimrc 2>/dev/null # Disable IPv6 until Cacti at least supports it echo "alias net-pf-10 off" >> /etc/modprobe.conf echo "alias ipv6 off" >> /etc/modprobe.conf /sbin/chkconfig --level 35 ip6tables off #init_ssh ssh_cf="/etc/ssh/sshd_config" sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf #client sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
  • 6. IT 运维专家网 http://www.linuxtone.org # Remove the ISO File translation files find / -name TRANS.TBL -exec rm {} ; /dev/null 2>/dev/null # Remove some unneeded services #-------------------------------------------------------------------------------- cat << EOF +--------------------------------------------------------------+ | === Welcome to Tunoff services === | +--------------------------------------------------------------+ EOF #--------------------------------------------------------------------------------- for i in `ls /etc/rc3.d/S*` do CURSRV=`echo $i|cut -c 15-` echo $CURSRV case $CURSRV in crond | irqbalance | microcode_ctl | network | random | sendmail | sshd | syslog | local | mysqld ) echo "Base services, Skip!" ;; *) echo "change $CURSRV to off" chkconfig --level 235 $CURSRV off service $CURSRV stop ;; esac done # file descriptors ulimit -HSn 65535 echo -ne " * soft nofile 65536 * hard nofile 65536 " >>/etc/security/limits.conf . 5.让系统从 kickstart 配置启动 # vi /ltos/ isolinux/ isolinux.cfg default auto prompt 1 timeout 600 display boot.msg IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
  • 7. IT 运维专家网 http://www.linuxtone.org F1 boot.msg F2 options.msg F3 general.msg F4 param.msg F5 rescue.msg label linux kernel vmlinuz append initrd=initrd.img label text kernel vmlinuz append initrd=initrd.img text label auto kernel vmlinuz append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img label ks kernel vmlinuz append ks initrd=initrd.img label local localboot 1 label memtest86 kernel memtest append - 二.个性化定制你的系统(问答形式) 1.如何定制安装开机画面: 启动画面用的是一种比较奇怪的格式 lss16,它限制图片使用 16 种颜色,除去前景和背景色只能有 14 种颜 色。我们需要 ppmtolss16 giftopnm 等程序,系统一般默认都安装了。 一般用 gimp 生成一个 index 模式的 gif 图形,颜色限制为 14, 然后通过如下的办法进行转: 安装 yum -y install syslinux giftopnm < splash.gif | ppmtolss16 > splash.lss 另外你还需要修改 isolinux/boot.msg 文件,做一些个性化的提示. ?如何生成高质量的图。 先用 photoshop 打开任何一张图片,然后在文件的下拉菜单里,保存的时候选择“保存为 WEB 和设备使用格 式“,再然后选择 gif 再选择 16 色保存就 OK. 仍后利用 giftopnm < splash.gif | ppmtolss16 > splash.lss 转换即可. 2.如何生成 GRUP 的 xpm 文件? (1) 将备一张 640 x 480 16 色图片,档案类型为 JPG 的格式 (2)convert grub.gif -colors 14 -geometry 640x480! splash.xpm && gzip -9 splash.xpm (3) 直接替换/boot/grup/splash.xpm.gz 文件即可. IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
  • 8. IT 运维专家网 http://www.linuxtone.org ? 利用上面方法生成的图片可能无法显示,或者质量不高,如何生成高质量的 grub 图片呢. 利用文中后面我提供的 ltospackl.tar.gz 里面的 grubtool.exe 即可在 windows 平台将 jpg,bmp 图生成为.xpm.gz 格式的文件,直接替换/boot/grup 下的文件即可. 2.如何去掉安装过程中的 CentOS 字样? 在安装光盘里面有两个.buildstamp 文件,一个位于 stage2.img 中,一个位于 initrd.img 中, 安装光盘运行时读取的是 initrd.img 中的那个.buildstamp 文件,所以只要把 initrd.img 文件改了就可以了。 如何解压 initr.dimg 文件: 2.6 内核中的 initrd.img 采用 cpio 压缩,不再是 2.4 内核使用的 ext2 格式,无法使用 mount -o loop 挂载。需 要使用 gunzip 解压缩,然后再使用 利用 cpio 给 img 解包 # cd /ltos/isolinux/ # cp initrd.img /tmp/initrd.img.gz # cd /tmp # gunzip initrd.img.gz # mkdir initrd # mv initrd.img initrd # cd initrd # cpio -ivmd < initrd.img 仍后修改.buildstamp 文件,将 CentOS 改为 LTOS 即可. 如何制作 initrd.img 文件: #假设当前目录位于准备好的 initrd 文件系统的根目录下 # find . | cpio -c -o > ../initrd.img # gzip ../initrd.img # mv initrd.img.gz initrd.img # cp initrd.img /ltos/isolinux/ 仍后将 initrd.img 复制到/ltos/isolinux/ 3. 如何替换安装以后的 grub ? 在安装光盘里的 ks.cfg 文件里写好替换 splash.xpm.gz 文件即可. 4. 如何去掉启动过程中的"CentOS release 5 (Final)" 在安装光盘里的 ks.cfg 文件里写好脚本,直接替换/etc/redhat-release 即可. 三.打包生成 ISO 文件发布 # cd /ltos # declare -x discinfo=`head -1 .discinfo` # createrepo -u "media://$discinfo" -g repodata/comps.xml . 生成 ISO 文件 #mkisofs -R -J -T -r -l -d -allow-multidot -allow-leading-dots -no-bak -o /tmp/ltos-0.1-i386.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table . Md5 IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
  • 9. IT 运维专家网 http://www.linuxtone.org /usr/lib/anaconda-runtime/implantisomd5 /tmp/ltos-0.1-i386.iso 相关脚本及制作工具下载: http://www.linuxtone.org/project/ltos/ltospack.tar.gz //相关脚本及工具下载. 四.安装光盘效果演示图 启动安装光盘 Grub 界面 IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!
  • 10. IT 运维专家网 http://www.linuxtone.org 系统登陆界面演示 五.参考文档(并对以下文章作者表示感谢和致敬! ) 1. http://lingxiang.tang.googlepages.com/createalesssizecentos5 2. http://sipx-wiki.calivia.com/index.php/A_Kickstart_CD_for_sipX_on_CentOS 3. http://linux.chinaunix.net/ebook/doc/2009/04/02/1095757.shtml 4. http://www.ibm.com/developerworks/cn/linux/l-k26initrd/ IT 运维专家网------“我为人人,人人为我!知识源于分享,源于交流!”---LinuxTone 技术交流分享社区!