Skip to content

Commit

Permalink
Merge pull request #2629 from OSInside/mount_custom_partition_in_syst…
Browse files Browse the repository at this point in the history
…em_mount

Fix ImageSystem mount procedure
  • Loading branch information
Conan-Kudo authored Sep 1, 2024
2 parents 08e736b + a2134f0 commit 53d4b90
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kiwi/builder/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ def _build_main_system(
):
with ImageSystem(
device_map, self.root_dir,
system.get_volumes() if self.volume_manager_name else {}
system.get_volumes() if self.volume_manager_name else {},
self.custom_partitions if self.custom_partitions else {}
) as image_system:
image_system.mount()
disk_system = SystemSetup(
Expand Down
18 changes: 17 additions & 1 deletion kiwi/system/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from kiwi.path import Path
from kiwi.defaults import Defaults
from kiwi.mount_manager import MountManager
from kiwi.storage.disk import ptable_entry_type

log = logging.getLogger('kiwi')

Expand All @@ -34,7 +35,8 @@ class ImageSystem:
**Access the target image from the block layer**
"""
def __init__(
self, device_map: Dict, root_dir: str, volumes: Dict = {}
self, device_map: Dict, root_dir: str,
volumes: Dict = {}, partitions: Dict[str, ptable_entry_type] = {}
) -> None:
"""
Construct a new ImageSystem object
Expand All @@ -47,6 +49,7 @@ def __init__(
self.device_map = device_map
self.root_dir = root_dir
self.volumes = volumes
self.partitions = partitions
self.mount_list: List[MountManager] = []

def __enter__(self):
Expand Down Expand Up @@ -104,6 +107,19 @@ def mount(self) -> None:
self.mount_list.append(efi_mount)
efi_mount.mount()

if self.partitions:
for map_name in sorted(self.partitions.keys()):
if map_name in self.device_map:
partition_mount = MountManager(
device=self.device_map[map_name].get_device(),
mountpoint=os.path.join(
root_mount.mountpoint,
self.partitions[map_name].mountpoint.lstrip(os.sep)
)
)
self.mount_list.append(partition_mount)
partition_mount.mount()

if self.volumes:
self._mount_volumes(root_mount.mountpoint)

Expand Down
18 changes: 17 additions & 1 deletion test/unit/system/mount_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from kiwi.system.mount import ImageSystem
from kiwi.storage.mapped_device import MappedDevice
from kiwi.storage.disk import ptable_entry_type


class TestImageSystem:
Expand All @@ -21,15 +22,26 @@ def setup(self, mock_os_path_exists):
'readonly': MappedDevice('/dev/readonly-root-device', Mock()),
'boot': MappedDevice('/dev/boot-device', Mock()),
'efi': MappedDevice('/dev/efi-device', Mock()),
'var': MappedDevice('/dev/var-device', Mock())
}
self.volumes = {
'name': {
'volume_options': 'a,b,c',
'volume_device': '/dev/vgroup/volume'
}
}
self.partitions = {
'var': ptable_entry_type(
mbsize=100,
clone=1,
partition_name='p.lxvar',
partition_type='t.linux',
mountpoint='/var',
filesystem='ext3'
)
}
self.image_system = ImageSystem(
self.device_map, 'root_dir', self.volumes
self.device_map, 'root_dir', self.volumes, self.partitions
)

@patch('os.path.exists')
Expand All @@ -55,6 +67,10 @@ def test_mount(self, mock_MountManager):
device='/dev/efi-device',
mountpoint=os.path.join(root_mount_mountpoint, 'boot', 'efi')
),
call(
device='/dev/var-device',
mountpoint=os.path.join(root_mount_mountpoint, 'var')
),
call(
device='/dev/vgroup/volume',
mountpoint=os.path.join(root_mount_mountpoint, 'name')
Expand Down

0 comments on commit 53d4b90

Please sign in to comment.