2012-05-18 20:27:25 +04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
SILENT=false
|
2012-12-18 21:42:33 +04:00
|
|
|
MRPROPER=false
|
2012-08-17 11:08:15 +04:00
|
|
|
NICE_CMD="nice -n 19 ionice -c2"
|
2012-12-20 23:10:47 +04:00
|
|
|
CONFIG_FILE=/proc/config.gz
|
2013-04-02 12:56:58 +04:00
|
|
|
GENKERNEL_ARGS="--oldconfig"
|
|
|
|
USE_GENKERNEL=true
|
2012-05-18 20:27:25 +04:00
|
|
|
|
2012-10-26 11:27:57 +04:00
|
|
|
[ -f /etc/gentoo-upgrade.conf ] && source /etc/gentoo-upgrade.conf
|
|
|
|
|
2012-05-18 20:27:25 +04:00
|
|
|
# available parameters
|
2012-12-20 23:10:47 +04:00
|
|
|
eval set -- "`getopt -o hsc: --long help,silent,mrproper,config: -- \"$@\"`"
|
2012-05-18 20:27:25 +04:00
|
|
|
|
|
|
|
while true ; do
|
2013-04-02 12:56:58 +04:00
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
echo "Usage: kernel-rebuild.sh [keys]..."
|
|
|
|
echo "Keys:"
|
|
|
|
echo -e "-h, --help\t\tShow this help and exit."
|
|
|
|
echo -e "-s, --silent\t\tMake with silentoldconfig."
|
|
|
|
echo -e "--mrproper\t\tClean kernel sources before rebuild."
|
|
|
|
echo -e "-c, --config [CONFIG]\tPath to custom kernel config."
|
|
|
|
echo
|
|
|
|
echo -e "This program works on any GNU/Linux with GNU Baurne's shell"
|
|
|
|
echo -e "Report bugs to <mecareful@gmail.com>"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-s|--silent) SILENT=true ; shift ;;
|
|
|
|
--mrproper) MRPROPER=true ; shift ;;
|
|
|
|
-c|--config) CONFIG_FILE=$2 ; shift 2 ;;
|
|
|
|
--) shift ; break ;;
|
|
|
|
*) echo "Internal error!" ; exit -1 ;;
|
|
|
|
esac
|
2012-05-18 20:27:25 +04:00
|
|
|
done
|
|
|
|
|
2013-04-02 12:56:58 +04:00
|
|
|
[ "$SILENT" != "true" ] && GENKERNEL_ARGS="$GENKERNEL_ARGS --menuconfig"
|
|
|
|
[ "$MRPROPER" == "true" ] && GENKERNEL_ARGS="$GENKERNEL_ARGS --mrproper"
|
|
|
|
which genkernel &>/dev/null || USE_GENKERNEL=false
|
|
|
|
|
2012-10-26 11:27:57 +04:00
|
|
|
# remounting file systems ro->rw
|
|
|
|
for fs in $RW_REMOUNT; do
|
2013-04-02 12:56:58 +04:00
|
|
|
if [[ "$fs" =~ ^/+usr/*$ || "$fs" =~ ^/+boot/*$ ]]; then
|
|
|
|
echo "remounting $fs -> rw"
|
|
|
|
mount -o remount,rw $fs
|
|
|
|
[ 0 -ne $? ] && echo "mount -o remount,rw $fs failed ;-( =======" && exit -1
|
|
|
|
fi
|
2012-10-26 11:27:57 +04:00
|
|
|
done
|
|
|
|
|
2012-05-18 20:27:25 +04:00
|
|
|
cd /usr/src/linux
|
|
|
|
[ "$?" != "0" ] && echo /usr/src/linux doesn\'t exist && exit -1
|
|
|
|
|
2012-12-18 21:42:33 +04:00
|
|
|
if [ true == "$MRPROPER" ]; then
|
2013-04-02 12:56:58 +04:00
|
|
|
make clean && make mrproper
|
|
|
|
[ 0 -ne $? ] && echo "make clean && make mrproper failed ;-( =======" && exit -1
|
2012-12-18 21:42:33 +04:00
|
|
|
fi
|
2012-12-20 23:10:47 +04:00
|
|
|
echo CONFIG_FILE=$CONFIG_FILE
|
2012-05-18 20:27:25 +04:00
|
|
|
zcat $CONFIG_FILE >.config 2>/dev/null || cat $CONFIG_FILE >.config
|
2012-08-31 13:56:41 +04:00
|
|
|
[ "$?" != "0" ] && echo "$CONFIG_FILE doesn't exist or /usr mounted as read-only" && exit -1
|
2012-05-18 20:27:25 +04:00
|
|
|
|
2013-04-03 14:39:29 +04:00
|
|
|
make olddefconfig
|
|
|
|
[ "$?" != "0" ] && echo "======= make olddefconfig failed ;-( =======" && exit -1
|
2012-05-18 20:27:25 +04:00
|
|
|
|
2013-02-15 11:02:30 +04:00
|
|
|
# aufs3 patches
|
|
|
|
if [[ `qlist -IC sys-fs/aufs3 | wc -l` != 0 ]]; then
|
2013-04-02 12:56:58 +04:00
|
|
|
make modules_prepare
|
|
|
|
[ 0 -ne $? ] && echo "make modules_prepare failed ;-(" && exit -1
|
|
|
|
emerge -1 sys-fs/aufs3
|
|
|
|
[ 0 -ne $? ] && echo "emerge -1 sys-fs/aufs3 failed ;-(" && exit -1
|
2013-02-15 11:02:30 +04:00
|
|
|
fi
|
|
|
|
|
2014-07-07 13:05:52 +04:00
|
|
|
jobs=$((`getconf _NPROCESSORS_ONLN`+1))
|
|
|
|
|
2013-04-02 12:58:17 +04:00
|
|
|
if [ "$USE_GENKERNEL" == "true" ]; then
|
2014-07-07 13:05:52 +04:00
|
|
|
MENUCONFIG_MODE=single_menu MENUCONFIG_COLOR=mono genkernel --makeopts=-j$jobs $GENKERNEL_ARGS all
|
2013-04-02 12:56:58 +04:00
|
|
|
[ 0 -ne $? ] && echo "genkernel $GENKERNEL_ARGS all failed ;-( =======" && exit -1
|
2012-05-18 20:27:25 +04:00
|
|
|
else
|
2013-04-02 12:56:58 +04:00
|
|
|
if [ true != "$SILENT" ]; then
|
|
|
|
TERM=screen make MENUCONFIG_MODE=single_menu MENUCONFIG_COLOR=mono menuconfig
|
|
|
|
[ "$?" != "0" ] && echo "======= make menuconfig failed ;-( =======" && exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# disable distcc for -march=native -mtune=native
|
|
|
|
grep 'CONFIG_X86_MARCH_NATIVE=y' .config &>/dev/null
|
|
|
|
if [[ "$?" == 0 ]]; then
|
|
|
|
$NICE_CMD make -j$jobs
|
|
|
|
[ 0 -ne $? ] && echo "Kernel build failed ;-(" && exit -1
|
|
|
|
else
|
|
|
|
# pump make -j$((jobs*3)) || make -j$jobs
|
|
|
|
$NICE_CMD make -j$jobs
|
|
|
|
[ 0 -ne $? ] && echo "Kernel build failed ;-(" && exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
$NICE_CMD make install
|
|
|
|
$NICE_CMD make modules_install
|
|
|
|
|
|
|
|
REVISION=`cat /usr/src/linux/include/config/kernel.release`
|
|
|
|
|
|
|
|
which dracut &>/dev/null && $NICE_CMD dracut --hostonly --force /boot/initramfs-$REVISION.img $REVISION
|
2012-05-18 20:27:25 +04:00
|
|
|
fi
|
|
|
|
|
2014-08-07 15:45:42 +04:00
|
|
|
# Updating Grub config
|
|
|
|
echo "Updating Grub menu"
|
|
|
|
if [ `which grub2-mkconfig 2>/dev/null` ]; then
|
|
|
|
[ -f /boot/grub/grub.cfg ] && grub2-mkconfig -o /boot/grub/grub.cfg
|
|
|
|
[ -f /boot/grub2/grub.cfg ] && grub2-mkconfig -o /boot/grub2/grub.cfg
|
|
|
|
else
|
|
|
|
[ -f /boot/grub/grub.conf ] && \
|
|
|
|
sed -i "s~\/boot\/vmlinuz-[0-9][^ ]*~\/boot\/vmlinuz-$REVISION~g;
|
|
|
|
s~\/boot\/kernel-genkernel-`uname -m`-[0-9][^ ]*~\/boot\/kernel-genkernel-`uname -m`-$REVISION~g;
|
|
|
|
s~\/boot\/initramfs-[0-9][^ ]*~\/boot\/initramfs-$REVISION.img~g" \
|
|
|
|
/boot/grub/grub.conf
|
|
|
|
fi
|
2012-12-01 01:48:28 +04:00
|
|
|
|
2012-05-18 20:27:25 +04:00
|
|
|
echo "--------- Rebuilding kernel modules ---------"
|
2013-03-12 11:38:51 +04:00
|
|
|
emerge -1v @module-rebuild
|
2012-05-18 20:27:25 +04:00
|
|
|
[ 0 -ne $? ] && echo "Upgrading kernel modules failed ;-(" && exit -1
|
|
|
|
|
|
|
|
cd $pwdtmp
|
|
|
|
|
2012-10-26 11:27:57 +04:00
|
|
|
# remounting file systems rw->ro
|
|
|
|
for fs in $RO_REMOUNT; do
|
2013-04-02 12:56:58 +04:00
|
|
|
if [[ "$fs" =~ ^/+usr/*$ || "$fs" =~ ^/+boot/*$ ]]; then
|
|
|
|
echo "remounting $fs -> ro"
|
2013-05-02 18:29:48 +04:00
|
|
|
mount -o remount,ro -force $fs
|
|
|
|
[ 0 -ne $? ] && echo "mount -o remount,ro -force $fs failed ;-( =======" && exit -1
|
2013-04-02 12:56:58 +04:00
|
|
|
fi
|
2012-10-26 11:27:57 +04:00
|
|
|
done
|
|
|
|
|
2012-05-18 20:27:25 +04:00
|
|
|
exit 0
|
|
|
|
|