CentOS iso 镜像定制 CentOS iso 镜像定制内核 kernelimages/pxeboot/vmlinuz根文件系统 initrdimages/pxeboot/initrd.img开机引导系统安装的内核vmlinuz及RAM镜像(initrd.img)在引导系统时会载入内存给系统的安装提供一个Linux安装引导平台文件夹中还有在不同模式下显示信息的boot.msg文件Anaconda是RedHat、CentOS、Fedora等Linux的安装管理程序使用Python编写。可以提供文本、图形等安装管理方式并支持Kickstart等脚本提供自动安装的功能。mksquashfs /mnt /root/install.img –all-root -noF usr/bin/anaconda 安装程序的主执行文件 usr/lib/anaconda/iw/ 图形安装模式的模块 usr/lib/anaconda/textw/ 文本安装模式的模块。 usr/share/anaconda/pixmaps/ 图形安装过程的图片 usr/share/anaconda/ui/ 安装过程中显示的文字 usr/lib/anaconda/dispatch.py 来控制整个安装的流程当一个Next或Back按钮被单击时的跳转 usr/lib/anaconda/vnc.py 用于控制对VNC进行设置当在安装过程中请求了VNC时1、下载并上传CentOS-7-x86_64-Minimal-1810.iso到虚拟机。centos下载地址2、创建目录media并挂载iso。mkdir /media mount CentOS-7-x86_64-Minimal-1810.iso /media3、创建镜像目录并拷贝/media下的所有文件。mkdir /root/TMPOS cp -pRf /media/* /root/TMPOS/ cp /media/.discinfo /root/TMPOS/ cp /media/.treeinfo /root/TMPOS/4、修改centos-release可选。iso 系统定制%define product_family CentOS http://rpm.pbone.net/index.php3/stat/3/srodzaj/2/search/centos-release-7-3.1611.el7.centos.src.rpm5、修改centos-logos可选。tar -xf centos-logos-70.0.6.tar.xz tar -cvf centos-logos-70.0.6.tar.xz centos-logos-70.0.6/ cd centos-logos-70.0.6/pixmaps6、修改isolinux可选。mkdir tmp cp initrd.img tmp/ xz -dc initrd.img |cpio -id vim .buildstamp ... ProductCentOS ... cd usr/share/pixmaps find . |cpio -c -o |xz -9 --formatlzma initrd.img7、修改LiveOS可选。cd LiveOS/ unsquashfs squashfs.img cd squashfs-root mkdir t mount -o rw rootfs.img t cd usr/share/anaconda/pixmaps/ cd usr/share/anaconda/pixmaps/rnotes/en/ vim etc/os-release vim etc/redhat-release vim etc/system-release vim etc/centos-release vim usr/lib64/python2.7/site-packages/pyanaconda/ui/gui/hubs/progress.py #self.set_warning(_(Use of this product is subject to the license agreement found at %s) % eulaLocation) umoun t rm -rf t rm -rf squashfs.img mksquashfs squashfs-root/ squashfs.img -all-root -noF rm -rf squashfs-root8、准备ks.cfg文件 isolinux/ks.cfg。安装前运行自定义脚本 %pre表示系统安装前此时ISO镜像文件被挂载到内存中Linux的/mnt/source 安装后运行自定义脚本 %post 在系统安装后执行 –不带参数其实就是在真实的操作系统里操作。 –nochroot 已安装的真实操作系统被挂载到内存虚拟操作系统中的/mnt/sysimage目录。这个参数的用途主要是配合%pre使用的。先将光盘里的文件copy到内存运行的虚拟操作系统再从内存虚拟操作系统copy到已安装的真实操作系统操作。 %post --nochroot mkdir /media mount /dev/cdrom /media/ cp /media/test1.txt /mnt/sysimage/root/ %end [说明]上面命令实现了从ISO镜像中拷贝文本文件到安装好的真实操作系统中。 #versionDEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard --vckeymapus --xlayoutsus # Reboot after installation reboot # Root password rootpw 123456 user --namekyos --password123456 --groupsusers # System timezone timezone Asia/Shanghai --isUtc --nontp # System language lang en_US.UTF-8 # Firewall configuration firewall --disabled # SELinux configuration selinux --disabled # System authorization information auth --useshadow --passalgosha512 # Use graphical install #graphical text firstboot --enable # SELinux configuration selinux --disabled # ignore unsupported hardware warning unsupported_hardware # SKIP CONFIGURING X skipx # Network information network --hostnamekyos #Allow partition the system as needed %include /tmp/partition.ks %pre #!/bin/sh drives for drv in ls -1 /sys/block | grep sd\|hd\|vd\|cciss; do if (grep -q 0 /sys/block/${drv}/removable); then decho ${drv} | sed -e s/!/\// drives${drives} ${d} fi done default_driveecho ${drives} | awk {print $1} act_memcat /proc/meminfo | grep MemTotal | awk {printf(%d,$2/1024)} if [ $act_mem -ge 16384 ];then act_mem16384 fi echo /tmp/partition.ks # System bootloader configuration echo bootloader --locationmbr --driveorder${default_drive} /tmp/partition.ks # Clear the Master Boot Record echo zerombr /tmp/partition.ks # Partition clearing information echo clearpart --all --drives${default_drive} /tmp/partition.ks echo part /boot --fstypexfs --ondisk${default_drive} --asprimary --size500 /tmp/partition.ks echo part /boot/efi --fstypeefi --ondisk${default_drive} --asprimary --size500 /tmp/partition.ks echo part swap --fstypeswap --ondisk${default_drive} --size${act_mem} /tmp/partition.ks echo part / --fstypexfs --grow --ondisk${default_drive} --size1 /tmp/partition.ks %end %packages core kolla %end %post --log/var/log/post.log #!/bin/bash #change net device to ethx #sed -i s/quiet/quiet net.ifnames0 biosdevname0/g /etc/default/grub #grub2-mkconfig -o /boot/grub2/grub.cfg cd /etc/sysconfig/network-scripts before_network_script$(ls ifcfg-*|grep -v lo|grep -v eth*) net_dev_num$(ls ifcfg-*|grep -v lo|wc -l) rm -rf $before_network_script for ((i0;i$net_dev_num;i)); do echo TYPEEthernet BOOTPROTOstatic DEVICEeth$i ONBOOTno DNS1 IPADDR GATEWAY NETMASK |tee /etc/sysconfig/network-scripts/ifcfg-eth$i done #add pcadmin to sudoers echo tmpos ALL(ALL) ALL /etc/sudoers # add tmpos to group users usermod -a -G users tmpos # kolla systemctl disable postfix systemctl disable NetworkManager systemctl enable docker systemctl enable ntpd.service mkdir -p /etc/systemd/system/docker.service.d tee /etc/systemd/system/docker.service.d/kolla.conf EOF [Service] MountFlagsshared EOF cp -r /usr/share/kolla-ansible/etc_examples/kolla /etc/kolla/ cp -r /usr/share/kystack /opt %end9、修改isolinux.cfg文件,isolinux/isolinux.cfg。找到lable linux在append里面添加kscdrom:/isolinux/ks.cfg net.ifnames0 biosdevname0修改LABLETMPOS在之后构建TMPOS时-V参数会用到。 net.ifnames0 biosdevname0 修改网卡名为ethx。 ... label linux menu label ^Install TMPOS kernel vmlinuz # append initrdinitrd.img inst.stage2hd:LABELCentOS\x207\x20x86_64 quiet append initrdinitrd.img kscdrom:/isolinux/ks.cfg inst.stage2hd:LABELTMPOS quiet net.ifnames0 biosdevname0 ... [说明]斜体部分可选代表是否在安装时对网络部分进行提示交互。 其他相关label可以根据需求注释掉。 注意点 1memu label 后面的内容是在光盘引导起来菜单的内容^后面的字母是菜单的快捷键 2通过inst.ks关键字指明ks.cfg文件位置 3inst.stages2标识的是系统按照介质位置这里使用hd:LABEL表明寻找的是label为TMPOS的安装介质使用LABEL关键字的好处是可以精确指定安装介质为什么label是TMPOS是因为我在制作光盘镜像的时候指定的方法在后面有介绍。 default vesamenu.c32 timeout 10 display boot.msg # Clear the screen when exiting the menu, instead of leaving the menu displayed. # For vesamenu, this means the graphical background is still displayed without # the menu itself for as long as the screen remains in graphics mode. menu clear menu background splash.png menu title KYOS menu vshift 8 menu rows 18 menu margin 8 #menu hidden menu helpmsgrow 15 menu tabmsgrow 13 # Border Area menu color border * #00000000 #00000000 none # Selected item menu color sel 0 #ffffffff #00000000 none # Title bar menu color title 0 #ff7ba3d0 #00000000 none # Press [Tab] message menu color tabmsg 0 #ff3a6496 #00000000 none # Unselected menu item menu color unsel 0 #84b8ffff #00000000 none # Selected hotkey menu color hotsel 0 #84b8ffff #00000000 none # Unselected hotkey menu color hotkey 0 #ffffffff #00000000 none # Help text menu color help 0 #ffffffff #00000000 none # A scrollbar of some type? Not sure. menu color scrollbar 0 #ffffffff #ff355594 none # Timeout msg menu color timeout 0 #ffffffff #00000000 none menu color timeout_msg 0 #ffffffff #00000000 none # Command prompt text menu color cmdmark 0 #84b8ffff #00000000 none menu color cmdline 0 #ffffffff #00000000 none # Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message. menu tabmsg Press Enter to continue. menu separator # insert an empty line menu separator # insert an empty line label linux menu label ^Install TMPOS menu default kernel vmlinuz append initrdinitrd.img inst.stage2hd:LABELTMPOS quiet net.ifnames0 biosdevname0 inst.kshd:LABELTMPOS:/isolinux/ks.cfg menu separator # insert an empty line menu separator # insert an empty line menu end10、安装相关软件。yum -y install xorriso syslinux isomd5sum squashfs-tools createrepo11、准备efi启动。mkdir -p /root/TMPOS/efi_image dd bs1M count100 if/dev/zero of/root/TMPOS/efiboot.img mkfs.vfat -n EFI /root/TMPOS/efiboot.img umount -l /root/TMPOS/efi_image || true mount /root/TMPOS/efiboot.img /root/TMPOS/efi_image echo default0 /root/TMPOS/EFI/BOOT/BOOTX64.conf echo timeout 60 /root/TMPOS/EFI/BOOT/BOOTX64.conf echo hiddenmenu /root/TMPOS/EFI/BOOT/BOOTX64.conf echo title Install TMPOS /root/TMPOS/EFI/BOOT/BOOTX64.conf echo kernel /vmlinuz biosdevname0 showmenuyes inst.stage2hd:LABELTMPOS quiet inst.kshd:LABELTMPOS:/isolinux/ks.cfg /root/TMPOS/EFI/BOOT/BOOTX64.conf echo initrd /initrd.img /root/TMPOS/EFI/BOOT/BOOTX64.conf 修改 /root/TMPOS/EFI/BOOT/grub.cfg 添加 ... menuentry Install TMPOS --class fedora --class gnu-linux --class gnu --class os { linuxefi /images/pxeboot/vmlinuz inst.stage2hd:LABELTMPOS quiet net.ifnames0 biosdevname0 inst.kshd:LABELTMPOS:/isolinux/ks.cfg initrdefi /images/pxeboot/initrd.img ... cp -r /root/TMPOS/isolinux/vmlinuz /root/TMPOS/efi_image/ cp -r /root/TMPOS/isolinux/initrd.img /root/TMPOS/efi_image/ cp -rf /root/TMPOS/EFI/ /root/TMPOS/efi_image/ umount /root/TMPOS/efi_image mv -f /root/TMPOS/efiboot.img /root/TMPOS/images/ rm -rf /root/TMPOS/efi_image/12、准备安装源。1将需要的源追加复制到/root/TMPOS/Packages中。 2) 清除/root/TMPOS/repodata 中除了*.comps.xml外的其他文件并将新加的包名写入*.comps.xml里 packagereq typedefaultntp/packagereq packagereq typedefaultvim-enhanced/packagereq packagereq typedefaultiftop/packagereq packagereq typedefaulttelnet/packagereq packagereq typedefaultnmap/packagereq packagereq typedefaultmlocate/packagereq packagereq typedefaultnet-tools/packagereq packagereq typedefaultatop/packagereq packagereq typedefaultiftop/packagereq packagereq typedefaultvim/packagereq packagereq typedefaultwget/packagereq packagereq typedefaulttmux/packagereq packagereq typedefaultiotop/packagereq packagereq typedefaulthtop/packagereq packagereq typedefaultexpect/packagereq packagereq typedefaulttree/packagereq packagereq typedefaultpython2-pip/packagereq packagereq typedefaultepel-release/packagereq /packagelist /group group idkolla/id nameKolla/name name xml:langen_USKolla/name descriptionKolla packages/description defaulttrue/default uservisibletrue/uservisible packagelist packagereq typedefaultansible/packagereq packagereq typedefaultkolla-ansible/packagereq packagereq typedefaultdocker-ce/packagereq packagereq typedefaultpython-docker-py/packagereq packagereq typedefaultpython2-pbr/packagereq packagereq typedefaultpython2-oslo-utils/packagereq packagereq typedefaultpython2-oslo-config/packagereq packagereq typedefaultpython2-jinja2/packagereq packagereq typedefaultopenstack-selinux/packagereq packagereq typedefaultpython2-openstackclient/packagereq packagereq typedefaultpython2-magnumclient/packagereq /packagelist /group 3构建源 yum -y install createrepo cd /root/TMPOS createrepo -g repodata/*comps.xml . 4) 在/root/TMPOS/isolinux/ks.cf中添加相应组名 %packages core kolla %end13、构建TMPOS。mkisofs参数简介 -o 指定映像文件的名称。 -o /root/boot.iso 创建完后放在哪 -b指定在制作可开机光盘时所需的开机映像文件。 -c 制作可开机光盘时会将开机映像文件中的no-eltorito-catalog全部内容作成一个文件。 -c isolinux/boot.cat 指明引导时显示菜单的文件 -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 的系统上。 -V “CentOS 6.6 X86_64 boot disk”指明光盘标签为”CentOS 6.6 X86_64 boot disk“ xorriso -as mkisofs \ -V TMPOS -p tmp \ -J -R \ -graft-points \ -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table \ -isohybrid-mbr /usr/share/syslinux/isohdpfx.bin \ -eltorito-alt-boot -e images/efiboot.img -no-emul-boot \ -isohybrid-gpt-basdat \ -o /root/TMPOS/TMPOS.iso /root/TMPOS/ \ --boot-catalog-hide implantisomd5 /root/TMPOS/TMPOS.iso14、make.sh