IT 運(yùn)維專家網(wǎng)
http://www.linuxtone.org利用CentOS快速構(gòu)建自己的發(fā)行版
作者:
NetSeek
http://www.linuxtone.org日期:
2009-4-10
版本號:V1
【背景】
我的朋友不少是個人網(wǎng)站站長并且網(wǎng)站運(yùn)營的都很不錯。但是每次業(yè)務(wù)擴(kuò)容裝Linux系統(tǒng)都讓他們很頭痛。有的IDC技術(shù)不會裝Linux系統(tǒng),或者有的就是裝一次系統(tǒng)收取一定的費(fèi)用。為此一個朋友向我提出能不能做一個精簡一點(diǎn)的CentOS發(fā)行版,并且針對LinuxTone論壇里的<<構(gòu)建高性能的LEMP第三版>做個版本并且集成初始化優(yōu)化腳本。為此我建立了LTOS這個發(fā)行版。以下是具體的制作過程和朋友們一起分享!希望能共同進(jìn)步并且支持
http://www.linuxtone.org的發(fā)展!
一.制作LTOS具體過程
光盤結(jié)構(gòu)介紹
* isolinux 目錄存放光盤啟動時的安裝界面信息
* images 目錄包括了必要的啟動映像文件
* CentOS 目錄存放安裝軟件包及信息
* .discinfo 文件是安裝價質(zhì)的識別信息
* lemp.tar.gz 文件存放系統(tǒng)初始化及其相關(guān)程序安裝腳本.
》》環(huán)境說明:CentOS 5.3-i386 Vmware Workstation上完成制作工作.
1.安裝制作發(fā)行版所需的基本軟件包
# 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 //進(jìn)入此目錄刪除一些無關(guān)的文件,仍后進(jìn)入后面的工作.
[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 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!
IT 運(yùn)維專家網(wǎng)
http://www.linuxtone.org-r--r--r-- 1 root root 7048 Mar 21 23:05 TRANS.TBL
3.定制package.list軟件包清單
如安裝一個CentOS5.3的系統(tǒng),根據(jù)自己的需求選擇軟件包;如果想你的系統(tǒng)很小,建議選擇最少的包。安裝完成以后,在系統(tǒng)里會產(chǎn)生日志。日文文件存放在/root/install.log。
# cat install.log | grep Installing | sed 's/Installing //g'|sed 's/^[0-9]\+://g' > packages.list
#mkdir /ltos/CentOS 建立存放rpm包的目錄.
創(chuàng)建自動提取相關(guān)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 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!
IT 運(yùn)維專家網(wǎng)
http://www.linuxtone.orgdone
執(zhí)行以上腳本將定制ltos必要的rpm復(fù)制到/ltos/CentOS目錄
返回到/ltos目錄下,執(zhí)行createrepo程序生成repodata下的comps.xml文件
#cd /ltos
#createrepo -g repodata/comps.xml .
4.配置kickstart腳本
通過CentOS5.3定制安裝系統(tǒng)以后,會在系統(tǒng)里產(chǎn)生一個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 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!
IT 運(yùn)維專家網(wǎng)
http://www.linuxtone.orgmouse 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 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!
IT 運(yùn)維專家網(wǎng)
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 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!
IT 運(yùn)維專家網(wǎng)
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.讓系統(tǒng)從kickstart配置啟動
# vi /ltos/ isolinux/ isolinux.cfg
default auto
prompt 1
timeout 600
display boot.msg
IT 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!
IT 運(yùn)維專家網(wǎng)
http://www.linuxtone.orgF1 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 -
二.個性化定制你的系統(tǒng)(問答形式)
1.如何定制安裝開機(jī)畫面:
啟動畫面用的是一種比較奇怪的格式lss16,它限制圖片使用16種顏色,除去前景和背景色只能有14種顏色。我們需要ppmtolss16 giftopnm等程序,系統(tǒng)一般默認(rèn)都安裝了。
一般用gimp生成一個index模式的gif圖形,顏色限制為14, 然后通過如下的辦法進(jìn)行轉(zhuǎn):
安裝yum -y install syslinux
giftopnm < splash.gif | ppmtolss16 > splash.lss
另外你還需要修改isolinux/boot.msg文件,做一些個性化的提示.
?如何生成高質(zhì)量的圖。
先用photoshop打開任何一張圖片,然后在文件的下拉菜單里,保存的時候選擇“保存為WEB和設(shè)備使用格式“,再然后選擇gif再選擇16色保存就OK.
仍后利用giftopnm < splash.gif | ppmtolss16 > splash.lss 轉(zhuǎn)換即可.
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 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!
IT 運(yùn)維專家網(wǎng)
http://www.linuxtone.org 利用上面方法生成的圖片可能無法顯示,或者質(zhì)量不高,如何生成高質(zhì)量的grub圖片呢.
利用文中后面我提供的ltospackl.tar.gz里面的grubtool.exe即可在windows平臺將jpg,bmp圖生成為.xpm.gz格式的文件,直接替換/boot/grup下的文件即可.
2.如何去掉安裝過程中的CentOS字樣?
在安裝光盤里面有兩個.buildstamp文件,一個位于stage2.img中,一個位于initrd.img中,
安裝光盤運(yùn)行時讀取的是initrd.img中的那個.buildstamp文件,所以只要把initrd.img文件改了就可以了。
如何解壓initr.dimg文件:
2.6內(nèi)核中的initrd.img采用cpio壓縮,不再是2.4內(nèi)核使用的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文件:
#假設(shè)當(dāng)前目錄位于準(zhǔn)備好的initrd文件系統(tǒng)的根目錄下
# find . | cpio -c -o > ../initrd.img
# gzip ../initrd.img
# mv initrd.img.gz initrd.img
# cp initrd.img /ltos/isolinux/
仍后將initrd.img復(fù)制到/ltos/isolinux/
3. 如何替換安裝以后的grub ?
在安裝光盤里的ks.cfg文件里寫好替換splash.xpm.gz文件即可.
4. 如何去掉啟動過程中的"CentOS release 5 (Final)"
在安裝光盤里的ks.cfg文件里寫好腳本,直接替換/etc/redhat-release即可.
三.打包生成ISO文件發(fā)布
# 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 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!
IT 運(yùn)維專家網(wǎng)
http://www.linuxtone.org/usr/lib/anaconda-runtime/implantisomd5 /tmp/ltos-0.1-i386.iso
相關(guān)腳本及制作工具下載:
http://www.linuxtone.org/project/ltos/ltospack.tar.gz //相關(guān)腳本及工具下載.
四.安裝光盤效果演示圖
啟動安裝光盤
Grub界面
IT 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!
IT 運(yùn)維專家網(wǎng)
http://www.linuxtone.org系統(tǒng)登陸界面演示
五.參考文檔(并對以下文章作者表示感謝和致敬?。?br>1.
http://lingxiang.tang.googlepages.com/createalesssizecentos52.
http://sipx-wiki.calivia.com/index.php/A_Kickstart_CD_for_sipX_on_CentOS3.
http://linux.chinaunix.net/ebook/doc/2009/04/02/1095757.shtml4.
http://www.ibm.com/developerworks/cn/linux/l-k26initrd/IT 運(yùn)維專家網(wǎng)------“我為人人,人人為我!知識源于分享,源于交流!”---LinuxTone 技術(shù)交流分享社區(qū)!