封装自己的LINUX光盘

一、之前有写过一篇管理定制CentOS5.6的文章,最近公司外网生产环境准备用CentOS6系列的,手动安装是在是太麻烦,所以就又研究了一些6系列的封装,其实和5系列的差不多,就是有几个文件不一样,还有就是ks.cfg这个文件我又更新了新内容。

二、开始定制
1、安装需要的用到的软件包
[root@localhost ~]# yum -y install createrepo mkisofs
2、生成安装系统所需要的rpm文件列表
[root@localhost ~]# awk '/Installing/{print $2}' install.log |sed 's/^[0-9]*://g' >/root/packages.list

3、创建工作目录
[root@localhost ~]# mkdir -p /mnt/cdrom
[root@localhost ~]# mkdir -p /data/OS
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
4、复制文件
[root@localhost ~]# rsync -a --exclude=Packages /mnt/cdrom/* /data/OS/
[root@localhost ~]# cp /mnt/cdrom/.discinfo /data/OS/
5、复制精简后的rpm包
a、撰写脚本

cat cp.sh
#!/bin/bash
DVD='/mnt/Packages'    #DVD镜像存放包路径
PACKDIR='/root/package.txt'     #记录的是现在系统里安装的所有包名
NEW_DVD='/root/iso/Packages/'   # 新镜像需要包的存放路径
while read LINE;
     do cp ${DVD}/${LINE}*.rpm  /${NEW_DVD} || echo "$LINE don't cp.......";
     done < package.txt


[root@localhost ~]# chmod +x /data/cprmps.sh
[root@localhost ~]# sh /data/cprmps.sh

6、撰写ks.cfg文件
[root@localhost ~]# vi /data/OS/isolinux/ks.cfg

# Kickstart file automatically generated by anaconda.

#version=RHEL6
install
cdrom
lang en_US.UTF-8
keyboard us
network --device eth0 --onboot no --bootproto static --ip 192.168.1.222 --netmask 255.255.255.0 --gateway 192.168.1.1 --nameserver 8.8.8.8 --hostname wy.cn
rootpw  --iscrypted $6$qonSDczLascaQ556$dty34p2Ff9VVM70Zek0Utht5pK1n4dvx0mAEEV7Y6aPbl7590mrVb9sN8v6Q3JJdx99uzrU/5CBXfUKVE1cFr1
firewall --disabled
authconfig --enableshadow --passalgo=sha512 --enablefingerprint
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# 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

part /boot --fstype=ext4 --size=500
part pv.XHGICy-t31o-N3CL-0QxU-G2l4-gaKE-uleXGL --grow --size=1
volgroup vg_wy --pesize=4096 pv.XHGICy-t31o-N3CL-0QxU-G2l4-gaKE-uleXGL
logvol / --fstype=ext4 --name=lv_root --vgname=vg_wy --grow --size=1024 --maxsize=51200
logvol swap --name=lv_swap --vgname=vg_wy --grow --size=2032 --maxsize=4064
repo --name="centos"  --baseurl=file:///mnt/source --cost=100
reboot

%packages
@additional-devel
@base
@core
@development
@perl-runtime
@server-policy
libXinerama-devel
xorg-x11-proto-devel
startup-notification-devel
libgnomeui-devel
libbonobo-devel
libXau-devel
libgcrypt-devel
popt-devel
libXrandr-devel
libxslt-devel
libglade2-devel
gnutls-devel
mtools
sgpio
jpackage-utils
perl-DBD-SQLite
%end

%post
# file descriptors
ulimit -HSn 655350
echo "* soft nofile 655350" >> /etc/security/limits.conf
echo "* hard nofile 655350" >> /etc/security/limits.conf

#set ntp
ntpdate 1.cn.pool.ntp.org && /sbin/hwclock --systohc
/bin/cat > /etc/cron.daily/ntpdate << _ntpdate
#!/bin/bash
/sbin/ntpdate 1.cn.pool.ntp.org && /sbin/hwclock --systohc
_ntpdate

#set /etc/sysctl.conf
/bin/cat > /etc/sysctl.conf << _sysctl
fs.file-max = 1000000
kernel.core_uses_pid = 1
kernel.msgmax = 65536
kernel.msgmnb = 65536
kernel.shmall = 4294967296
kernel.shmmax = 68719476736
kernel.sysrq = 0
net.core.netdev_max_backlog = 262144
net.core.rmem_default = 2097152
net.core.rmem_max = 16777216
net.core.somaxconn = 262144
net.core.wmem_default = 2097152
net.core.wmem_max = 16777216
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.ip_conntrack_max = 819200
net.ipv4.ip_forward = 0
net.ipv4.ip_local_port_range = 1024    65000
net.ipv4.neigh.default.gc_thresh1 = 10240
net.ipv4.neigh.default.gc_thresh2 = 40960
net.ipv4.neigh.default.gc_thresh3 = 81920
net.ipv4.netfilter.ip_conntrack_max = 819200
net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait = 60
net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait = 120
net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 120
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_max_tw_buckets = 51200
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_reordering = 5
net.ipv4.tcp_retrans_collapse = 0
net.ipv4.tcp_retries2 = 5
net.ipv4.tcp_rmem = 4096        87380   4194304
net.ipv4.tcp_sack = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_wmem = 4096        16384   4194304
net.ipv6.conf.all.disable_ipv6 = 1
_sysctl
source /etc/profile
sysctl -e -p
/etc/init.d/avahi-daemon stop
/etc/init.d/yum-updatesd stop
chkconfig avahi-daemon off
chkconfig yum-updatesd off

echo "WyLinux release 6.0 (Based on CentOS 6.0)" > /etc/centos-release
sed -i 's/CentOS Linux release 6.0 (Final)/WyLinux release 6.0 (Based on CentOS 6.0)/g' /etc/issue
sed -i 's/CentOS Linux release 6.0 (Final)/WyLinux release 6.0 (Based on CentOS 6.0)/g' /etc/issue.net
sed -i 's/localhost.localdomain/WyLinux/g' /etc/sysconfig/network
sed -i 's/CentOS/WyLinux/g' /etc/rc.d/rc.sysinit
sed -i 's/rhgb/WyLinux/g' /boot/grub/grub.conf

mkdir -p /media/cdrom
mount -o loop /dev/cdrom /media/cdrom
cp -rf /media/cdrom/web.tar.gz /usr/local/
cd /usr/local/
chmod 755 -R *.tar.gz
tar xvzf web.tar.gz
rm -rf web.tar.gz
/usr/local/apache/bin/apachectl start




7、生成comps.xml文件

[root@localhost ~]# cd /data/OS
[root@localhost ~]# createrepo -g repodata/*-comps.xml /data/OS/

8、让系统启动读开始,ks.cfg的内容
修改lable linux
[root@localhost ~]# vi /data/OS/isolinux/isolinux.cfg
label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel vmlinuz
  append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img

9、生成ISO镜像文件

[root@localhost ~]# declare -x discinfo=`head -1 .discinfo`
[root@localhost ~]#  createrepo -u "media://$discinfo" -g repodata/*-comps.xml /data/OS/
[root@localhost ~]# mkisofs  -r -l -allow-multidot -allow-leading-dots -no-bak -o /data/kingsoft_centos6.3_1.0.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -input-charset UTF-8 /data/OS/

10、生成MD5校验码
[root@localhost ~]# /usr/bin/md5sum /data/kingsoft_centos6.3_1.0.iso
2de68609b36db23cca4956b2779465ed  /data/kingsoft_centos6.3_1.0.iso

你可能感兴趣的:(cd,光盘,封装linux)