-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinitramfs-and-grub-update.sh
More file actions
executable file
·79 lines (67 loc) · 2.52 KB
/
initramfs-and-grub-update.sh
File metadata and controls
executable file
·79 lines (67 loc) · 2.52 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
#!/bin/bash
echo "#####################################################"
echo "ETJAKEOC TKT kernel initramfs and GRUB2 update script"
echo "#####################################################"
echo "#####################################################"
echo "This script should be adaptable to any distribution."
echo "It will attempt to generate a new 'initrd' image for your system"
echo "and update your GRUB2 bootloader menu for you."
echo "Please press enter to continue."
read -r dummy_variable
# Find the TKT kernel package
tkt_k=$(find /lib/modules -name '*TKT*')
if [ -z "$tkt_k" ]; then
echo "Error: TKT kernel package not found."
exit 1
fi
# Extract the kernel version from the package filename
tkt_version=$(basename "$tkt_k" | sed 's/kernel-\([0-9.]*\).*/\1/')
if [ -z "$tkt_version" ]; then
echo "Error: Unable to extract TKT kernel version."
exit 1
fi
# Probe for the name of the GRUB configuration command
if command -v grub-mkconfig >/dev/null 2>&1; then
grub_config_command="grub-mkconfig"
elif command -v grub2-mkconfig >/dev/null 2>&1; then
grub_config_command="grub2-mkconfig"
else
echo "Error: Unable to find grub-mkconfig or grub2-mkconfig command."
exit 1
fi
# Probe if dracut is available
if command -v dracut >/dev/null 2>&1; then
use_dracut=true
else
use_dracut=false
fi
# Probe if mkinitcpio is available
if command -v mkinitcpio >/dev/null 2>&1; then
use_mkinitcpio=true
else
use_mkinitcpio=false
fi
# Probe if update-initramfs is available
if command -v update-initramfs >/dev/null 2>&1; then
use_update_initramfs=true
else
use_update_initramfs=false
fi
# Generate initramfs using dracut if available, mkinitcpio if available, otherwise use update-initramfs
if [ "$use_dracut" = true ]; then
echo "Running 'dracut' to generate the 'initramfs' file..."
sudo dracut --kver "$tkt_version"
elif [ "$use_mkinitcpio" = true ]; then
echo "Running 'mkinitcpio' to generate the 'initramfs' file..."
sudo mkinitcpio -k "$tkt_version" -g "/boot/initramfs-${tkt_version}.img"
elif [ "$use_update_initramfs" = true ]; then
echo "Running 'update-initramfs' to generate the 'initramfs' file..."
sudo update-initramfs -c -k "$tkt_version"
else
echo "Error: Unable to find dracut, mkinitcpio, or update-initramfs command."
exit 1
fi
# Update GRUB configuration
echo "Updating the GRUB boot loader menu to add the new kernel..."
sudo "$grub_config_command" -o /boot/grub/grub.cfg
echo "Everything completed successfully. Please reboot, and enjoy your new kernel! :D"