minor changed -- tweaking the initramfs

This commit is contained in:
KatolaZ 2018-02-08 23:48:18 +00:00
parent 48c403521b
commit e442fb034b
2 changed files with 276 additions and 12 deletions

View File

@ -0,0 +1,232 @@
#!/bin/bash
# ----------------------------------------------------------------------
#
# This file is part of microdevuan, a set of scripts to create minimal
# devuan live images
#
# ----------------------------------------------------------------------
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ----------------------------------------------------------------------
#
# (c) KatolaZ <katolaz@freaknet.org> (2016)
#
# ----------------------------------------------------------------------
####
##
## This will create a minimal initrd without too much garbage
##
## KatolaZ -- 2016-05-14
##
##
if [ $# -le 3 ]; then
echo "Usage: $0 <initrd_orig> <initrd_new> <initrd_compression> <initrd_micro>"
exit 1
fi
####
##
## Config options --
##
OLDPWD=`pwd`
INITRD_ORIG=$1
INITRD_NEW=$2
INITRD_COMPR=$3
INITRD_MICRO=$4
echo "$0: got $1 $2 $3 $4"
WORK_DIR=/tmp/initrd_new
MODULE_DIR=lib/modules/`uname -r`/kernel
####
##
## unpack the current initrd image
##
if [ ! -d ${WORK_DIR} ]; then
mkdir ${WORK_DIR}
else
rm -rf ${WORKDIR}/*
fi
####
##
## Determine how the original initrd was compressed...
##
INITRD_FILE=`file ${INITRD_ORIG}`
if [ `echo ${INITRD_FILE} | grep gzip | wc -l` = 1 ]; then
INITRD_UNCOMPRESS=zcat;
elif [ `echo ${INITRD_FILE} | grep bzip2 | wc -l` = 1 ]; then
INITRD_UNCOMPRESS=bzcat;
elif [ `echo ${INITRD_FILE} | grep " xz " | wc -l` = 1 ]; then
INITRD_UNCOMPRESS=xzcat;
else
echo "Unable to determine the format of ${INITRD_ORIG} -- Aborting!!!"
exit 1;
fi
echo -n "===> Uncompressing the original init using ${INITRD_UNCOMPRESS}..."
cd ${WORK_DIR}; `${INITRD_UNCOMPRESS} ${INITRD_ORIG} | cpio -id`
echo "done!"
####
##
## Remove unnecessary ethernet modules -- we already know
## that the root partition is not over nfs...
##
echo -n "===> Removing network drivers..."
##rm -rf ${MODULE_DIR}/drivers/net/ethernet/*
rm -rf ${MODULE_DIR}/drivers/net/*
echo "done!"
####
##
## Remove unnecessary filesystem support
##
##
echo -n "===> Removing unnecessary filesystems drivers..."
##rm -rf ${MODULE_DIR}/fs/nfs
rm -rf ${MODULE_DIR}/fs/xfs
rm -rf ${MODULE_DIR}/fs/btrfs
##rm -rf ${MODULE_DIR}/fs/ext4
rm -rf ${MODULE_DIR}/fs/fat
rm -rf ${MODULE_DIR}/fs/fuse
rm -rf ${MODULE_DIR}/fs/hfs
rm -rf ${MODULE_DIR}/fs/hfsplus
rm -rf ${MODULE_DIR}/fs/reiserfs
rm -rf ${MODULE_DIR}/fs/ntfs
rm -rf ${MODULE_DIR}/fs/jfs
rm -rf ${MODULE_DIR}/fs/jffs2
rm -rf ${MODULE_DIR}/fs/udf
rm -rf ${MODULE_DIR}/fs/nls
rm -rf ${MODULE_DIR}/fs/nfs_common
echo "done!"
####
##
## Remove the lftp and qla2xxx drivers (FibreChannel)
##
echo -n "===> Removing unnecessary SCSI drivers..."
rm -rf ${MODULE_DIR}/drivers/scsi/lpfc
rm -rf ${MODULE_DIR}/drivers/scsi/qla2xxx
echo "done!"
####
##
## Maybe we might remove everything in usr/lib
##
echo -n "===> Removing unnecessary libraries in /usr/lib..."
##rm -rf usr/lib/*
echo "done!"
####
##
## Remove unnecessary stuff in /bin and /sbin
##
echo -n "===> Removing unnecessary stuff in /bin and /sbin..."
#rm -rf bin/rsync bin/wget
#rm -rf sbin/acpid
#rm -rf lib/systemd
echo "done!"
####
##
## Now we create the new slim initrd
##
# echo -n "===> Creating new initrd '${INITRD_NEW}' using ${INITRD_COMPR}..."
# find . | cpio -H newc -o | `echo ${INITRD_COMPR}` > ${INITRD_NEW}
# echo "done!"
####
##
## Now we go for the extremely stripped down initrd
##
rm -rf ${MODULE_DIR}/drivers/scsi/fnic
rm -rf ${MODULE_DIR}/drivers/scsi/csiostor
rm -rf ${MODULE_DIR}/drivers/scsi/isci
rm -rf ${MODULE_DIR}/drivers/scsi/cxgbi
rm -rf ${MODULE_DIR}/drivers/scsi/megaraid
rm -rf ${MODULE_DIR}/drivers/scsi/mpt2sas
rm -rf ${MODULE_DIR}/drivers/scsi/mpt3sas
rm -rf ${MODULE_DIR}/drivers/scsi/pm8001
rm -rf ${MODULE_DIR}/drivers/scsi/qla4xxx
rm -rf ${MODULE_DIR}/drivers/scsi/aic7xxx
rm -rf ${MODULE_DIR}/drivers/scsi/bfa
####
##
## Now we create the micro initrd
##
cat <<EOF
*************************************************************************
** WARNING!!!! DO NOT INTERRUPT THE CREATION OF INITRD OR YOUR IMAGE **
** WILL COME OUT COMPLETELY BROKEN (AND YOU MIGHT NEED TO START FROM **
** SCRATCH!!!) **
*************************************************************************
EOF
echo -n "===> Creating new initrd '${INITRD_MICRO}' using ${INITRD_COMPR}..."
find . | cpio -H newc -o | `echo ${INITRD_COMPR}` > ${INITRD_MICRO}
echo -n "done!"
####
##
## Remove the directory
##
cd ${OLDPWD} && rm -rf ${WORK_DIR}
exit 0

View File

@ -23,6 +23,7 @@ BLENDPATH="${BLENDPATH:-$(dirname $0)}"
source $BLENDPATH/config source $BLENDPATH/config
blend_release_path=$BLENDPATH/$release/ blend_release_path=$BLENDPATH/$release/
blend_scripts=${blend_release_path}/scripts
###source $BLENDPATH/$release/devuan-minimal-live.release ###source $BLENDPATH/$release/devuan-minimal-live.release
@ -56,7 +57,7 @@ blend_postinst() {
#install-custdebs || zerr #install-custdebs || zerr
pushd "$strapdir" pushd "$strapdir"
sudo rsync -avx --no-o --no-g "$blend_release_path"/rootfs_overlay/* . || zerr sudo rsync -avx --no-o --no-g "$blend_release_path"/rootfs_overlay/* . || zerr
chmod 755 etc/init.d/boot_beep sudo chmod 755 etc/init.d/boot_beep
## TODO: ## TODO:
## insserv boot_beep ## insserv boot_beep
popd popd
@ -182,6 +183,7 @@ EOF
} }
## UNUSED
iso_write_grub_cfg() { iso_write_grub_cfg() {
fn iso_write_grub_cfg "(override)" fn iso_write_grub_cfg "(override)"
req=(workdir arch username) req=(workdir arch username)
@ -239,10 +241,21 @@ menuentry "Memory test" {
EOF EOF
} }
blend_finalize() { ## put the "create_initrd.sh" script
fn blend_finalize
req=(strapdir username default_shell) ##func
ckreq || return 1 put_create_initrd(){
sudo cp ${blend_scripts}/create_initrd.sh ${strapdir}/ >/dev/null
## Now we make it executable
sudo chmod 755 ${strapdir}/create_initrd.sh
}
## put the "finalize" script, that does the final work
## func
put_finalize(){
cat <<EOF | sudo tee ${strapdir}/finalize >/dev/null cat <<EOF | sudo tee ${strapdir}/finalize >/dev/null
#!/bin/sh #!/bin/sh
@ -254,13 +267,6 @@ done
chsh -s "${default_shell}" ${username} chsh -s "${default_shell}" ${username}
chown -R 1000:1000 /home/${username} chown -R 1000:1000 /home/${username}
cp /home/${username}/Desktop/refractainstaller.desktop /usr/share/applications/
chmod +x /home/${username}/Desktop/refractainstaller.desktop
# This can go away when desktop-base is fixed to do the grub theme.
grep -q GRUB_THEME /etc/default/grub || {
printf "\nGRUB_THEME=/usr/share/desktop-base/grub-themes/desktop-grub-theme/theme.txt\n" >> /etc/default/grub
}
# Not sure if this has been fixed (in devuan-baseconf?) # Not sure if this has been fixed (in devuan-baseconf?)
mv /data/etc/apt/apt.conf.d/05disable-suggests /etc/apt/apt.conf.d/ mv /data/etc/apt/apt.conf.d/05disable-suggests /etc/apt/apt.conf.d/
@ -284,6 +290,21 @@ insserv boot_beep
setcap 'cap_sys_tty_config+ep' /usr/bin/fbterm setcap 'cap_sys_tty_config+ep' /usr/bin/fbterm
chmod u+s /usr/bin/fbterm chmod u+s /usr/bin/fbterm
## Make initramfs
SLIM_INITRD=initrd_devuan.img
MICRO_INITRD=initramfs-\$(uname -r).img
INITRD_COMPR="xz --check=crc32 --x86 -6 -"
/create_initrd.sh /boot/initrd.img-`uname -r` /boot/\${SLIM_INITRD} \
"\${INITRD_COMPR}" /boot/\${MICRO_INITRD}
unlink /initrd.img
ln -s /boot/\${MICRO_INITRD} /initrd.img
## rm create_initrd.sh
##sudo rm /create_initrd.sh
## package list ## package list
dpkg -l | awk '/^ii/ { print $2 " " $3 }' > /home/${username}/package_list dpkg -l | awk '/^ii/ { print $2 " " $3 }' > /home/${username}/package_list
@ -292,7 +313,18 @@ apt-get update
apt-get clean apt-get clean
updatedb updatedb
EOF EOF
}
blend_finalize() {
fn blend_finalize
req=(strapdir username default_shell)
ckreq || return 1
put_create_initrd
put_finalize
chroot-script -d finalize || zerr chroot-script -d finalize || zerr
} }