From cc69c1f9f858dfde2110455032880ad9df461fe5 Mon Sep 17 00:00:00 2001 From: Miauwkeru Date: Thu, 8 Feb 2024 15:58:05 +0000 Subject: [PATCH 1/2] Add mount by LABEL= for ext filesystems (DIS-2894) --- dissect/target/plugins/os/unix/_os.py | 5 +++++ tests/plugins/os/unix/test__os.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/dissect/target/plugins/os/unix/_os.py b/dissect/target/plugins/os/unix/_os.py index 5a0017b77..75b4d3e53 100644 --- a/dissect/target/plugins/os/unix/_os.py +++ b/dissect/target/plugins/os/unix/_os.py @@ -222,6 +222,9 @@ def _add_mounts(self) -> None: # but instead a volume_id which is not case-sensitive fs_id = fs_id[:4].upper() + "-" + fs_id[4:].upper() + if fs.__type__ == "ext": + fs_volume_name = fs.extfs.volume_name + if ( (fs_id and (fs_id == dev_id and (subvol == fs_subvol or subvolid == fs_subvolid))) or (fs_volume_name and (fs_volume_name == volume_name)) @@ -353,6 +356,8 @@ def parse_fstab( volume_name = "-".join(part.replace("-", "--") for part in dev.rsplit("/")[-2:]) elif dev.startswith("UUID="): dev_id = dev.split("=")[1] + elif dev.startswith("LABEL="): + volume_name = dev.split("=")[1] else: log.warning("Unsupported mount device: %s %s", dev, mount_point) continue diff --git a/tests/plugins/os/unix/test__os.py b/tests/plugins/os/unix/test__os.py index c727d78ed..b14754b73 100644 --- a/tests/plugins/os/unix/test__os.py +++ b/tests/plugins/os/unix/test__os.py @@ -39,6 +39,8 @@ /dev/vg-main/lv-data /data auto default 0 2 /dev/disk/by-uuid/af0b9707-0945-499a-a37d-4da23d8dd245 /moredata auto default 0 2 + +LABEL=foo /foo auto default 0 2 """ # noqa @@ -65,6 +67,7 @@ def test_parse_fstab(tmp_path): ("F631-BECA", None, "/boot/efi", "vfat", "defaults,discard,umask=0077"), (None, "vg--main-lv--var", "/var", "auto", "default"), (None, "vg--main-lv--data", "/data", "auto", "default"), + (None, "foo", "/foo", "auto", "default"), } From 22be0e0b3a5d7e5241ca5104c8eebc979390b110 Mon Sep 17 00:00:00 2001 From: Miauwkeru Date: Fri, 9 Feb 2024 08:54:25 +0000 Subject: [PATCH 2/2] Remove dev_id check --- dissect/target/plugins/os/unix/_os.py | 39 +++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/dissect/target/plugins/os/unix/_os.py b/dissect/target/plugins/os/unix/_os.py index 75b4d3e53..81710ecc5 100644 --- a/dissect/target/plugins/os/unix/_os.py +++ b/dissect/target/plugins/os/unix/_os.py @@ -203,32 +203,29 @@ def _add_mounts(self) -> None: fs_subvol = None fs_subvolid = None fs_volume_name = fs.volume.name if fs.volume and not isinstance(fs.volume, list) else None - last_mount = None - - if dev_id: - if fs.__type__ == "xfs": - fs_id = fs.xfs.uuid - elif fs.__type__ == "ext": - fs_id = fs.extfs.uuid - last_mount = fs.extfs.last_mount - elif fs.__type__ == "btrfs": - fs_id = fs.btrfs.uuid - fs_subvol = fs.subvolume.path - fs_subvolid = fs.subvolume.objectid - elif fs.__type__ == "fat": - fs_id = fs.fatfs.volume_id - # This normalizes fs_id to comply with libblkid generated UUIDs - # This is needed because FAT filesystems don't have a real UUID, - # but instead a volume_id which is not case-sensitive - fs_id = fs_id[:4].upper() + "-" + fs_id[4:].upper() - - if fs.__type__ == "ext": + fs_last_mount = None + + if fs.__type__ == "xfs": + fs_id = fs.xfs.uuid + elif fs.__type__ == "ext": + fs_id = fs.extfs.uuid + fs_last_mount = fs.extfs.last_mount fs_volume_name = fs.extfs.volume_name + elif fs.__type__ == "btrfs": + fs_id = fs.btrfs.uuid + fs_subvol = fs.subvolume.path + fs_subvolid = fs.subvolume.objectid + elif fs.__type__ == "fat": + fs_id = fs.fatfs.volume_id + # This normalizes fs_id to comply with libblkid generated UUIDs + # This is needed because FAT filesystems don't have a real UUID, + # but instead a volume_id which is not case-sensitive + fs_id = fs_id[:4].upper() + "-" + fs_id[4:].upper() if ( (fs_id and (fs_id == dev_id and (subvol == fs_subvol or subvolid == fs_subvolid))) or (fs_volume_name and (fs_volume_name == volume_name)) - or (last_mount and (last_mount == mount_point)) + or (fs_last_mount and (fs_last_mount == mount_point)) ): self.target.log.debug("Mounting %s (%s) at %s", fs, fs.volume, mount_point) self.target.fs.mount(mount_point, fs)