-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrub2_Utility.sh
executable file
·59 lines (53 loc) · 1.3 KB
/
Grub2_Utility.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
#!/usr/bin/env bash
script_version="0.0.1"
function show_error()
{
local msg="${1}"
echo "${msg}"
exit 1
}
function check_root_access()
{
if [ "$(id -u)" != "0" ]; then
show_error "Error! You must execute the script as the 'root user."
fi
}
function check_sudo_command()
{
if [ ! -n ${SUDO_USER} ]; then
show_error "Error! You must invoke the script using 'sudo'."
fi
}
check_root_access
check_sudo_command
echo "Welcome to Repair, Restore or Reinstall Grub 2"
echo "for Linux (Ububtu,Mint,Remix)"
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "First give us the partision name to mounted!"
echo "for example :sda1"
read primary_partision
mount /dev/$primary_partision /mnt
mount --bind /dev /mnt/dev &&
mount --bind /dev/pts /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
echo "The partistion has been mounted!"
chroot /mnt
echo "Now we are in /mnt "
echo "Please give us the root name partision"
echo "for example : sda"
read root_partision
echo "Starting repair grub2"
grub-install /dev/$root_partision
grub-install --recheck /dev/$root_partision
update-grub
echo "Grub2 repair has finish"
echo "Try to umount partision"
exit &&
umount /mnt/sys &&
umount /mnt/proc &&
umount /mnt/dev/pts &&
umount /mnt/dev &&
umount /mnt
echo "Umount has finish, your system is restarting.."
exit