Chinaunix首页 | 论坛 | 博客
  • 博客访问: 107380
  • 博文数量: 29
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 240
  • 用 户 组: 普通用户
  • 注册时间: 2014-07-11 15:42
个人简介

多少人爱你青春欢畅的时辰, 爱你的美丽假意和真心, 只有一个人爱你那朝圣者的灵魂, 爱你衰老了的连上痛苦的皱纹.

文章分类

全部博文(29)

文章存档

2018年(1)

2015年(2)

2014年(26)

我的朋友

分类: LINUX

2014-10-31 16:49:12

1.Create installing list

pastedGraphic_4.png


#!/bin/bash 

############################################################ 

# 生成RPM包packages.list列表、拷贝packages.list中RPM包列表 

############################################################ 

prog=copyrpm.sh 

###拷贝光盘内容到/disk,排除Packages目录 

#cd /mnt/cdrom 

#ls -a|grep -v "Packages"|xargs -i cp -rp {} /disk/ 

###生成RPM包packages.list列表 

build_packages_list(){ 

poin_file=$2 

cat /root/install.log | grep Installing | sed 's/Installing //g' > $poin_file 

###拷贝packages.list中RPM包列表到指定位置 

copy_packages_list(){ 

DEBUG=0 

DVD_CD=$3        #/disk/Packages 

ALL_RPMS_DIR=$2      #/mnt/cdrom/Packages/

DVD_RPMS_DIR=$DVD_CD 

packages_list=$4    #/root/packages.list 

number_of_packages=`cat $packages_list | wc -l` 

i=1 

while [ $i -le $number_of_packages ] ; do 

                line=`head -n $i $packages_list | tail -n -1` 

                name=`echo $line | awk '{print $1}'` 

                version=`echo $line | awk '{print $3}' | cut   -f    2   -d    :` 

                if [ $DEBUG -eq "1" ] ; then 

                                echo $i: $line 

                                echo $name 

                                echo $version 

                fi 

                if [ $DEBUG -eq "1" ] ; then 

                                ls $ALL_RPMS_DIR/$name-$version* 

                                if [ $? -ne 0 ] ; then 

                                                echo "cp $ALL_RPMS_DIR/$name$version* " 

                                fi 

                else 

                                echo "cp $ALL_RPMS_DIR/$name-$version* $DVD_RPMS_DIR/" 

                                cp $ALL_RPMS_DIR/$name$version* $DVD_RPMS_DIR/ 

                                # in case the copy failed 

                                if [ $? -ne 0 ] ; then 

                                                echo "cp $ALL_RPMS_DIR/$name$version* " 

                                                cp $ALL_RPMS_DIR/$name* $DVD_RPMS_DIR/ 

                                fi 

                fi 

                i=`expr $i + 1` 

done 


###模糊查找rpm包,并拷贝指定文件夹 

find_packages_list() { 

root_dir=$2    #源目录 

decs_dir=$3    #目标目录 

load_file=$4 #检查列表 

xorg_dim=$5    #通配规则 


for i in `cat $load_file|sort|uniq -c|awk '{print$2}'` 

do 

   if [ $decs_dir = "--test" ];then 

      case "$xorg_dim" in 

                --fr) 

                            echo "=====================$i(fr)========================" 

                            echo `/bin/find $root_dir -name "*$i"`

echo "===============================================" 

                            ;; 

                --br) 

                            echo "=====================$i(br)========================" 

                            echo `/bin/find $root_dir -name "$i*"` 

                            echo "===============================================" 

                            ;; 

                --all) 

                            echo "=====================$i(all)========================" 

                            echo `/bin/find $root_dir -name "*$i*"` 

                            echo "==============================================="  

                            ;; 

                  *) 

                            echo "=====================$i(default)===============" 

                            echo `/bin/find $root_dir -name "*$i*"` 

                            echo "===============================================" 

                            ;; 

              esac 


  elif [ -d $decs_dir ];then 

      case "$decs_dir" in 

                --fr) 

                         find $root_dir -name "*$i" -type f -exec cp -rf {} $decs_dir \; 

                            echo $i 

                            ;;       

                --br) 

                            find $root_dir -name "$i*" -type f -exec cp -rf {} $decs_dir \; 

                            echo $i 

                            ;; 

                --all) 

                            find $root_dir -name "*$i*" -type f -exec cp -rf {} $decs_dir \; 

                            echo $i 

                            ;; 

                  *) 

                            find $root_dir -name "*$i*" -type f -exec cp -rf {} $decs_dir \; 

                            echo $i 

                            ;; 

                  esac 

  else 

                echo "Usage: {--test|destination_dir}" 

                exit 1 

  fi 

