-
Notifications
You must be signed in to change notification settings - Fork 2
/
boot-drive-restore
executable file
·47 lines (35 loc) · 891 Bytes
/
boot-drive-restore
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
#!/bin/bash
if [ $# -lt 3 ]; then
echo "$(basename $0) [Boot device] [Boot partition mount point] [Boot image compressed file name]"
exit 1
fi
if [[ $EUID > 0 ]]; then # we can compare directly with this syntax.
echo "Please run as root/sudo!"
exit 1
fi
DEV=$1
MNT=$2
BAK=$3
[ -b ${DEV} ] || {
echo "Invalid device \"${DEV}\"." >&2
exit 1
}
mountpoint ${MNT} &>/dev/null || {
echo "Invalid mount point \"${MNT}\"." >&2
exit 1
}
[ -f ${BAK} ] || {
echo "Invalid backup file \"${BAK}\"." >&2
exit 1
}
command -v parted > /dev/null || apt install -y parted || exit $?
echo -e "Target device info:\n"
parted ${DEV} print
echo -e "Target mount point info:\n"
ls ${MNT}
echo ""
read -p "Are you sure? (CTRL-C to exit)"
grub-install --force --boot-directory=${MNT} ${DEV} \
&& cd ${MNT} \
&& rm -rf ${MNT}/* \
&& tar xvf ${BAK} --strip-components=1 -C ${MNT}