linux 镜像自动安装,定制centos7安装镜像 实现光盘自动安装

使用场景:

在没有网络,不能使用kickstart或cobbler自动化部署的环境中,只有U盘或光驱的时候。

制作场景:

由于我们要制作centos7系统的定制系统,所以我们要在centos7宿主机上进行。避免干扰,提高成功的几率

第一:准备完整的安装镜像CentOS-7-x86_64-DVD-1708.iso,挂载到虚拟机,并同时创建一个用于编辑存放的目录centos7

mkdir -p /home/centos7

mount /dev/cdrom /mnt

cd /mnt && ls -l

#常见目录用途说明

isolinux:存放光盘启动时的安装界面信息

images:包含了必要的启动映像文件

Packages:存放安装软件包及信息

repodata:存放rpm包的依赖信息

.discinfo:此文件是安装介质的识别信息

第二:复制光盘文件到可编辑目录centos7

cp -rf /mnt/* /home/centos7 #这种复制方法不会复制.开头的隐藏文件

#.diskinfo文件需求单独拷贝下: #可做可不做,这是一步无意义的操作

cp /mnt/.discinfo /home

第三:编辑响应文件ks.cfg文件(系统安装的时候,按照ks.cfg文件的内容进行安装,我们把ks.cfg文件放到isolinux目录下:)

cd /centos7/isolinux

vim ks.cfg

#version=RHEL/CentOS7.4 by wsfnk

install

# Keyboard layouts

keyboard 'us'

# Reboot after installation

reboot

# Run the Setup Agent on first boot

firstboot --enable

# Network information

#network --bootproto=dhcp --device=enp2s0 --onboot=off --ipv6=auto

#network --hostname=localhost.localdomain

# Root password

rootpw --plaintext 1234

# System timezone

timezone Asia/Shanghai --isUtc

# System language

lang en_US

# Firewall configuration

firewall --disabled

# System authorization information

auth --useshadow --passalgo=sha512

# Use CDROM installation media

cdrom

# Use graphical install #使用文本界面安装

text

# Use graphical install #使用图形界面安装

#graphical

# SELinux configuration

selinux --disabled

# Do not configure the X Window System

skipx

# System bootloader configuration

ignoredisk --only-use=sda

bootloader --location=mbr

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information

part /boot --fstype="xfs" --size=500

part /boot/efi --fstype="xfs" --size=500

part swap --fstype="swap" --size=1024

part / --fstype="xfs" --grow --size=1

%packages

@base

@core

@development

@hardware-monitoring

#@performance

#@remote-system-management

#telnet

#tree

%end

#注意:

#1)因为CentOS7系统网卡规则更复杂,为了ks.cfg更通用,最好ks.cfg不用制定网卡配置。

#2)为了兼容mbr方式和EFI方式,同时创建了/boot和/boot/efi分区。

第四:配置mbr引导方式

编辑isoliuux目录下的isolinux.cfg文件,添加自己的内容,在isolinux.cfg文件中label linux下面添加自己的

vim /home/centos7/isolinux/isolinux.cfg

label auto

menu label ^Auto install CentOS 7.4 --wsfnk

kernel vmlinuz

append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7 inst.ks=cdrom:/isolinux/ks.cfg quiet

#注意点:

#1)memu label 后面的内容是在光盘引导起来菜单的内容,^后面的字母是菜单的快捷键;

#2)通过inst.ks关键字指明ks.cfg文件位置;

#3)inst.stages2标识的是系统按照介质位置,这里使用hd:LABEL表明寻找的是label为CENTOS7的安装介质,使用LABEL关键字的好处是可以精确指定安装介质,为什么label是CENTOS7,是因为我在制作光盘镜像的时候指定的,方法在后面有介绍。

第五:配置EFI引导方式(在此grub.cfg文件的适当位置,添加如下信息)

vim /home/centos7/EFI/BOOT/grub.cfg

menuentry 'Auto Install CentOS 7.4 --wsfnk' --class fedora --class gnu-linux --class gnu --class os {

linuxefi /images/pxeboot/vmlinuz inst.ks=cdrom:/isolinux/ks.cfg inst.stage2=hd:LABEL=CENTOS7 quiet

initrdefi /images/pxeboot/initrd.img

}

第六:生成ISO镜像

cd /home/centos7 #先进入当前目录

genisoimage -v -cache-inodes -joliet-long -R -J -T -V CENTOS7 -o /root/centos7.iso \

-c isolinux/boot.cat -bisolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table \

-eltorito-alt-boot -b images/efiboot.img -no-emul-boot .

第七:导出刚才生成的镜像(用浏览器打开http://ip:8000,将镜像通过web下载下来)

cd /home/centos7

python -m SimpleHTTPServer #使用python的http模块,将其共享出来

第八:注意事项及genisoimage的用法

#1):制作centos7的镜像时,要使用centos7系统为宿主,不要使用centos6,因为两者系统的genisoimage命令的版本不一样,6的系统制作出来的iso不能在efi环境启动;

#2):如果要在efi启动,需要添加如下参数:

-eltorito-alt-boot -bimages/efiboot.img -no-emul-boot

#3):通过-V参数指定光盘label

4):

#genisoimage命令参数简介

-o 指定生成的映像文件保存路径及名称。

-b 指定在制作可开机光盘时所需的开机映像文件。

-c 制作可开机光盘时,会将开机映像文件中的no-eltorito-catalog全部内容作成一个文件。

-no-emul-boot 非模拟模式启动。

-boot-load-size 4 设置载入部分的数量。

-boot-info-table 在启动的图像中现实信息。

-joliet-long 使用 joliet 格式的目录与文件名称,长文件名支持。

-R 或 -rock 使用 Rock RidgeExtensions 。

-J 或 -joliet 使用 Joliet 格式的目录与文件名称。

-v 或 -verbose 执行时显示详细的信息。

-T 或-translation-table 建立文件名的转换表,适用于不支持 Rock Ridge Extensions 的系统上。

第九:测试使用

b187f651a637461634de2977ec5b6d41.gif

b187f651a637461634de2977ec5b6d41.gif

如果文章对你有帮助,欢迎点击上方按钮打赏作者