done 

}

case "$1" in 

  -b) 

                if [ $2 ];then 

                                      build_packages_list -b $2 

                                else 

                                    echo    "Nothing input!!! " 

                                fi 

                ;; 

  -c) 

                if [ $2 -a    $3   -a $4 ];then 

                                      copy_packages_list -c $2 $3 $4 

                                else 

                                      echo "Nothing input!!! " 

                                fi 

                ;; 

  -f) 

                if [ $2 -a $3 -a $4 -a $4 -a $5 ];then 

                                find_packages_list -f $2 $3 $4 $5 

                        else 

                                echo "Nothing input!!! " 

                        fi 

                ;; 

  --h|--help) 

                echo "===============================================================" 

                echo "这个脚本主要用在定制linux_base 系时,将install.log 文件中安装的rpm包" 

                echo "导到一个文件列表中;然后再将该导出的文件中的rpm包列表全部拷贝到将要" 

                echo "定制的base版系统的Packages文件夹中.这些rpm包为裁剪原版系统后所得的" 

                echo "基本包." 

                echo "使用方法:" 

                echo "      1、生成RPM列表:$prog -b {export_file}" 

                echo "         例子:$prog -b /root/soft.list" 

                echo "      2、拷贝RPM包:$prog -c {source_dir} {destination_dir} {inport_file}"  

                echo "           例子:$prog -c /mnt/cdrom/ /disk/ /root/soft.list" 

                echo "      3、查找并拷贝rpm包:" 

                echo "            $prog -f {source_dir} {destination_dir} {inport_file} {fr,br,all}" 

                echo "            $prog -f /mnt/cdrom/ /disk/ /root/soft.list --all" 

                echo "      4、只测试不拷贝文件:" 

                echo "            $prog -f {source_dir} --test {inport_file} {fr,br,all}" 

                echo "            $prog -f /mnt/cdrom/ --test /root/soft.list --all" 

                echo " ==============================================================" 

                ;; 

  *) 

                echo $"Usage: $prog {-b|-c|--h|--help}" 

                exit 1 

esac 




mkisofs -o mycentos.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T ./


2.Package kernel

Basic tools:

bash# yum -y install anaconda repodata createrepo mkisofs yum-utils anacondaanaconda-help busybox-anaconda anaconda-runtime


3.Copy necessary RPM from ISO


Bash# cat  /Disk/.discinfo 

1385726732.061157 

6.5 

x86_64 

ALL


Bash# find /kvm/diskimg/ -name TRANS.TBL -exec rm -f {} \; -print


4.Define Packages u need


  • a.update initscripts

Packages# rm -f initscripts*rpm

Packages# yumdownloader initscripts


  • b.update kernel.rpm

Packages# ls kernel-* 

kernel-2.6.32-431.el6.x86_64.rpm  

kernel-firmware-2.6.32-431.el6.noarch.rpm

Packages# rm -f kernel-*

Packages# cp kernel.rpm to Packages/


Tips:

  • c.update other.rpm

bash# yumdownloader ethtool

ethtool-3.5-1.2.el6_5.x86_64.rpm

bash# yumdownloader lsof

