Skip to content

Commit

Permalink
devices: create /dev/mapper/<logical-volume> as well
Browse files Browse the repository at this point in the history
When we create the device node inside the buildroot so far it's
very minimal - just `/dev/{vg}-{lv}` with the appopriate major/minor.

However when mount runs it will create a mapper device with the
same major/minor under `/dev/mapper/{escaped(vg)}-{escaped(lv)}`
and use that to mount the actual filesystem. Without this additional
device findmnt will not be able to detect the udev attributes of
the source (as the source is just missing from /dev).

This commit create the right mapper in the same way that we
create the non-mapper device node.
  • Loading branch information
mvo5 committed Aug 21, 2024
1 parent 31176aa commit e0f64d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion devices/org.osbuild.lvm2.lv
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ SCHEMA = """
"volume": {
"type": "string",
"description": "Logical volume to active"
}
},
}
"""

def escaped_lv_mapper_name(vg, lv: str) -> str:
"""
Return the name of the mapper device under /dev/mapper/ for the given vg, lv
"""
return f'{vg.replace("-", "--")}-{lv.replace("-", "--")}'


class LVService(devices.DeviceService):

Expand Down Expand Up @@ -198,6 +204,11 @@ class LVService(devices.DeviceService):

os.makedirs(os.path.join(devpath, vg), exist_ok=True) # type: ignore
self.ensure_device_node(fullpath, major, minor)
# also create the device under the mapper dir as this is what
# findmnt will need to get the uuid of the filesystem
os.makedirs(os.path.join(devpath, "mapper"), exist_ok=True)
mapper_path = os.path.join(devpath, "mapper", escaped_lv_mapper_name(vg, lv))
self.ensure_device_node(mapper_path, major, minor)

data = {
"path": devname,
Expand Down
7 changes: 7 additions & 0 deletions devices/test/test_lv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/python3

DEVICES_NAME = "org.osbuild.lvm2.lv"


def test_lvm2_escaped_lv_mapper_name(tmp_path, devices_module):
assert devices_module.escaped_lv_mapper_name("1d2b2150-8de2-4b68-b387-f9bc709190e8", "lvroot") == "1d2b2150--8de2--4b68--b387--f9bc709190e8-lvroot"

0 comments on commit e0f64d5

Please sign in to comment.