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

[转]订制CentOS自安装光盘

2011-01-09 15:51 169 查看
本文转自:http://www.v2ns.cn/?post=62

参考了老曹的利用CentOS快速构建自己的发行版

,以自己的切身体会,修改了kickstart脚本
文件
,去除了全自动
存在的问题:不够灵活,对于分区限制太死。

下载地址

: http://blog.freebsdsystem.org/LEMPOS/LEMPOS-0.1.3-i386.iso

下面摘录了老曹的文章

一.制作
LEMPOS具体过程


光盘结构介绍


* isolinux

目录
存放光盘启动时的安装界面信息


*images

目录包括了必要的启动映像文件


*CentOS

目录存放安装软件
包及信息


*.discinfo

文件是安装价质的识别信息


*lemp.tar.gz

文件存放系统
初始化及其相关程序安装脚本
.


*AutoLEMP-0.1.2.tar.bz2
AutOLEMP程序


》》环境说明:
CentOS 5.3-i386
xen

上完成制作工作
.


1.
安装制作发行版所需的基本软件包


# yum -y install anaconda-runtime createrepo yum-utils anacondaanaconda-help busybox-anaconda mkisofs

2.
制作
LEMPOS

源文件夹


# mkdir /lempos

# 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 LEMPOS]# ls -al

total 88

8 16:43 .discinfo

4096 Mar 21 23:04 images

4096 Apr 12 00:00 isolinux

1root root 14371 Apr 11 23:16 lemp.tar.gz
//

这个软件包是我们后面要建立的,读者可以分析一下后面的

ks.cfg
脚本就可以明白他的用途

.

4096 Apr 11 21:00 repodata

7048 Mar 21 23:05 TRANS.TBL

AutoLEMP-0.1.2.tar.bz2

3.
定制
package.list

软件包清单


如安装一个

CentOS5.3
的系统,根据自己的需求选择软件包

;
如果想你的系统很小,建议选择最少的包。安装完成以后,在系统里会产生日志
。日文文件存放在

/root/install.log


#pwd

/root

# cat install.log | grepInstalling | sed 's/Installing //g'|sed 's/^[0-9]/+://g' > packages.list

#mkdir /lempos/CentOS

建立存放

rpm
包的目录

.

创建自动提取相关

rpm
脚本

:

#vi cprpms.sh

#!/bin/bash

DEBUG=0

LT_CD=/mnt/cdrom

ALL_RPMS_DIR=/mnt/cdrom/CentOS

#
挂载光盘存放的目录

LT_RPMS_DIR=/lempos/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`

done

执行以上脚本将定制

ltos
必要的

rpm
复制到

/lempos/CentOS
目录

返回到

/ltos
目录下,执行

createrepo
程序生成

repodata
下的

comps.xml
文件

#cd /lempos

#createrepo -g repodata/comps.xml .

4.
配置
kickstart

脚本


通过

CentOS5.3
定制安装系统以后,会在系统里站生一个

kickstart
安装脚本

(/root/anaconda-ks.cfg
)

# cp anaconda-ks.cfg /lempos/isolinux/ks.cfg

# vi/ltos/isolinux/ks.cfg
并修改脚本如下

:

# Kickstart file automatically generated by anaconda.

install

text

cdrom

#lang en_US.UTF-8

#keyboard us

network --device eth0 --bootproto static --ip 192.168.1.17 --netmask
255.255.255.0 --gateway 192.168.1.1 --nameserver
202.102.154.3,202.102.152.3 --hostname autolemp

#rootpw --iscrypted $1$jPZf0P0r$JRe7pd.5wq9k.VZEMOgdq/

firewall --disabled

authconfig --enableshadow --enablemd5

selinux --disabled

timezone Asia/Shanghai

bootloader --location=mbr --driveorder=sda

# 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 --linux

#part /boot --fstype ext3 --size=100

#part swap --size=512 注释掉,然后系统安装时就会提示分区的

#part / --fstype ext3 --size=100 --grow

%packages

@editors

@text-internet

@core

@base

device-mapper-multipath

-acpid

-readahead

-aspell-en

-apmd

-aspell

-vconfig

-rsync

-autofs

-pcmciautils

-firstboot-tui

-cpuspeed

-NetworkManager

-tcpdump

-rsh

-nfs-utils

-smartmontools

-telnet

-bluez-utils

-usbutils

. #

# ------- 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

cp /mnt/cdrom/AutoLEMP-0.1.2.tar.bz2 /mnt/sysimage/tmp/AutoLEMP-0.1.2.tar.bz2 > /dev/null

rm -rf /mnt/sysimage/etc/issue

cd /mnt/sysimage/tmp/

tar -zxvf lemp.tar.gz > /dev/null

tar -jxvf AutoLEMP-0.1.2.tar.bz2 -C /mnt/sysimage/usr/local

# 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

rm -rf lemp.tar.gz && rm -rf boot && rm -rf etc

rm -rf AutoLEMP-0.1.2.tar.bz2

# Unmount 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

# 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 | sshd | syslog | local )

echo "Base services, Skip!"

;;

*)

echo "change $CURSRV to off"

chkconfig --level 235 $CURSRV off

service $CURSRV stop

;;

esac

done


.

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


1.
如何定制安装开机画面
:


启动画面用的是一种比较奇怪的格式

lss16
,它限制图片使用

16
种颜色,除去前景和背景色只能有

14
种颜色。我们需要

ppmtolss16giftopnm
等程序,系统一般默认都安装了。

一般用

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.gz

(3)
直接替换

/boot/grup/splash.xpm.gz
文件即可

.

?

利用上面方法生成的图片可能无法显示,或者质量不高,如何生成高质量的

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

# cp initrd.img /ltos/isolinux/

仍后将

initrd.img
复制到

/ltos/isolinux/

3.

如何替换安装以后的


grub?


在安装光盘里的

ks.cfg
文件里写好替换

splash.xpm.gz
文件即可

.

4.

如何去掉启动过程中的


"CentOSrelease 5 (Final)"


在安装光盘里的

ks.cfg
文件里写好脚本,直接替换

/etc/redhat
-release
即可

.




.

打包生成


ISO

文件发布



# cd /ltos

# declare -x discinfo=`head -1 .discinfo`

# createrepo -u "media://$discinfo" -grepodata/comps.xml .

生成


ISO

文件



#mkisofs -R -J -T -r -l -d -allow-multidot-allow-leading-dots -no-bak -o /tmp/LEMPOS-0.1.3-i386.iso /

-b isolinux/isolinux.bin -c isolinux/boot.cat-no-emul-boot -boot-load-size 4 -boot-info-table .

Md5


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

附录:lemp.tar.gz分解

解压后,会发现存在 boot etc 两个目录,里面总共包括network、redhat-release、splash.xpm.gz

登陆界面就是在network这个系统脚本中,分别在55行,149 150 151代码,因为/etc/issue本身不是脚本文件,可以用^[[32;1m这样的代码来实现彩色。更改自己需要的信息

相关脚本及制作工具
下载


:
http://www.linuxtone.org/project/ltos/ltospack.tar.gz
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: