live-sdk

simple distro kit (livecd edition)
git clone git://parazyd.org/live-sdk.git
Log | Files | Refs | Submodules | README | LICENSE

create_initrd.sh (5328B)


      1 #!/bin/bash
      2 
      3 # ----------------------------------------------------------------------
      4 #
      5 # This file is part of microdevuan, a set of scripts to create minimal 
      6 # devuan live images
      7 # 
      8 # ----------------------------------------------------------------------
      9 #
     10 # This program is free software: you can redistribute it and/or modify
     11 # it under the terms of the GNU General Public License as published by
     12 # the Free Software Foundation, either version 3 of the License, or (at
     13 # your option) any later version.
     14 # 
     15 # This program is distributed in the hope that it will be useful, but
     16 # WITHOUT ANY WARRANTY; without even the implied warranty of
     17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     18 # General Public License for more details.
     19 # 
     20 # You should have received a copy of the GNU General Public License
     21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     22 #
     23 # ----------------------------------------------------------------------
     24 #
     25 # (c) KatolaZ <katolaz@freaknet.org> (2016)
     26 #
     27 # ----------------------------------------------------------------------
     28 
     29 ####
     30 ##
     31 ## This will create a minimal initrd without too much garbage
     32 ##
     33 ## KatolaZ -- 2016-05-14
     34 ##
     35 ##
     36 
     37 if [ $# -le 3 ]; then
     38 	echo "Usage: $0 <initrd_orig> <initrd_new> <initrd_compression> <initrd_micro>"
     39 	exit 1	
     40 fi
     41 
     42 
     43 ####
     44 ##
     45 ## Config options -- 
     46 ##
     47 
     48 OLDPWD=`pwd`
     49 INITRD_ORIG=$1
     50 INITRD_NEW=$2
     51 INITRD_COMPR=$3
     52 INITRD_MICRO=$4
     53 
     54 
     55 WORK_DIR=/tmp/initrd_new
     56 
     57 MODULE_DIRS=$(ls lib/modules/)
     58 
     59 ####
     60 ##
     61 ## unpack the current initrd image
     62 ##
     63 
     64 if [ ! -d ${WORK_DIR} ]; then
     65 	  mkdir  ${WORK_DIR}
     66 else
     67     rm -rf ${WORKDIR}/*
     68 fi
     69 
     70 
     71 
     72 ####
     73 ##
     74 ## Determine how the original initrd was compressed...
     75 ##
     76 
     77 INITRD_FILE=`file -L ${INITRD_ORIG}`
     78 
     79 if [ `echo ${INITRD_FILE} | grep gzip | wc -l` == 1 ]; then
     80     INITRD_UNCOMPRESS=zcat;
     81 elif [ `echo ${INITRD_FILE} | grep bzip2 | wc -l` == 1 ]; then 
     82     INITRD_UNCOMPRESS=bzcat;
     83 elif [ `echo ${INITRD_FILE} | grep " xz " | wc -l` == 1 ]; then 
     84     INITRD_UNCOMPRESS=xzcat;
     85 else
     86     echo "Unable to determine the format of ${INITRD_ORIG} -- Aborting!!!"
     87     exit 1;
     88 fi
     89 
     90 echo -n "===> Uncompressing the original init using ${INITRD_UNCOMPRESS}..."    
     91 
     92 cd ${WORK_DIR}; `${INITRD_UNCOMPRESS} ${INITRD_ORIG} | cpio -id` 
     93 
     94 echo "done!"
     95 
     96 ####
     97 ##
     98 ## Remove unnecessary ethernet modules -- we already know
     99 ## that the root partition is not over nfs...
    100 ## 
    101 
    102 for M in ${MODULE_DIRS}; do 
    103 
    104 	echo "===> Removing drivers for kernel version ${M} <==="
    105 
    106 	MODULE_DIR="lib/modules/${M}/kernel"
    107 	
    108 	echo -n "===> Removing unnecessary network drivers..."    
    109 
    110 	##rm -rf ${MODULE_DIR}/drivers/net/ethernet/*
    111 	rm -rf ${MODULE_DIR}/drivers/net/*
    112 
    113 	echo "done!"
    114 	
    115 	####
    116 	##
    117 	## Remove unnecessary filesystem support
    118 	##
    119 	##
    120 	
    121 	echo -n "===> Removing unnecessary filesystems drivers..."    
    122 	
    123 	##rm -rf ${MODULE_DIR}/fs/nfs
    124 	rm -rf ${MODULE_DIR}/fs/xfs
    125 	rm -rf ${MODULE_DIR}/fs/btrfs
    126 	##rm -rf ${MODULE_DIR}/fs/ext4
    127 	##rm -rf ${MODULE_DIR}/fs/fat
    128 	rm -rf ${MODULE_DIR}/fs/fuse
    129 	rm -rf ${MODULE_DIR}/fs/hfs
    130 	rm -rf ${MODULE_DIR}/fs/hfsplus
    131 	rm -rf ${MODULE_DIR}/fs/reiserfs
    132 	rm -rf ${MODULE_DIR}/fs/ntfs
    133 	rm -rf ${MODULE_DIR}/fs/jfs
    134 	rm -rf ${MODULE_DIR}/fs/jffs2
    135 	rm -rf ${MODULE_DIR}/fs/udf
    136 	##rm -rf ${MODULE_DIR}/fs/nls
    137 	rm -rf ${MODULE_DIR}/fs/nfs_common
    138 	
    139 	echo "done!"
    140 	
    141 	####
    142 	##
    143 	## Remove the lftp and qla2xxx drivers (FibreChannel)
    144 	##
    145 	
    146 	echo -n "===> Removing unnecessary SCSI drivers..."    
    147 
    148 	
    149 	rm -rf ${MODULE_DIR}/drivers/scsi/lpfc
    150 	rm -rf ${MODULE_DIR}/drivers/scsi/qla2xxx
    151 	rm -rf ${MODULE_DIR}/drivers/scsi/fnic
    152 	rm -rf ${MODULE_DIR}/drivers/scsi/csiostor
    153 	rm -rf ${MODULE_DIR}/drivers/scsi/isci
    154 	rm -rf ${MODULE_DIR}/drivers/scsi/cxgbi
    155 	rm -rf ${MODULE_DIR}/drivers/scsi/megaraid
    156 	rm -rf ${MODULE_DIR}/drivers/scsi/mpt2sas
    157 	rm -rf ${MODULE_DIR}/drivers/scsi/mpt3sas
    158 	rm -rf ${MODULE_DIR}/drivers/scsi/pm8001
    159 	rm -rf ${MODULE_DIR}/drivers/scsi/qla4xxx
    160 	rm -rf ${MODULE_DIR}/drivers/scsi/aic7xxx
    161 	rm -rf ${MODULE_DIR}/drivers/scsi/bfa
    162 
    163 	echo "done!"
    164 		
    165 	## remove the gpu driver folder  altogether
    166 	
    167 	echo -n "===> Removing unnecessary GPU drivers..."    
    168 	
    169 	rm -rf ${MODULE_DIR}/drivers/gpu/
    170 	
    171 	echo "done"
    172 
    173 	echo -n "===> Removing unnecessary firmware..."    
    174 	
    175 	rm -rf ${MODULE_DIR}/firmware/radeon/
    176 	rm -rf ${MODULE_DIR}/firmware/cxgb4
    177 
    178 	echo "done"
    179 
    180 	
    181 done
    182 
    183 ##
    184 ## Remove unnecessary stuff in /bin and /sbin
    185 ##
    186 
    187 echo -n "===> Removing unnecessary stuff in /bin and /sbin..."    
    188 
    189 #rm -rf bin/rsync bin/wget
    190 #rm -rf sbin/acpid
    191 #rm -rf lib/systemd
    192 
    193 echo "done!"
    194 
    195 
    196 ####
    197 ##
    198 ## Maybe we might remove everything in usr/lib
    199 ##
    200 
    201 echo -n "===> Removing unnecessary libraries in /usr/lib..."    
    202 
    203 ##rm -rf usr/lib/*
    204 
    205 echo "done!"
    206 
    207 ####
    208 
    209 
    210 ####
    211 ##
    212 ## Now we create the micro initrd
    213 ##
    214 
    215 cat <<EOF
    216 *************************************************************************
    217 **  WARNING!!!! DO NOT INTERRUPT THE CREATION OF INITRD OR YOUR IMAGE  **
    218 **  WILL COME OUT COMPLETELY BROKEN (AND YOU MIGHT NEED TO START FROM  **
    219 **  SCRATCH!!!)                                                        **
    220 *************************************************************************
    221 EOF
    222 
    223 
    224 echo -n "===> Creating new initrd '${INITRD_MICRO}' using ${INITRD_COMPR}..."    
    225 
    226 find . | cpio -H newc -o | `echo ${INITRD_COMPR}` > ${INITRD_MICRO}
    227 
    228 echo -n "done!"
    229 
    230 ####
    231 ##
    232 ## Remove the directory
    233 ##
    234 
    235 cd ${OLDPWD} && rm -rf ${WORK_DIR}
    236 
    237 exit 0