2017-4-30 - create customized CentOS ISO & Installation Udisk

2017-4-30 - create customized CentOS ISO & Installation Udisk

ISO Generation

  1. install minimal CentOS6.9
    1.1 network is disabled after firstboot, so enable it
  1. sed -i '/ONBOOT=no/ONBOOT=yes/g' /etc/sysconfig/network-scripts/ifcfg-eth0 
  2. service network restart 

1.2 enable yum cache, so that we can figure out the extra packages under /var/cache/yum/…

  1. sed -i '/keepcache=o/keepcache=1/g' /etc/yum.conf 

1.3 install wget and unzip, rsync used to download and unzip oakmgr install image

  1. mkdir -p /root/oakmgr_install 
  2. cd /root/oakmgr_install 
  3. yum install -y wget unzip rsync 
  4. wget -O 1.zip 'http://139.196.170.238:8000/f/90b5b579b9/?raw=1'  
  5. unzip 1.zip 
  1. prepare the new ISO root directory, and sync all files from original CD except Packages, and repdata directory
  1. mkdir /dev/cdrom 
  2. mount /dev/cdrom /mnt/cdrom 
  3. mkdir -p /ISO/{Packages,repodata} 
  4. rsync -a --exclude=Packages/ --exclude=repodata/ /mnt/cdrom/ /ISO/ 
  1. analyze /root/install.log and cp the useful rpm to new ISO root directory
  1. #!/bin/bash 
  2. cd /root 
  3. awk '/Installing/{print $2}' install.log | sed 's/^*://g' > package.txt 
  4.  
  5. DVD='/mnt/cdrom/Packages' 
  6. PACKDIR='/root/package.txt' 
  7. NEW_DVD='/ISO/Packages' 
  8.  
  9. while read LINE 
  10. do 
  11. cp ${DVD}/${LINE}*.rpm /${NEW_DVD} || echo "$LINE don't cp..." 
  12. done < package.txt 
  13.  
  14. rm -rf package.txt 
  1. generate ks.cfg based on /root/anaconda-ks.cfg
  1. cd /ISO 
  2. cp /root/anaconda-ks.cfg isolinux/ks.cfg 
  3. vi isolinux/ks.cfg 

ks.cfg

  1. # Kickstart file automatically generated by anaconda. 
  2.  
  3. #version=DEVEL 
  4. install 
  5. text 
  6. cdrom 
  7. lang en_US.UTF-8 
  8. keyboard us 
  9. network --onboot yes --device eth0 --bootproto dhcp --noipv6 
  10. rootpw --iscrypted $6$3o1deF8J0xweYap4$2vG3kVQfJxhYBb.v/qGaHeJApOcwK16fOrfkwu6kYjTBYnrKyaPTHGshgVIg3YQf/ZPS8u/Biq2gxse.weYOp. 
  11. firewall --service=ssh 
  12. authconfig --enableshadow --passalgo=sha512 
  13. selinux --enforcing 
  14. firstboot --disable 
  15. timezone --utc Asia/Shanghai 
  16. bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" 
  17. # The following is the partition information you requested 
  18. # Note that any partitions you deleted are not expressed 
  19. # here so unless you clear all partitions first, this is 
  20. # not guaranteed to work 
  21. clearpart --all --initlabel --drives=sda 
  22.  
  23. part /boot --fstype=ext4 --size=500 
  24. part pv.008002 --grow --size=1 
  25.  
  26. volgroup vg_oakmgr --pesize=4096 pv.008002 
  27. logvol / --fstype=ext4 --name=lv_root --vgname=vg_oakmgr --grow --size=1024 --maxsize=51200 
  28. logvol swap --name=lv_swap --vgname=vg_oakmgr --grow --size=2048 --maxsize=2048 
  29.  
  30. #repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100 
  31.  
  32. reboot --eject 
  33.  
  34. %packages --nobase 
  35. @core 
  36.  
  37. %post --nochroot --log=/mnt/sysimage/root/post_cp.log 
  38. umount /dev/cdrom 
  39. mkdir -p /mnt/source 
  40. mount /dev/cdrom /mnt/source 
  41.  
  42. %post --log=/root/post_install.log 
  43. cd /mnt/source/oakmgr_install 
  44. ./setup.sh 
  45.  
  46.  
  47. %end 
  48.  
  1. add ks.cfg into isolinux.cfg to enable it during install
  1. chomd 644 isolinux/isolinux.cfg 
  2. vi isolinux/isolinux.cfg 
  3. chmod 444 isolinux/isolinux.cfg 

