秃鹫

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理


//轻量级Centos定制发行版
====================================================================================================
一、基础

//操作环境:
VM+CentOS-6.4-x86_64-minimal.iso

//基本软件
yum -y install createrepo genisoimage

//VM需设置1个光驱 挂载DVD1
安装centos6.4X 86_64系统,所需组件自行定义,安装后得到install.log和anaconda-ks.cfg文件

//初始目录
mkdir /mnt/cd1 #建立光盘的挂载目录
mount /dev/cdrom /mnt/cd1 #挂载DVD
mkdir -p /root/centos_1905/Packages #建立定制光盘文件目录


二、定制系统文件的准备

新定制系统由以上系统组件包说决定,文件由install.log安装日志得来

vi /root/cp_files.sh

#!/bin/bash
for i in $(awk '/Installing/ {print $2}' install.log)
do
cp /mnt/cd1/Packages/${i}.rpm /root/centos_1905/Packages
[ $? != 0 ] && echo "copy ${i} is faied"
done

//拷贝文件
rsync -a --exclude=Packages /mnt/cd1/ /root/centos_1905/


三、下载Development Tools相关软件

另找机器,通过yum -y groupinstall "Development Tools"缓存相关软件包

需安装其他基础依赖包,都可通过yum准备相关文件。

//开启缓存
vi /etc/yum.conf
keepcache=1

拷贝相关软件到Packages下

//find . -name "*.rpm"|xargs -i mv {} ~/temp


三、ks文件准备 (非自动安装忽略此步)

ks文件由系统安装所得anaconda-ks.cfg进行修改所得 (也可用 system-config-kickstart 生成)
密码生成工具 grub-crypt

vi /root/centos_1905/isolinux/ks.cfg

# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot no --device eth0 --bootproto dhcp --noipv6
network --onboot no --device eth1 --bootproto dhcp --noipv6
rootpw --iscrypted $6$ap3J1vcG32p9wu7m$Q4YQJdR4jvxNjhTDNhw0d/qFdcd/TufkoZ3GZ4VZ7fkna3oZEnAYrXAqrBk11b6S6.gAWqsb8.EBAuerI8k/l.
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Asia/Chongqing
bootloader --location=mbr --driveorder=xvda --append="crashkernel=auto console=hvc0 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 --linux --drives=xvda
#volgroup VolGroup --pesize=4096 pv.202002
#logvol /home --fstype=ext4 --name=lv_home --vgname=VolGroup --grow --size=100
#logvol / --fstype=ext4 --name=lv_root --vgname=VolGroup --grow --size=1024 --maxsize=51200
#logvol swap --name=lv_swap --vgname=VolGroup --grow --size=4000 --maxsize=4000

#part /boot --fstype=ext4 --size=500
#part pv.202002 --grow --size=1

#repo --name="CentOS" --baseurl=cdrom:xvdd --cost=100

%packages --nobase
@core
%end

四、让系统从kickstart配置启动安装 (非自动安装忽略此步)

vi /root/centos_1905/isolinux/isolinux.cfg

default auto
timeout 600
display boot.msg

menu background splash.jpg
menu title Welcome to CentOS 6.4!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000

label auto
menu label ^Auto Install system
menu default
kernel vmlinuz
append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img

label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img
label vesa
menu label Install system with ^basic video driver
kernel vmlinuz
append initrd=initrd.img xdriver=vesa nomodeset
label rescue
menu label ^Rescue installed system
kernel vmlinuz
append initrd=initrd.img rescue
label local
menu label Boot from ^local drive
localboot 0xffff
label memtest86
menu label ^Memory test
kernel memtest
append -

五、重新生成comps.xml