lsof-4.82-4.el6.x86_64.rpm

bash# yumdownloader dstat

dstat-0.7.0-1.el6.noarch.rpm

bash# yumdownloader telnet

telnet-0.17-47.el6_3.1.x86_64.rpm

bash# yumdownloader tcpdump

tcpdump-4.0.0-3.20090921gitdf3cb4.2.el6.x86_64.rpm

bash# yumdownloader wget

wget-1.12-1.11.el6_5.x86_64.rpm

bash# yumdownloader libpcap.x86_64

libpcap-1.4.0-1.20130826git2dbcaa1.el6.x86_64.rpm 

bash# yumdownloader man

man-1.6f-32.el6.x86_64.rpm


5.Modify&generate repo


[root@UCSKVMS003 Disk]# ls repodata/

4298a169e67b5307206fe9452123299eec5ce6679a1ba7fa75bcef0918ab4b54-a.xml.gz

666bb333cbb296c039ceb35eb38600afe31f7d11c2866010627dabf7f3718b46-primary.sqlite.bz2

7f286da6eeccccde31443c7142fb50ceff892fc0ae312ff3ca6cbcd3ddef2700-filelists.xml.gz

b29244f1bc0b1fa7eb4da4ad0c9a67e895bdf2dbfd1330197e4c6e10b1887dd2-primary.xml.gz

b98066d2866eac72e99d30fd88b308409376f38a3f60a3a030269de1f8cd798c-other.sqlite.bz2

bd99971feb50ae04073fdf793dc245f5ee4739b172f3fbd86c8df8fc2863113e-other.xml.gz

c835df571cc201349726ccaffaf1f9103d0e1b7b5e546205df38ff803024b957-filelists.sqlite.bz2

e8699122b72de35f5a26d970cfba2fb4f625da276f4bb6478b0e502f9948593e-a.xml

repomd.xml

6.Generate Kickstart


[root@UCSKVMS003 centos_dvd]# cat isolinux/myks.cfg 

# Kickstart file automatically generated by anaconda.


#version=DEVEL

install

cdrom

lang en_US.UTF-8

keyboard us

#network --onboot yes --device eth0 --bootproto dhcp --noipv6

#network --onboot yes --device eth1 --bootproto dhcp --noipv6

#network --onboot yes --device eth2 --bootproto dhcp --noipv6

#network --onboot yes --device eth3 --bootproto dhcp --noipv6

#network --onboot yes --device eth4 --bootproto dhcp --noipv6

rootpw  --iscrypted $6$ann9woCn3F0wlOy9$/Em0/FZmecg7kY0uV9p/BtYwDnA/.u6wXllkEYV5yM2sd5V/scFXujDj2OxJtWBl3p9OCA/R6ZcwMJv/8Nq1B0

firewall --service=ssh

authconfig --enableshadow --passalgo=sha512

selinux --disabled

timezone --utc Asia/Shanghai

bootloader --location=partition --driveorder=sdb,sda --append="crashkernel=auto rhgb quiet"

# The following is the partition information you requested

# Note that any partitions you deleted are not expressed

# here so unless you clear all partitions first, this is

# not guaranteed to work

#clearpart --all --drives=sdb


#part None --fstype=ext4 --onpart=sda1 --noformat

#part pv.008002 --onpart=sda2 --noformat


#part /boot/efi --fstype=efi --grow --maxsize=200 --size=50

#part /boot --fstype=ext4 --size=500

#part pv.008019 --grow --size=1


#volgroup vg_ucskvms003 --pesize=4096 pv.008019

#logvol / --fstype=ext4 --name=lv_root --vgname=vg_ucskvms003 --size=195364

#logvol swap --name=lv_swap --vgname=vg_ucskvms003 --size=32868


#repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100


%packages

@core

%post --log=/usr/src/install.log


dracut -f -v --hostonly -k '/lib/modules/3.17.0+' /boot/initramfs-3.17.0+.img 3.17.0+


