kickstart 自動安裝 CentOS7

環境

  • CentOS7.6
  • genisoimage 1.1.11
  • CentOS-7-x86_64-Minimal-1810.iso

複製 iso 內容到本地磁盤

mount -o loop CentOS-7-x86_64-Minimal-1810.iso /mnt/
mkdir -p /home/iso/centos7
cd /mnt && cp -af * .* /home/iso/centos7/

建立 isolinux/ks.cfg

  • mbr 啓動,/home/iso/centos7/isolinux/ks.cfg 內容以下
    # Install OS instead of upgrade
    install
    # Reboot after installation
    reboot
    # System authorization information
    auth --enableshadow --passalgo=sha512
    # Use CDROM installation media
    cdrom
    # Use graphical install
    graphical
    # Run the Setup Agent on first boot
    firstboot --enable
    ignoredisk --only-use=sda
    # Keyboard layouts
    keyboard --vckeymap=cn --xlayouts='cn'
    # System language
    lang zh_CN.UTF-8
    # Firewall configuration
    firewall --disabled
    # SELinux configuration
    selinux --disabled
    
    # Network information
    #network  --bootproto=dhcp --device=eth0 --onboot=off --ipv6=auto --no-activate
    #network  --hostname=localhost.localdomain
    
    # Root password(111111)
    rootpw --iscrypted $6$kD.hMvv5nCY8a/SM$Gnmb4zspkuyL75BP2Gj.1SGUaWBugXkd/zMFhoDndp9CSi8VP7R5JP7rfWzL4y7fy8crH3ryDT4PFkKCc7/xM.
    # System services
    services --enabled="chronyd"
    # System timezone
    timezone Asia/Shanghai --isUtc
    # Clear the Master Boot Record
    zerombr
    # System bootloader configuration
    bootloader --location=mbr --boot-drive=sda
    # Partition clearing information
    clearpart --none --initlabel
    # Disk partitioning information
    part /boot --fstype="xfs" --ondisk=sda --size=512
    part / --fstype="xfs" --ondisk=sda --grow --size=1
    
    %packages
    @^minimal
    @core
    chrony
    
    %end
    
    %post
    lsblk > /root/lsblk
    %end
    
    %addon com_redhat_kdump --disable --reserve-mb='auto'
    
    %end
    
    %anaconda
    pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
    pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    %end
  • efi 啓動,/home/iso/centos7/isolinux/ks.cfg 內容以下
    # Install OS instead of upgrade
    install
    # Reboot after installation
    reboot
    # System authorization information
    auth --enableshadow --passalgo=sha512
    # Use CDROM installation media
    cdrom
    # Use graphical install
    graphical
    # Run the Setup Agent on first boot
    firstboot --enable
    ignoredisk --only-use=sda
    # Keyboard layouts
    keyboard --vckeymap=cn --xlayouts='cn'
    # System language
    lang zh_CN.UTF-8
    # Firewall configuration
    firewall --disabled
    # SELinux configuration
    selinux --disabled
    
    # Network information
    #network  --bootproto=dhcp --device=eth0 --onboot=off --ipv6=auto --no-activate
    #network  --hostname=localhost.localdomain
    
    # Root password(111111)
    rootpw --iscrypted $6$kD.hMvv5nCY8a/SM$Gnmb4zspkuyL75BP2Gj.1SGUaWBugXkd/zMFhoDndp9CSi8VP7R5JP7rfWzL4y7fy8crH3ryDT4PFkKCc7/xM.
    # System services
    services --enabled="chronyd"
    # System timezone
    timezone Asia/Shanghai --isUtc
    # Clear the Master Boot Record
    zerombr
    # System bootloader configuration
    bootloader --location=mbr --boot-drive=sda
    # Partition clearing information
    clearpart --none --initlabel
    # Disk partitioning information
    part /boot --fstype="xfs" --ondisk=sda --size=512
    part /boot/efi --fstype="xfs" --ondisk=sda --size=512
    part / --fstype="xfs" --ondisk=sda --grow --size=1
    
    %packages
    @^minimal
    @core
    chrony
    
    %end
    
    %post
    %end
    
    %addon com_redhat_kdump --disable --reserve-mb='auto'
    
    %end
    
    %anaconda
    pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
    pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
    %end

修改啓動項文件

  • mbr 啓動,只需修改 isolinux/isolinux.cfg
    • 刪除 "label check" 下的 "menu default" 一行
    • 在 "label linux" 一行上方添加以下內容
      label auto
        menu label ^Auto install CentOS 7
        menu default
        kernel vmlinuz
        append initrd=initrd.img inst.stage2=hd:LABEL=CentOS7 inst.ks=cdrom:/isolinux/ks.cfg quiet
  • efi 啓動,只需修改 EFI/BOOT/grub.cfg
    • 修改第一行
      set default="0"
    • 在 "### BEGIN /etc/grub.d/10_linux ###" 一行下添加以下內容
      menuentry 'Auto Install CentOS 7' --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 鏡像

  • mbr 啓動,執行以下命令
    genisoimage -v -R -J -T -V CentOS7 \
        -b isolinux/isolinux.bin \
        -c isolinux/boot.cat \
        -cache-inodes \
        -joliet-long \
        -no-emul-boot \
        -boot-load-size 4 \
        -boot-info-table \
        -o /home/centos7.iso \
        /home/iso/centos7
  • efi 啓動,執行以下命令
    genisoimage -v -R -J -T -V CentOS7 \
       -b images/efiboot.img \
        -c isolinux/boot.cat \
        -cache-inodes \
        -joliet-long \
        -no-emul-boot \
        -boot-load-size 4 \
        -boot-info-table \
        -o /home/centos7-efi.iso \
        /home/iso/centos7
相關文章
相關標籤/搜索