@@ -364,11 +364,14 @@ def _mount_partition(self, part_mod: PartitionModification) -> None:
364364 target = self .target / part_mod .relative_mountpoint
365365 device_handler .mount (part_mod .dev_path , target , options = part_mod .mount_options )
366366 elif part_mod .fs_type == FilesystemType .Btrfs :
367- self ._mount_btrfs_subvol (
368- part_mod .dev_path ,
369- part_mod .btrfs_subvols ,
370- part_mod .mount_options ,
371- )
367+ # Only mount BTRFS subvolumes that have mountpoints specified
368+ subvols_with_mountpoints = [sv for sv in part_mod .btrfs_subvols if sv .mountpoint is not None ]
369+ if subvols_with_mountpoints :
370+ self ._mount_btrfs_subvol (
371+ part_mod .dev_path ,
372+ part_mod .btrfs_subvols ,
373+ part_mod .mount_options ,
374+ )
372375 elif part_mod .is_swap ():
373376 device_handler .swapon (part_mod .dev_path )
374377
@@ -379,14 +382,20 @@ def _mount_lvm_vol(self, volume: LvmVolume) -> None:
379382 device_handler .mount (volume .dev_path , target , options = volume .mount_options )
380383
381384 if volume .fs_type == FilesystemType .Btrfs and volume .dev_path :
382- self ._mount_btrfs_subvol (volume .dev_path , volume .btrfs_subvols , volume .mount_options )
385+ # Only mount BTRFS subvolumes that have mountpoints specified
386+ subvols_with_mountpoints = [sv for sv in volume .btrfs_subvols if sv .mountpoint is not None ]
387+ if subvols_with_mountpoints :
388+ self ._mount_btrfs_subvol (volume .dev_path , volume .btrfs_subvols , volume .mount_options )
383389
384390 def _mount_luks_partition (self , part_mod : PartitionModification , luks_handler : Luks2 ) -> None :
385391 if not luks_handler .mapper_dev :
386392 return None
387393
388394 if part_mod .fs_type == FilesystemType .Btrfs and part_mod .btrfs_subvols :
389- self ._mount_btrfs_subvol (luks_handler .mapper_dev , part_mod .btrfs_subvols , part_mod .mount_options )
395+ # Only mount BTRFS subvolumes that have mountpoints specified
396+ subvols_with_mountpoints = [sv for sv in part_mod .btrfs_subvols if sv .mountpoint is not None ]
397+ if subvols_with_mountpoints :
398+ self ._mount_btrfs_subvol (luks_handler .mapper_dev , part_mod .btrfs_subvols , part_mod .mount_options )
390399 elif part_mod .mountpoint :
391400 target = self .target / part_mod .relative_mountpoint
392401 device_handler .mount (luks_handler .mapper_dev , target , options = part_mod .mount_options )
@@ -398,15 +407,20 @@ def _mount_luks_volume(self, volume: LvmVolume, luks_handler: Luks2) -> None:
398407 device_handler .mount (luks_handler .mapper_dev , target , options = volume .mount_options )
399408
400409 if volume .fs_type == FilesystemType .Btrfs and luks_handler .mapper_dev :
401- self ._mount_btrfs_subvol (luks_handler .mapper_dev , volume .btrfs_subvols , volume .mount_options )
410+ # Only mount BTRFS subvolumes that have mountpoints specified
411+ subvols_with_mountpoints = [sv for sv in volume .btrfs_subvols if sv .mountpoint is not None ]
412+ if subvols_with_mountpoints :
413+ self ._mount_btrfs_subvol (luks_handler .mapper_dev , volume .btrfs_subvols , volume .mount_options )
402414
403415 def _mount_btrfs_subvol (
404416 self ,
405417 dev_path : Path ,
406418 subvolumes : list [SubvolumeModification ],
407419 mount_options : list [str ] = [],
408420 ) -> None :
409- for subvol in sorted (subvolumes , key = lambda x : x .relative_mountpoint ):
421+ # Filter out subvolumes without mountpoints to avoid errors when sorting
422+ subvols_with_mountpoints = [sv for sv in subvolumes if sv .mountpoint is not None ]
423+ for subvol in sorted (subvols_with_mountpoints , key = lambda x : x .relative_mountpoint ):
410424 mountpoint = self .target / subvol .relative_mountpoint
411425 options = mount_options + [f'subvol={ subvol .name } ' ]
412426 device_handler .mount (dev_path , mountpoint , options = options )
0 commit comments