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

使用场景:

特殊业务场景里在没有网络,不能使用kickstart或cobbler自动化部署,只能用U盘或光驱。

CentOS7.x后用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 by 

install

# Reboot after installation

reboot --eject

# Run the Setup Agent on first boot

firstboot --enable

# Keyboard layouts

keyboard --vckeymap=us --xlayouts='us'

# System language

lang zh_CN.UTF-8

# Root password

#rootpw --iscrypted 123456

rootpw "password"

# System timezone

timezone Asia/Shanghai --isUtc

# Firewall configuration

firewall --enabled --service=ssh,ntp,http,https --port=55555

# Network information

network  --bootproto=dhcp --ipv6=auto --activate

network  --hostname=xlgcOS

# System authorization information

auth --useshadow  --passalgo=sha512

services --enabled="chronyd"

user --groups=wheel --name=xlgc --password=$6$g2oZK8SNS7Zluex.$0hgDTvLvcZq7hYMHfcJw4QfYQSWbpUO09MM1bGttMVSxV9WeGngnQUa3ZoJ5SbTavdTZHrXmuzoBtUoWgLOsu0 --iscrypted --gecos="xlgc"

# Use CDROM installation media

cdrom

# Use graphical install

graphical

# SELinux configuration

selinux --disabled

# Do not configure the X Window System

skipx

# Clear the Master Boot Record

zerombr

# System bootloader configuration

part /boot --fstype="ext4" --size=1024

part swap --fstype="swap" --size=16384

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

%packages

@^minimal

@core

-abrt-addon-ccpp

-abrt-addon-python

-abrt-cli

-abrt-console-notification

-bash-completion

-blktrace

-bridge-utils

-bzip2

-chrony

-cryptsetup

-dmraid

-dosfstools

-ethtool

-fprintd-pam

-gnupg2

-hunspell

-hunspell-en

-kmod-kvdo

-kpatch

-ledmon

-libaio

-libreport-plugin-mailx

-libstoragemgmt

-lvm2

-man-pages

-man-pages-overrides

-mdadm

-mlocate

-mtr

-nano

-ntpdate

-pinfo

-plymouth

-pm-utils

-rdate

-rfkill

-rng-tools

-rsync

-scl-utils

-setuptool

-smartmontools

-sos

-sssd-client

-strace

-sysstat

-systemtap-runtime

-tcpdump

-tcsh

-teamd

-time

-unzip

-usbutils

-vdo

-vim-enhanced

-virt-what

-wget

-which

-words

-xfsdump

-xz

-yum-langpacks

-yum-utils

-zip

-net-snmp

-net-snmp-utils

-net-tools.x86_64

%end

%post

echo "welcome">> /etc/motd

echo "Use of this product is subject to the license agreement found at /usr/share/centos-release/EULA" >> /etc/motd

/usr/local/bin/patch_fd_1024.sh 200000

sed -i '/^#Port/c Port 55555' /etc/ssh/sshd_config

sed -i '/^#PermitRootLogin/c PermitRootLogin yes' /etc/ssh/sshd_config

sed -i '/^#UseDNS/c UseDNS no' /etc/ssh/sshd_config

echo "blacklist ast" > /etc/modprobe.d/ast.conf

sed -i '/^ONBOOT/c ONBOOT=no' /etc/sysconfig/network-scripts/ifcfg-e*

sed -i '/password    requisite/c password    requisite    pam_cracklib.so retry=3 minlen=10 minclass=2' /etc/pam.d/system-auth

sed -i "/localhost/s;$; XlgcOS;g" /etc/hosts

echo "" > /etc/yum.repos.d/CentOS-Base.repo

echo "net.ipv4.tcp_fin_timeout = 3" >> /etc/sysctl.conf

sysctl -p /etc/sysctl.conf

chage -d0 root

sudo chage -d0 xlgc

echo "LANG=en_US.utf8" >> /etc/locale.conf

rpm -e NetworkManager-tui

rpm -e NetworkManager-team

rpm -e NetworkManager-wifi

rpm -e NetworkManager

rpm -e NetworkManager-libnm

# 这里我直接启动了SNMP功能

systemctl disable snmpd.service

EOF

mkinitrd -f /boot/initramfs-3.10.0-862.11.6.el7.x86_64.img 3.10.0-862.11.6.el7.x86_64

%end


第四:配置mbr引导方式

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

vim /home/centos7/isolinux/isolinux.cfg

label auto menu label ^Auto install  CentOS 7.4

kernel vmlinuz

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

或则

label auto menu label ^Auto install  CentOS 7.4

kernel vmlinuz

append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7  ks=CENTOS7 :/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.6' --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}

也可以这样写(注意全文黑体加粗的一定要一样包括大小写)

menuentry 'Auto Install CentOS 7.6' --class fedora --class gnu-linux --class gnu --class os {      linuxefi /images/pxeboot/vmlinuz   ks=CENTOS7 :/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 的系统上。

声明:本文转载自 xiaoli110的博客,作者为 xiaoli110,原文网址:http://xiaoli110.blog.51cto.com/1724/1617541/

你可能感兴趣的:(定制centos7安装镜像 实现光盘自动安装)