Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for /dev/disk/by-uuid in fstab parsing #409

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions dissect/target/plugins/os/unix/_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,25 @@ def parse_fstab(
volume_name = None
if dev.startswith(("/dev/mapper", "/dev/gpt")):
volume_name = dev.rsplit("/")[-1]
elif dev.startswith("/dev/disk/by-uuid"):
dev_id = dev.rsplit("/")[-1]
elif dev.startswith("/dev/") and dev.count("/") == 3:
# When composing a vg-lv name, LVM2 replaces hyphens with double hyphens in the vg and lv names
# Emulate that here when combining the vg and lv names
volume_name = "-".join(part.replace("-", "--") for part in dev.rsplit("/")[-2:])
elif dev.startswith("UUID="):
dev_id = dev.split("=")[1]
try:
dev_id = uuid.UUID(dev_id)
except ValueError:
pass
else:
log.warning("Unsupported mount device: %s %s", dev, mount_point)
continue

if mount_point == "/":
continue

if dev_id:
try:
dev_id = uuid.UUID(dev_id)
except ValueError:
pass

yield dev_id, volume_name, fs_type, mount_point
7 changes: 5 additions & 2 deletions tests/test_plugins_os_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
/dev/mapper/vg--main-lv--var /var auto default 0 2

/dev/vg-main/lv-data /data auto default 0 2

/dev/disk/by-uuid/af0b9707-0945-499a-a37d-4da23d8dd245 /moredata auto default 0 2
""" # noqa


Expand All @@ -49,15 +51,16 @@ def test_parse_fstab():

records = list(parse_fstab(fs.path("/etc/fstab")))

# 10 input records minus
# 11 input records minus
# 2 unsupported mount devices (proc, /dev/disk/cloud/azure_resource-part1)
# 2 swap partitions
# 1 root partition
# = 5 expected results
# = 6 expected results

assert set(records) == {
(UUID("5d1f1508-069b-4274-9bfa-ae2bf7ffb5e0"), None, "ext4", "/home"),
(UUID("28a25297-9825-4f87-ac41-f9c20cd5db4f"), None, "ext4", "/boot"),
(UUID("af0b9707-0945-499a-a37d-4da23d8dd245"), None, "auto", "/moredata"),
("F631-BECA", None, "vfat", "/boot/efi"),
(None, "vg--main-lv--var", "auto", "/var"),
(None, "vg--main-lv--data", "auto", "/data"),
Expand Down