-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathget-udev-unrecognized-devices.sh
More file actions
54 lines (51 loc) · 1.89 KB
/
get-udev-unrecognized-devices.sh
File metadata and controls
54 lines (51 loc) · 1.89 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
#!/bin/sh
recognized=`ls -l /dev/disk/by-uuid |grep -v ^total |rev |cut -d'/' -f1 |rev |sort |tr '\n' '|' |sed 's/.$//'`
# 1. lsblk shows all drives and partitions, including not mounted
# - basically all /dev/sd* and /dev/nvme* devices + some other, not
# interesting entries (loop devices, LUKS encrypted volumes etc.)
#
# 2. grep " 0 part" leaves just partitions (UUID and non-UUID ones)
#
# 3. now filter out all partitions smaller than 1G - the intention
# is to remove Microsoft Reserved Partitions, that look like
# possibly encrypted, and trigger VeraCrypt key search, while
# not having any useful data
#
# https://en.wikipedia.org/wiki/Microsoft_Reserved_Partition
#
# this possibly removes also other (UUID) partitions smaller than 1G,
# but at this stage we are interested only in non-UUID ones, while
# UUID partitions are already processed, and are removed below
lsblk -b -P -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,PARTTYPE | awk -v recognized="$recognized" '
BEGIN {
split(recognized, uuids, "|");
for (i in uuids) {
if (uuids[i] != "") {
known[uuids[i]] = 1;
}
}
}
$0 ~ /TYPE="part"/ {
name = size = fstype = mount = uuid = parttype = "";
for (i = 1; i <= NF; i++) {
split($i, kv, "=");
key = kv[1];
val = kv[2];
gsub(/^"/, "", val);
gsub(/"$/, "", val);
if (key == "NAME") name = val;
else if (key == "SIZE") size = val;
else if (key == "FSTYPE") fstype = val;
else if (key == "MOUNTPOINT") mount = val;
else if (key == "UUID") uuid = val;
else if (key == "PARTTYPE") parttype = val;
}
if (size + 0 < 1073741824) next;
if (uuid != "" && uuid in known) next;
if (fstype == "swap" || mount == "[SWAP]") next;
if (fstype == "crypto_LUKS") next;
if (parttype ~ /0657FD6D-A4AB-43C4-84E5-0933C84B4F4F/i) next;
if (parttype == "0x82") next;
print name;
}
'