定制centos镜像

准备材料:

1.CentOS-7.0-1406-x86_64-DVD.iso

2.安装genisoimage工具

制作步骤:

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文件需求单独拷贝下:     
  

 cp /root/centos7/.discinfo /root/iso

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

[root@localhost centos7_iso]# cd /root/centos7_iso/
[root@localhost centos7_iso]# vim ks.cfg

#version=RHEL/CentOS7 by centos7.3
install
cdrom
lang zh_CN.UTF-8
keyboard 'us'
rootpw --iscrypted $6$RmgR38wbFvHVqtwZ$DSMVofI4.v1KJ75bUPnK6gXzugAcQ.lvUSN7RV/ztejiLFHJ1XoISnpM7isS4DldC0f3rpWM2drc1n0IbNUx0.
firewall --disabled
authconfig --enableshadow  --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai

%include /tmp/ks.inc
graphical
firstboot --disable
#reboot --eject
reboot
%packages
@additional-devel
@base
@core
@debugging
@development
@dial-up
@directory-client
@performance
userspace-rcu
screen
dialog
libgcc.i686
glibc.i686
libstdc++.i686
libuuid.i686
tree
iftop
nload
mtools
mkisofs
%end

%pre

var=$(cat /sys/devices/virtual/dmi/id/board_name)
if [ $var == "SC612DI-16F" ];then
    P=--interactive
    DISK_SIZE=`mdadm --detail /dev/md126 | awk '/Array Size *:*/{printf("%d",$4/1024)}'`
elif [ $var == "VirtualBox" ];then
    D=sda
    P="--only-use=$D"
    HDD=/dev/$D
    DISK_SIZE=`fdisk -l $HDD |awk '/Disk.*:.*bytes/{printf("%d",$5/1024/1024)}'`
else
    D=`ls -ld /sys/block/sd?|grep -v usb|awk -F/ '{if(index($0,"1f.2")>0){print $NF;exit 0;}if(NR==1)D=$NF;}'`
    P="--only-use=$D"
    HDD=/dev/$D
    if [ $LANG == "en_US.UTF-8" ];then
        DISK_SIZE=`fdisk -l $HDD |awk '/Disk.*:.*bytes/{printf("%d",$5/1024/1024)}'`
    else
        DISK_SIZE=`fdisk -l $HDD |awk 'NR==2 {printf("%d",$4/1024/1024)}'`
    fi
fi

if [ $var == "VirtualBox" ];then
   BOOT_SIZE=512
   SWAP_SIZE=1024
   ROOT_SIZE=--grow
elif [ $var == "SC612DI-16F" ];then
   if [ $DISK_SIZE -lt 460800 ] && [ $DISK_SIZE -gt 205000 ];then
      BOOT_SIZE=512
      SWAP_SIZE=8192
      RUDE_SIZE=10240
   elif [ $DISK_SIZE -lt 205000 ] && [ $DISK_SIZE -gt 102400 ];then
      BOOT_SIZE=512
      SWAP_SIZE=4096
      RUDE_SIZE=5120
   else
      BOOT_SIZE=1024
      SWAP_SIZE=16384
      RUDE_SIZE=20480
   fi
   TMP_SIZE=$[DISK_SIZE-BOOT_SIZE-SWAP_SIZE-RUDE_SIZE]
   ROOT_SIZE="--size=$TMP_SIZE"
else
   if [ $DISK_SIZE -lt 460800 ] && [ $DISK_SIZE -gt 205000 ];then
      BOOT_SIZE=512
      SWAP_SIZE=8192
   elif [ $DISK_SIZE -lt 205000 ] && [ $DISK_SIZE -gt 102400 ];then
      BOOT_SIZE=512
      SWAP_SIZE=4096
   else
      BOOT_SIZE=1024
      SWAP_SIZE=16384
   fi
   ROOT_SIZE=--grow
fi

cat<<-END>/tmp/ks.inc
skipx
zerombr
clearpart --all
ignoredisk $P
bootloader --location=mbr
part /boot --fstype="ext4" --size=$BOOT_SIZE
part swap --fstype="swap" --size=$SWAP_SIZE
part / --fstype="ext4" $ROOT_SIZE
END
%end

%post
eject
reboot
%end

%addon com_redhat_kdump --disable
%end

3.进入isolinux目录,编辑isolinux.cfg文件,整个文件代码如下:

[root@localhost centos7_iso]# cd isolinux/
[root@localhost isolinux]# 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 -KLFS
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
#  menu label ^Install CentOS Linux 7
#  kernel vmlinuz
  #append initrd=initrd.img inst.stage2=hd:LABEL=ENTOS7 quiet
#  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet

label custom
  menu label [^C]ustom 7 by autoinstall
  menu default
  kernel vmlinuz
#  append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7:/isolinux/ks.cfg inst.ks=cdrom:/isolinux/ks.cfg
  append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7 inst.ks=hd:LABEL=CENTOS7:/ks.cfg quiet
  #append initrd=initrd.img inst.ks=hd:LABEL=CENTOS7:/ks.cfg inst.stage2=hd:LABEL=CENTOS7 quiet
  #append initrd=initrd.img inst.ks=hd:sdb4=sdb4:/ks.cfg inst.stage2=hd:sdb4=sdb4 quiet
#label check
#  menu label Test this ^media & install CentOS Linux 7
#  menu default
#  kernel vmlinuz
#  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet

menu separator # insert an empty line

# utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting

label vesa
  menu indent count 5
  menu label Install CentOS Linux 7 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=CentOS\x207\x20x86_64 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=CentOS\x207\x20x86_64 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标识的是系统按照介质位置,这里使用hd:LABEL表明寻找的是label为CENTOS7的安装介质,使用LABEL关键字的好处是可以精确指定安装介质,为什么label是CENTOS7,是因为我在制作光盘镜像的时候指定的,方法在后面有介绍。
 

4.修改镜像源配置
1)将需要增加的rpm软件包放到Packages目录下面
2)复制comps.xml文件

[root@localhost centos7_iso]# cd /root/centos7_iso/
[root@localhost centos7_iso]# cp /root/centos7_iso/repodata/*comps.xml comps.xml


3)清空repodata目录

[root@localhost centos7_iso]# rm -rf repodata/*


4)重新生成源文件

[root@localhost centos7_iso]# createrepo -g comps.xml .


注意:
如果是需要删除软件包,则步骤是:
1)将需要删除的rpm软件包从Packages目录下面删除
2)复制comps.xml文件

[root@localhost centos7_iso]# cd /root/centos7_iso/
[root@localhost centos7_iso]# cp /root/centos7_iso/repodata/*comps.xml comps.xml
[root@localhost centos7_iso]# vim comps.xml 


此时需要编译comps.xml文件将删除的包名从comps.xml文件里面删除
3)清空repodata目录

[root@localhost centos7_iso]# rm -rf repodata/*


4)重新生成源文件

[root@localhost centos7_iso]# createrepo -g comps.xml .

5.生成镜像
 

genisoimage -v -cache-inodes -joliet-long -R -J -T -V CENTOS7 -o /root/CentOS-7-x86_64_Custom.iso -c isolinux/boot.cat -bisolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -b images/efiboot.img -no-emul-boot .

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值