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
    

转载于:https://my.oschina.net/colben/blog/3102457

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值