Skip to content

Commit 5c47118

Browse files
Update get-udev-unrecognized-devices.sh
1 parent da05892 commit 5c47118

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

src/get-udev-unrecognized-devices.sh

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,36 @@ recognized=`ls -l /dev/disk/by-uuid |grep -v ^total |rev |cut -d'/' -f1 |rev |so
1919
# but at this stage we are interested only in non-UUID ones, while
2020
# UUID partitions are already processed, and are removed below
2121

22-
lsblk |grep " 0 part" |egrep -v "(K|M) 0 part" |tr -d '─├└' |cut -d' ' -f1 |egrep -v "($recognized)"
23-
24-
25-
# TODO: filter out LUKS-encrypted Linux swap partitions:
26-
# https://wiki.archlinux.org/title/Dm-crypt/Swap_encryption
27-
#
28-
# these are tricky, since:
29-
# - they can have any size
30-
# - they HAVE UUID while initialized and attached as swap at current system run
31-
# - they have different UUID after each reboot
32-
# - they no longer have UUID (and are totally unrecognized) after removing
33-
# them from /etc/crypttab and reboot
22+
lsblk -b -P -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,PARTTYPE | awk -v recognized="$recognized" '
23+
BEGIN {
24+
split(recognized, uuids, "|");
25+
for (i in uuids) {
26+
if (uuids[i] != "") {
27+
known[uuids[i]] = 1;
28+
}
29+
}
30+
}
31+
$0 ~ /TYPE="part"/ {
32+
name = size = fstype = mount = uuid = parttype = "";
33+
for (i = 1; i <= NF; i++) {
34+
split($i, kv, "=");
35+
key = kv[1];
36+
val = kv[2];
37+
gsub(/^"/, "", val);
38+
gsub(/"$/, "", val);
39+
if (key == "NAME") name = val;
40+
else if (key == "SIZE") size = val;
41+
else if (key == "FSTYPE") fstype = val;
42+
else if (key == "MOUNTPOINT") mount = val;
43+
else if (key == "UUID") uuid = val;
44+
else if (key == "PARTTYPE") parttype = val;
45+
}
46+
if (size + 0 < 1073741824) next;
47+
if (uuid != "" && uuid in known) next;
48+
if (fstype == "swap" || mount == "[SWAP]") next;
49+
if (fstype == "crypto_LUKS") next;
50+
if (parttype ~ /0657FD6D-A4AB-43C4-84E5-0933C84B4F4F/i) next;
51+
if (parttype == "0x82") next;
52+
print name;
53+
}
54+
'

0 commit comments

Comments
 (0)