0% found this document useful (0 votes)
216 views

Kernel CK Ubuntu

This Bash script downloads and applies various patches to customize a Linux kernel build, including the BFS and BFQ schedulers. It downloads files from online sources, applies patches, configures the kernel, and cleans up files and folders. The script provides status updates and handles dependencies to build a patched Ubuntu kernel.

Uploaded by

ravenkill
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
216 views

Kernel CK Ubuntu

This Bash script downloads and applies various patches to customize a Linux kernel build, including the BFS and BFQ schedulers. It downloads files from online sources, applies patches, configures the kernel, and cleans up files and folders. The script provides status updates and handles dependencies to build a patched Ubuntu kernel.

Uploaded by

ravenkill
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

#!

/usr/bin/env bash
#http://viajemotu.wordpress.com/2012/08/13/kernel-ck-for-ubuntu-precise/
#https://github.com/chilicuil/learn/blob/master/sh/is/kernel-ck-ubuntu
# $ time bash kernel-ck-ubuntu
#####################################
#kernel version base
kernel=3.11
#kernel specific version
patchkernel=3.11.7
#BFQ patch
bfq=3.11.0-v6r2
vbfq=v6r2
#CK patch
patchck=3.11-ck1
#sufix
ckk=ck1
#arch
arqt=$(dpkg --print-architecture)
#####################################
################################################################################
####################################################
##############################################DO NOT EDIT BELOW UNLESS YOU KNOW
WHAT YOU'RE DOING###################################
################################################################################
####################################################
#the /tmp partitions usually have noexec
tmp_path="$HOME/.tmp/kernel-ck-ubuntu-$patchkernel"
curr_path=$PWD
apps_default="kernel-package gcc-4.6 libncurses5 libncurses5-dev build-essential
patch fakeroot bc"
CL=$(printf "%s\\n" "$(expr $(grep -c processor /proc/cpuinfo) + 1 )")
trap _cleanup SIGINT SIGTERM #trap ctrl-c
_header()
{
clear
printf "%b\\n" "\033[1m-------------------------------\033[7m $0 $patchkerne
l \033[0m\033[1m------------------------------\033[0m"
printf "%b\\n" "\033[1m Original:\033[0m
http://sourceforge.net/projects
/scriptkernel/"
printf "%b\\n" "\033[1m Inspired by:\033[0m http://omicron.homeip.net/proje
cts/#easy_e17.sh"
printf "%b\\n" "\033[1m Updates:\033[0m
https://github.com/chilicuil/le
arn/blob/master/sh/is/kernel-ck-ubuntu"
printf "%s\\n"
"
send your push request!"
printf "\\n"
printf "%b\\n" "\033[1m Patches:\033[0m
-bfq, -ck, -ubuntu"
printf "%b\\n" "\033[1m Config:\033[0m
http://repo-ck.com/"
printf "\\n"
printf "%b\\n" "\033[1m----------------\033[7m Current Configuration: edit t
he script to change them \033[0m\033[1m--------------\033[0m"
printf "%s\\n" " build path:
$tmp_path"
printf "%s\\n" " kernel:
$patchkernel"
printf "%s\\n" " -bfq patchset:
$bfq"

printf "%s\\n" " -ck patchset:


$patchck"
printf "%s\\n" " -ubuntu patchset: v$patchkernel"
printf "%s\\n" " sufix:
$ckk"
printf "%s\\n" " arch:
$arqt"
printf "%s\\n" " concurrency level: $CL"
printf "%b\\n" "\033[1m------------------------------------------------------------------------------------\033[0m"
}
_cmd()
{ #print current command, exits on fail
[ -z "$1" ] && return 0
printf "%s " "
printf "\\n"
eval "$@"

$ $@"

status=$?
[ X"$status" != X"0" ] && exit $status || return
}
_cmdsudo()
{ #print && execute a command, exits if command fails
[ -z "$1" ] && return 1
_cmdsudo_var_serr=$$
printf "%s " "
$ $@"
printf "\\n"
printf "%s\\n" "$sudopwd" | $sudocmd eval "$@" > /tmp/"$_cmdsudo_var_serr".o
ut 2>&1
_cmdsudo_var_status=$?
[ X"$_cmdsudo_var_status" != X"0" ] && { cat /tmp/"$_cmdsudo_var_serr".out;
\
rm -rf /tmp/"$_cmdsudo_var_serr".out; exit $_cmdsudo_var_status; } \
|| { rm -rf /tmp/"$_cmdsudo_var_serr".out; return $_cmdsudo_var_status;
}
}
_handscui()
{
[ -z $1 ] && { printf "%5s\n" ""; return 1; }
pid=$1
animation_state=1
if [ ! "$(ps -p $pid -o comm=)" ]; then
printf "%5s\n" ""
return
fi
printf "%s" "

"

while [ "`ps -p $pid -o comm=`" ]; do


printf "%b" "\b\b\b\b\b"
case $animation_state in
1)
printf "%s" '\o@o\'
animation_state=2
;;
2)

printf "%s" '|o@o|'


animation_state=3
;;
3)
printf "%s" '/o@o/'
animation_state=4
;;
4)
printf "%s" '|o@o|'
animation_state=1
;;
esac
sleep 1
done
printf "%b" "\b\b\b\b\b" && printf "%5s\n" ""
}
_getroot()
{ #get sudo's password, define $sudopasswd and $sudocmd
local tmp_path="/tmp"; local sudotest; local insudoers;
if [ ! X"$LOGNAME"
printf "%s\\n"
printf "%s\\n"
sudotest=`type

= X"root" ]; then
"Detecting user $LOGNAME (non-root) ..."
"Checking if sudo is available ..."
sudo >/dev/null 2>/dev/null; printf "%s\\n" "$?"`

if [ X"$sudotest" = X"0" ]; then


printf "%s\\n" "
Requesting sudo's password, I'll be carefull I p
romise =)"
sudo -K
if [ -e "$tmp_path/sudo.test" ]; then
rm -f "$tmp_path/sudo.test"
fi
while [ -z "$sudopwd" ]; do
printf "%s" "
- enter sudo-password: "
stty -echo
read sudopwd
stty echo
# password check
printf "%s\\n" "$sudopwd" | sudo -S touch "$tmp_path/sudo.test"
> "$tmp_path/sudo.output" 2>&1
insudoers=$(grep -i "sudoers" "$tmp_path/sudo.output")
if [ -n "$insudoers" ]; then
printf "%s\\n" "$sudopwd" | sudo -S rm "$tmp_path/sudo.outpu
t" > /dev/null 2>&1
exit
fi
if [ ! -e "$tmp_path/sudo.test" ]; then
sudopwd=""
fi
done
sudocmd="/usr/bin/sudo -S"
printf "%s\\n" "$sudopwd" | $sudocmd rm -f "$tmp_path/sudo.test" > /
dev/null 2>&1
printf "\\n"

else
printf "%s\\n" "You're not root and sudo isn't available. Please run
this script as root!"
exit
fi
fi
}
_cleanup()
{
stty echo
printf "%b\\n" "\033[1m-------------------\033[7m Cleanup \033[0m\033[1m------------------\033[0m"
printf "%s\\n" "[+] deleting files at $tmp_path ..."
#printf "%s\\n" "$sudopwd" | $sudocmd rm -v $tmp_path/patch*
#printf "%s\\n" "$sudopwd" | $sudocmd rm -v $tmp_path/*.patch
printf "%s\\n" "$sudopwd" | _cmd $sudocmd rm -rf $tmp_path/linux-$patchkerne
l-$ckk
#printf "%s\\n" "$sudopwd" | $sudocmd mount -o remount /tmp
#rm -rf $tmp_path 2>/dev/null
if [ -z "$1" ]; then
exit
fi
}
_waitfor()
{
[ -z "$1" ] && return 1
printf "%s " "
$ $@ ..."
eval "$@" > /dev/null 2>&1 &
sleep 1s
_handscui $(pidof $1)
}
_waitforsudo()
{
[ -z "$1" ] && return 1
printf "%s " "
$ sudo $@ ..."
printf "%s" "$sudopwd" | $sudocmd $@ > /dev/null 2>&1 &
sleep 1s
_handscui $(pidof $1)
}
_header
_getroot
printf "%b\\n" "\033[1m--------------------------------\033[7m Fixing dependenci
es \033[0m\033[1m--------------------------------\033[0m"
_waitforsudo apt-get update
_waitforsudo apt-get install --no-install-recommends -y $apps_default
printf "%b\\n" "\033[1m--------------------------------\033[7m Downloading archi
ves \033[0m\033[1m-------------------------------\033[0m"
printf "%s\\n" "[+] downloading main vanilla kernel tree ..."

_cmd mkdir -p $tmp_path


_cmd cd $tmp_path
_waitfor wget --no-check-certificate -N http://www.kernel.org/pub/linux/kernel/v
3.x/linux-$kernel.tar.bz2
printf "%s\\n" "[+] downloading mainstream patches ..."
_waitfor wget --no-check-certificate -N http://www.kernel.org/pub/linux/kernel/v
3.x/patch-$patchkernel.bz2
printf "%s\\n" "[+] downloading -ck patches ..."
_waitfor wget -N http://ck.kolivas.org/patches/3.0/$kernel/$patchck/patch-$patch
ck.bz2
printf "%s\\n" "[+] downloading bfq patches ..."
_waitfor wget -N http://algo.ing.unimo.it/people/paolo/disk_sched/patches/$bfq/0
001-block-cgroups-kconfig-build-bits-for-BFQ-$vbfq-$kernel.patch
_waitfor wget -N http://algo.ing.unimo.it/people/paolo/disk_sched/patches/$bfq/0
002-block-introduce-the-BFQ-$vbfq-I-O-sched-for-$kernel.patch
_waitfor wget -N http://algo.ing.unimo.it/people/paolo/disk_sched/patches/$bfq/0
003-block-bfq-add-Early-Queue-Merge-EQM-to-BFQ-$vbfq-for-$kernel.0.patch
printf "%s\\n" "[+] downloading ubuntu patches ..."
_waitfor wget -N http://kernel.ubuntu.com/~kernel-ppa/mainline/v$patchkernel-sau
cy/0001-base-packaging.patch
_waitfor wget -N http://kernel.ubuntu.com/~kernel-ppa/mainline/v$patchkernel-sau
cy/0002-debian-changelog.patch
printf "%b\\n" "\033[1m--------------------------------------\033[7m Applying pa
tches \033[0m\033[1m------------------------------\033[0m"
printf "%s\\n" "[+] uncompresing kernel to $tmp_path/linux-$kernel/ ..."
if [ ! -d "/$tmp_path/linux-$kernel/" ]; then
_waitfor "bzcat < $tmp_path/linux-$kernel.tar.bz2 | tar xvf -"
fi
printf "%s\\n" "[+] uncompresing patches ..."
_waitfor bunzip2 patch-$patchkernel.bz2 patch-$patchck.bz2
printf "%s\\n" "[+] moving to $tmp_path/linux-$patchkernel-$ckk"
_waitfor rm -rf linux-$patchkernel-$ckk
_waitfor cp -R "linux-$kernel" "linux-$patchkernel-$ckk"
_cmd cd linux-$patchkernel-$ckk
printf "%s\\n"
_cmd patch -p1
_cmd patch -p1
_cmd patch -p1
patch
_cmd patch -p1
ch
_cmd patch -p1
ernel.0.patch
_cmd patch -p1
_cmd patch -p1

"[+] applying patches (verbose output) ..."


< ../patch-$patchkernel
< ../patch-$patchck
< ../0001-block-cgroups-kconfig-build-bits-for-BFQ-$vbfq-$kernel.
< ../0002-block-introduce-the-BFQ-$vbfq-I-O-sched-for-$kernel.pat
< ../0003-block-bfq-add-Early-Queue-Merge-EQM-to-BFQ-$vbfq-for-$k
< ../0001-base-packaging.patch
< ../0002-debian-changelog.patch

printf "%b\\n" "\033[1m-----------------------------\033[7m Configuring kernel \


033[0m\033[1m----------------------------------\033[0m"
printf "%s\\n" "[+] downloading optimized config from http://repo-ck.com ...
"
#_waitfor wget "http://liquorix.net/sources/$kernel/config.$arqt"

##TODO 05-11-2013 20:30 >> liquorix.net current configuration breaks -ck kernel
#
starting in >= 3.10, check from time to time if it ca
n be reused
#for now use config mirrored from http://repo-ck.com/
_waitfor wget "http://javier.io/mirror/3.11/config.$arqt"
_cmd cp "config.$arqt" .config
##tmp fix for bug #663474, disable lguest hypervisor, http://lguest.ozlabs.org/l
guest.txt
##http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=663474
if [ X"$arqt" = X"i386" ]; then
sed -i "/CONFIG_LGUEST_GUEST/d" .config
sed -i "/CONFIG_LGUEST/d" .config
elif [ X"$arqt" = X"amd64" ]; then
if [ ! -d ./arch/amd64 ]; then
cd arch
ln -s x86 amd64
cd fi
fi
##thanks to StefanescuCristian: https://github.com/chilicuil/learn/commit/c2d445
5
printf "%s\\n" "[+] making sure BFS and BFQ are enabled in config"
sed -i "/CONFIG_SCHED_CFS=y/d" .config
sed -i "s/# CONFIG_SCHED_BFS is not set/CONFIG_SCHED_BFS=y/g" .config
sed -i "s/# CONFIG_IOSCHED_BFQ is not set/CONFIG_IOSCHED_BFQ=y/g" .config
sed -i "s/CONFIG_DEFAULT_CFQ=y/# CONFIG_DEFAULT_CFQ is not set/g" .config
sed -i "s/CONFIG_DEFAULT_DEADLINE=y/# CONFIG_DEFAULT_DEADLINE is not set/g" .con
fig
sed -i "s/CONFIG_DEFAULT_NOOP=y/# CONFIG_DEFAULT_NOOP is not set/g" .config
sed -i "s/CONFIG_DEFAULT_IOSCHED="cfq"/CONFIG_DEFAULT_IOSCHED="bfq"/g" .config
sed -i "s/CONFIG_DEFAULT_IOSCHED="deadline"/CONFIG_DEFAULT_IOSCHED="bfq"/g" .con
fig
sed -i "s/CONFIG_DEFAULT_IOSCHED="noop"/CONFIG_DEFAULT_IOSCHED="bfq"/g" .config
sed -i "s/# CONFIG_DEFAULT_BFQ is not set/CONFIG_DEFAULT_BFQ=y/g" .config
printf "%s\\n" "[+] making sure CONFIG_HZ is set to 1000, better performance + f
ixes in resume|suspending issues"
sed -i -e 's/^CONFIG_HZ_300=y/# CONFIG_HZ_300 is not set/' \
-i -e 's/^# CONFIG_HZ_1000 is not set/CONFIG_HZ_1000=y/' \
-i -e 's/^CONFIG_HZ=300/CONFIG_HZ=1000/' .config
##printf "%s\\n" "[+] optimizying even more, using streamline_config.pl ...
"
##chmod +x ./scripts/kconfig/streamline_config.pl && ./scripts/kconfig/streamlin
e_config.pl > config_strip
###make localmodconfig
##mv config_strip .config
##printf "%s\\n" "[+] running menuconfig ...
##make menuconfig

"

printf "%b\\n" "\033[1m-------------------------------\033[7m Compiling kernel \


033[0m\033[1m----------------------------------\033[0m"
printf "%s\\n" "[+] running make-kpkg ...
"
CONCURRENCY_LEVEL=$CL
printf "\\n" | _cmd fakeroot make-kpkg --initrd kernel_image kernel_headers modu
les_image

printf "%b\\n" "\033[1m-------------------------------------\033[7m DONE \033[0m


\033[1m----------------------------------\033[0m"
printf "%s\\n" "[+] copying debs files ..."
_cmd cp ../linux-*.deb "$curr_path"
printf "%s\\n" "[+] you may want to install the generated packages and reboot yo
ur system, run: $ sudo dpkg -i linux-*.deb"
printf "%s\\n" "[+] have fun ^_^!"

You might also like