CentOS 7全自动安装光盘制作
需要制作的光盘依赖于 挂在的镜像
复制光盘文件
挂载iso镜像
##创建目录用于挂载光盘的目录 mkdir /root/centos7 ##挂载iso镜像 mount /dev/sr0 /root/centos7
复制挂光盘文件到编辑目录进行编辑
##创建编辑目录 mkdir /root/centos_iso ##拷贝镜像文件 cp /root/centos7/* /root/centos_iso/ ##diskinfo 文件需求单独拷贝下: cp /root/centos7/.discinfo /root/iso
编辑ks.cfg文件 (系统安装的时候,按照 ks.cfg 文件的内容进行安装,我们把 ks.cfg 文件放到 isolinux 目录下)
##进入路径下
cd /root/centos7_iso/isolinux
##编辑ks.cfg文件
vim ks.cfg
#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
@core
%end
##注意:
root明文密码格式:rootpw --plaintext 1234
root加密密码格式:rootpw --iscrypted 111111111111111111111111111
配置MBR引导方式
##编辑grub.cfg
vim /root/centos7_iso/EFI/BOOT/grub.cfg
menuentry 'Install CentOS 7' --class Fedora--class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=CENTOS7 quiet
initrdefi /images/pxeboot/initrd.img
}
menuentry 'Install CentOS 7 custom byxiaoli110' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.ks=cdrom:/isolinux/ks.cfginst.stage2=hd:LABEL=CENTOS7 quiet
initrdefi /images/pxeboot/initrd.img
}
##
注意: 1)LABEL后面的名称 文件中原有的也对应修改 2)memu label 后面的内容是在光盘引导起来菜单的内容, ^ 后面的字母是菜单的快捷键 3) inst.stages2 标识的是系统按照介质位置,这里使用 hd:LABEL 表明寻找的是 label 为 CENTOS7 的安装介质,使用 LABEL 关键字的好处是可以精确指定安装介质,为什么 label 是 CENTOS7 ,是因为我在制作光盘镜像的时候指定的
生成ISO镜像
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 .
注意:
1 )制作镜像要使用 CentOS7 的系统,不要使用 CentOS6 的系统,因为两者系统的 genisoimage 命令的版本不一样, 6 的系统制作出来的 iso 不能在 efi 环境启动;
2 )如果要在 efi 启动,需要添加如下参数:
-eltorito-alt-boot -bimages/efiboot.img -no-emul-boot3 )通过 -V 参数指定光盘 label
( 2 ) 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 的系统上。
( 3 ) genisoimage 、 mkisofs 、 xorrios 几个命令的区别
说起 genisoimage 和 mkisofs ,其实里面是有点故事的。
最早的时候, Linux 系统使用 cdrtools 工具来管理 iso 及光盘, mkisofs 是 cdrtools 里面的一个工具,后来 cdrtools 更好了了授权许可,从 GPL 修改为 CDDL 许可,开源社区又推出了一套基于 GPL 的工具, cdrkit , mkisofs 也被 genisoimage 去掉,现在系统中的 mkisofs 实际是 genisoimage 的软连接:
ls -l /usr/bin/mkisofs
/usr/bin/mkisofs ->/etc/alternatives/mkisofs
ls -l /etc/alternatives/mkisofs
/etc/alternatives/mkisofs ->/usr/bin/genisoimagexorrios 是另外一个比较流行的制作 iso 镜像的工具,并且有一个参数 -asmkisofs 可以和 mkiso 命令兼容。
如果不想直接手写ks.cfg文件,可以安装Kickstart工具
##删除现有的包,如果有的话
yum remove -y system-config-kickstart
##重建yum缓存
yum clean all
yum makecache
##安装Kickstart
yum install -y system-config-kickstart
制作Kickstart文件
如果是最小化安装的Linux ,可以转化成图形化,更好的操作
##列出组列表
yum grouplist
##安装
yum groupinstall -y "GNOME Desktop"
##设置成图形模式
systemctl set-default graphical.target
##设置成命令模式
systemctl set-default multi-user.target
##重启
reboot