Skip to content

Commit 37b9dcc

Browse files
committed
ci: Create script for installing custom kernel
Creating a script to build and install a modified kernel with patches applied. Signed-off-by: Jack Thomson <[email protected]>
1 parent c9fa6fe commit 37b9dcc

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
3+
# We need sudo privilleges to install the kernel
4+
if [ "$(id -u)" -ne 0 ]; then
5+
echo "This script must be run as root or with sudo privileges"
6+
exit 1
7+
fi
8+
9+
# Currently this script only works on Ubuntu instances
10+
if ! grep -qi 'ubuntu' /etc/os-release; then
11+
echo "This script currently only works on Ubuntu."
12+
exit 1
13+
fi
14+
15+
confirm() {
16+
if [[ "$*" == *"-y"* ]]; then
17+
return 0
18+
fi
19+
20+
while true; do
21+
echo "This script will build and install a new kernel. Run this script at your own risk"
22+
read -p "Do you want to continue? (y/n) " yn
23+
case $yn in
24+
[Yy]*) return 0 ;;
25+
[Nn]*)
26+
echo "Exiting..."
27+
exit 1
28+
;;
29+
*) echo "Please answer yes or no." ;;
30+
esac
31+
done
32+
}
33+
34+
# Make sure a user really wants to run this script
35+
confirm "$@"
36+
37+
KERNEL_URL=$(cat kernel_url)
38+
KERNEL_COMMIT_HASH=$(cat kernel_commit_hash)
39+
KERNEL_VERSION=$(cat kernel_version)
40+
KERNEL_PATCHES_DIR=$(pwd)/patches
41+
KERNEL_CONFIG_OVERRIDES=$(pwd)/kernel_config_overrides
42+
43+
TMP_BUILD_DIR=$(mktemp -d -t kernel-build-XXXX)
44+
45+
pushd .
46+
cd $TMP_BUILD_DIR
47+
48+
echo "Cloning kernel repository into" $TMP_BUILD_DIR
49+
50+
# We checkout the repository that way to make it as
51+
# small and fast as possible
52+
git init
53+
git remote add origin $KERNEL_URL
54+
git fetch --depth 1 origin $KERNEL_COMMIT_HASH
55+
git checkout FETCH_HEAD
56+
57+
# Apply our patches on top
58+
for PATCH in $KERNEL_PATCHES_DIR/*.patch; do
59+
echo "Applying patch:" $(basename $PATCH)
60+
git apply $PATCH
61+
done
62+
63+
echo "Making kernel config ready for build"
64+
# We use olddefconfig to automatically pull in the
65+
# config from the AMI and update to the newest
66+
# defaults
67+
make olddefconfig
68+
69+
# Disable the ubuntu keys
70+
scripts/config --disable SYSTEM_TRUSTED_KEYS
71+
scripts/config --disable SYSTEM_REVOCATION_KEYS
72+
73+
# Apply our config overrides on top of the config
74+
scripts/kconfig/merge_config.sh .config $KERNEL_CONFIG_OVERRIDES
75+
76+
# Finally run olddefconfig again to make sure any
77+
# new options are configured before build
78+
make olddefconfig
79+
80+
echo "Building kernel this may take a while"
81+
make -j $(nproc)
82+
echo "Building kernel modules"
83+
make modules -j $(nproc)
84+
echo "Kernel build complete!"
85+
86+
echo "Installing kernel modules..."
87+
make INSTALL_MOD_STRIP=1 modules_install
88+
echo "Installing kernel..."
89+
make INSTALL_MOD_STRIP=1 install
90+
echo "Update initramfs"
91+
update-initramfs -c -k $KERNEL_VERSION
92+
echo "Updating GRUB..."
93+
update-grub
94+
95+
echo "Kernel built and installed successfully!"
96+
97+
# Some cleanup after we are done
98+
popd
99+
rm -rf $TMP_BUILD_DIR
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7eb172143d5508b4da468ed59ee857c6e5e01da6
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_EXPERT=y
2+
CONFIG_KVM_SW_PROTECTED_VM=y
3+
CONFIG_KVM_AMD_SEV=y
4+
CONFIG_DEBUG_INFO=y

resources/hiding_ci/kernel_url

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/torvalds/linux.git

resources/hiding_ci/kernel_version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.14.0-rc5+

0 commit comments

Comments
 (0)