前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS7全自动安装光盘制作详解

CentOS7全自动安装光盘制作详解

作者头像
力哥聊运维与云计算
发布2019-06-28 12:50:48
7.1K2
发布2019-06-28 12:50:48
举报

CentOS7全自动安装光盘制作详解

1 复制光盘文件

1)挂载iso镜像

创建目录用于挂载光盘:

代码语言:javascript
复制
mkdir /root/centos7

挂载iso镜像

代码语言:javascript
复制
mount -o loop CentOS-7.0-1406-x86_64-DVD.iso/root/centos7

2)复制光盘文件到编辑目录进行编辑

因为挂载上iso镜像是只读的,如果要编辑,需要将文件复制出来,再编辑。

首先创建编辑目录:

代码语言:javascript
复制
mkdir /root/centos7_iso

复制光盘文件:

代码语言:javascript
复制
cp -rf /root/centos7/* /root/centos7_iso/

diskinfo文件需求单独拷贝下:

代码语言:javascript
复制
cp /root/centos7/.discinfo /root/iso

2 编辑ks.cfg文件

系统安装的时候,按照ks.cfg文件的内容进行安装,我们把ks.cfg文件放到isolinux目录下:

代码语言:javascript
复制
cd /root/centos7_iso/isolinux
vim ks.cfg

我的ks.cfg文件内容如下:

代码语言:javascript
复制
#version=RHEL/CentOS7 by xiaoli110
install
# Keyboard layouts
keyboard 'us'
# Reboot after installation
reboot
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
#network --bootproto=dhcp --device=enp2s0 --onboot=off --ipv6=auto
#network --bootproto=dhcp --device=enp3s0 --onboot=off --ipv6=auto
#network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted 111111111111111111111111111
# System timezone
timezone Asia/Shanghai
# System language
lang zh_CN
# Firewall configuration
firewall --enabled --ssh
 
# System authorization information
auth --useshadow  --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs"--size=500
part /boot/efi --fstype="xfs"--size=500
part swap --fstype="swap"--size=16000
part / --fstype="xfs" --grow--size=1
 
%packages
@base
@core
@development
@hardware-monitoring
@performance
@remote-system-management
%end

注意:

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

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

3配置mbr引导方式

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

代码语言:javascript
复制
label linux
 menu label ^Install CentOS 7
 kernel vmlinuz
 append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7 quiet
 
label custom
 menu label ^Custom CentOS 7 by xiaoli110
 kernel vmlinuz
 append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7 inst.ks=cdrom:/isolinux/ks.cfg

注意点:

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

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

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

4 配置EFI引导方式

1)EFI简介

EFI可扩展固件接口(ExtensibleFirmware Interface 的缩写),是英特尔主导推出的一种替代BIOS的升级方案。最早由英特尔开发,于2005年将此规范格式交由UEFI论坛来推广与发展,后来并更改名称为Unified EFI(UEFI)。UEFI论坛于2007年1月7日释出并发放2.1版本的规格,其中增加与改进了加密编码(cryptography)、网络认证(network authentication)与用户接口架构(User Interface Architecture)。

EFI是用模块化,C语言风格的参数堆栈传递方式,动态链接的形式构建的系统,较BIOS而言更易于实现,容错和纠错特性更强,缩短了系统研发的时间。

EFI在概念上非常类似于一个低阶的操作系统,并且具有操控所有硬件资源的能力。

2)配置EFI引导

进入光盘目录EFI/BOOT/,编辑grub.cfg文件,添加自己的菜单:

代码语言:javascript
复制
menuentry 'Install CentOS 7' --class fedora--class gnu-linux --class gnu --class os {
       linuxefi /p_w_picpaths/pxeboot/vmlinuz inst.stage2=hd:LABEL=CENTOS7 quiet
       initrdefi /p_w_picpaths/pxeboot/initrd.img
}
menuentry 'Install CentOS 7 custom byxiaoli110' --class fedora --class gnu-linux --class gnu --class os {
       linuxefi /p_w_picpaths/pxeboot/vmlinuz inst.ks=cdrom:/isolinux/ks.cfginst.stage2=hd:LABEL=CENTOS7 quiet
       initrdefi /p_w_picpaths/pxeboot/initrd.img
}

和mbr方式类似,指明ks.cfg文件位置和安装源位置。

5 生成iso镜像

经过我踩过多个坑,成功的生成镜像,并且能在EFI和mbr环境安装的镜像生成命令如下:

代码语言:javascript
复制
genisop_w_picpath -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 p_w_picpaths/efiboot.img       -no-emul-boot .

(1)中间踩过的几个坑:

1)制作镜像要使用CentOS7的系统,不要使用CentOS6的系统,因为两者系统的genisop_w_picpath命令的版本不一样,6的系统制作出来的iso不能在efi环境启动;

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

代码语言:javascript
复制
 -eltorito-alt-boot     -bp_w_picpaths/efiboot.img       -no-emul-boot

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

(2)genisop_w_picpath命令参数简介

-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 的系统上。

(3)genisop_w_picpath、mkisofs、xorrios几个命令的区别

说起genisop_w_picpath和mkisofs,其实里面是有点故事的。

最早的时候,Linux系统使用cdrtools工具来管理iso及光盘,mkisofs是cdrtools里面的一个工具,后来cdrtools更好了了授权许可,从GPL修改为CDDL许可,开源社区又推出了一套基于GPL的工具,cdrkit,mkisofs也被genisop_w_picpath去掉,现在系统中的mkisofs实际是genisop_w_picpath的软连接:

代码语言:javascript
复制
ls -l /usr/bin/mkisofs
/usr/bin/mkisofs ->/etc/alternatives/mkisofs
ls -l /etc/alternatives/mkisofs
/etc/alternatives/mkisofs ->/usr/bin/genisop_w_picpath

xorrios是另外一个比较流行的制作iso镜像的工具,并且有一个参数-asmkisofs可以和mkiso命令兼容。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-03-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档