自制centos7自启动镜像

  1. 准备一个ISO,拷贝其中所有内容

mount /dev/sr0 /mnt
mkdir /mkos
cp -ar /mnt/* /mkos/
  1. 准备ks文件

新安装一个操作系统后,/root会有一个ks模板:anaconda.ks,参考红帽官方文档,魔改它

https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/8/html/performing_an_advanced_rhel_installation/_kickstart_references

最小化ks

# cat /mkos/.ks.santiagod
#version=RHEL7 minimal
# Use graphical/text install  #图形化/字符安装界面
#text
graphical

#使用系统上的第一个光驱执行安装,光盘安装配置
cdrom
#装机使用的yum源
#repo --name="centos7" --baseurl=file:///run/install/repo

#要实际运行安装,必须指定 cdrom、harddrive、hmc、nfs、liveimg 或 url 之一
#url --url=file:///run/install/repo/
#跑流程用,跳过url引起的的网络激活面板
#network --device eth0 --bootproto=dhcp --onboot=yes 

#最小化安装,及其他预装应用
%packages
@^minimal
kexec-tools
bash-completion

curl
wget
tar
unzip
ipmitool

make
gcc

%end

#使用美式键盘
keyboard --xlayouts='us'
#系统默认语言设置,即环境变量$LANG,--addsupport添加对附加语言的支持
lang en_US.UTF-8 --addsupport=zh_CN

#设置主机名
network  --hostname=santiagod.ks


#enable时,系统第一次引导时启动 Initial Setup,设置语言、鼠标、键盘、root 密码、安全级别、时区以及默认网络配置。默认为disable
firstboot --disable

#使用这个选项在没有用户互动的情况下接受最终用户许可证协议(End User License Agreement,EULA)。指定这个选项可防止 Initial Setup 在完成安装并第一次重启系统后提示您接受该许可证
eula --agreed

#系统时区上海,使用UTC时间,默认开启时间同步
timezone Asia/Shanghai --isUtc

# Root password: Admin123!
rootpw --iscrypted $6$uMfDCfQnqrZgk/yL$F.DkU0TF2k14QNqLUv.cc8X16ZUXGe/8Q./rspkY1tKnmOywrgcBx.eEA7u9oWT/u2T6jzNM410EL1Uy5oPk9/

#禁用selinux与firewalld
firewall --disabled
selinux  --disabled

#安装完成后,重启系统
#--eject - 在重新启动前尝试弹出可引导介质(DVD、USB 或其他介质)
reboot --eject

%include /tmp/part-include

#禁用kdump
%addon com_redhat_kdump --disable --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


#------------------------------------------------------------------------------------------------------------------------------------------------------
%pre

###设置系统盘
#找到大于32G的盘;测试语句,非sda盘即sdb盘
vgname=santiagod
disk=$(while read line;do awk 'BEGIN{} {if ($3 >= 33554432 && $2 == 0) print $4} END{}';done < /proc/partitions|grep -Ew 'sda|vda|hda'
#不可用于U盘,此项可能格式化U盘:disk=$(while read line;do awk 'BEGIN{} {if ($3 >= 33554432 && $2 == 0) print $4} END{}';done < /proc/partitions|grep -Ew 'sda|vda|hda' || while read line;do awk 'BEGIN{} {if ($3 >= 33554432 && $2 == 0) print $4} END{}';done < /proc/partitions|grep -Ew 'sdb|vdb|hdb' )
#disk=sda,vda,hda

cat > /tmp/part-include << EOF_PART
clearpart --all --initlabel

#基于 UEFI 的 AMD64、Intel 64 和 64 位 ARM 需要 200 MiB EFI 系统分区。推荐的最小值是 200 MiB,默认大小为 600 MiB,最大为 60
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值