//清空repodata
rm -rf /root/centos_1905/repodata/*

//生成XML(详见附录)
vi /root/centos_1905/repodata/comps.xml

//生成依赖 comps.xml
createrepo -g /root/centos_1905/repodata/comps.xml /root/centos_1905/

mv /root/centos_1905/repodata/*-comps.xml /root/centos_1905/repodata/comps.xml


cd /root/centos_1905/
declare -x discinfo=$(head -1 .discinfo)
createrepo -u "media://$discinfo" -g /root/centos_1905/repodata/comps.xml /root/centos_1905/


六、ISO文件的生成

mkisofs -o Centos_1905-text-6.4-x86_64-minimal.iso -input-charset utf-8 -b isolinux/isolinux.bin -c isolinux/boot.cat -joliet-long -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -V centos_1905 -T /root/centos_1905

mkisofs -o Centos_1905_all_6_14-6.4-x86_64-minimal.iso -input-charset utf-8 -b isolinux/isolinux.bin -c isolinux/boot.cat -joliet-long -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -V centos_1905 -T /root/centos_1905

mkisofs -o Centos_text-6.5-x86_64-minimal.iso -input-charset utf-8 -b isolinux/isolinux.bin -c isolinux/boot.cat -joliet-long -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -V centos_1905 -T /root/centos_1905

mkisofs -o Centos_1905-6.5-x86_64-minimal.iso -input-charset utf-8 -b isolinux/isolinux.bin -c isolinux/boot.cat -joliet-long -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -V centos_1905 -T /root/centos_1905


//打包普通
mkisofs -o m1905.iso -input-charset utf-8 -joliet-long -R -J -v -V centos_1905 -T /root/shell

七、生成检验
//yum install anaconda

/usr/bin/implantisomd5 /root/iso/Centos_1905-6.5-x86_64-minimal.iso

 

//拷贝去安装
scp Centos_1905-6.5-x86_64-minimal.iso root@192.168.3.200:/home/public/ISO

 

//绿色+开发包
Centos_text-6.5-x86_64-minimal.iso
===================================================================================
yum -y groupinstall "Development tools"
yum -y install wget
yum -y install lrzsz


//绿色+开发包+自带监控+票务基础包
Centos_1905-6.5-x86_64-minimal.iso
===================================================================================
基于上面系统

wget http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm && rpm -ivh epel-release-6-8.noarch.rpm

yum -y install ntp
yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
yum -y install cmake ncurses ncurses-devel libaio libaio-devel
yum -y install libxml2 libxml2-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel giflib giflib-devel freetype freetype-devel gd gd-devel glibc glibc-devel glib2 glib2-devel curl curl-devel e2fsprogs e2fsprogs-devel openssl openssl-devel libmcrypt-devel mhash mhash-devel
yum -y install lzo lzo-devel pam pam-devel automake pkgconfig


yum -y install openvpn
yum -y install salt-minion
yum -y install zabbix22-agent


//绿色+开发包+自带监控+票务基础包+票务系统
Centos_1905_pw-6.5-x86_64-minimal.iso

//绿色+开发包+自带监控+票务基础包+票务TMS
Centos_1905_tms-6.5-x86_64-minimal.iso

//绿色+开发包+自带监控+票务基础包+中心系统
Centos_1905_center-6.5-x86_64-minimal.iso


//聚包
mkdir ~/packages
find /mnt/cd1/Packages/ -name "*.rpm"|xargs -i cp {} ~/Packages
find /var/cache/yum/x86_64/6/ -name "*.rpm"|xargs -i cp {} ~/Packages


//快速配置文件
1、相关软件包
ls *.rpm > rpm_list.txt

2、RPM 截取包名和版本号 生成相关XML文件

 


//快速安装
======================================================
mkdir -p /root/centos_1905/Packages

cp ks.cfg /root/centos_1905/isolinux/ks.cfg
cp isolinux.cfg /root/centos_1905/isolinux/isolinux.cfg


附录 剔除低版本RPM 生成comps.xml
======================================================
1、将所有RPM包放到一个文件夹下 find /var/cache/yum -name *.rpm | xargs -i cp {} ~/pk/
2、整理出RPM包列表 ls *.rpm > rpm_list.txt
3、运行如下脚本 生成 comps.xml

<?php

//rpm_list.txt
//ls *.rpm > rpm_list.txt

$list = file_get_contents('rpm_list.txt');

$list_arr = explode("\n",$list);

$ok_arr = array();
$no_arr = array();

foreach($list_arr as $val)
{
if($val)
{

//正则分割 软件名 + 版本
$val_t_arr = preg_split("/(-[\d].)(.*)/",$val,0,3);

$key = $val_t_arr[0];
$val = $val_t_arr[1].$val_t_arr[2];

if(isset($ok_arr[$key]))
{
$re = strcmp($ok_arr[$key],$val);

//var_dump($ok_arr[$key]);
//var_dump($val);
//var_dump($re);

if($re > 0)
{
$no_arr[$key] = $val;
}
else
{
$no_arr[$key] = $ok_arr[$key];
$ok_arr[$key] = $val;
}

}
else
{
$ok_arr[$key] = $val;
}
}
}

//var_dump($ok_arr);
$list = '';
foreach($ok_arr as $key => $val)
{
$list .= " <packagereq type='mandatory'>".$key."</packagereq>"."\n";
}


$head = "<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE comps PUBLIC "-//CentOS//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<name xml:lang="am">ማዕከላዊ ቦታ</name>
<name xml:lang="ar">اللبّ</name>
<name xml:lang="as">ভিত্তি</name>
<name xml:lang="bal">هستگ</name>
<name xml:lang="be">Падмурак</name>
<name xml:lang="bg">Основа</name>
<name xml:lang="bn">কোর</name>
<name xml:lang="bn_IN">কোর</name>
<name xml:lang="bs">Jezgra</name>
<name xml:lang="ca">Nucli</name>
<name xml:lang="cs">Úplný základ</name>
<name xml:lang="cy">Craidd</name>
<name xml:lang="da">Grundlæggende</name>
<name xml:lang="de">Kern</name>
<name xml:lang="el">Πυρήνας</name>
<name xml:lang="en_GB">Core</name>
<name xml:lang="es">Núcleo</name>
<name xml:lang="et">Tuum</name>
<name xml:lang="fa">اصل</name>
<name xml:lang="fi">Keskeiset</name>
<name xml:lang="fr">Core</name>
<name xml:lang="gl">Núcleo</name>
<name xml:lang="gu">મૂળ</name>
<name xml:lang="he">ליבה</name>
<name xml:lang="hi">कोर</name>
<name xml:lang="hr">Jezgra</name>
<name xml:lang="hu">Mag</name>
<name xml:lang="hy">Հիմք</name>
<name xml:lang="ia">Nucleo</name>
<name xml:lang="id">Inti</name>
<name xml:lang="ilo">Bugas</name>
<name xml:lang="is">Lágmarkskerfi</name>
<name xml:lang="it">Principale</name>
<name xml:lang="ja">コア</name>
<name xml:lang="ka">ბირთვი</name>
<name xml:lang="kn">ಅಂತಸ್ಸಾರ</name>
<name xml:lang="ko">핵심</name>
<name xml:lang="lv">Pamatsistēma</name>
<name xml:lang="mai">कोर</name>
<name xml:lang="mk">Основни</name>
<name xml:lang="ml">കോറ്‍</name>
<name xml:lang="mr">कोर</name>
<name xml:lang="ms">Teras</name>
<name xml:lang="nb">Kjerne</name>
<name xml:lang="ne">कोर</name>
<name xml:lang="nl">Kern</name>
<name xml:lang="no">Kjerne</name>
<name xml:lang="nso">Bogare</name>
<name xml:lang="or">ପ୍ରମୂଖ</name>
<name xml:lang="pa">ਮੂਲ</name>
<name xml:lang="pl">Rdzeń</name>
<name xml:lang="pt">Núcleo</name>
<name xml:lang="pt_BR">Núcleo</name>
<name xml:lang="ro">Nucleu</name>
<name xml:lang="ru">Основа</name>
<name xml:lang="si">න්‍යෂ්ඨිය</name>
<name xml:lang="sk">Jadro</name>
<name xml:lang="sl">Jedro</name>
<name xml:lang="sq">Bërthama</name>
<name xml:lang="sr">Срж</name>
<name xml:lang="sr@latin">Srž</name>
<name xml:lang="sr@Latn">Srž</name>
<name xml:lang="sv">Grund</name>
<name xml:lang="ta">கோர்</name>
<name xml:lang="te">అంతర్భాగం</name>
<name xml:lang="tg">Система</name>
<name xml:lang="th">แกนหลัก</name>
<name xml:lang="tr">Çekirdek</name>
<name xml:lang="uk">Основа</name>
<name xml:lang="ur">مرکز</name>
<name xml:lang="vi">Lõi</name>
<name xml:lang="zh_CN">核心</name>
<name xml:lang="zh_TW">核心</name>
<name xml:lang="zu">Okuyikhona</name>
<description>Smallest possible installation.</description>
<description xml:lang="as">ন্যূনতম ইনস্টল।</description>
<description xml:lang="bn">ন্যূনতম ইনস্টলেশন।</description>
<description xml:lang="bn_IN">ন্যূনতম ইনস্টলেশন।</description>
<description xml:lang="cs">Nejmenší možná instalace.</description>
<description xml:lang="de">Kleinstmögliche Installation.</description>
<description xml:lang="es">La instalación más pequeña posible.</description>
<description xml:lang="fr">Plus petite installation possible.</description>
<description xml:lang="gu">નાનામાં નાના શક્ય સ્થાપન.</description>
<description xml:lang="hi">लघुतम संभावित संस्थापन.</description>
<description xml:lang="ia">Le minime possibile installation.</description>
<description xml:lang="it">Minima installazione possibile.</description>
<description xml:lang="ja">最小限のインストール</description>
<description xml:lang="kn">ಅತ್ಯಲ್ಪಸಾಧ್ಯ ಅನುಸ್ಥಾಪನೆ.</description>
<description xml:lang="ko">가능한 최소 설치</description>
<description xml:lang="ml">സാധ്യമായ ഏറ്റവും ചെറിയ ഇന്‍സ്റ്റലേഷന്‍.</description>
<description xml:lang="mr">शक्यतया सर्वात लहान प्रतिष्ठापन.</description>
<description xml:lang="or">କ୍ଷୁଦ୍ରତମ ସମ୍ଭାବ୍ଯ ସ୍ଥାପନା।</description>
<description xml:lang="pa">ਘੱਟੋ-ਘੱਟ ਸੰਭਵ ਇੰਸਟਾਲੇਸ਼ਨ।</description>
<description xml:lang="pl">Najmniejsza możliwa instalacja.</description>
<description xml:lang="pt_BR">Menor instalação possível</description>
<description xml:lang="ru">Минимально возможная установка</description>
<description xml:lang="sv">Minsta möjliga installation</description>
<description xml:lang="ta">மிகச் சிறிய செயல்படுத்தக்கூடிய நிறுவல்.</description>
<description xml:lang="te">సాధ్యమగు అతిచిన్న సంస్థాపన.</description>
<description xml:lang="uk">Мінімально можливе встановлення.</description>
<description xml:lang="zh_CN">最小可能安装。</description>
<description xml:lang="zh_TW">最小型安裝。</description>
<default>false</default>
<uservisible>false</uservisible>
<packagelist>
";

$boot = " <packagereq type="default">aic94xx-firmware</packagereq>
<packagereq type="default">alsa-firmware</packagereq>
<packagereq type="default">bfa-firmware</packagereq>
<packagereq type="default">dracut-config-rescue</packagereq>
<packagereq type="default">ivtv-firmware</packagereq>
<packagereq type="default">iwl100-firmware</packagereq>
<packagereq type="default">iwl1000-firmware</packagereq>
<packagereq type="default">iwl105-firmware</packagereq>
<packagereq type="default">iwl135-firmware</packagereq>
<packagereq type="default">iwl2000-firmware</packagereq>
<packagereq type="default">iwl2030-firmware</packagereq>
<packagereq type="default">iwl3160-firmware</packagereq>
<packagereq type="default">iwl3945-firmware</packagereq>
<packagereq type="default">iwl4965-firmware</packagereq>
<packagereq type="default">iwl5000-firmware</packagereq>
<packagereq type="default">iwl5150-firmware</packagereq>
<packagereq type="default">iwl6000-firmware</packagereq>
<packagereq type="default">iwl6000g2a-firmware</packagereq>
<packagereq type="default">iwl6000g2b-firmware</packagereq>
<packagereq type="default">iwl6050-firmware</packagereq>
<packagereq type="default">iwl7260-firmware</packagereq>
<packagereq type="default">iwl7265-firmware</packagereq>
<packagereq type="default">kernel-tools</packagereq>
<packagereq type="default">libertas-sd8686-firmware</packagereq>
<packagereq type="default">libertas-sd8787-firmware</packagereq>
<packagereq type="default">libertas-usb8388-firmware</packagereq>
<packagereq type="default">libsysfs</packagereq>
<packagereq type="default">linux-firmware</packagereq>
<packagereq type="default">microcode_ctl</packagereq>
<packagereq type="default">NetworkManager</packagereq>
<packagereq type="default">NetworkManager-team</packagereq>
<packagereq type="default">NetworkManager-tui</packagereq>
<packagereq type="default">NetworkManager-wifi</packagereq>
<packagereq type="default">postfix</packagereq>
<packagereq type="default">ql2100-firmware</packagereq>
<packagereq type="default">ql2200-firmware</packagereq>
<packagereq type="default">ql23xx-firmware</packagereq>
<packagereq type="default">rdma</packagereq>
<packagereq type="optional">dracut-config-generic</packagereq>
<packagereq type="optional">dracut-fips</packagereq>
<packagereq type="optional">dracut-fips-aesni</packagereq>
<packagereq type="optional">dracut-network</packagereq>
<packagereq type="optional">openssh-keycat</packagereq>
<packagereq type="optional">selinux-policy-mls</packagereq>
<packagereq type="optional">tboot</packagereq>
</packagelist>
</group>
<environment>
<id>minimal</id>
<name>Minimal Install</name>
<name xml:lang="as">নূন্যতম ইনস্টল</name>
<name xml:lang="bn_IN">ন্যূনতম ইনস্টল</name>
<name xml:lang="cs">Minimální instalace</name>
<name xml:lang="de">Minimale Installation</name>
<name xml:lang="es">Instalación mínima</name>
<name xml:lang="fr">Installation minimale</name>
<name xml:lang="gu">ન્યૂનતમ સ્થાપન</name>
<name xml:lang="hi">न्यूनतम संस्थापन</name>
<name xml:lang="it">Installazione minima</name>
<name xml:lang="ja">最小限のインストール</name>
<name xml:lang="kn">ಕನಿಷ್ಟ ಅನುಸ್ಥಾಪನೆ</name>
<name xml:lang="ko">최소 설치</name>
<name xml:lang="ml">ഏറ്റവും കുറഞ്ഞ ഇന്‍സ്റ്റോള്‍</name>
<name xml:lang="mr">किमान इंस्टॉल</name>
<name xml:lang="or">ସର୍ବନିମ୍ନ ସ୍ଥାପନ</name>
<name xml:lang="pa">ਘੱਟ ਤੋਂ ਘੱਟ ਇੰਸਟਾਲ</name>
<name xml:lang="pl">Minimalna instalacja</name>
<name xml:lang="pt_BR">Instalações Mínimas</name>
<name xml:lang="ru">Минимальная установка</name>
<name xml:lang="ta">குறைந்தபட்ச நிறுவல்</name>
<name xml:lang="te">కనీసపు సంస్థాపన</name>
<name xml:lang="uk">Мінімальна система</name>
<name xml:lang="zh_CN">最小安装</name>
<name xml:lang="zh_TW">最小型安裝</name>
<description>Basic functionality.</description>
<description xml:lang="as">মৌলি কাৰ্য্যকৰীতা।</description>
<description xml:lang="bn_IN">প্রাথমিক বৈশিষ্ট্য।</description>
<description xml:lang="cs">Základní funkcionalita.</description>
<description xml:lang="de">Grundlegende Funktionalität.</description>
<description xml:lang="es">Funcionalidad básica.</description>
<description xml:lang="fr">Fonctionnalité de base.</description>
<description xml:lang="gu">મૂળભૂત વિધેય.</description>
<description xml:lang="hi">मौलिक प्रकार्यात्मकता.</description>
<description xml:lang="it">Funzione di base.</description>
<description xml:lang="ja">基本的な機能です。</description>
<description xml:lang="kn">ಮೂಲಭೂತ ಕ್ರಿಯಾಶೀಲತೆ.</description>
<description xml:lang="ko">기본적인 기능입니다.</description>
<description xml:lang="ml">അടിസ്ഥാന പ്രവൃത്തിവിശേഷണം.</description>
<description xml:lang="mr">मूळ कार्यक्षमता.</description>
<description xml:lang="or">ସାଧାରଣ କାର୍ଯ୍ୟକାରିତା।</description>
<description xml:lang="pa">ਮੁੱਢਲੀ ਕਾਰਜਸ਼ੀਲਤਾ।</description>
<description xml:lang="pl">Podstawowa funkcjonalność.</description>
<description xml:lang="pt_BR">Função básica</description>
<description xml:lang="ru">Базовая функциональность.</description>
<description xml:lang="ta">அடிப்படை செயலம்சம்.</description>
<description xml:lang="te">ప్రాథమిక ఫంక్షనాలిటి.</description>
<description xml:lang="uk">Основні можливості.</description>
<description xml:lang="zh_CN">基本功能。</description>
<description xml:lang="zh_TW">基本功能。</description>
<display_order>5</display_order>
<grouplist>
<groupid>core</groupid>
<groupid>core</groupid>
</grouplist>
</environment>
</comps>
";


$xml = $head.$list.$boot;


file_put_contents('comps.xml',$xml);

//var_dump($no_arr);

foreach($no_arr as $key => $val)
{
echo 'rm -rf '.$key.$val.";\n";
}


//替换图片
==============================================

1、找到 images/install.img

2、挂在images
mount -o loop -t squashfs install.img /mnt

3、拷贝出内容
mkdir ~/tmp
rsync -av /mnt/ ~/tmp

4、更换图片
cd ~/tmp/usr/share/anaconda/pixmaps

5、重新打包
mksquashfs ~/tmp/ install_v1.img -all-root

6、更替install.img

 

//更换欢迎语
==============================================

1、找到 isolinux/initrd.img

2、解压
mkdir ~/tmp2
cd ~/tmp2
xz -dc ~/centos_1905_micro_6.5/isolinux/initrd.img | cpio -id

3、修改
vi .buildstamp

4、重新打包
find . | cpio -c -o | xz -9 --format=lzma > ~/initrd_v1.img

5、更替initrd.img

posted on 2017-08-14 10:19  运维蚂蚁  阅读(293)  评论(0编辑  收藏  举报