Skip to content

Commit 9104694

Browse files
committed
add basic mdadm support
Signed-off-by: Zen <[email protected]>
1 parent 68f7bd9 commit 9104694

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/ugrd/fs/mdraid.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__version__ = '0.1.0'
2+
3+
4+
def md_init(self):
5+
return "mdadm --assemble --scan"

src/ugrd/fs/mdraid.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
binaries = ['mdadm']
2+
3+
[imports.init_early]
4+
"ugrd.fs.mdadm" = [ "md_init" ]

src/ugrd/fs/mounts.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'desultory'
2-
__version__ = '4.16.4'
2+
__version__ = '4.16.5'
33

44
from pathlib import Path
55
from zenlib.util import contains, pretty_print
@@ -375,6 +375,9 @@ def _autodetect_dm(self, mountpoint, device=None) -> None:
375375
autodetect_luks(self, source_device, dev_name, dm_info)
376376
elif dm_info.get('type') == 'LVM2_member':
377377
autodetect_lvm(self, source_device, dev_name, dm_info)
378+
elif dm_info.get('type') == 'linux_raid_member':
379+
autodetect_raid(self, source_device, dev_name, dm_info)
380+
raise NotImplementedError("RAID autodetection not implemented.")
378381
else:
379382
raise RuntimeError("Unknown device mapper device type: %s" % dm_info.get('type'))
380383

@@ -388,6 +391,15 @@ def _autodetect_dm(self, mountpoint, device=None) -> None:
388391
self.logger.debug("Slave does not appear to be a DM device: %s" % slave)
389392

390393

394+
@contains('autodetect_root_raid', "Skipping RAID autodetection, autodetect_root_raid is disabled.", log_level=30)
395+
@contains('hostonly', "Skipping RAID autodetection, hostonly mode is disabled.", log_level=30)
396+
def autodetect_raid(self, mount_loc, dm_num, dm_info) -> None:
397+
""" Autodetects MD RAID mounts and sets the raid config. """
398+
if 'ugrd.fs.raid' not in self['modules']:
399+
self.logger.info("Autodetected MDRAID mount, enabling the mdraid module.")
400+
self['modules'] = 'ugrd.fs.mdraid'
401+
402+
391403
@contains('autodetect_root_dm', "Skipping device mapper autodetection, autodetect_root_dm is disabled.", log_level=30)
392404
@contains('hostonly', "Skipping device mapper autodetection, hostonly mode is disabled.", log_level=30)
393405
def autodetect_root_dm(self) -> None:

src/ugrd/fs/mounts.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ autodetect_root = true
1313
autodetect_root_dm = true
1414
autodetect_root_luks = true
1515
autodetect_root_lvm = true
16+
autodetec_root_raid = true
1617
autodetect_init_mount = true
1718
late_fstab = "/etc/fstab.late"
1819

@@ -53,6 +54,7 @@ autodetect_root = "bool" # Add the autodetect_root property, if defined, the ro
5354
autodetect_root_dm = "bool" # Whether or not to try to autodetect device-mapper partitions
5455
autodetect_root_luks = "bool" # Whether or not to try to autodetect LUKS partitions
5556
autodetect_root_lvm = "bool" # Whether or not to try to autodetect LVM partitions
57+
autodetec_root_raid = "bool" # Whether or not to try to autodetect MDRAID partitions
5658
autodetect_init_mount = "bool" # Adds a late_mount for the init target if it exists under a mount on the host
5759
resolve_root_dev = "bool" # Whether or not to attempt resolve the root device source
5860
_mounts = "dict" # The mounts information

0 commit comments

Comments
 (0)