CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统

一、实验目的

利用u盘引导实现无人值守安装CentOS系统,解决系统管理员因服务器无自带光驱的情况下实现u盘引导安装,同时安装系统过程利用网络HTTP网络服务提供安装文件,以达到全程无人值守安装。

二、实验准备

首先需参考光盘里的启动文件,利用启动文件构建一个启动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 #创建存放光盘启动目录文件夹
[root@CentOS6 /mnt/cdrom/isolinux]#cp * /app/myiso/   #将当前目录下文件复制到myiso文件内
[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

在桌面环境下配置Kickstart

system-config-kickstart

A. 设置语言,键盘,时区,Root密码,安装完毕后重启等。

CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第1张图片
1.png

B. 设置安装方式,这篇文章介绍的是HTTP方式的安装,故选择HTTP

CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第2张图片
1.png

C. 安装MBR

CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第3张图片
1.png

D.设置分区


CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第4张图片
1.png

E.配置网络

CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第5张图片
1.png

F. 认证配置


CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第6张图片
认证服务.png

G. SELinux 和防火墙配置


CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第7张图片
禁用防火墙.png

H. 图形环境配置


CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第8张图片
图形环境配置.png

I. 软件包安装选择


CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第9张图片
安装包.png

J.设置安装后运行脚本


CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第10张图片
设置安装后运行脚本.png

K.存盘退出


CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第11张图片
存盘退出.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" ##这个选项告诉安装程序:到服务器172.18.254.65 的HTTP根目录下的cdrom 文件夹下寻找安装介质
# 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 #此条命令必须添加,不然系统会让用户手动选择是否清除所有数据,这就需要人为干预了,从而导致自动化过程失败;
# 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引导启动的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 #应答文件
 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 #应答文件
 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)

测试镜像能否正确引导

CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第12张图片
选择镜像文件.png
CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第13张图片
成功引导.png

安装成功

CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统_第14张图片
image.png

正确引导安装成功后,我们既可将引导镜像灌入至u盘
dd if=/dev/sr0 of=/dev/sdb
(注意:dd 后建议sync确保文件写入磁盘)

你可能感兴趣的:(CentOS 6.9下U盘引导启动+Kickstart无人值守安装操作系统)