1. 复制光盘文件

1)挂载iso镜像

#创建目录用于挂载光盘
mkdir /root/centos7
#挂载iso镜像
mount -o loop CentOS-7.0-1406-x86_64-DVD.iso /root/centos7

2)复制光盘文件到编辑目录进行编辑

因为挂载上iso镜像是只读的,如果要编辑,需要将文件复制出来,再编辑。

#首先创建编辑目录:
mkdir /root/centos7_iso
#复制光盘文件:
cp -rf /root/centos7/* /root/centos7_iso/
#diskinfo treeinfo文件需单独拷贝下:
cp /root/centos7/.discinfo /root/centos7_iso/
cp /root/centos7/.treeinfo /root/centos7_iso/

2. 编辑ks.cfg文件

系统安装的时候,按照ks.cfg文件的内容进行安装,我们把ks.cfg文件放到isolinux目录下:

cd /root/centos7_iso/isolinux
vim ks-init.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$JtB/A66X$GCT7X3FCJVAPGd3sEY0mx0
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use cdrom installation media
cdrom
# Use text mode install
#text
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

#firstboot --enable
#ignoredisk --only-use=sda

# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0 --onboot=no
network --hostname=localhost.localdomain
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="-quiet" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
#part /boot --fstype="xfs" --size=2048
#part swap --fstype="swap" --size=4096
##part / --fstype="xfs" --grow --size=1
#part pv.01 --size=1 --grow
#volgroup vg_root pv.01
#logvol / --vgname=vg_root --size=1 --grow --name=lv_root
#clearpart --initlabel --list=sda1
#为了兼容mbr方式和EFI方式,同时创建了/boot和/boot/efi分区
part /boot --fstype="xfs" --ondisk=sda --size=1024
part /boot/efi --fstype="xfs" --ondisk=sda --size=1024
part pv.363 --fstype="lvmpv" --ondisk=sda --size=1 --grow
volgroup df --pesize=4096 pv.363
logvol swap --fstype="swap" --size=4096 --name=swap --vgname=df
logvol /home --fstype="xfs" --size=512000 --name=home --vgname=df
logvol / --fstype="xfs" --size=1 --grow --name=root --vgname=df

%packages
@core --optional
chrony
kexec-tools
@wcg-tools
@wcg
@segw
%end

%pre

%end

%post
/home/wcg/initWCGOS.sh
%end
vim ks-recovery.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$JtB/A66X$GCT7X3FCJVAPGd3sEY0mx0
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use cdrom installation media
cdrom
# Use text mode install
#text
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

#firstboot --enable
#ignoredisk --only-use=sda

# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0 --onboot=no
network --hostname=localhost.localdomain
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="-quiet" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
#clearpart --all --initlabel
# Disk partitioning information
#part /boot --fstype="xfs" --size=2048
#part swap --fstype="swap" --size=4096
##part / --fstype="xfs" --grow --size=1
#part pv.01 --size=1 --grow
#volgroup vg_root pv.01
#logvol / --vgname=vg_root --size=1 --grow --name=lv_root
#clearpart --list=sda1
part /boot --fstype="xfs" --ondisk=sda --size=1024
part /boot/efi --fstype="xfs" --ondisk=sda --size=1024
part pv.18 --fstype="lvmpv" --noformat --onpart=sda2
part pv.19 --fstype="lvmpv" --ondisk=sda --size=1 --grow
volgroup df --noformat --useexisting
volgroup li --pesize=4096 pv.19
logvol swap --fstype="swap" --size=4086 --name=swap --vgname=li
logvol / --fstype="xfs" --size=1 --grow --name=root --vgname=df --fsoptions="/dev/mapper/df-home                   xfs     defaults        0 0"

%packages
@core --optional
chrony
kexec-tools
@wcg-tools
@wcg
@segw
%end

%pre

%end

%post
/home/wcg/initWCGOS.sh
%end

3. 配置mbr引导方式

#编辑isolinux目录下的isolinux.cfg文件,添加自己的内容,在isolinux.cfg文件中label linux下面添加自己的labe
vim isolinux.cfg
default vesamenu.c32
timeout 600

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title CentOS Linux 7 for WCG
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label linux for ks-init
  menu label Install CentOS7.3 for WCG with KS-init
  menu default
  kernel vmlinuz
  #append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
  #append initrd=initrd.img ks=cdrom:/isolinux/ks.cfg
  #append initrd=initrd.img ks=hd:LABEL=WCGOS/isolinux/ks.cfg
  append initrd=initrd.img inst.stage2=hd:LABEL=WCGOS inst.ks=hd:LABEL=WCGOS:/isolinux/ks-init.cfg

label linux for ks-recovery
  menu label Install CentOS7.3 for WCG with KS-recovery
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=WCGOS inst.ks=hd:LABEL=WCGOS:/isolinux/ks-recovery.cfg

label linux
  menu label Install CentOS7.3 for WCG with ^GUI
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=WCGOS quiet

label check
  menu label Test this ^media & install CentOS7.3 for WCG
#menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=WCGOS rd.live.check quiet
#append initrd=initrd.img ks=cdrom:/isolinux/ks.cfg rd.live.check

menu separator # insert an empty line

# utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting

label vesa
  menu indent count 5
  menu label Install CentOS7.3 for WCG in ^basic graphics mode
  text help
  Try this option out if you're having trouble installing
  CentOS Linux 7.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=WCGOS xdriver=vesa nomodeset quiet

label rescue
  menu indent count 5
  menu label ^Rescue a CentOS Linux system
  text help
  If the system will not boot, this lets you access files
  and edit config files to try to get it booting again.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=WCGOS rescue quiet

label memtest
  menu label Run a ^memory test
  text help
  If your system is having issues, a problem with your
  system's memory may be the cause. Use this utility to
  see if the memory is working correctly.
  endtext
  kernel memtest

menu separator # insert an empty line

label local
  menu label Boot from ^local drive
  localboot 0xffff

menu separator # insert an empty line
menu separator # insert an empty line

label returntomain
  menu label Return to ^main menu
  menu exit

menu end

注意点: 1)memu label 后面的内容是在光盘引导起来菜单的内容,^后面的字母是菜单的快捷键 2)通过inst.ks关键字指明ks.cfg文件位置 3)inst.stages2标识的是系统按照介质位置

4. 配置EFI引导方式

#进入光盘目录EFI/BOOT/,编辑grub.cfg文件,添加自己的菜单
menuentry 'Install CentOS 7' --class fedora--class gnu-linux --class gnu --class os {
       linuxefi /p_w_picpaths/pxeboot/vmlinuz inst.stage2=hd:LABEL=WCGOS quiet
       initrdefi /p_w_picpaths/pxeboot/initrd.img
}
menuentry 'Install CentOS 7 custom dongfeng' --class fedora --class gnu-linux --class gnu --class os {
       linuxefi /p_w_picpaths/pxeboot/vmlinuz inst.ks=cdrom:/isolinux/ks-init.cfg inst.stage2=hd:LABEL=WCGOS quiet
       initrdefi /p_w_picpaths/pxeboot/initrd.img
}

5. 定制rpm

vim comps.xml
<?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="en_GB">Core</name>
    <description>Smallest possible installation.</description>
    <default>false</default>
    <uservisible>false</uservisible>
    <packagelist>
      <packagereq type="mandatory">audit</packagereq>
      <packagereq type="mandatory">basesystem</packagereq>
      <packagereq type="mandatory">bash</packagereq>
      <packagereq type="mandatory">biosdevname</packagereq>
      <packagereq type="mandatory">btrfs-progs</packagereq>
      <packagereq type="mandatory">coreutils</packagereq>
      <packagereq type="mandatory">cronie</packagereq>
      <packagereq type="mandatory">curl</packagereq>
      <packagereq type="mandatory">dhclient</packagereq>
      <packagereq type="mandatory">e2fsprogs</packagereq>
      <packagereq type="mandatory">filesystem</packagereq>
      <packagereq type="mandatory">firewalld</packagereq>
      <packagereq type="mandatory">glibc</packagereq>
      <packagereq type="mandatory">hostname</packagereq>
      <packagereq type="mandatory">initscripts</packagereq>
      <packagereq type="mandatory">iproute</packagereq>
      <packagereq type="mandatory">iprutils</packagereq>
      <packagereq type="mandatory">iptables</packagereq>
      <packagereq type="mandatory">iputils</packagereq>
      <packagereq type="mandatory">irqbalance</packagereq>
      <packagereq type="mandatory">kbd</packagereq>
      <packagereq type="mandatory">kexec-tools</packagereq>
      <packagereq type="mandatory">less</packagereq>
      <packagereq type="mandatory">man-db</packagereq>
      <packagereq type="mandatory">ncurses</packagereq>
      <packagereq type="mandatory">openssh-clients</packagereq>
      <packagereq type="mandatory">openssh-server</packagereq>
      <packagereq type="mandatory">parted</packagereq>
      <packagereq type="mandatory">passwd</packagereq>
      <packagereq type="mandatory">plymouth</packagereq>
      <packagereq type="mandatory">policycoreutils</packagereq>
      <packagereq type="mandatory">procps-ng</packagereq>
      <packagereq type="mandatory">rootfiles</packagereq>
      <packagereq type="mandatory">rpm</packagereq>
      <packagereq type="mandatory">rsyslog</packagereq>
      <packagereq type="mandatory">selinux-policy-targeted</packagereq>
      <packagereq type="mandatory">setup</packagereq>
      <packagereq type="mandatory">shadow-utils</packagereq>
      <packagereq type="mandatory">sudo</packagereq>
      <packagereq type="mandatory">systemd</packagereq>
      <packagereq type="mandatory">tar</packagereq>
      <packagereq type="mandatory">tuned</packagereq>
      <packagereq type="mandatory">util-linux</packagereq>
      <packagereq type="mandatory">vim-minimal</packagereq>
      <packagereq type="mandatory">xfsprogs</packagereq>
      <packagereq type="mandatory">yum</packagereq>
      <packagereq type="mandatory">aic94xx-firmware</packagereq>
      <packagereq type="mandatory">alsa-firmware</packagereq>
      <packagereq type="mandatory">bfa-firmware</packagereq>
      <packagereq type="mandatory">dracut-config-rescue</packagereq>
      <packagereq type="mandatory">ivtv-firmware</packagereq>
      <packagereq type="mandatory">iwl100-firmware</packagereq>
      <packagereq type="mandatory">iwl1000-firmware</packagereq>
      <packagereq type="mandatory">iwl105-firmware</packagereq>
      <packagereq type="mandatory">iwl135-firmware</packagereq>
      <packagereq type="mandatory">iwl2000-firmware</packagereq>
      <packagereq type="mandatory">iwl2030-firmware</packagereq>
      <packagereq type="mandatory">iwl3160-firmware</packagereq>
      <packagereq type="mandatory">iwl3945-firmware</packagereq>
      <packagereq type="mandatory">iwl4965-firmware</packagereq>
      <packagereq type="mandatory">iwl5000-firmware</packagereq>
      <packagereq type="mandatory">iwl5150-firmware</packagereq>
      <packagereq type="mandatory">iwl6000-firmware</packagereq>
      <packagereq type="mandatory">iwl6000g2a-firmware</packagereq>
      <packagereq type="mandatory">iwl6000g2b-firmware</packagereq>
      <packagereq type="mandatory">iwl6050-firmware</packagereq>
      <packagereq type="mandatory">iwl7260-firmware</packagereq>
      <packagereq type="mandatory">iwl7265-firmware</packagereq>
      <packagereq type="mandatory">kernel-tools</packagereq>
      <packagereq type="mandatory">libertas-sd8686-firmware</packagereq>
      <packagereq type="mandatory">libertas-sd8787-firmware</packagereq>
      <packagereq type="mandatory">libertas-usb8388-firmware</packagereq>
      <packagereq type="mandatory">libsysfs</packagereq>
      <packagereq type="mandatory">linux-firmware</packagereq>
      <packagereq type="mandatory">microcode_ctl</packagereq>
      <packagereq type="mandatory">NetworkManager</packagereq>
      <packagereq type="mandatory">NetworkManager-team</packagereq>
      <packagereq type="mandatory">NetworkManager-tui</packagereq>
      <packagereq type="mandatory">NetworkManager-wifi</packagereq>
      <packagereq type="mandatory">postfix</packagereq>
      <packagereq type="mandatory">ql2100-firmware</packagereq>
      <packagereq type="mandatory">ql2200-firmware</packagereq>
      <packagereq type="mandatory">ql23xx-firmware</packagereq>
      <packagereq type="mandatory">rdma</packagereq>
      <packagereq type="mandatory">dracut-config-generic</packagereq>
      <packagereq type="mandatory">dracut-fips</packagereq>
      <packagereq type="mandatory">dracut-fips-aesni</packagereq>
      <packagereq type="mandatory">dracut-network</packagereq>
      <packagereq type="mandatory">openssh-keycat</packagereq>
      <packagereq type="mandatory">selinux-policy-mls</packagereq>
      <packagereq type="mandatory">tboot</packagereq>
    </packagelist>
  </group>
  <group>
	<id>wcg-tools</id>
	<name>WCG-Tools</name>
	<name xml:lang="en_GB">WCG-Tools</name>
	<description>WCG Tools installation.</description>
	<default>false</default>
	<uservisible>false</uservisible>
	<packagelist>
		<packagereq type="mandatory">curl</packagereq>
		<packagereq type="mandatory">fcgi</packagereq>
		<packagereq type="mandatory">gsoap</packagereq>
		<packagereq type="mandatory">hiredis</packagereq>
		<packagereq type="mandatory">keepalived</packagereq>
		<packagereq type="mandatory">lksctp-tools</packagereq>
		<packagereq type="mandatory">nginx</packagereq>
		<packagereq type="mandatory">redis</packagereq>
		<packagereq type="mandatory">spawn-fcgi</packagereq>
		<packagereq type="mandatory">tftp</packagereq>
		<packagereq type="mandatory">tftp-server</packagereq>
		<packagereq type="mandatory">xinetd</packagereq>
		<packagereq type="mandatory">vconfig</packagereq>
		<packagereq type="mandatory">net-tools</packagereq>
		<packagereq type="mandatory">tmux</packagereq>
		<packagereq type="mandatory">lrzsz</packagereq>
		<packagereq type="mandatory">tcpdump</packagereq>
		<packagereq type="mandatory">htop</packagereq>
		<packagereq type="mandatory">sysstat</packagereq>
		<packagereq type="mandatory">epel-release</packagereq>
	</packagelist>
  </group>
  <group>
    <id>wcg</id>
	<name>WCG</name>
	<name xml:lang="en_GB">WCG</name>
    <description>WCG installation.</description>
	<default>false</default>
	<uservisible>false</uservisible>
	<packagelist>
        <packagereq type="mandatory">WCG</packagereq>
	</packagelist>
  </group>
  <group>
	<id>segw</id>
	<name>SeGW</name>
	<name xml:lang="en_GB">SeGW</name>
	<description>SeGW installation.</description>
	<default>false</default>
	<uservisible>false</uservisible>
	<packagelist>
		<packagereq type="mandatory">strongswan</packagereq>
	</packagelist>
  </group>
  <environment>
    <id>miniwcg</id>
    <name>Minimal Install for WCG</name>
    <description>Basic functionality for WCG.</description>
    <display_order>5</display_order>
    <grouplist>
      <groupid>core</groupid>
	</grouplist>
	<grouplist>
	  <groupid>wcg-tools</groupid>
	</grouplist>
	<grouplist>
	  <groupid>wcg</groupid>
	</grouplist>
	<grouplist>
	  <groupid>segw</groupid>
	</grouplist>
  </environment>
</comps>
sed -ri '/xml:lang/{/en_GB|zh_CN/!d}' isolinux/comps.xml
createrepo -v -g isolinux/comps.xml .

5. 生成iso镜像

mkisofs -R -J -T -v -no-emul-boot --boot-load-size 4 --boot-info-table -V "WCGOS" -b isolinux/isolinux.bin -c isolinux/boot.cat -o ../WCGOS.iso -eltorito-alt-boot -b p_w_picpaths/efiboot.img -no-emul-boot .
isohybrid -e 2 WCGOS.iso
implantisomd5 WCGOS.iso