-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrecover-bootloader
executable file
·88 lines (66 loc) · 3.22 KB
/
recover-bootloader
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
#!/bin/bash
function yn-n() {
# N is the default
local REPLY
read -p "${1} [y/N] " -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
return 0
else
return 1
fi
}
function read-existing-path() {
read -r -p "${1}: " name || fail
if [ -z "${name}" ] || [ ! -e "${name}" ]; then
echo "That file doesn't exist!" 1>&2
exit 1
else
echo "${name}"
fi
}
function fail() {
echo -e "\e[31mSomething went wrong!\e[0m"
exit 1
}
cat <<EOF
This script will reinstall the bootloader from the Linux Mint 21.1
installer live USB, if for some reason you can no longer boot your installed
system (make sure you use the Live USB that matches the version of the installed
system).
EOF
if ! yn-n "Continue?"; then
exit 0
fi
# Not completely foolproof, but should do the job...
if ! lsb_release -a 2>/dev/null | grep 'vera' &>/dev/null || ! type ubiquity &>/dev/null; then
cat <<EOF
You are not running on the Linux Mint 21.1 installer live USB. Cannot go
any further.
EOF
exit 1
fi
if [ ! -e '/sys/firmware/efi' ]; then
echo 'Your firmware is BIOS. This script only supports UEFI. Cannot go any further.'
exit 1
fi
echo &&
CRYPTPART="$(read-existing-path "Enter the name of the physical partition where your encrypted container is located; typically something like /dev/sda1, /dev/sda2, /dev/nvme0n1p2, etc.")" &&
echo &&
sudo cryptsetup open "${CRYPTPART}" "$(basename "${CRYPTPART}")_crypt" &&
echo &&
ROOTDEV="$(read-existing-path "Enter the path of the device where your root partition is located; using the example names from the installation script, this would be /dev/mapper/mint-root, but of course yours might be different.")" &&
echo &&
UEFIBOOT="$(read-existing-path "Enter the name of the UEFI boot partition; typically something like /dev/sda1 or /dev/sdb2 for hard drives, or /dev/nvme0n1p1 or /dev/nvme0n2p1 for NVME SSDs")" &&
sudo mount "${ROOTDEV}" /mnt &&
sudo mount --bind /dev /mnt/dev &&
sudo mount --bind /dev/pts /mnt/dev/pts &&
sudo mount --bind /sys /mnt/sys &&
sudo mount --bind /proc /mnt/proc &&
sudo mount --bind /run /mnt/run &&
sudo mount "${UEFIBOOT}" /mnt/boot/efi &&
sudo chroot /mnt locale-gen --purge --no-archive &&
sudo chroot /mnt update-initramfs -u &&
sudo chroot /mnt update-grub &&
sudo chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --boot-directory=/boot --modules="all_video boot btrfs cat chain configfile crypto cryptodisk disk diskfilter echo efifwsetup efinet ext2 fat font gettext gcry_arcfour gcry_blowfish gcry_camellia gcry_cast5 gcry_crc gcry_des gcry_dsa gcry_idea gcry_md4 gcry_md5 gcry_rfc2268 gcry_rijndael gcry_rmd160 gcry_rsa gcry_seed gcry_serpent gcry_sha1 gcry_sha256 gcry_sha512 gcry_tiger gcry_twofish gcry_whirlpool gfxmenu gfxterm gfxterm_background gzio halt hfsplus iso9660 jpeg keystatus loadenv loopback linux linuxefi lsefi lsefimmap lsefisystab lssal luks lvm mdraid09 mdraid1x memdisk minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png raid5rec raid6rec reboot search search_fs_uuid search_fs_file search_label sleep squash4 test true video zfs zfscrypt zfsinfo" --recheck &&
sudo umount /mnt/boot/efi /mnt/proc /mnt/dev/pts /mnt/dev /mnt/sys /mnt/run /mnt &&
echo 'Finished'