歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

封裝自己的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

Copyright © Linux教程網 All Rights Reserved