diff --git a/dissect/target/plugins/os/unix/_os.py b/dissect/target/plugins/os/unix/_os.py index 4f714637a..45bfba9d6 100644 --- a/dissect/target/plugins/os/unix/_os.py +++ b/dissect/target/plugins/os/unix/_os.py @@ -4,7 +4,7 @@ import re import uuid from struct import unpack -from typing import Iterator, Optional, Tuple, Union +from typing import Iterator, Optional, Union from dissect.target.filesystem import Filesystem from dissect.target.helpers.fsutil import TargetPath @@ -277,7 +277,7 @@ def _get_architecture(self, os: str = "unix") -> Optional[str]: def parse_fstab( fstab: TargetPath, log: logging.Logger = log, -) -> Iterator[Tuple[Union[uuid.UUID, str], str, str, str]]: +) -> Iterator[tuple[Union[uuid.UUID, str], str, str, str]]: """Parse fstab file and return a generator that streams the details of entries, with unsupported FS types and block devices filtered away. """ @@ -315,7 +315,9 @@ def parse_fstab( if dev.startswith(("/dev/mapper", "/dev/gpt")): volume_name = dev.rsplit("/")[-1] elif dev.startswith("/dev/") and dev.count("/") == 3: - volume_name = "-".join(dev.rsplit("/")[-2:]) + # 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: diff --git a/dissect/target/volumes/lvm.py b/dissect/target/volumes/lvm.py index c1f3218cb..d16aac050 100644 --- a/dissect/target/volumes/lvm.py +++ b/dissect/target/volumes/lvm.py @@ -48,5 +48,7 @@ def _detect_volume(fh: BinaryIO) -> bool: def _volumes(self) -> Iterator[Volume]: for num, lv in enumerate(self.lvm.volume_group.logical_volumes): - name = f"{lv.vg.name}-{lv.metadata.name}" + # When composing a vg-lv name, LVM2 replaces hyphens with double hyphens in the vg and lv names + # Emulate that here for the volume name + name = f"{lv.vg.name.replace('-', '--')}-{lv.metadata.name.replace('-', '--')}" yield Volume(lv, num, None, lv.size, None, name, raw=lv, vs=self) diff --git a/tests/test_plugins_os_unix.py b/tests/test_plugins_os_unix.py index 0b6bd1885..5502cd9c0 100644 --- a/tests/test_plugins_os_unix.py +++ b/tests/test_plugins_os_unix.py @@ -28,6 +28,10 @@ UUID=F631-BECA /boot/efi vfat defaults,discard,umask=0077 0 0 /dev/disk/cloud/azure_resource-part1 /mnt auto defaults,nofail,x-systemd.requires=cloud-init.service,comment=cloudconfig 0 2 + +/dev/mapper/vg--main-lv--var /var auto default 0 2 + +/dev/vg-main/lv-data /data auto default 0 2 """ # noqa @@ -41,14 +45,16 @@ def test_parse_fstab(): records = list(parse_fstab(fs.path("/etc/fstab"))) - # 8 input records minus + # 10 input records minus # 2 unsupported mount devices (proc, /dev/disk/cloud/azure_resource-part1) # 2 swap partitions # 1 root partition - # = 3 expected results + # = 5 expected results assert set(records) == { (UUID("5d1f1508-069b-4274-9bfa-ae2bf7ffb5e0"), None, "ext4", "/home"), (UUID("28a25297-9825-4f87-ac41-f9c20cd5db4f"), None, "ext4", "/boot"), ("F631-BECA", None, "vfat", "/boot/efi"), + (None, "vg--main-lv--var", "auto", "/var"), + (None, "vg--main-lv--data", "auto", "/data"), }