[Centos系统] 定制centos镜像

368 0
Honkers 2026-6-3 03:58:50 来自手机 | 显示全部楼层 |阅读模式

准备材料:

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

2.安装genisoimage工具

制作步骤:

1.复制光盘文件

1)挂载iso镜像
创建目录用于挂载光盘:
   

  1. mkdir /root/centos7
复制代码


挂载iso镜像:     
    

  1. mount -o loop CentOS-7.0-1406-x86_64-DVD.iso/root/centos7
复制代码


2)复制光盘文件到编辑目录进行编辑
因为挂载上iso镜像是只读的,如果要编辑,需要将文件复制出来,再编辑。首先创建编辑目录:
     

  1. mkdir /root/centos7_iso
复制代码


复制光盘文件:
     

  1. cp -rf /root/centos7/* /root/centos7_iso/
复制代码


diskinfo文件需求单独拷贝下:     
  

  1.  cp /root/centos7/.discinfo /root/iso
复制代码

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

  1. [root@localhost centos7_iso]# cd /root/centos7_iso/
  2. [root@localhost centos7_iso]# vim ks.cfg
  3. #version=RHEL/CentOS7 by centos7.3
  4. install
  5. cdrom
  6. lang zh_CN.UTF-8
  7. keyboard 'us'
  8. rootpw --iscrypted $6$RmgR38wbFvHVqtwZ$DSMVofI4.v1KJ75bUPnK6gXzugAcQ.lvUSN7RV/ztejiLFHJ1XoISnpM7isS4DldC0f3rpWM2drc1n0IbNUx0.
  9. firewall --disabled
  10. authconfig --enableshadow  --passalgo=sha512
  11. selinux --disabled
  12. timezone Asia/Shanghai
  13. %include /tmp/ks.inc
  14. graphical
  15. firstboot --disable
  16. #reboot --eject
  17. reboot
  18. %packages
  19. @additional-devel
  20. @base
  21. @core
  22. @debugging
  23. @development
  24. @dial-up
  25. @directory-client
  26. @performance
  27. userspace-rcu
  28. screen
  29. dialog
  30. libgcc.i686
  31. glibc.i686
  32. libstdc++.i686
  33. libuuid.i686
  34. tree
  35. iftop
  36. nload
  37. mtools
  38. mkisofs
  39. %end
  40. %pre
  41. var=$(cat /sys/devices/virtual/dmi/id/board_name)
  42. if [ $var == "SC612DI-16F" ];then
  43.     P=--interactive
  44.     DISK_SIZE=`mdadm --detail /dev/md126 | awk '/Array Size *:*/{printf("%d",$4/1024)}'`
  45. elif [ $var == "VirtualBox" ];then
  46.     D=sda
  47.     P="--only-use=$D"
  48.     HDD=/dev/$D
  49.     DISK_SIZE=`fdisk -l $HDD |awk '/Disk.*:.*bytes/{printf("%d",$5/1024/1024)}'`
  50. else
  51.     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;}'`
  52.     P="--only-use=$D"
  53.     HDD=/dev/$D
  54.     if [ $LANG == "en_US.UTF-8" ];then
  55.         DISK_SIZE=`fdisk -l $HDD |awk '/Disk.*:.*bytes/{printf("%d",$5/1024/1024)}'`
  56.     else
  57.         DISK_SIZE=`fdisk -l $HDD |awk 'NR==2 {printf("%d",$4/1024/1024)}'`
  58.     fi
  59. fi
  60. if [ $var == "VirtualBox" ];then
  61.    BOOT_SIZE=512
  62.    SWAP_SIZE=1024
  63.    ROOT_SIZE=--grow
  64. elif [ $var == "SC612DI-16F" ];then
  65.    if [ $DISK_SIZE -lt 460800 ] && [ $DISK_SIZE -gt 205000 ];then
  66.       BOOT_SIZE=512
  67.       SWAP_SIZE=8192
  68.       RUDE_SIZE=10240
  69.    elif [ $DISK_SIZE -lt 205000 ] && [ $DISK_SIZE -gt 102400 ];then
  70.       BOOT_SIZE=512
  71.       SWAP_SIZE=4096
  72.       RUDE_SIZE=5120
  73.    else
  74.       BOOT_SIZE=1024
  75.       SWAP_SIZE=16384
  76.       RUDE_SIZE=20480
  77.    fi
  78.    TMP_SIZE=$[DISK_SIZE-BOOT_SIZE-SWAP_SIZE-RUDE_SIZE]
  79.    ROOT_SIZE="--size=$TMP_SIZE"
  80. else
  81.    if [ $DISK_SIZE -lt 460800 ] && [ $DISK_SIZE -gt 205000 ];then
  82.       BOOT_SIZE=512
  83.       SWAP_SIZE=8192
  84.    elif [ $DISK_SIZE -lt 205000 ] && [ $DISK_SIZE -gt 102400 ];then
  85.       BOOT_SIZE=512
  86.       SWAP_SIZE=4096
  87.    else
  88.       BOOT_SIZE=1024
  89.       SWAP_SIZE=16384
  90.    fi
  91.    ROOT_SIZE=--grow
  92. fi
  93. cat<<-END>/tmp/ks.inc
  94. skipx
  95. zerombr
  96. clearpart --all
  97. ignoredisk $P
  98. bootloader --location=mbr
  99. part /boot --fstype="ext4" --size=$BOOT_SIZE
  100. part swap --fstype="swap" --size=$SWAP_SIZE
  101. part / --fstype="ext4" $ROOT_SIZE
  102. END
  103. %end
  104. %post
  105. eject
  106. reboot
  107. %end
  108. %addon com_redhat_kdump --disable
  109. %end
