#!/bin/sh
rootdir=`pwd`
rm -rf ${rootdir}/centos*
KERNEL_DIR=${rootdir}/kernel
ROOTFS_DIR=${rootdir}/rootfs
if [ -d ${KERNEL_DIR} ]; then
echo "remove kernel dir"
rm -rf ${KERNEL_DIR}
fi
echo "mkdir kernel dir"
mkdir ${KERNEL_DIR}
if [ -d ${ROOTFS_DIR} ]; then
echo "remove rootfs dir"
rm -rf ${ROOTFS_DIR}
fi
echo "mkdir rootfs dir"
mkdir ${ROOTFS_DIR}
rm -rf centos7_*
#-------- reduce /var/lib/rpm/Packages----------
rpm --rebuilddb
echo "--run:yum clean all"
yum clean all
echo "Begin to copy kernel ...."
cp -cpR /boot/initramfs-3.10.0-327.4.5.el7.x86_64.img ${KERNEL_DIR}
cp -cpR /boot/symvers-3.10.0-327.4.5.el7.x86_64.gz ${KERNEL_DIR}
cp -cpR /boot/System.map-3.10.0-327.4.5.el7.x86_64 ${KERNEL_DIR}
cp -cpR /boot/vmlinuz-3.10.0-327.4.5.el7.x86_64 ${KERNEL_DIR}
echo "Copy kernel finish..."
echo "Begin to copy rootfs..."
cp -cpR /bin ${ROOTFS_DIR}
cp -cpR /dev ${ROOTFS_DIR}
cp -cpR /etc ${ROOTFS_DIR}
cp -cpR /lib ${ROOTFS_DIR}
cp -cpR /lib64 ${ROOTFS_DIR}
cp -cpR /opt ${ROOTFS_DIR}
cp -cpR /root ${ROOTFS_DIR}
cp -cpR /run ${ROOTFS_DIR}
cp -cpR /sbin ${ROOTFS_DIR}
cp -cpR /srv ${ROOTFS_DIR}
cp -cpR /tmp ${ROOTFS_DIR}
cp -cpR /usr ${ROOTFS_DIR}
cp -cpR /var ${ROOTFS_DIR}
mkdir -p ${ROOTFS_DIR}/boot
mkdir -p ${ROOTFS_DIR}/bootloader
mkdir -p ${ROOTFS_DIR}/ftp
mkdir -p ${ROOTFS_DIR}/media
mkdir -p ${ROOTFS_DIR}/proc
mkdir -p ${ROOTFS_DIR}/sys
mkdir -p ${ROOTFS_DIR}/tar
mkdir -p ${ROOTFS_DIR}/system
mkdir -p ${ROOTFS_DIR}/home
cp -cpR /home/fornax ${ROOTFS_DIR}/home
cp -cpR /home/hillstone ${ROOTFS_DIR}/home
cp -cpR /data ${ROOTFS_DIR}
rm -rf ${ROOTFS_DIR}/data/db-data/ib_logfile*
rm -rf ${ROOTFS_DIR}/data/db-data/ibtmp1
rm -rf ${ROOTFS_DIR}/usr/share/man/*
rm -rf ${ROOTFS_DIR}/usr/share/doc/*
rm -rf ${ROOTFS_DIR}/var/lib/mysql
sed -i "s/^IPADDR.*$/IPADDR=0.0.0.0/g" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s/^IPADDR.*$/IPADDR=0.0.0.0/g" /etc/sysconfig/network-scripts/ifcfg-eth1
#add by liulin 2016-3-22 11:28:42
rm -rf ${ROOTFS_DIR}/usr/share/locale/*
cp -cpR /usr/share/locale/zh_[C]* ${ROOTFS_DIR}/usr/share/locale/
cp -cpR /usr/share/locale/zh ${ROOTFS_DIR}/usr/share/locale/
cp -cpR /usr/share/locale/en ${ROOTFS_DIR}/usr/share/locale/
cp -cpR /usr/share/locale/en_US ${ROOTFS_DIR}/usr/share/locale/
#----------remove /usr/sbin/mysqld-debug------------
rm -rf ${ROOTFS_DIR}/usr/sbin/mysqld-debug
#remove /var/log/xxx
echo "" > ${ROOTFS_DIR}/var/log/audit/audit.log
rm -rf ${ROOTFS_DIR}/var/log/sa/*
rm -rf ${ROOTFS_DIR}/var/log/cron-*
rm -rf ${ROOTFS_DIR}/var/log/cron-*
rm -rf ${ROOTFS_DIR}/var/log/messages-*
echo "" > ${ROOTFS_DIR}/var/log/mysqld.log
#--------------remove mysql tools---------------------
rm -rf ${ROOTFS_DIR}/usr/bin/mysql_upgrade
rm -rf ${ROOTFS_DIR}/usr/bin/mysqlslap
rm -rf ${ROOTFS_DIR}/usr/bin/mysqlpump
rm -rf ${ROOTFS_DIR}/usr/bin/mysqlshow
rm -rf ${ROOTFS_DIR}/usr/bin/mysqlimport
rm -rf ${ROOTFS_DIR}/usr/bin/mysqlcheck
rm -rf ${ROOTFS_DIR}/usr/bin/mysql_config_editor
rm -rf ${ROOTFS_DIR}/usr/bin/mysql_secure_installation
#rm -rf ${ROOTFS_DIR}/usr/bin/mysql_install_db
rm -rf ${ROOTFS_DIR}/usr/bin/myisamchk
rm -rf ${ROOTFS_DIR}/usr/bin/myisampack
rm -rf ${ROOTFS_DIR}/usr/bin/myisamlog
rm -rf ${ROOTFS_DIR}/usr/bin/myisam_ftdump
rm -rf ${ROOTFS_DIR}/usr/bin/resolve_stack_dump
rm -rf ${ROOTFS_DIR}/usr/bin/mysql_tzinfo_to_sql
rm -rf ${ROOTFS_DIR}/usr/bin/mysql_ssl_rsa_setup
rm -rf ${ROOTFS_DIR}/usr/bin/mysql_plugin
rm -rf ${ROOTFS_DIR}/usr/bin/innochecksum
#------------remove /usr/bin/ tools---------
rm -rf ${ROOTFS_DIR}/usr/bin/perror
rm -rf ${ROOTFS_DIR}/usr/bin/dwp
rm -rf ${ROOTFS_DIR}/usr/bin/replace
#remove /usr/lib64/xxx
rm -rf ${ROOTFS_DIR}/usr/lib64/mysql/mecab
rm -rf ${ROOTFS_DIR}/usr/lib64/mysql/plugin/libpluginmecab.so
rm -rf ${ROOTFS_DIR}/usr/lib64/mysql/plugin/debug
#--------rm man-db-----------
rm -rf ${ROOTFS_DIR}/etc/cron.daily/man-db.cron
rm -rf ${ROOTFS_DIR}/etc/man_db.conf
rm -rf ${ROOTFS_DIR}/etc/sysconfig/man-db
rm -rf ${ROOTFS_DIR}/usr/bin/apropos
rm -rf ${ROOTFS_DIR}/usr/bin/catman
rm -rf ${ROOTFS_DIR}/usr/bin/lexgrog
rm -rf ${ROOTFS_DIR}/usr/bin/man
rm -rf ${ROOTFS_DIR}/usr/bin/mandb
rm -rf ${ROOTFS_DIR}/usr/bin/manpath
rm -rf ${ROOTFS_DIR}/usr/bin/whatis
rm -rf ${ROOTFS_DIR}/usr/lib64/man-db
rm -rf ${ROOTFS_DIR}/usr/lib64/man-db/libman-2.6.3.so
rm -rf ${ROOTFS_DIR}/usr/lib64/man-db/libman.so
rm -rf ${ROOTFS_DIR}/usr/lib64/man-db/libmandb-2.6.3.so
rm -rf ${ROOTFS_DIR}/usr/lib64/man-db/libmandb.so
rm -rf ${ROOTFS_DIR}/usr/libexec/man-db
rm -rf ${ROOTFS_DIR}/usr/libexec/man-db/globbing
rm -rf ${ROOTFS_DIR}/usr/libexec/man-db/manconv
rm -rf ${ROOTFS_DIR}/usr/sbin/accessdb
#---------rm zip ----------
rm -rf ${ROOTFS_DIR}/usr/bin/zip
rm -rf ${ROOTFS_DIR}/usr/bin/zipcloak
rm -rf ${ROOTFS_DIR}/usr/bin/zipnote
rm -rf ${ROOTFS_DIR}/usr/bin/zipsplit
#--------rm yum(yum can use)-----------
rm -rf ${ROOTFS_DIR}/var/lib/yum/yumdb/*
rm -rf ${ROOTFS_DIR}/var/lib/yum/history*
echo "--------all is finish-------------"
echo "----------------------------"
du -sh ${rootdir}/
du -sh ${rootdir}/*
echo "----------------------------"
echo
echo
echo "now begin to tar /rootfs and /kernel to xxx.tar.gz"
packageDate=`date "+%Y-%m-%d-%H%M"`
tar -zcvf centos7_${packageDate}_hsa.tar.gz ./kernel/ ./rootfs/
转载请标明出处:http://www.cnblogs.com/ssslinppp/