-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildKernel.sh
executable file
·77 lines (62 loc) · 2.7 KB
/
buildKernel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
#set -x
kernelSrcDir=linux
cd "$kernelSrcDir" || exit 1
printf "Cleanup and checkout...\n"
if ! make distclean; then
printf "Did you clone kernel sources to directory: %s?\n" "$kernelSrcDir"
exit 1
else
git reset --hard
git clean -d -f
git pull origin linux-rolling-lts || exit 1
#git pull origin linux-rolling-stable || exit 1
fi
# get kernel version from git tag
kernelVersionDir=$(git tag --merged HEAD --sort=taggerdate | tail -n1)
kernelVersion=${kernelVersionDir#v} # remove character "v" in version string
# download corresponding git module from Ubuntu mainline repo to extract and use Ubuntu kernel config
kernelUrl=https://kernel.ubuntu.com/~kernel-ppa/mainline/${kernelVersionDir}
kernelVersionLong=$(echo "$kernelVersion" | awk 'BEGIN {FS="."}{printf "%02d%02d%02d", $1, $2, $3;}')
kernelFileName=$(curl -sL "$kernelUrl" | grep -iEo "linux-modules-${kernelVersion}-${kernelVersionLong}-generic_${kernelVersion}-${kernelVersionLong}.[0-9]{12}_amd64.deb" | head -1)
kernelDeb=${kernelUrl}/amd64/${kernelFileName}
if [[ ! -f "../${kernelFileName}" ]]; then
printf "Downloading kernel %s config from Ubuntu... " "$kernelVersion"
if ! wget -O "../${kernelFileName}" -q "${kernelDeb}"; then
printf "\nProblem downloading kernel %s config from Ubuntu mainline: %s. Exiting now!\n" "$kernelVersion" "$kernelDeb"
exit 1
fi
printf "success\n\n"
fi
printf "Extracting config... "
dpkg-deb --fsys-tarfile "../${kernelFileName}" | tar xOf - ./boot/config-"${kernelVersion}"-"${kernelVersionLong}"-generic >.config || exit 1
cp .config ../config-"${kernelVersion}" || exit 1
printf "success\n\n"
git log -1 --pretty=oneline
echo "Do you wish to compile this kernel?"
echo "$ARCH"
select yn in "Yes" "No"; do
case $yn in
Yes) break ;;
No) exit 1 ;;
esac
done
export KCFLAGS="-march=native -mtune=native -O3 -pipe" KCPPFLAGS="-march=native -mtune=native -O3 -pipe"
printf "Modify kernel options...\n"
scripts/config --enable DEBUG_INFO_NONE
scripts/config --disable CONFIG_DEBUG_INFO
scripts/config --disable CONFIG_DEBUG_INFO_DWARF5
scripts/config --disable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
scripts/config --disable DEBUG_INFO_DWARF4
scripts/config --disable DEBUG_INFO_DWARF5
scripts/config --disable CONFIG_MODULE_SIG_ALL
scripts/config --set-str SYSTEM_TRUSTED_KEYS ""
scripts/config --set-str SYSTEM_REVOCATION_KEYS ""
printf "Modify optimizations in Makefile...\n\n"
sed -i 's/-O2/-O3/g' Makefile
printf "make clean build...\n"
make clean
make ARCH=x86_64 oldconfig
time nice make -j$(($(nproc) + 1)) bindeb-pkg LOCALVERSION=-"$(whoami)"-"$(hostname)" >>../build.log || exit 1
cd .. || exit 1
printf "done!\nYou can install now using:\nsudo dpkg -i linux-*%s*.deb\n" "$(whoami)"