复制代码

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

  1. [root@localhost centos7_iso]# cd isolinux/
  2. [root@localhost isolinux]# vim isolinux.cfg
  3. default vesamenu.c32
  4. timeout 600
  5. display boot.msg
  6. # Clear the screen when exiting the menu, instead of leaving the menu displayed.
  7. # For vesamenu, this means the graphical background is still displayed without
  8. # the menu itself for as long as the screen remains in graphics mode.
  9. menu clear
  10. menu background splash.png
  11. menu title CentOS Linux 7 -KLFS
  12. menu vshift 8
  13. menu rows 18
  14. menu margin 8
  15. #menu hidden
  16. menu helpmsgrow 15
  17. menu tabmsgrow 13
  18. # Border Area
  19. menu color border * #00000000 #00000000 none
  20. # Selected item
  21. menu color sel 0 #ffffffff #00000000 none
  22. # Title bar
  23. menu color title 0 #ff7ba3d0 #00000000 none
  24. # Press [Tab] message
  25. menu color tabmsg 0 #ff3a6496 #00000000 none
  26. # Unselected menu item
  27. menu color unsel 0 #84b8ffff #00000000 none
  28. # Selected hotkey
  29. menu color hotsel 0 #84b8ffff #00000000 none
  30. # Unselected hotkey
  31. menu color hotkey 0 #ffffffff #00000000 none
  32. # Help text
  33. menu color help 0 #ffffffff #00000000 none
  34. # A scrollbar of some type? Not sure.
  35. menu color scrollbar 0 #ffffffff #ff355594 none
  36. # Timeout msg
  37. menu color timeout 0 #ffffffff #00000000 none
  38. menu color timeout_msg 0 #ffffffff #00000000 none
  39. # Command prompt text
  40. menu color cmdmark 0 #84b8ffff #00000000 none
  41. menu color cmdline 0 #ffffffff #00000000 none
  42. # Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
  43. menu tabmsg Press Tab for full configuration options on menu items.
  44. menu separator # insert an empty line
  45. menu separator # insert an empty line
  46. #label linux
  47. #  menu label ^Install CentOS Linux 7
  48. #  kernel vmlinuz
  49.   #append initrd=initrd.img inst.stage2=hd:LABEL=ENTOS7 quiet
  50. #  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
  51. label custom
  52.   menu label [^C]ustom 7 by autoinstall
  53.   menu default
  54.   kernel vmlinuz
  55. #  append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7:/isolinux/ks.cfg inst.ks=cdrom:/isolinux/ks.cfg
  56.   append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7 inst.ks=hd:LABEL=CENTOS7:/ks.cfg quiet
  57.   #append initrd=initrd.img inst.ks=hd:LABEL=CENTOS7:/ks.cfg inst.stage2=hd:LABEL=CENTOS7 quiet
  58.   #append initrd=initrd.img inst.ks=hd:sdb4=sdb4:/ks.cfg inst.stage2=hd:sdb4=sdb4 quiet
  59. #label check
  60. #  menu label Test this ^media & install CentOS Linux 7
  61. #  menu default
  62. #  kernel vmlinuz
  63. #  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
  64. menu separator # insert an empty line
  65. # utilities submenu
  66. menu begin ^Troubleshooting
  67.   menu title Troubleshooting
  68. label vesa
  69.   menu indent count 5
  70.   menu label Install CentOS Linux 7 in ^basic graphics mode
  71.   text help
  72.     Try this option out if you're having trouble installing
  73.     CentOS Linux 7.
  74.   endtext
  75.   kernel vmlinuz
  76.   append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet
  77. label rescue
  78.   menu indent count 5
  79.   menu label ^Rescue a CentOS Linux system
  80.   text help
  81.     If the system will not boot, this lets you access files
  82.     and edit config files to try to get it booting again.
  83.   endtext
  84.   kernel vmlinuz
  85.   append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet
  86. label memtest
  87.   menu label Run a ^memory test
  88.   text help
  89.     If your system is having issues, a problem with your
  90.     system's memory may be the cause. Use this utility to
  91.     see if the memory is working correctly.
  92.   endtext
  93.   kernel memtest
  94. menu separator # insert an empty line
  95. label local
  96.   menu label Boot from ^local drive
  97.   localboot 0xffff
  98. menu separator # insert an empty line
  99. menu separator # insert an empty line
  100. label returntomain
  101.   menu label Return to ^main menu
  102.   menu exit
  103. 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文件

  1. [root@localhost centos7_iso]# cd /root/centos7_iso/
  2. [root@localhost centos7_iso]# cp /root/centos7_iso/repodata/*comps.xml comps.xml
复制代码


3)清空repodata目录

  1. [root@localhost centos7_iso]# rm -rf repodata/*
复制代码


4)重新生成源文件

  1. [root@localhost centos7_iso]# createrepo -g comps.xml .
复制代码


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

  1. [root@localhost centos7_iso]# cd /root/centos7_iso/
  2. [root@localhost centos7_iso]# cp /root/centos7_iso/repodata/*comps.xml comps.xml
  3. [root@localhost centos7_iso]# vim comps.xml 
复制代码


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

  1. [root@localhost centos7_iso]# rm -rf repodata/*
复制代码


4)重新生成源文件

  1. [root@localhost centos7_iso]# createrepo -g comps.xml .
复制代码

5.生成镜像
 

  1. 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 .
复制代码

 

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行