一、實驗?zāi)康?/h4>
利用u盤引導(dǎo)實現(xiàn)無人值守安裝CentOS系統(tǒng),解決系統(tǒng)管理員因服務(wù)器無自帶光驅(qū)的情況下實現(xiàn)u盤引導(dǎo)安裝,同時安裝系統(tǒng)過程利用網(wǎng)絡(luò)HTTP網(wǎng)絡(luò)服務(wù)提供安裝文件,以達到全程無人值守安裝。
二、實驗準備
首先需參考光盤里的啟動文件,利用啟動文件構(gòu)建一個啟動u盤
[root@CentOS6 /mnt/cdrom/isolinux]#ls
boot.cat initrd.img memtest vesamenu.c32
boot.msg isolinux.bin splash.jpg vmlinuz
grub.conf isolinux.cfg TRANS.TBL
參考此目錄文件制作u盤啟動
[root@CentOS6 /mnt/cdrom/isolinux]#mkdir /app/myiso #創(chuàng)建存放光盤啟動目錄文件夾
[root@CentOS6 /mnt/cdrom/isolinux]#cp * /app/myiso/ #將當前目錄下文件復(fù)制到myiso文件內(nèi)
[root@CentOS6 /mnt/cdrom/isolinux]#cd /app/myiso/
[root@CentOS6 /app/myiso]#ls
boot.cat initrd.img memtest vesamenu.c32
boot.msg isolinux.bin splash.jpg vmlinuz
grub.conf isolinux.cfg TRANS.TBL
生成 .cfg文件,安裝kickstart
# yum install system-config-kickstart
在桌面環(huán)境下配置Kickstart
system-config-kickstart
A. 設(shè)置語言,鍵盤,時區(qū),Root密碼,安裝完畢后重啟等。

1.png
B. 設(shè)置安裝方式,這篇文章介紹的是HTTP方式的安裝,故選擇HTTP

1.png
C. 安裝MBR

1.png
D.設(shè)置分區(qū)

1.png
E.配置網(wǎng)絡(luò)

1.png
F. 認證配置

認證服務(wù).png
G. SELinux 和防火墻配置

禁用防火墻.png
H. 圖形環(huán)境配置

圖形環(huán)境配置.png
I. 軟件包安裝選擇

安裝包.png
J.設(shè)置安裝后運行腳本

設(shè)置安裝后運行腳本.png
K.存盤退出

存盤退出.png
打開/var/www/html/ ks6-mini.cfg 文件進行查看并做修改
[root@CentOS7 /var/www/html/centos]#cat ks6-mini.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://172.18.254.65/centos/6" ##這個選項告訴安裝程序:到服務(wù)器172.18.254.65 的HTTP根目錄下的cdrom 文件夾下尋找安裝介質(zhì)
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel #此條命令必須添加,不然系統(tǒng)會讓用戶手動選擇是否清除所有數(shù)據(jù),這就需要人為干預(yù)了,從而導(dǎo)致自動化過程失??;
# Disk partitioning information
part /boot --fstype="ext4" --size=5000
part / --fstype="ext4" --size=20000
part swap --fstype="swap" --size=2048
%post
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo << EOF
[base]
baseurl=file:///mnt/cdrom
gpgcheck=0
EOF
useradd lai
echo magedu | passwd --stdin lai
%end
%packages
autofs
@core
@workstation-policy
@server-policy
vim
@base
%end
將要生成iso引導(dǎo)啟動的isolinux.cfg文件進行修改,以此達到符合啟動要求
1 default vesamenu.c32
2 #prompt 1
3 timeout 600
4
5 display boot.msg
6
7 menu background splash.jpg
8 menu title Welcome to CentOS 6.9 Automatic Install!
9 menu color border 0 #ffffffff #00000000
10 menu color sel 7 #ffffffff #ff000000
11 menu color title 0 #ffffffff #00000000
12 menu color tabmsg 0 #ffffffff #00000000
13 menu color unsel 0 #ffffffff #00000000
14 menu color hotsel 0 #ff000000 #ffffffff
15 menu color hotkey 7 #ffffffff #ff000000
16 menu color scrollbar 0 #ffffffff #00000000
17
18 label linux
19 menu label Install an ^Mini system
20 kernel vmlinuz
21 append initrd=initrd.img ks=http://172.18.254.65/ks6-mini.cfg #應(yīng)答文件
22 label desktop
23 menu label Install an ^desktop system
24 kernel vmlinuz
25 append initrd=initrd.img ks=http://172.18.254.65/ks6-desktop.cfg #應(yīng)答文件
26 label local
27 menu default
28 menu label Boot from ^local drive
29 localboot 0xffff
指定/app/myiso目錄與文件制作成ISO 9660格式鏡像文件
[root@CentOS6 /app]#mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6.9 x86_64 boot" -b isolinux/isolinux.bin -c 4 --boot-info-table -V "CentOS 6.9 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/centos6_boot.iso /app/myiso/
I: -input-charset not specified, using utf-8 (detected in locale settings)
genisoimage 1.1.9 (Linux)
Scanning /app/myiso/
Scanning /app/myiso/isolinux
Excluded: /app/myiso/isolinux/TRANS.TBL
Excluded by match: /app/myiso/isolinux/boot.cat
Writing: Initial Padblock Start Block 0
Done with: Initial Padblock Block(s) 16
Writing: Primary Volume Descriptor Start Block 16
Done with: Primary Volume Descriptor Block(s) 1
Writing: Eltorito Volume Descriptor Start Block 17
Size of boot image is 4 sectors -> No emulation
Done with: Eltorito Volume Descriptor Block(s) 1
Writing: Joliet Volume Descriptor Start Block 18
Done with: Joliet Volume Descriptor Block(s) 1
Writing: End Volume Descriptor Start Block 19
Done with: End Volume Descriptor Block(s) 1
Writing: Version block Start Block 20
Done with: Version block Block(s) 1
Writing: Path table Start Block 21
Done with: Path table Block(s) 4
Writing: Joliet path table Start Block 25
Done with: Joliet path table Block(s) 4
Writing: Directory tree Start Block 29
Done with: Directory tree Block(s) 2
Writing: Joliet directory tree Start Block 31
Done with: Joliet directory tree Block(s) 2
Writing: Directory tree cleanup Start Block 33
Done with: Directory tree cleanup Block(s) 0
Writing: Extension record Start Block 33
Done with: Extension record Block(s) 1
Writing: The File(s) Start Block 34
21.93% done, estimate finish Fri Sep 15 10:59:56 2017
43.79% done, estimate finish Fri Sep 15 10:59:54 2017
65.71% done, estimate finish Fri Sep 15 10:59:53 2017
87.57% done, estimate finish Fri Sep 15 10:59:53 2017
Total translation table size: 4483
Total rockridge attributes bytes: 1360
Total directory bytes: 2048
Path table size(bytes): 26
Done with: The File(s) Block(s) 22658
Writing: Ending Padblock Start Block 22692
Done with: Ending Padblock Block(s) 150
Max brk space used 0
22842 extents written (44 MB)
[root@CentOS6 ~]#file centos6_boot.iso
centos6_boot.iso: ISO 9660 CD-ROM filesystem data 'CentOS 6.9 x86_64 boot' (bootable)
測試鏡像能否正確引導(dǎo)

選擇鏡像文件.png

成功引導(dǎo).png
安裝成功

image.png
正確引導(dǎo)安裝成功后,我們既可將引導(dǎo)鏡像灌入至u盤
dd if=/dev/sr0 of=/dev/sdb
(注意:dd 后建議sync確保文件寫入磁盤)