基于CentOS制作Linux发行版光盘
基于CentOS制作Linux发行版光盘Posted by 楚霏– 2011-12-28############################################## Custom Linux ISO Bulid# Author: 楚霏# Company: chengyongxu.com# Date: 2011-04-28# Update: 20
·
基于CentOS制作Linux发行版光盘
Posted by
– 2011-12-28
#############################################
# Custom Linux ISO Bulid
# Author: 楚霏
# Company: chengyongxu.com
# Date: 2011-04-28
# Update: 2011-12-23
# Env: CentOS 5.5 x86_64 && CentOS 6.2 x86_64
#############################################
一、安装制作发行版所需的基本软件包并创建工作目录
1 | yum -y install anaconda-runtime createrepo yum-utils anacondaanaconda-help busybox-anaconda mkisofs |
2 | mkdir /os |
3 | mkdir /mnt/cdrom |
二、复制母盘文件
01 | #挂载光盘镜像 |
02 | mount -t iso9660 -o loop /usr/ local /src/CentOS-5.5-x86_64-bin-DVD-1of2.iso /mnt/cdrom |
03 | mount -t iso9660 -o loop /usr/ local /src/CentOS-6.2-x86_64-bin-DVD1.iso /mnt/cdrom |
04 | cd /mnt/cdrom |
05 | #将光盘文件拷到工作目录 |
06 | tar -cf - . | ( cd /os ; tar -xvpf - ) |
07 | #删除无用的文件 |
08 | cd /os/ |
09 | rm RELEASE-NOTES-* -f |
10 |
11 | #centos5下是: |
12 | rm -rf /os/CentOS/* |
13 | #centos6下是: |
14 | rm -rf /os/Packages/* |
三、定制package.list软件包清单
01 | #以一台最小安装的线上服务器作为模板,将这台模板服务器安装时的/root/anaconda-ks.cfg拷贝到本地 |
02 | #然后把这台模板服务器的RPM包信息导出拷贝到本地,导出方法是: |
03 | rpm -qa | awk -F- '{print $1}' >> packages.list |
04 | #可以统计一下条数 |
05 | wc -l /root/packages.list |
06 | #如果你指定了alias cp=cp -i,刚先取消 |
07 | alias cp = cp |
08 |
09 | #把需要的RPM包列表中的包从光盘镜像拷贝到目标目录的相应位置 |
10 | #centos5下是: |
11 | for i in ` cat /root/packages.list`; do cp -vrf /mnt/cdrom/CentOS/$i* /os/CentOS/; done |
12 | #centos6下是: |
13 | for i in ` cat /root/packages.list`; do cp -vrf /mnt/cdrom/Packages/$i* /os/Packages/; done |
14 |
15 | #把想安装系统之后放入系统的源码包(chengyongxu.com.tar.gz)放入工作目录下 |
16 | mv chengyongxu.com. tar .gz /os/ |
17 | #下载光盘镜像中没有,但又需要的RPM包,例如: |
18 | #centos5下是: |
20 | wget http://mirrors.163.com/centos/5.5/extras/x86_64/RPMS/mhash-devel-0.9.9-1.el5.centos.x86_64.rpm |
21 |
22 | #执行createrepo程序生成repodata下的comps.xml文件 |
23 | cd /os |
24 | #centos6下需要: |
25 | mv repodata/*-comps.xml repodata/comps.xml |
26 |
27 | createrepo -g repodata/comps.xml . |
四、配置kickstart
001 | cd /os |
002 | #把模板服务器上anaconda-ks.cfg拷贝到工作目录 |
003 | #订制完光盘默认密码是模板服务器装系统时的密码 |
004 | cp anaconda-ks.cfg /os/ks.cfg |
005 | vi /os/isolinux/ks.cfg 并修改脚本如下: |
006 | vi ks.cfg |
007 | #CentOS 5的配置如下 |
008 | #ks.cfg的详解请参考<a href="http://www.chengyongxu.com/blog/anaconda-ks-cfg%E8%AF%A6%E8%A7%A3/" title="ks.cfg详解" target="_blank">http://www.chengyongxu.com/blog/anaconda-ks-cfg%E8%AF%A6%E8%A7%A3/</a> |
009 | #----------------------------引用文字-开始---------------------------- |
010 | # Kickstart file automatically generated by anaconda. |
011 |
012 | install |
013 | cdrom |
014 | lang en_US.UTF-8 |
015 | keyboard us |
016 | network --device eth0 --bootproto dhcp -- hostname localhost |
017 | rootpw --iscrypted $1$kAVanbBp$QjTH30VQgnj/.gYkQ6aN0 |
018 | firewall --enabled --port=22:tcp |
019 | authconfig --enableshadow --enablemd5 |
020 | selinux --enforcing |
021 | timezone --utc Asia/Shanghai |
022 | bootloader --location=mbr --driveorder=sda |
023 | # The following is the partition information you requested |
024 | # Note that any partitions you deleted are not expressed |
025 | # here so unless you clear all partitions first, this is |
026 | # not guaranteed to work |
027 | #clearpart --linux |
028 | clearpart --all --initlabel |
029 | part /boot --fstype ext3 --size=200 --asprimary |
030 | part / --fstype ext3 --size=40965 |
031 | part swap --size=10245 |
032 | part /data --fstype ext3 --size=1 --grow |
033 |
034 | %packages |
035 | @base |
036 | @core |
037 | @dialup |
038 | @editors |
039 | @text-internet |
040 | keyutils |
041 | trousers |
042 | fipscheck |
043 | device-mapper-multipath |
044 | autoconf |
045 | automake |
046 | bison |
047 | bzip2 -devel |
048 | compat-gcc-34-g77 |
049 | compat-libstdc++-296 |
050 | compat-libstdc++-33 |
051 | curl |
052 | curl-devel |
053 | e2fsprogs-devel |
054 | flex |
055 | freetype-devel |
056 | gcc |
057 | gcc-c++ |
058 | gettext-devel |
059 | krb5-devel |
060 | libidn-devel |
061 | libjpeg-devel |
062 | libpng-devel |
063 | libtiff-devel |
064 | libtool |
065 | libxml2 |
066 | libxml2-devel |
067 | ncurses-devel |
068 | ntp |
069 | openssl-devel |
070 | pam-devel |
071 | sysstat |
072 | mhash-devel |
073 | zlib-devel |
074 |
075 | # chengyongxu.com System Install |
076 | %post --nochroot |
077 |
078 | # Mount CDROM |
079 | mkdir -p /mnt/cdrom |
080 | mount -r -t iso9660 /tmp/cdrom /mnt/cdrom |
081 |
082 | # Copy our files, extract it ,then move to right locations |
083 | cp /mnt/cdrom/chengyongxu.com. tar .gz /mnt/sysimage/tmp/chengyongxu.com. tar .gz> /dev/null |
084 | cd /mnt/sysimage/tmp/ |
085 | tar -zxvf chengyongxu.com. tar .gz > /dev/null |
086 | cp -R /mnt/sysimage/tmp/src/* /mnt/sysimage/usr/ local /src/ >/dev/null 2>/dev/null |
087 |
088 | # Umount CDROM |
089 | umount /mnt/cdrom |
090 |
091 | %post |
092 |
093 | # ssh configration |
094 | sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ ssh /sshd_config |
095 |
096 | # Disable IPV6 |
097 | sed -i 's/\IPV6\=yes/\IPV6\=no/g' /etc/sysconfig/network |
098 | echo ' alias net-pf-10 off |
099 | alias ipv6 off' >> /etc/modprobe.conf |
100 |
101 | # Vim syntax on |
102 | VI_IN_BASH=` grep vim /root/.bashrc` |
103 | if [ -z "$VI_IN_BASH" ] |
104 | then |
105 | echo "alias vi='vim'" >> /root/.bashrc |
106 | source /root/.bashrc |
107 | fi |
108 |
109 | # rsync configration |
110 | echo "alias rsync='rsync -apur --partial -e \"ssh -p 22 -c arcfour\"'" >> /root/.bashrc |
111 |
112 | # Show detail when use the "history" command |
113 | echo "HISTTIMEFORMAT=\"%Y-%m-%d %H:%M:%S \"" >> /etc/profile |
114 |
115 | # Turn off unnecessary services |
116 | SERVICE_NEED= "apmd|atd|auditd|cpuspeed|crond|mdmonitor|mdmpd|microcode-ctl|network|ntpd|readahed_early|readahead_later|smartd|sshd|syslog|irqbalance" |
117 | SERVICE_NONEED=`chkconfig --list| awk '{print $1}' | grep -vE $SERVICE_NEED` |
118 | SERVICE_NEED_LIST=` echo $SERVICE_NEED| sed "s/|/ /g" ` |
119 | for i in $SERVICE_NONEED; do chkconfig --level 2345 $i off; service $i stop; done |
120 | for i in $SERVICE_NEED_LIST; do chkconfig --level 2345 $i on; service $i start; done |
121 | #----------------------------引用文字-结束---------------------------- |
122 |
123 | #CentOS 6的配置如下 |
124 | #----------------------------引用文字-开始---------------------------- |
125 | # Kickstart file automatically generated by anaconda. |
126 |
127 | #version=RHEL6 |
128 | install |
129 | cdrom |
130 | lang en_US.UTF-8 |
131 | keyboard us |
132 | #network --device eth0 --bootproto dhcp --hostname localhost |
133 | rootpw --iscrypted $6$5q5hu2jMre1MaP4f$DUEVi7i0qo/4Vrh7iiuemzwLVv96pGWVO.T/SzRLE15qYDY9ZP/UfVNXpsoYTZsNLWrlce.yudFo.L7/BlG1 |
134 | firewall --service= ssh |
135 | authconfig --enableshadow --passalgo=sha512 --enablefingerprint |
136 | selinux --enforcing |
137 | timezone --utc Asia/Shanghai |
138 | bootloader --location=mbr --driveorder=sda --append= "crashkernel=auto rhgb quiet" |
139 | # The following is the partition information you requested |
140 | # Note that any partitions you deleted are not expressed |
141 | # here so unless you clear all partitions first, this is |
142 | # not guaranteed to work |
143 | #clearpart --none --drives=sda |
144 | clearpart --all --initlabel |
145 | part /boot --fstype=ext4 --size=200 --asprimary |
146 | part / --fstype=ext4 --size=40965 |
147 | part swap --size=10245 |
148 | part /data --fstype=ext4 --size=1 --grow |
149 |
150 | repo --name= "CentOS" --baseurl= file :///mnt/ source --cost=100 |
151 |
152 | %packages |
153 | @base |
154 | @client-mgmt-tools |
155 | @console-internet |
156 | @core |
157 | @server-policy |
158 | autoconf |
159 | automake |
160 | bison |
161 | bzip2 -devel |
162 | cmake |
163 | compat-gcc-34-g77 |
164 | compat-libstdc++-296 |
165 | compat-libstdc++-33 |
166 | curl |
167 | curl-devel |
168 | device-mapper-multipath |
169 | e2fsprogs-devel |
170 | flex |
171 | freetype-devel |
172 | ftp |
173 | gcc |
174 | gcc-c++ |
175 | gettext-devel |
176 | htop |
177 | iptraf |
178 | krb5-devel |
179 | lftp |
180 | libidn-devel |
181 | libjpeg-devel |
182 | libpng-devel |
183 | libtiff-devel |
184 | libtool |
185 | libxml2 |
186 | libxml2-devel |
187 | logwatch |
188 | lrzsz |
189 | make |
190 | ncurses-devel |
191 | ntp |
192 | openssl-devel |
193 | pam-devel |
194 | patch |
195 | sgpio |
196 | sysstat |
197 | trousers |
198 | mhash-devel |
199 | unix2dos |
200 | unzip |
201 | zlib-devel |
202 | %end |
203 |
204 | # chengyongxu.com System Install |
205 | # CentOS 6 Can not use post --nochroot |
206 | %post --nochroot |
207 |
208 | # Mount CDROM |
209 | mkdir -p /mnt/cdrom |
210 | mount -r -t iso9660 /dev/cdrom /mnt/cdrom |
211 |
212 | # Copy our files, extract it ,then move to right locations |
213 | cd /mnt/cdrom/ |
214 | tar -zmxvf chengyongxu.com. tar .gz -C /mnt/sysimage/usr/ local /src/ > /dev/null |
215 | cd /mnt |
216 |
217 | # Umount CDROM |
218 | umount /mnt/cdrom |
219 |
220 | %post |
221 |
222 | # ssh configration |
223 | sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ ssh /sshd_config |
224 |
225 | # Disable IPV6 |
226 | echo "NETWORKING_IPV6=no" >> /etc/sysconfig/network |
227 | echo ' alias net-pf-10 off |
228 | options ipv6 disable=1' >> /etc/modprobe.d/ipv6-off.conf |
229 |
230 | # Vim syntax on |
231 | VI_IN_BASH=` grep vim /root/.bashrc` |
232 | if [ -z "$VI_IN_BASH" ] |
233 | then |
234 | echo "alias vi='vim'" >> /root/.bashrc |
235 | source /root/.bashrc |
236 | fi |
237 |
238 | # rsync configration |
239 | echo "alias rsync='rsync -apur --partial -e \"ssh -p 22 -c arcfour\"'" >> /root/.bashrc |
240 |
241 | # Show detail when use the "history" command |
242 | echo "HISTTIMEFORMAT=\"%Y-%m-%d %H:%M:%S \"" >> /etc/profile |
243 |
244 | # Add a crontab task |
245 | echo "0 */8 * * * /usr/sbin/ntpdate 210.72.145.44" >> /var/spool/ cron /root |
246 |
247 | # If forget this, will output error : "sudo: sorry, you must have a tty to run sudo" on system boot |
248 | sed -i 's/Defaults requiretty/#Defaults requiretty/g' /etc/sudoers |
249 |
250 | # Install Nginx PHP MySQL Memcached GD Libxml Libmcrypt Libevent Sphinx Nrpe |
251 | tar -zmxvf /usr/ local /src/Etc_Init.d. tar .gz -C /etc/init.d/ > /dev/null |
252 | tar -zmxvf /usr/ local /src/my.cnf. tar .gz -C /etc/ > /dev/null |
253 | tar -zmxvf /usr/ local /src/Usr_Local. tar .gz -C /usr/ local / > /dev/null |
254 |
255 | # Add Users |
256 | groupadd www -g 88 |
257 | useradd -u 88 -g www www -m |
258 | useradd mysql |
259 | useradd nagios |
260 |
261 | # Add services |
262 | chkconfig --add nginx |
263 | chkconfig --add memcached |
264 | chkconfig --add mysqld |
265 | chkconfig --add nrpe |
266 | chkconfig --add sphinx |
267 |
268 | # Turn off unnecessary services |
269 | SERVICE_NEED= "apmd|atd|auditd|cpuspeed|crond|irqbalance|memcached|mdmonitor|mdmpd|microcode-ctl|network|nginx|ntpd|nrpe|readahed_early|readahead_later|smartd|sphinx|sshd|syslog" |
270 | SERVICE_NONEED=`chkconfig --list| awk '{print $1}' | grep -vE $SERVICE_NEED` |
271 | SERVICE_NEED_LIST=` echo $SERVICE_NEED| sed "s/|/ /g" ` |
272 | for i in $SERVICE_NONEED; do chkconfig --level 2345 $i off; service $i stop; done |
273 | for i in $SERVICE_NEED_LIST; do chkconfig --level 2345 $i on; service $i start; done |
274 |
275 | # By 楚霏 (yxcx@yahoo.cn<script type="text/javascript"> |
276 | /* <![CDATA[ */ |
277 | ( function (){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName( "script" );l=b[b.length-1].previousSibling;a=l.getAttribute( 'data-cfemail' ); if (a){s= '' ;r=parseInt(a.substr(0,2),16); for (j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})(); |
278 | /* ]]> */ |
279 | </script>) |
280 | #----------------------------引用文字-结束---------------------------- |
五、让系统从kickstart配置启动
01 | #修改disk/isolinux/isolinux.cfg文件,如下是我的一个配置文件 |
02 | vi isolinux/isolinux.cfg |
03 | #把default选项改为ks |
04 | #append ks initrd=initrd.img改为append ks=cdrom:/ks.cfg initrd=initrd.img |
05 | #----------------------------引用文字-开始---------------------------- |
06 | default ks |
07 | prompt 1 |
08 | timeout 600 |
09 | display boot.msg |
10 | F1 boot.msg |
11 | F2 options.msg |
12 | F3 general.msg |
13 | F4 param.msg |
14 | F5 rescue.msg |
15 | label linux |
16 | kernel vmlinuz |
17 | append initrd=initrd.img |
18 | label text |
19 | kernel vmlinuz |
20 | append initrd=initrd.img text |
21 | label ks |
22 | kernel vmlinuz |
23 | append ks=cdrom:/ks.cfg initrd=initrd.img |
24 | label local |
25 | localboot 1 |
26 | label memtest86 |
27 | kernel memtest |
28 | append - |
29 | #----------------------------引用文字-结束---------------------------- |
30 |
31 | #CentOS 6的配置如下 |
32 | #----------------------------引用文字-开始---------------------------- |
33 | default ks |
34 | prompt 1 |
35 | timeout 60 |
36 |
37 | display boot.msg |
38 |
39 | menu background splash.jpg |
40 | menu title Welcome to CentOS 6.2! |
41 | menu color border 0 #ffffffff #00000000 |
42 | menu color sel 7 #ffffffff #ff000000 |
43 | menu color title 0 #ffffffff #00000000 |
44 | menu color tabmsg 0 #ffffffff #00000000 |
45 | menu color unsel 0 #ffffffff #00000000 |
46 | menu color hotsel 0 #ff000000 #ffffffff |
47 | menu color hotkey 7 #ffffffff #ff000000 |
48 | menu color scrollbar 0 #ffffffff #00000000 |
49 |
50 | label linux |
51 | menu label ^Install or upgrade an existing system |
52 | menu default |
53 | kernel vmlinuz |
54 | append initrd=initrd.img |
55 | label ks |
56 | kernel vmlinuz |
57 | append ks=cdrom:/ks.cfg initrd=initrd.img |
58 | label vesa |
59 | menu label Install system with ^basic video driver |
60 | kernel vmlinuz |
61 | append initrd=initrd.img xdriver=vesa nomodeset |
62 | label rescue |
63 | menu label ^Rescue installed system |
64 | kernel vmlinuz |
65 | append initrd=initrd.img rescue |
66 | label local |
67 | menu label Boot from ^ local drive |
68 | localboot 0xffff |
69 | label memtest86 |
70 | menu label ^Memory test |
71 | kernel memtest |
72 | append - |
73 | #----------------------------引用文字-结束---------------------------- |
六、生成光盘镜像
1 | mkisofs -R -J -T -V Boot --allow-multidot --allow-leading-dots -no-bak -input-charset UTF-8 -b isolinux/isolinux.bin -c isolinux/boot. cat -no-emul-boot --boot-load-size 4 --boot-info-table -o /tmp/chengyongxu.com-Linux-Release-20111223-x64.iso . |
2 | #可以计算一下md5并保存信息 |
3 | md5sum /tmp/Chengyonxu.com-Linux-Release-20111223-x64.iso >> /tmp/md5.txt |
七、参考文档
http://bbs.linuxtone.org/thread-2448-1-1.html
http://bbs.linuxtone.org/thread-1240-1-1.html
http://hi.baidu.com/zj8la8la/blog/item/8aac2b02b8fd5b85d53f7c7c.html
更多推荐
已为社区贡献5条内容
所有评论(0)