echo "initrd /initramfs-3.17.0+.img" >>/boot/grub/grub.conf


mkdir -p /mnt/cdrom


mount -r -t iso9660 /dev/cdrom /mnt/cdrom


unalias cp


cp -r /mnt/cdrom/opt /root


find /lib/modules/3.17.0+ -name ixgbe.ko -exec rm -f {} \;


install -D -m 644 /root/opt/ixgbe.ko /lib/modules/3.17.0+/kernel/drivers/net/ixgbe/ixgbe.ko


/sbin/depmod -a

@system-management-snmp

@server-policy

openvswitch

openvswitch-debuginfo

kmod-openvswitch

@workstation-policy

%end

%post

mkdir -p /data

mkdir -p /dist/dist

mkdir -p /dist/src

mkdir -p /mnt/cdrom

7.Update isolinux.cfg


Edit these code:

vi isolinux/isolinux.cfg

labels linux

  menu label ^Install or upgrade an existing system

  menu default

  kernel vmlinuz

  append ks=cdrom:/isolinux/myks.cfg initrd=initrd.img


8.Transfer to ISO

bash# cd /Disk

Disk# mkisofs -o ../J-k3.17.0+base6.5V19.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T /kvm/diskimg/

/usr/bin/implantisomd5 ../J-k3.17.0+base6.5V19.iso


1.Reading initrd.img


[root@UCSKVMS003 tmp]# file initrd-kernel_3.17.0+.img 

initrd-kernel_3.17.0+.img: ASCII cpio archive (SVR4 with no CRC)


Exert cpio format:

[root@UCSKVMS003 initrd0]# cpio -idmv


# file initrd.img

initrd.img: LZMA compressed data, streamed


Exert LZMA format

[root@UCSKVMS003 initrd6.5]# xz -dc tinitrd6.5.img | cpio -id



2.Compress initrd


bash#cd /lib/modules/`uname -r`

bash#mkinitrd /tmp/initrd.`uname -r`.img   `uname -r`

bash#cd /tmp

bash#mv initrd.`uname –r`.img initrd.`uname –r`.img.gz

bash#gunzip initrd.`uname -r`.img.gz

cpio

#假设当前目录位于准备好的initrd文件系统的根目录下

bash# find . | cpio -c -o > ../initrd.img

bash# gzip ../initrd.img


  • Cleanup Old .configure before make new kernel

bash# make mrproper

bash# make menuconfig

bash# make clean


LZMA format

#find . | cpio -c -o | xz -9 --format=lzma > initrd.img


rpm -qpR NetworkManager-glib-0.8.1-66.el6.i686.rpm 

/sbin/ldconfig  

/sbin/ldconfig  

dbus >= 1.1

dbus-glib >= 0.86-3

libc.so.6  


—————————————


cd Packages/

rpm --initdb --dbpath Packages/

rpm --test --dbpath /kvm/diskimg/Packages/ -Uvh *.rpm

9.Repodata optimization

1. comps.xml include multi-language

2. remove the unness我们先去除不需要的语言,这里我只需要英文,

3

sed -ri '/xml:lang/ {/en_GB|zh_CN/!d}' comps.xml # 如果需要保留其他语言比如中文,在en_GB后添加"?zh_CN"


