admin管理员组文章数量:1568305
文章目录
- 前言
- 一、刻录USB
- 二、配置以BIOS方式启动引导
- 2.1 引导文件配置
- 2.2 KS文件配置
- 三、以EFI方式启动引导
- 3.1 引导文件
- 3.2 KS文件
- 四、 总结
前言
之前安装系统,例如在VMware虚拟机中或物理服务器中,都是根据图形界面上的指示进行下一步这类的操作。
现在将无人为干预的U盘自动化安装系统的配置记录一下。
一、刻录USB
刻录需要几样东西,除了U盘以外,另两样则是:
1)ISO镜像文件,这个根据自己的需求下载对应的系统镜像文件即可,本文使用的是CentOS 7镜像;
2)刻录软件,可以选择UltraISO或者Rufus,其具体使用方式,此处不做介绍,可自行百度摸索。
二、配置以BIOS方式启动引导
系统ISO镜像文件刻录到U盘后,此时即可通过它来安装操作系统到服务器上,但这种方式往往在安装过程中需要人工点击时区、目标磁盘、设置账号密码等操作。
此时,我是希望它能全程自动化完成安装过程中所需要配置的内容,无需人为干预的。
那么,就需要以下两个文件的配置,即引导文件和Kickstart文件的配置,来实现这一目的。
2.1 引导文件配置
引导文件,我这边主要修改的便是开机菜单选项的内容(照着前面修改即可,注意路径名必须一致),即添加上一个新的开机选项,并将其设置为默认,其ks文件指向U盘中我们即将配置的Kickstart文件。
引导文件的路径为:USB盘符:/isolinux/syslinux.cfg
default vesamenu.c32
timeout 200 # 默认为600,即菜单选项超时为60秒,这边改为200,即20秒
display boot.msg
...
...
label linux
menu label ^Install CentOS 7
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
label check
menu label Test this ^media & install CentOS 7
#menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
####### 添加的内容 #######
label linux-ks
menu label Kickstart Installation of CentOS 7
menu default # 将其他label的menu default注释掉,这边添加为默认选项
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 inst.ks=hd:LABEL=CentOS\x207\x20x86_64:/centos7-ks-bios.cfg quiet
添加自定义label,设置menu的label(菜单选项显示的文本内容),设置本label为默认选项(注释掉前面其他label的default),当等待时间超时后,系统会进入默认选项。kernel和append的内容照着前面复刻一份即可,但append的后面需注意添加上ks文件的路径,即指向CentOS 7 x86_64/centos7-ks-bios.cfg
文件(\x20
表示空格)
2.2 KS文件配置
Kickstart文件并不是在刻录镜像时自动生成的,而是需要自己单独新建个文件,这边命名就是centos7-ks-bios.cfg
,位置放在U盘根目录下。ks文件的内容,其实可以在一个现有系统中找到/root/anaconda-ks.cfg
,根据该文件做自定义调整;或者安装system-config-kickstart
包,一步步根据需要定制自己的ks文件。【Linux】自定义生成Kickstart(system-config-kickstart)
这边放一个具体示例:
#version=DEVEL
#Install OS instead of upgrade
install
# System authorization information 密码启用shadow方式,使用sha512加密方式
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install 使用文本方式安装,非图形化界面
text
# Run the Setup Agent on first boot
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts 键盘布局
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information 网络配置,这边就配置了dhcp,也可直接定义IP地址
network --bootproto=dhcp --ipv6=auto --onboot=on --activate
#network --bootproto=static --device=eth0 --gateway=192.168.112.254 --ip=192.168.112.20 --nameserver=114.114.114.114 --netmask=255.255.255.0
network --hostname=asdfv
# Root password
# default 000000
rootpw --iscrypted $6$re6WtU5u8cKmIwpY$CJMAKR/cvQ8hDfSRB6eNtEH.qHIBXpzZoli5QCPM2fXZ7kzxxM/6vAQspTtEuvSTxyLoDas97WIqBDI4Ff6ln/
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Disk partitioning information
# 20G 对盘符进行分区,这边可根据实际进行修改,size的单位为MB
part /boot --fstype="xfs" --ondisk=sda --size=1024
part / --fstype="xfs" --ondisk=sda --size=10240
part /data --fstype="xfs" --ondisk=sda --size=5120
part swap --fstype="swap" --ondisk=sda --size=3072
# 安装指定软件包
%packages
@^minimal
@core
@development
net-tools
tree
sysstat
traceroute
iproute
tcpdump
lrzsz
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
# 这边配置,在系统安装完成后需要执行的命令。此处示例为创建本地YUM源
%post
# some configuration after install,eg. yumrepo useradd
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat > /etc/yum.repos.d/base.repo << EOF
[base]
name=iso
basurl=file:///mnt/
gpgckeck=0
enabled=1
EOF
%end
%anaconda
# password policy 密码策略,可根据需要修改
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
# 所有安装及配置完成后,重启
reboot
三、以EFI方式启动引导
3.1 引导文件
若是以EFI方式引导的话,则需要修改
USB:/EFI/BOOT/grub.cfg
文件,添加上和前面相类似的菜单选项,ks文件指向目标。
set default="2" # 设置默认为第3个选项,这个就是数组的下标,从0开始算
...
set timeout=6 # 设置超时为6秒, 单位是秒
...
menuentry 'Kickstart Installation of CentOS 7' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=CENTOS\x207\x20X86_64 inst.ks=hd:LABEL=CENTOS\x207\x20X86_64:/centos7-ks-efi.cfg quiet
initrdefi /images/pxeboot/initrd.img
}
3.2 KS文件
这块内容和前面BIOS的KS文件内容基本一样的,可根据需要进行修改。
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --ipv6=auto --onboot=on --activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$yaZQ9CkRRIukN3ag$DewKZEbd/9Uj3A4E14QgZlli07tXThDi.QAI5i9flVglIQHspYvko1hoPB9Ydv8HuDyqUB7pcH5pDzBZXuNqt.
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
user --name=admin --password=$6$C/y6BU92s1VHuXVA$FOeMdzmRifU1EVOLSFzonkmzWoYXhEallHPiCxmQcjJ94KymP2BNt42FxRjMoSghYBCRAmr15AqArhGJHY/AG/ --iscrypted --uid=1000 --gecos="admin" --gid=1000
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Disk partitioning information
part /boot/efi --fstype="efi" --ondisk=sda --size=200 --fsoptions="umask=0077,shortname=winnt"
# 20G
part /boot --fstype="xfs" --ondisk=sda --size=1024
part / --fstype="xfs" --ondisk=sda --size=10240
part /data --fstype="xfs" --ondisk=sda --size=5120
part swap --fstype="swap" --ondisk=sda --size=3072
%packages
@^minimal
@core
@development
chrony
net-tools
sysstat
tree
%end
%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
reboot
四、 总结
以上就是U盘自动化安装系统的配置,至于将其实际应用一下,这块内容我放到后面一篇文章里【Linux】使用U盘自动化安装Linux(VMware虚拟机)。
版权声明:本文标题:【Linux】Kickstart 配置U盘自动化安装Linux系统 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1727606761a1122685.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论