2012-05-18 20:27:25 +04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
SILENT=false
|
2012-08-17 11:08:15 +04:00
|
|
|
NICE_CMD="nice -n 19 ionice -c2"
|
2012-05-18 20:27:25 +04:00
|
|
|
|
|
|
|
# available parameters
|
|
|
|
eval set -- "`getopt -o hs --long help,silent -- \"$@\"`"
|
|
|
|
|
|
|
|
while true ; do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
echo "Usage: kernel-rebuild.sh [keys]..."
|
|
|
|
echo "Keys:"
|
|
|
|
echo -e "-h, --help\tShow this help and exit."
|
|
|
|
echo -e "-s, --silent \tMake with silentoldconfig."
|
|
|
|
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 ;;
|
|
|
|
--) shift ; break ;;
|
|
|
|
*) echo "Internal error!" ; exit -1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
CONFIG_FILE=/proc/config.gz
|
|
|
|
[ "$1" != "" ] && CONFIG_FILE=$1
|
|
|
|
|
|
|
|
cd /usr/src/linux
|
|
|
|
[ "$?" != "0" ] && echo /usr/src/linux doesn\'t exist && exit -1
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if [ true == "$SILENT" ]; then
|
|
|
|
yes "" | make silentoldconfig
|
|
|
|
[ "$?" != "0" ] && echo "======= yes \"\" | make silentoldconfig failed ;-( =======" && exit -1
|
|
|
|
else
|
|
|
|
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
|
2012-05-19 15:06:54 +04:00
|
|
|
jobs=$((`grep "^processor" /proc/cpuinfo -c`+1))
|
2012-05-18 20:27:25 +04:00
|
|
|
if [[ "$?" == 0 ]]; then
|
2012-08-17 10:51:32 +04:00
|
|
|
$NICE_CMD make -j$jobs
|
2012-05-18 20:27:25 +04:00
|
|
|
[ 0 -ne $? ] && echo "Kernel build failed ;-(" && exit -1
|
|
|
|
else
|
|
|
|
# pump make -j$((jobs*3)) || make -j$jobs
|
2012-08-17 10:51:32 +04:00
|
|
|
$NICE_CMD make -j$jobs
|
2012-05-18 20:27:25 +04:00
|
|
|
[ 0 -ne $? ] && echo "Kernel build failed ;-(" && exit -1
|
|
|
|
fi
|
|
|
|
|
2012-08-17 11:46:40 +04:00
|
|
|
echo "remounting /boot -> rw"
|
2012-05-18 20:27:25 +04:00
|
|
|
mount -o remount,rw /boot
|
|
|
|
|
2012-08-17 10:51:32 +04:00
|
|
|
$NICE_CMD make install
|
|
|
|
$NICE_CMD make modules_install
|
2012-05-18 20:27:25 +04:00
|
|
|
|
|
|
|
REVISION=`cat /usr/src/linux/include/config/kernel.release`
|
2012-07-08 01:13:47 +04:00
|
|
|
|
2012-08-17 10:51:32 +04:00
|
|
|
which dracut &>/dev/null && $NICE_CMD dracut --hostonly --force /boot/initramfs-$REVISION.img $REVISION
|
2012-07-08 01:13:47 +04:00
|
|
|
|
|
|
|
sed -i "s~\/boot\/vmlinuz-[0-9][^ ]*~\/boot\/vmlinuz-$REVISION~g;
|
2012-07-08 01:18:11 +04:00
|
|
|
s~\/boot\/initramfs-[0-9][^ ]*~\/boot\/initramfs-$REVISION.img~g" \
|
2012-07-08 01:13:47 +04:00
|
|
|
/boot/grub/grub.conf
|
2012-05-18 20:27:25 +04:00
|
|
|
|
2012-08-17 11:46:40 +04:00
|
|
|
echo "remounting /boot -> ro"
|
2012-05-18 20:27:25 +04:00
|
|
|
mount -o remount,ro /boot
|
|
|
|
|
|
|
|
echo "--------- Rebuilding kernel modules ---------"
|
|
|
|
emerge -1qv @module-rebuild
|
|
|
|
[ 0 -ne $? ] && echo "Upgrading kernel modules failed ;-(" && exit -1
|
|
|
|
|
|
|
|
cd $pwdtmp
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|