isolinux.cfg

  1. append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img 
  1. modify oakmgr_install/installer/installer.sh
  1. read -t3 -n 1 PRODUCT_TYPE 
  2. [ "$?" -ne 0 ] && PRODUCT_TYPE="4" 
  3. read -t 3 -n 1 isContinue 
  4. [ "$?" -ne 0 ] && isContinue="Y" 
  1. copy oakmgr_install into new iso directory
  1. rsync -a /root/oakmgr_install /ISO/ 
  1. generate packages metadata
  1. createrepo -v -g /mnt/cdrom/repodata/*-minimal-x86_64.xml ./ 
  2. declare -x discinfo=`head -1 .discinfo` 
  3. createrepo -u "media://$discinfo" -g repodata/*-minimal-x86_64.xml . 
  1. generate iso, and setup md5sum
  1. mkisofs -o CentOS-6.9_64.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T /ISO/ 
  2. /usr/bin/implantisomd5 /ISO/CentOS-6.4_64.iso 
  1. test it with vmware

Installation Udisk

  1. make partition on udisk
  1. cfdisk /dev/sdb 
  2. ext2 100M for boot 
  3. ext2 others for store iso and oakmgr_install 
  1. generate bootable udisk based on minimal ISO
  1. mkdir /mnt/{cdrom,boot,data} 
  2. mount /dev/cdrom /mnt/cdrom 
  3. mount /dev/sdb1 /mnt/boot 
  4. mount /dev/sdb2 /mnt/data 
  5.  
  6. cp -a /dev/cdrom/isolinux /mnt/boot/syslinux 
  7. cd /mnt/boot/syslinux && mv isolinux.cfg syslinux.cfg 
  8. cp CentOS6-minimal-x86_64.iso /mnt/data 
  9. cp ~/oakmgr_install /mnt/data/ 
  1. add kickstart script
  1. vi /mnt/boot/syslinux/ks.cfg 

/mnt/boot/syslinux/ks.cfg

  1. # Kickstart file automatically generated by anaconda. 
  2.  
  3. #version=DEVEL 
  4. install 
  5. text 
  6. harddrive --partition=sda2 --dir=  
  7. lang en_US.UTF-8 
  8. keyboard us 
  9. network --onboot yes --device eth0 --bootproto dhcp --noipv6 
  10. rootpw --iscrypted $6$3o1deF8J0xweYap4$2vG3kVQfJxhYBb.v/qGaHeJApOcwK16fOrfkwu6kYjTBYnrKyaPTHGshgVIg3YQf/ZPS8u/Biq2gxse.weYOp. 
  11. firewall --service=ssh 
  12. authconfig --enableshadow --passalgo=sha512 
  13. selinux --enforcing 
  14. firstboot --disable 
  15. timezone --utc Asia/Shanghai 
  16. bootloader --location=mbr --driveorder=sdb,sda --append="nousbstorage crashkernel=auto rhgb quiet" 
  17. # The following is the partition information you requested 
  18. # Note that any partitions you deleted are not expressed 
  19. # here so unless you clear all partitions first, this is 
  20. # not guaranteed to work 
  21. clearpart --all --initlabel --drives=sdb 
  22. ignoredisk --only-use=sdb 
  23. part /boot --fstype=ext4 --size=500 
  24. part pv.008002 --grow --size=1 
  25.  
  26. volgroup vg_oakmgr --pesize=4096 pv.008002 
  27. logvol / --fstype=ext4 --name=lv_root --vgname=vg_oakmgr --grow --size=1024 --maxsize=51200 
  28. logvol swap --name=lv_swap --vgname=vg_oakmgr --grow --size=2048 --maxsize=2048 
  29.  
  30. reboot --eject 
  31.  
  32. %packages --nobase 
  33. @core 
  34.  
  35. %post --nochroot --log=/mnt/sysimage/root/post_cp.log 
  36. umount /dev/sda2 
  37.  
  38. %post --log=/root/post_install.log 
  39. mkdir /mnt/source 
  40. mount /dev/sda2 /mnt/source 
  41. cd /mnt/source/oakmgr_install 
  42. ./setup.sh 
  43.  
  44.  
  45. %end 
  46.  
  1. add ks.cfg into syslinux.cfg
  1. kernel vmlinuz 
  2. append ks=hd:sda2:/ks.cfg initrd=initrd.img 
  1. install syslinux
  1. cp /usr/lib/syslinux/bios/*.c32 /mnt/boot/syslinux/ 
  2. extlinux --install /mnt/boot/syslinux 
  3. dd bs=440 count=1 if=/usr/lib/syslinux/bios/mbr.bin of=/dev/sdb 
  4. cp /mnt/cdrom/images /mnt/data 
  1. modify oakmgr_install/installer/installer.sh
  1. read -t3 -n 1 PRODUCT_TYPE 
  2. [ "$?" -ne 0 ] && PRODUCT_TYPE="4" 
  3. read -t 3 -n 1 isContinue 
  4. [ "$?" -ne 0 ] && isContinue="Y" 
  1. test with vmware
  1. add new harddisk with(SICS:0:0) into vmware with udisk 

2017-4-30 nicephil@gmail.com

posted on 2017-05-02 13:05  nicephil  阅读(459)  评论(0编辑  收藏  举报

导航