-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenable kernel
More file actions
192 lines (158 loc) Β· 4.56 KB
/
Copy pathenable kernel
File metadata and controls
192 lines (158 loc) Β· 4.56 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
# Interactive kernel module browser, enabler, and blacklister
# Usage: sudo ./enable_modules_interactive.sh
set -e
KERNEL_DIR="/lib/modules/$(uname -r)"
BLACKLIST_FILE="/etc/modprobe.d/blacklist.conf"
echo "π§ Kernel version: $(uname -r)"
echo
# --- Function: list directories and let user choose one ---
choose_directory() {
local base_dir="$1"
local dirs=()
echo "π Contents of $base_dir:"
local i=1
for d in "$base_dir"*/; do
[ -d "$d" ] || continue
dirs+=("$d")
echo " [$i] $(basename "$d")"
((i++))
done
# Option for other modules in this folder
local other_modules=($(find "$base_dir" -maxdepth 1 -type f -name "*.ko*" | sort))
if [ ${#other_modules[@]} -gt 0 ]; then
echo " [$i] Other modules in this folder"
dirs+=("other_modules")
fi
if [ ${#dirs[@]} -eq 0 ]; then
echo "β οΈ No subdirectories or modules found here."
return 1
fi
echo
read -p "β‘οΈ Enter number to open a directory (or 'b' to go back): " choice
if [[ "$choice" == "b" ]]; then
return 1
fi
local selected="${dirs[$((choice-1))]}"
echo
if [ "$selected" == "other_modules" ]; then
scan_modules "$base_dir"
elif [ -d "$selected" ]; then
echo "π You selected: $selected"
echo
choose_next "$selected"
else
echo "β Invalid choice."
return 1
fi
}
# --- Function: recursive navigation ---
choose_next() {
local dir="$1"
local subdirs=()
for s in "$dir"*/; do
[ -d "$s" ] || continue
subdirs+=("$s")
done
if [ ${#subdirs[@]} -gt 0 ]; then
choose_directory "$dir"
else
scan_modules "$dir"
fi
}
# --- Function: scan modules, enable, disable, blacklist ---
scan_modules() {
local dir="$1"
echo "π Scanning for modules in: $dir"
echo
local modules=($(find "$dir" -maxdepth 1 -type f -name "*.ko*" | sort))
if [ ${#modules[@]} -eq 0 ]; then
echo "β οΈ No modules found here."
return
fi
local enabled_modules=()
local not_enabled=()
local index=1
for m in "${modules[@]}"; do
modname=$(modinfo --field name "$m" 2>/dev/null)
[ -z "$modname" ] && continue
if lsmod | grep -qw "^$modname"; then
echo " β
[$index] $modname (ENABLED)"
enabled_modules+=("$modname")
else
echo " β [$index] $modname (NOT ENABLED)"
not_enabled+=("$modname")
fi
((index++))
done
echo
# --- Enable section ---
if [ ${#not_enabled[@]} -gt 0 ]; then
echo "β The following modules are NOT enabled:"
for i in "${!not_enabled[@]}"; do
echo " [$((i+1))] ${not_enabled[$i]}"
done
echo
read -p "β‘οΈ Type numbers (space-separated) of modules to enable, or 'a' for all, or Enter to skip: " choices
echo
if [ -n "$choices" ]; then
local to_enable=()
if [[ "$choices" == "a" ]]; then
to_enable=("${not_enabled[@]}")
else
for c in $choices; do
idx=$((c-1))
to_enable+=("${not_enabled[$idx]}")
done
fi
for mod in "${to_enable[@]}"; do
echo "πΉ Enabling: $mod"
if sudo modprobe "$mod"; then
echo " β
Loaded successfully."
else
echo " β οΈ Failed to load module: $mod"
fi
done
echo
fi
fi
# --- Disable section ---
if [ ${#enabled_modules[@]} -gt 0 ]; then
echo "β
The following modules are ENABLED:"
for i in "${!enabled_modules[@]}"; do
echo " [$((i+1))] ${enabled_modules[$i]}"
done
echo
read -p "β‘οΈ Type numbers to DISABLE (space-separated), or 'a' for all, or Enter to skip: " disable_choices
echo
if [ -n "$disable_choices" ]; then
local to_disable=()
if [[ "$disable_choices" == "a" ]]; then
to_disable=("${enabled_modules[@]}")
else
for c in $disable_choices; do
idx=$((c-1))
to_disable+=("${enabled_modules[$idx]}")
done
fi
for mod in "${to_disable[@]}"; do
echo "π» Disabling: $mod"
if sudo modprobe -r "$mod" 2>/dev/null; then
echo " β
Unloaded successfully."
if ! grep -q "^blacklist $mod$" "$BLACKLIST_FILE" 2>/dev/null; then
echo "blacklist $mod" | sudo tee -a "$BLACKLIST_FILE" > /dev/null
echo " π Added to blacklist: $BLACKLIST_FILE"
fi
else
echo " β οΈ Failed to unload module: $mod"
fi
done
echo
fi
fi
}
# --- Start interactive navigation ---
choose_directory "$KERNEL_DIR/"
sudo nano enable_modules_interactive.sh
sudo chmod +x enable_modules_interactive.sh
./enable_modules_interactive.sh