2020-09-13

使用 kickstart 半自動(dòng)化安裝CentOS系統(tǒng)
制作ks.cfg應(yīng)答文件

system-config-kickstart   #centos7利用命令圖型界面生成ks文件
#功能由 system-config-kickstart 包提供
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png
image.png

image.png
image.png
image.png

生成配置文件格式

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$2DigeYTY$dr6c8S9qYgkLpzHxECF2a1
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use CDROM installation media
cdrom
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eh0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=1024
part swap --fstype="swap" --size=2048
part / --fstype="ext4" --size=102400
part /data --fstype="ext4" --size=51200

依照~/anaconda-ks.cfg文件修改ks.cfg

ignoredisk --only-use=sda                            #此行必須指定
zerombr
text                  #系統(tǒng)安裝為命令行模式
reboot             #安裝完成后重啟
clearpart --all --initlabel        #清除原有卷標(biāo)
selinux --disabled #禁用SELinux
firewall --disabled #禁用firewalld
url --url=http://10.0.0.7/centos/os/8/  #系統(tǒng)安裝文件路徑
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda  #此行必須指定
network  --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network  --hostname=centos8.magedu.org
rootpw --iscrypted
$6$j9YhzDUnQVnxaAk8$qv7rkMcPAEbV5yvwsP666DXWYadd3jYjkA9fpxAo9qYotjGGBUclCGoP1TRv
gHBpqgc5n0RypMsPTQnVDcpO01
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
user --name=wang --
password=6oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9p
TogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang"
#autopart --type=lvm      #自動(dòng)創(chuàng)建成邏輯卷
#part / --fstype xfs --size 1 --grow --ondisk sda 可以實(shí)現(xiàn)根自動(dòng)使用所有剩余空間
#創(chuàng)建分區(qū)及文件系統(tǒng)
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024
%packages       #系統(tǒng)安裝時(shí),設(shè)置安裝包
@^minimal-environment
kexec-tools
vim
curl
wget
tree
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda  #anaconda文件,這里設(shè)置的是用戶創(chuàng)建規(guī)則
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
%post                         #安裝后腳本,這里是建立普通用戶centos8,密碼123456
useradd centos8
echo 123456 | passwd --stdin centos8 &> /dev/null
%end
image.png
mkdir –pv /data/myiso 
mount /dev/sr0 /mnt     #將系統(tǒng)安裝iso掛到/mnt下
cp -r /mnt/isolinux/ /data/myiso/ 
tree /data/myiso/ 
/data/myiso/
└── isolinux
    ├── boot.cat
    ├── boot.msg
    ├── grub.conf
    ├── initrd.img
    ├── isolinux.bin
    ├── isolinux.cfg
    ├── ldlinux.c32
    ├── libcom32.c32
    ├── libutil.c32
    ├── memtest
    ├── splash.png
    ├── TRANS.TBL
    ├── vesamenu.c32
    └── vmlinuz

vim /data/myiso/isolinux/isolinux.cfg 
#方法1:應(yīng)答方件放在ISO文件里 
label linux menu 
label ^Auto Install CentOS Linux 8 
kernel vmlinuz  initrd=initrd.img text ks=cdrom:/myks.cfg 
#方法2:應(yīng)答方件放在http服務(wù)器上 
label linux menu 
label ^Auto Install CentOS Linux 8 
kernel vmlinuz append initrd=initrd.img quiet 
ks=http://10.0.0.8/ksdir/centos8.cfg 
label rescue menu 
label ^Rescue a CentOS Linux system 
kernel vmlinuz 
append initrd=initrd.img 
inst.repo=http://10.0.0.7/centos/os/8/ rescue quiet label 
local menu default menu label Boot from ^local drive
localboot 0xffff 
cp /root/myks.cfg /data/myiso/
yum -y install mkisofs 
mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --bootinfo-table -V "CentOS 8.0 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso /data/myiso/  #制作iso文件

實(shí)現(xiàn)pxe安裝雙系統(tǒng)centos6、centos7

準(zhǔn)備工作

先創(chuàng)建ks.cfg 應(yīng)答文件

需要開啟 DHCP服務(wù) TFTP服務(wù) syslinux服務(wù)

配置dhcp

yum -y install dhcp  #centos6、7
dnf -y install dhcp-server #centos8
vim /etc/dhcp/dhcpd.cfg  #配置dhcp服務(wù)
subnet 10.0.0.0 netmask 255.255.255.0 {
  range 10.0.0.26 10.0.0.30;
  option routers 10.0.0.2;    
  next-server 10.0.0.7;   # 指定tftp服務(wù)器
  filename "pxelinux.0";  #指定pxe文件,固定文件名
  option domain-name-servers 180.76.76.76,223.5.5.5;
}
systemctl enable --now dhcp 

配置tftp

yum/dnf -y install tftp-server
systemctl enable --now tftp  #啟動(dòng)tftp

創(chuàng)建pxe文件

cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
# 8需要從iso鏡像中復(fù)制 /isolinux/{ldlinux.c32,libcom32.c32,libutil.c32} 
#到/var/lib/tftpboot/
vim /var/lib/tftpboot/pxelinux.cfg/default #編輯pxe菜單
#default 文件格式,參考isolinux.cfg 修改
default menu.c32
timeout 600
menu title Install CentOS Linux

label linux7
 menu label Auto Install CentOS Linux ^7
 kernel centos7/vmlinuz
 append initrd=centos7/initrd.img ks=http://10.0.0.7/ksdir/7ks.cfg

label linux6
 menu label Auto Install CentOS Linux ^6
 kernel centos6/vmlinuz
 append initrd=centos6/initrd.img ks=http://10.0.0.7/ksdir/6ks.cfg

label local
 menu default
 menu label Boot from ^local drive
 localboot 0xffff


image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容