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

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

    1 复制光盘文件

    1 )挂载 iso 镜像

    创建目录用于挂载光盘:

    perl">
    mkdir /root/centos7

    挂载 iso 镜像

    mount -o loop CentOS-7.0-1406-x86_64-DVD.iso/root/centos7

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

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

    首先创建编辑目录:

    mkdir /root/centos7_iso

    复制光盘文件:

    cp -rf /root/centos7/* /root/centos7_iso/

    diskinfo 文件需求单独拷贝下:

    cp /root/centos7/.discinfo /root/iso

    2 编辑 ks.cfg 文件

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

    cd /root/centos7_iso/isolinux
    vim ks.cfg

    我的 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
    @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 文件,添加自己的菜单:

    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
    }
    

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

    5 生成 iso 镜像

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

    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 )中间踩过的几个坑:

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

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

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

    3 )通过 -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/genisoimage

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

原文地址:https://www.cnblogs.com/out8/p/4350953.html