@@ -410,37 +410,6 @@ def get_zpool_info(self, poolname=None) -> Union[dict, None]:
410
410
return self ["_zpool_info" ][poolname ]
411
411
412
412
413
- @contains ("hostonly" , "Skipping init mount autodetection, hostonly mode is disabled." , log_level = 30 )
414
- @contains ("autodetect_init_mount" , "Init mount autodetection disabled, skipping." , log_level = 30 )
415
- @contains ("init_target" , "init_target must be set" , raise_exception = True )
416
- def autodetect_init_mount (self ) -> None :
417
- """Checks the parent directories of init_target, if the path is a mountpoint, add it to late_mounts."""
418
- init_mount = _find_mountpoint (self , self ["init_target" ])
419
- if init_mount == "/" :
420
- return
421
-
422
- if init_mount in self ["late_mounts" ]:
423
- return self .logger .debug ("Init mount already detected: %s" % init_mount )
424
-
425
- if init_mount not in self ["_mounts" ]:
426
- raise AutodetectError ("Init mount not found in host mounts: %s" % init_mount )
427
-
428
- self .logger .info ("Detected init mount: %s" % colorize (init_mount , "cyan" ))
429
- mount_name = init_mount .removeprefix ("/" )
430
- mount_dest = init_mount
431
- mount_device = self ["_mounts" ][init_mount ]["device" ]
432
- mount_type = self ["_mounts" ][init_mount ]["fstype" ]
433
- mount_options = self ["_mounts" ][init_mount ]["options" ]
434
- blkid_info = self ["_blkid_info" ][mount_device ]
435
- mount_source_type , mount_source = _get_mount_source_type (self , blkid_info , with_val = True )
436
- self ["late_mounts" ][mount_name ] = {
437
- "destination" : mount_dest ,
438
- mount_source_type : mount_source ,
439
- "type" : mount_type ,
440
- "options" : mount_options ,
441
- }
442
-
443
-
444
413
@contains ("hostonly" , "Skipping virtual block device enumeration, hostonly mode is disabled." , log_level = 30 )
445
414
def get_virtual_block_info (self ) -> dict :
446
415
"""Populates the virtual block device info. (previously device mapper only)
@@ -673,6 +642,28 @@ def autodetect_luks(self, source_dev, dm_num, blkid_info) -> None:
673
642
)
674
643
675
644
645
+ @contains ("hostonly" , "Skipping init mount autodetection, hostonly mode is disabled." , log_level = 30 )
646
+ @contains ("autodetect_init_mount" , "Init mount autodetection disabled, skipping." , log_level = 30 )
647
+ @contains ("init_target" , "init_target must be set" , raise_exception = True )
648
+ def autodetect_init_mount (self ) -> None :
649
+ """Checks the parent directories of init_target, if the path is a mountpoint, add it to late_mounts."""
650
+ for mountpoint in ["/usr" , "/var" , "/etc" ]:
651
+ _autodetect_mount (self , mountpoint , "late_mounts" , missing_ok = True )
652
+
653
+ init_mount = _find_mountpoint (self , self ["init_target" ])
654
+ if init_mount == "/" :
655
+ return
656
+
657
+ if init_mount in self ["late_mounts" ]:
658
+ return self .logger .debug ("Init mount already detected: %s" % init_mount )
659
+
660
+ if init_mount not in self ["_mounts" ]:
661
+ raise AutodetectError ("Init mount not found in host mounts: %s" % init_mount )
662
+
663
+ self .logger .info ("Detected init mount: %s" % colorize (init_mount , "cyan" ))
664
+ _autodetect_mount (self , init_mount , "late_mounts" )
665
+
666
+
676
667
@contains ("autodetect_root" , "Skipping root autodetection, autodetect_root is disabled." , log_level = 30 )
677
668
@contains ("hostonly" , "Skipping root autodetection, hostonly mode is disabled." , log_level = 30 )
678
669
def autodetect_root (self ) -> None :
@@ -697,11 +688,14 @@ def autodetect_root(self) -> None:
697
688
_autodetect_dm (self , "/" )
698
689
699
690
700
- def _autodetect_mount (self , mountpoint ) -> str :
701
- """Sets mount config for the specified mountpoint.
691
+ def _autodetect_mount (self , mountpoint , mount_class = "mounts" , missing_ok = False ) -> str :
692
+ """Sets mount config for the specified mountpoint, in the specified mount class.
693
+
702
694
Returns the "real" device path for the mountpoint.
703
695
"""
704
696
if mountpoint not in self ["_mounts" ]:
697
+ if missing_ok :
698
+ return self .logger .debug ("Mountpoint not found in host mounts: %s" % mountpoint )
705
699
self .logger .error ("Host mounts:\n %s" % pretty_print (self ["_mounts" ]))
706
700
raise AutodetectError ("auto_mount mountpoint not found in host mounts: %s" % mountpoint )
707
701
@@ -728,24 +722,25 @@ def _autodetect_mount(self, mountpoint) -> str:
728
722
mount_name = "root" if mountpoint == "/" else mountpoint .removeprefix ("/" )
729
723
730
724
# Don't overwrite existing mounts if a source type is already set
731
- if mount_name in self ["mounts" ] and any (s_type in self ["mounts" ][mount_name ] for s_type in SOURCE_TYPES ):
725
+ if mount_name in self [mount_class ] and any (s_type in self [mount_class ][mount_name ] for s_type in SOURCE_TYPES ):
732
726
return self .logger .warning (
733
727
"[%s] Skipping autodetection, mount config already set:\n %s"
734
- % (colorize (mountpoint , "yellow" ), pretty_print (self ["mounts" ][mount_name ]))
728
+ % (colorize (mountpoint , "yellow" ), pretty_print (self [mount_class ][mount_name ]))
735
729
)
736
730
737
- mount_config = {mount_name : {"type" : "auto" , "options" : ["ro" ]}} # Default to auto and ro
731
+ # For standard mounts, default to auto and ro
732
+ if mount_class == "mounts" :
733
+ mount_config = {mount_name : {"options" : ["ro" ]}}
734
+ else : # For other mounts, use the existing mount config
735
+ mount_config = {mount_name : {"options" : self ["_mounts" ][mountpoint ].get ("options" , ["default" ])}}
736
+
738
737
fs_type = mount_info .get ("type" , fs_type ) or "auto"
739
738
if fs_type == "auto" :
740
739
self .logger .warning ("Failed to autodetect mount type for mountpoint:" % (colorize (mountpoint , "yellow" )))
741
740
else :
742
741
self .logger .info ("[%s] Autodetected mount type from device: %s" % (mount_device , colorize (fs_type , "cyan" )))
743
742
mount_config [mount_name ]["type" ] = fs_type .lower ()
744
743
745
- # for zfs mounts, set the path to the pool name
746
- if fs_type == "zfs" :
747
- mount_config [mount_name ]["path" ] = mount_device
748
-
749
744
for source_type in SOURCE_TYPES :
750
745
if source := mount_info .get (source_type ):
751
746
self .logger .info (
@@ -758,7 +753,11 @@ def _autodetect_mount(self, mountpoint) -> str:
758
753
if fs_type != "zfs" : # For ZFS, the source is the pool name
759
754
raise AutodetectError ("[%s] Failed to autodetect mount source." % mountpoint )
760
755
761
- self ["mounts" ] = mount_config
756
+ # for zfs mounts, set the path to the pool name
757
+ if fs_type == "zfs" :
758
+ mount_config [mount_name ]["path" ] = mount_device
759
+
760
+ self [mount_class ] = mount_config
762
761
return mount_device
763
762
764
763
0 commit comments