cnetos7 ISO 镜像自定义制作
简介:
此自定义镜像针对centos7 系统版本,通过tar 打包原系统服务将其放入ISO镜像中在安装时执行解压导入新安装系统中实现系统服务的自定义安装。针对cnetos7 目前只测试出这一种方案,暂时没找到其他好的方案实现系统的模板ISO制作,目前版本存在缺陷镜像中的tar包非加密存在安全问题。如果有更好的方案还请大佬指导。
制作系统tar包
原系统将服务进行删减,删除没用的日志和缓存数据保证系统的最小可用。删减完成后运行以下命令将系统打包:
tar cvpzf backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/dev --exclude=/etc/fstab --exclude=/boot --exclude=/backup.tar.gz --exclude=/mnt --exclude=/sys --exclude=/media --exclude=/etc/sysconfig/network-scripts/ /
使用原centos7 mini镜像进行挂载修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #镜像名称:CentOS-7-x86_64-Minimal-2009.iso #将其挂载到系统中(随便一个操作系统用来制作系统镜像) #安装必要依赖 yum install -y genisoimage #挂载镜像 mount -o loop . /CentOS-7-x86_64-Minimal-2009 .iso /mnt #复制镜像到/ISO目录 mkdir /ISO cp -a /mnt/ * /ISO #修改镜像内容 #1、制作应答文件ks.cfg #2、修改/ISO/isolinux/isolinux.cfg #3、修改/ISO/isolinux/grub.conf #4、修改/ISO/EFI/BOOT/grub.cfg #5、修改镜像的LABEL为CentOS7 原系统为 CentOS\x207\x20x86_64 由于带空格所以有\x20 为了有些系统不识别这里给换成CentOS7 #6、放入tar包 cat > /ISO/isolinux/ks .cfg<<EOF #version=DEVEL # 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=us --xlayouts= 'us' # System language lang en_US.UTF-8 # Network information network --bootproto=dhcp --device=ens33 --onboot=off --onboot=on --ipv6=auto --no-activate network -- hostname =localhost.localdomain # Root password rootpw --iscrypted $6$rOMaGigzYAyI5Ata$3RzuCFJ2Oksrr6ZpLf0sJI2C8qa4dkP.k1RhCpf5hm5Si4lWvBE8YyOVmZ5uMyI6eIXhKfewTciTr7OKyO /bB0 # System services services --disabled= "chronyd" # System timezone timezone Asia /Shanghai --isUtc --nontp # System bootloader configuration bootloader --append= " crashkernel=auto" --location=mbr --boot-drive=sda # Partition clearing information clearpart --none --initlabel # Disk partitioning information part pv.156 --fstype= "lvmpv" --ondisk=sda --size=9215 part /boot --fstype= "xfs" --ondisk=sda --size=1024 volgroup centos --pesize=4096 pv.156 logvol / --fstype= "xfs" --grow --maxsize=51200 --size=1024 --name=root --vgname=centos logvol swap --fstype= "swap" --size=1023 --name=swap --vgname=centos %packages @^minimal @core kexec-tools %end %addon com_redhat_kdump -- enable --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 %post --nochroot cp /run/install/repo/Packages/backup . tar .gz /mnt/sysimage/ chmod +x /mnt/sysimage/etc/rc .d /rc . local echo "cd / && tar xpfz backup.tar.gz -C / && rm -f /backup.tar.gz && rm -f /etc/sysconfig/network-scripts/ifcfg-ens192 && reboot " >> /mnt/sysimage/etc/rc .d /rc . local %end EOF #其中倒数第二行有个: rm -f /etc/sysconfig/network-scripts/ifcfg-ens192 是删除原系统网卡配置文件,需要根据自己系统进行修改。 #isolinux.cfg quiet后增加inst.ks=cdrom:/isolinux/ks.cfg #debug --graphics default=1 splashimage=@SPLASHPATH@ timeout 60 hiddenmenu title Install CentOS 7 findiso kernel @KERNELPATH@ @ROOT@ quiet inst.ks=cdrom: /isolinux/ks .cfg initrd @INITRDPATH@ #/ISO/isolinux/grub.conf quiet后增加inst.ks=cdrom:/isolinux/ks.cfg #debug --graphics default=1 splashimage=@SPLASHPATH@ timeout 60 hiddenmenu title Install CentOS 7 findiso kernel @KERNELPATH@ @ROOT@ quiet inst.ks=cdrom: /isolinux/ks .cfg initrd @INITRDPATH@ #/ISO/EFI/BOOT/grub.cfg /images/pxeboot/vmlinuz之后增加 inst.ks=hd:LABEL=CentOS7:/isolinux/ks.cfg ### BEGIN /etc/grub.d/10_linux ### menuentry 'Install CentOS 7' --class fedora --class gnu-linux --class gnu --class os { linuxefi /images/pxeboot/vmlinuz inst.ks=hd:LABEL=CentOS7: /isolinux/ks .cfg inst.stage2=hd:LABEL=CentOS7 quiet initrdefi /images/pxeboot/initrd .img } #修改 CentOS\x207\x20x86_64 为 CentOS7 sed -i 's/CentOS\\x207\\x20x86_64/CentOS7/g' /ISO/isolinux/isolinux .cfg sed -i 's/CentOS\\x207\\x20x86_64/CentOS7/g' /ISO/EFI/BOOT/grub .cfg sed -i 's/CentOS 7 x86_64/CentOS7/g' /ISO/EFI/BOOT/grub .cfg #放入tar包 cp backup. tar .gz /ISO/Packages #重新制作镜像 cd / genisoimage -joliet-long -V "CentOS7" -o CentOS7- test .iso -b isolinux /isolinux .bin -c isolinux /boot . cat -no-emul-boot \ -boot-load-size 4 -boot-info-table -R -J - v -cache-inodes -T -eltorito-alt-boot -e images /efiboot .img -no-emul-boot /ISO #使服务器BOIS模式能够识别U盘系统 isohybrid CentOS7- test .iso |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2020-03-12 linux pppoe 拨号经常没网问题