configure network ks.cfg


      libXt

      libXtst

      libxml2

      libXi

      libXft

      libX11

      libXext

      libpng

      libSM

      glib2

      gtk2

      libICE

      cairo

      dbus-libs

      dbus

      fontconfig

      freetype

      atk

      atk

      git

      gcc-c++

      gcc

      gettext

      libtool

      make

      patch

      pkgconfig

      redhat-rpm-config

      rpm-build

      ncurses-devel

      zlib-devel

      glibc-devel

      tigervnc-server

      qemu-img

      qemu-kvm

      libvirt-devel

      libvirt

      libvirt-client

      GConf2

      ModemManager

      ORBit2

      NetworkManager

      NetworkManager-glib

      anaconda

      anaconda-yum-plugins

      avahi-glib

      avahi-autoipd

      comps-extras

      cracklib-python

      cvs

      deltarpm

      device-mapper-multipath

      docbook-dtds

      dracut-kernel

      fcoe-utils

      gd

      glibc2-doc

      glibc2-static

      glibc-static

      glibc-utils

      glibmm24

      glibmm24-devel

      glibmm24-doc

      gnome-doc-utils-stylesheets

      gnome-keyring

      gnome-python2

      gnome-python2-canvas

      gnome-user-docs

      gnome-vfs2

      grubby

      gstreamer

      gstreamer-tools

      krb5-devel

      libIDL

      libXres

      libarchive

      libart_lgpl

      libattr

      libblkid

      libcanberra

      libcanberra-gtk2

      libcom_err-devel

      libconfig

      libcurl

      libdaemon

      liberation-fonts-common

      liberation-sans-fonts 

      libevent

#####

      libglade2

      libgnomecanvas

      libgudev1

      libhbaapi

      libhbalinux

      libnotify

      libreport-gtk

      libreport-newt

      libselinux-devel

      libselinux-python

      libsepol-devel

      libsigc++20

      libsigc++20-devel

      libsndfile

      libtdb

      libtool

      libuser-python

      libwnck

      lldpad

      lldpad-libs

      lm_sensors-libs

      lockdev

      logrotate

      lrzsz

      makebootfat

      minicom

      mobile-broadband-provider-info

      module-init-tools

      mtools

      net-snmp-libs

      net-snmp

      net-snmp-utils

      notification-daemon

      openssl-devel

      pcre

      perl-Compress-Raw-Zlib

      perl-Compress-Zlib

      perl-HTML-Parser

      perl-HTML-Tagset

      perl-IO-Compress-Base

      perl-IO-Compress-Zlib

      perl-URI

      perl-XML-Parser

      perl-libwww-perl

      ppp

      pycairo

      pygobject2

      pygtk2

      pygtk2-libglade

      pykickstart

      pyparted

      python-cryptsetup

      python-decorator

      python-deltarpm

      python-meh

      python-nss

      python-pyblock

      python-slip

      pyxf86config

      rarian

      rarian-compat

      sgml-common

      sound-theme-freedesktop

      squashfs-tools

      startup-notification

      syslinux

      syslinux-nonlinux

      system-config-date

      system-config-date-docs

      system-config-keyboard

      system-config-keyboard-base

      usermode-gtk

      wpa_supplicant

      xcb-util

      xml-common

      xulrunner

      zenity

      zlib-static

      glib2-doc

      glib2-static

      yum-plugin-downloadonly

      libXmu

  • network (可选)

    配置网络信息;在网络安装(NFS/HTTP/FTP)时必须指定;

    --bootproto=dhcp|bootp|static    指定ip获取方式,默认为dhcp/bootp;

    --device=    设置安装时激活来进行系统安装的网卡设备;该参数只在kickstart文件为本地文件时有效;若kickstart配置文件在网络上,安装程序会先初始化网卡然后去寻找kickstart文件;

    --ip=    ip设置

    --gateway=   网关

    --nameserver=  DNS设置

    --nodns         不设置DNS

    --netmask=   掩码

    --hostname= 设置安装后主机名称

    --onboot=    设置是否在系统启动时激活网卡

    --class=        设置DHCP的class值

    --noipv4        禁用该设备的ipv4功能

    --noipv6        禁用该设备的ipv6功能

    如将网络模式设置为静态模式,则必须在一行内写上ip,netmask、dns、gateway等信息;

    例:

    network –bootproto=static –ip=1.1.1.1 --metmask=255.0.0.0 --gateway=1.1.1.254 --nameserver=1.1.1.2

    network --bootproto=dhcp  --device=eth0


阅读(1652) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~