-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcheckPARTUUIDsInDDImage.sh
executable file
·76 lines (63 loc) · 2.28 KB
/
checkPARTUUIDsInDDImage.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
#######################################################################################################################
#
# Retrieve PARTUUIDs of Raspberry dd Backup image partitions /boot and /
# and check if they match in /boot/cmdline.txt and /etc/fstab
#
# Copyright (C) 2021 framp at linux-tips-and-tricks dot de
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#######################################################################################################################
MYSELF="$(basename "$0")"
VERSION="0.1"
GITREPO="https://github.com/framps/raspberryTools"
echo "$MYSELF $VERSION ($GITREPO)"
if [[ $USER != "root" ]]; then
echo "Call me as root"
exit 255
fi
if [[ -z $1 ]]; then
echo "Missing image file"
exit 255
fi
echo "Mounting image $1"
kpartx -av $1
rc=$?
if (( $rc != 0 )); then
echo "kpartx error: $rc"
exit 255
fi
echo
echo "Checking PARTUUIDs"
loopUUIDs=( $(blkid | grep "/dev/mapper/loop" | grep -E -o 'PARTUUID=".*"' | sed -e "s/PARTUUID=//" -e "s/\"//g") )
echo "loopUUID[0]: ${loopUUIDs[0]}"
echo "loopUUID[1]: ${loopUUIDs[1]}"
mount /dev/mapper/loop0p1 /mnt
cmdUUID=$(grep -Eo "root=PARTUUID=\S+" /mnt/cmdline.txt | sed "s/root=PARTUUID=//" )
echo "cmdLineUUID: $cmdUUID"
umount /mnt
mount /dev/mapper/loop0p2 /mnt
fstabUUIDs=( $(grep -E "/boot\s|/\s" /mnt/etc/fstab | grep -Eo 'PARTUUID=\S+' | sed "s/PARTUUID=//") )
echo "fstabUUID[0]: ${fstabUUIDs[0]}"
echo "fstabUUID[1]: ${fstabUUIDs[1]}"
umount /mnt
if [[ $cmdUUID != ${loopUUIDs[1]} ]] \
|| [[ ${fstabUUIDs[0]} != ${loopUUIDs[0]} ]] \
|| [[ ${fstabUUIDs[1]} != ${loopUUIDs[1]} ]]; then
echo "??? Mismatch ???"
else
echo "!!! Match !!!"
fi