自定义kickstart封装到ISO实现完全自动化安装

封装大致流程
0.下载 RHEL7.4 二进制 ISO
1.安装以下ISO工具:
yum install genisoimage isomd5sum syslinux
2.生成kickstart文件
3.把光盘ISO镜像挂载,复制到可编辑目录
4.把KS文件放在ISO的根目录下或者其他地方
5.编辑光盘的isolinux/isolinux.cfg文件,指定ks文件所在位置,设置为默认引导菜单
6.进入到光盘“根目录”重新生成封装ISO:
mkisofs -o ../meida/rhel7ks.iso -b isolinux/isolinux.bin -J -R -l
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table
-eltorito-alt-boot -e images/efiboot.img -no-emul-boot
-graft-points -V "cdrom" -jcharset utf-8 .
7.将 MD5 和植入 ISO:
implantisomd5 rhel7ks.iso

点击查看ks.cfg文件
#version=RHEL7
# Use graphical install
graphical
cdrom
install
#text

#repo --name="AppStream" --baseurl=http://192.168.18.122/rhel8OS/AppStream/
#repo --name="AppStream" --baseurl=cdrom:/AppStream/
reboot
%packages
#@^minimal-environment
#@standard
#kexec-tools
@Base
%end

# Keyboard layouts
keyboard --xlayouts='cn'
# System language
#lang zh_CN.UTF-8
lang en_US.UTF-8

# Network information
#network  --bootproto=static --device=ens160 --ipv6=auto --activate
network  --bootproto=dhcp
network  --hostname=ksinstallrhel74

# Use network installation
#url --url="http://192.168.18.122/rhel8OS/BaseOS/"
#url --url=cdrom:/BaseOS/

# Run the Setup Agent on first boot
firstboot --enable

ignoredisk --only-use=sda
#autopart

# Partition clearing information
clearpart --none --initlabel

# System timezone
timezone Asia/Shanghai --isUtc
auth --passalgo=sha512 --useshadow
#ignoredisk --only-use=sda
# System bootloader configuration
bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
#clearpart --none --initlabel
# Disk partitioning information
#GIVE 100G scsi disk 
part /boot/efi --fstype="efi" --ondisk=sda --size=500 --fsoptions="umask=0077,shortname=winnt"
part pv.5607 --fstype="lvmpv" --ondisk=sda --size=101399
part /boot --fstype="xfs" --ondisk=sda --size=500
volgroup rootvg --pesize=4096 pv.5607
logvol / --fstype="xfs" --size=10240 --name=root --vgname=rootvg
logvol /var --fstype="xfs" --size=10240 --name=var --vgname=rootvg
logvol /home --fstype="xfs" --size=10240 --name=home --vgname=rootvg
logvol swap --fstype="swap" --size=2000 --name=swap  --vgname=rootvg
selinux --disabled
firewall --enabled
# Root password
rootpw --iscrypted $6$jpk4NHQXAnqgyOPB$yvuTxqhhCZrWoVsE.V13cfdTpNfO4FyCRnILo0GietJF3/ENQ9JWtRAm4ZjQON5rsk0u62sxyMR/Mx4Kb.QVu1

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

点击查看isolinux.cfg文件
#default vesamenu.c32
default linux
timeout 60
prompt 1

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 Red Hat Enterprise Linux 7.4
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 ^KS Install Red Hat Enterprise Linux 7.4
  kernel vmlinuz
  append initrd=initrd.img ramdisk_size=8192  inst.stage2=hd:LABEL=cdrom expert ks=hd:LABEL=cdrom:/ks.cfg


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:https://www.redhat.com/sysadmin/optimized-iso-image
参考链接2:https://blog.csdn.net/xhuacmer/article/details/109805719#comments_13898492

posted @ 2022-09-18 12:21  笑傲运维  阅读(600)  评论(0编辑  收藏  举报