-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_rt_preempt_kernel_Pop_OS_multi.sh
executable file
·134 lines (102 loc) · 4.5 KB
/
install_rt_preempt_kernel_Pop_OS_multi.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# Exit on the first error.
set -e
# User input, you potentially need to update or change this values during your installation
VERSION_MAJOR=5
VERSION_SECOND=15
VERSION_MINOR=21
VERSION=$VERSION_MAJOR.$VERSION_SECOND.$VERSION_MINOR
VERSION_PATCH=$VERSION-rt30
DEFAULT_CONFIG=/boot/config-$(uname -r)
if [ ! -f $DEFAULT_CONFIG ]; then
echo "Configure file $FILE does not exist. Please use other file."
exit -1
fi
echo "========================================================================="
echo "==="
echo "=== Building kernel in ~/Downloads/rt_preempt_kernel_install"
echo "==="
echo "========================================================================="
# Install dependencies to build kernel.
sudo apt-get install -y libelf-dev libncurses5-dev libssl-dev kernel-package flex bison dwarves zstd
# Install packages to test rt-preempt.
sudo apt install rt-tests
# Create folder to build kernel.
mkdir -p ~/Downloads/rt_preempt_kernel_install
cd ~/Downloads/rt_preempt_kernel_install
# Download kernel version and patches.
wget -nc https://mirrors.edge.kernel.org/pub/linux/kernel/v$VERSION_MAJOR.x/linux-$VERSION.tar.xz
wget -nc http://cdn.kernel.org/pub/linux/kernel/projects/rt/$VERSION_MAJOR.$VERSION_SECOND/older/patch-$VERSION_PATCH.patch.xz
xz -cd linux-$VERSION.tar.xz | tar xvf -
# Apply patch
cd linux-$VERSION/
xzcat ../patch-$VERSION_PATCH.patch.xz | patch -p1
# Create necessary file, see: https://ubuntuforums.org/showthread.php?t=2373905
touch REPORTING-BUGS
sudo touch /usr/share/kernel-package/ChangeLog
# Copy default config and prompt for configuration screen.
cp $DEFAULT_CONFIG .config
echo "Please apply the following configurations in the next step:"
echo ""
echo "General setup ---> [Enter]"
echo " Local Version - append to kernel release: [Enter] - write '-preempt-rt' then <ok>."
echo ""
echo " Preemption Model (Voluntary Kernel Preemption (Desktop)) [Enter]"
echo " Fully Preemptible Kernel (RT) [Enter] #Select"
echo ""
echo "After Completing - Select <save> the config then <exit>."
read -p "Please read the above instructions" yn
make menuconfig -j
# Disable the SYSTEM_TRUSTED_KEYS from the config.
# SEE: https://askubuntu.com/a/1329625
scripts/config --set-str SYSTEM_TRUSTED_KEYS ""
scripts/config --set-str SYSTEM_REVOCATION_KEYS ""
# Build the kernel.
NUMBER_CPUS=`grep -c ^processor /proc/cpuinfo`
CONCURRENCY_LEVEL=$NUMBER_CPUS make-kpkg --rootcmd fakeroot --initrd kernel_image kernel_headers
# Install the build kernel.
sudo dpkg -i ../linux-headers-$VERSION_PATCH-preempt-rt_$VERSION_PATCH-preempt-rt-10.00.Custom_amd64.deb ../linux-image-$VERSION_PATCH-preempt-rt_$VERSION_PATCH-preempt-rt-10.00.Custom_amd64.deb
# https://www.reddit.com/r/pop_os/comments/guej8v/tutorial_switchchangeswap_kernels/
# copy kernel from boot into efi/EFI Pop_OS uses systemmd boot
sudo -i
cd /boot/efi/EFI/Pop_OS-*/
cp /boot/vmlinuz-$VERSION_PATCH-preempt-rt .
cp /boot/initrd.img-$VERSION_PATCH-preempt-rt .
# Make sure permission is correct for the new kernel
chmod --reference=vmlinuz.efi vmlinuz-$VERSION_PATCH-preempt-rt
chmod --reference=vmlinuz.efi initrd.img-$VERSION_PATCH-preempt-rt
# Add entry to loader
cd /boot/efi/loader
# Number seconds to wait to choose kernel
echo "timeout 5" >> loader.conf
# Update info in new config
cd ./entries
cp Pop_OS-current.conf Pop_OS-$VERSION_PATCH-preempt-rt.conf
sudo sed -i "s/vmlinuz.efi/vmlinuz.efi-$VERSION_PATCH/g" Pop_OS-$VERSION_PATCH-preempt-rt.conf
sudo sed -i "s/initrd.img/initrd.img-$VERSION_PATCH/g" Pop_OS-$VERSION_PATCH-preempt-rt.conf
# Create realtime config.
if [ ! -f /etc/security/limits.d/99-realtime.conf ]; then
sudo tee /etc/security/limits.d/99-realtime.conf > /dev/null <<EOL
@realtime - rtprio 99
@realtime - memlock unlimited
EOL
fi
if grep -q "realtime" /etc/group; then
echo "Realtime group already exists"
else
sudo groupadd realtime
fi
sudo usermod -a -G realtime $USER
# Change the permission on /dev/cpu_dma_latency. This allows other users to
# set the minimum desired latency for the CPU other than root (e.g. the current
# user from dynamic graph manager).
sudo chmod 0666 /dev/cpu_dma_latency
echo "========================================================================="
echo "==="
echo "=== Installation done. Please reboot and select new kernel from boot menu."
echo "==="
echo "=== Make sure to add all uses with rt permissions to the 'realtime' group using:"
echo "==="
echo "=== sudo usermod -a -G realtime $USER"
echo "==="
echo "========================================================================="