forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_kernel.sh
executable file
·152 lines (114 loc) · 3.01 KB
/
build_kernel.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#! /bin/bash
### Parameters
version="latest"
#LocalVersion="adc"
# Or remove the suffix
LocalVersion=
num_core=`nproc`
### Operations
op=$1
if [ -z "${op}" ]
then
echo "Please select the operation, e.g. build, install, replace, update_grub"
read op
fi
echo "Do the action ${op}"
# Detect Linux releases
OS_DISTRO=$( awk -F= '/^NAME/{print $2}' /etc/os-release | sed -e 's/^"//' -e 's/"$//' )
if [[ $OS_DISTRO == "CentOS Linux" ]]
then
echo "Running on CentOS..."
elif [ $OS_DISTRO == "Ubuntu" ]
then
echo "Running on Ubuntu..."
fi
## Functions
delete_old_kernel_contents () {
if [[ $OS_DISTRO == "CentOS Linux" ]]
then
echo "sudo rm /boot/initramfs-${version}${LocalVersion}.img /boot/System.map-${version}${LocalVersion} /boot/vmlinuz-${version}${LocalVersion} "
sleep 1
sudo rm /boot/initramfs-${version}${LocalVersion}.img /boot/System.map-${version}${LocalVersion} /boot/vmlinuz-${version}${LocalVersion}
elif [ $OS_DISTRO == "Ubuntu" ]
then
echo "sudo rm /boot/initrd.img-${version}* /boot/System.map-${version}* /boot/vmlinuz-${version}* "
sleep 1
sudo rm /boot/initrd.img-${version}* /boot/System.map-${version}* /boot/vmlinuz-${version}*
fi
}
install_new_kernel_contents () {
echo "install kernel modules"
sleep 1
sudo make modules_install
echo "install kernel image"
sleep 1
sudo make install
#echo "Install uapi kernel headers to /usr/include/linux/"
#sudo make headers_install INSTALL_HDR_PATH=/usr
}
update_grub_entries () {
if [[ $OS_DISTRO == "CentOS Linux" ]]
then
# For CentOS, there maybe 2 grub entries
echo "(MUST run with sudo)Delete old grub entry:"
efi_grub="/boot/efi/EFI/centos/grub.cfg"
if [[ -e /boot/efi/EFI/centos/grub.cfg ]]
then
echo " Delete EFI grub : sudo rm ${efi_grub}"
sleep 1
sudo rm ${efi_grub}
echo " Rebuild EFI grub : sudo grub-mkconfig -o ${efi_grub}"
sleep 1
sudo grub2-mkconfig -o ${efi_grub}
else
echo "Delete /boot/grub/grub.cfg"
sleep 1
sudo rm /boot/grub/grub.cfg
echo "Rebuild the grub.cfg"
echo "grub-mkconfig -o /boot/grub/grub.cfg"
sleep 1
sudo grub2-mkconfig -o /boot/grub/grub.cfg
fi
echo "Set default entry to Item 0"
sudo grub-set-default 0
echo "Current grub entry"
sleep 1
sudo grub2-editenv list
elif [ $OS_DISTRO == "Ubuntu" ]
then
# # Ubuntu: to list grub entries
# awk -F\' '/menuentry / {print $2}' /boot/grub/grub.cfg
echo " Rebuild grub"
sudo update-grub2
fi
}
### Do the action
if [ "${op}" = "build" ]
then
echo "make oldconfig"
sleep 1
make oldconfig
echo "make LOCALVERSION=${LocalVersion} -j${num_core}"
sleep 1
make LOCALVERSION="${LocalVersion}" -j${num_core}
elif [ "${op}" = "install" ]
then
delete_old_kernel_contents
sleep 1
install_new_kernel_contents
sleep 1
update_grub_entries
elif [ "${op}" = "replace" ]
then
delete_old_kernel_contents
sleep 1
echo "Install kernel image only"
sudo make install
sleep 1
update_grub_entries
elif [ "${op}" = "update_grub" ]
then
update_grub_entries
else
echo "!! Wrong Operation - ${op} !!"
fi