Make sure btrfs root volume is used when needed

With the possibility to switch off setting the default volume
an issue at other parts in the kiwi code which mounted the
btrfs based system were uncovered. Without any default volume
set it's required to transport the root volume if different
from / and pass the respective subvol= option to the mount.
This commit fixes it at the places where kiwi trusted btrfs
to have a correct default volume set
This commit is contained in:
Marcus Schäfer 2023-07-27 12:08:35 +02:00
parent 48149cea51
commit dd110f63a4
No known key found for this signature in database
GPG Key ID: A16C1128698C8CAC
7 changed files with 53 additions and 16 deletions

View File

@ -501,7 +501,8 @@ class BootLoaderConfigBase:
return gfxmode
def _mount_system(
self, root_device, boot_device, efi_device=None, volumes=None
self, root_device, boot_device, efi_device=None,
volumes=None, root_volume_name=None
):
self.root_mount = MountManager(
device=root_device
@ -522,7 +523,10 @@ class BootLoaderConfigBase:
mountpoint=self.root_mount.mountpoint + '/boot/efi'
)
self.root_mount.mount()
custom_root_mount_args = []
if root_volume_name and root_volume_name != '/':
custom_root_mount_args += [f'subvol={root_volume_name}']
self.root_mount.mount(options=custom_root_mount_args)
if not self.root_mount.device == self.boot_mount.device:
self.boot_mount.mount()

View File

@ -233,14 +233,18 @@ class BootLoaderConfigGrub2(BootLoaderConfigBase):
'root_device': string,
'boot_device': string,
'efi_device': string,
'system_volumes': volume_manager_instance.get_volumes()
'system_volumes':
volume_manager_instance.get_volumes(),
'system_root_volume':
volume_manager_instance.get_root_volume_name()
}
"""
self._mount_system(
boot_options.get('root_device'),
boot_options.get('boot_device'),
boot_options.get('efi_device'),
boot_options.get('system_volumes')
boot_options.get('system_volumes'),
boot_options.get('system_root_volume')
)
config_file = os.sep.join(
[

View File

@ -52,6 +52,7 @@ class BootLoaderInstallGrub2(BootLoaderInstallBase):
{
'target_removable': bool,
'system_volumes': list_of_volumes,
'system_root_volume': root volume name if required
'firmware': FirmWare_instance,
'efi_device': string,
'boot_device': string,
@ -71,12 +72,15 @@ class BootLoaderInstallGrub2(BootLoaderInstallBase):
self.proc_mount = None
self.sysfs_mount = None
self.volumes = None
self.root_volume_name = None
self.volumes_mount = []
self.target_removable = None
if custom_args and 'target_removable' in custom_args:
self.target_removable = custom_args['target_removable']
if custom_args and 'system_volumes' in custom_args:
self.volumes = custom_args['system_volumes']
if custom_args and 'system_root_volume' in custom_args:
self.root_volume_name = custom_args['system_root_volume']
if custom_args and 'firmware' in custom_args:
self.firmware = custom_args['firmware']
if custom_args and 'install_options' in custom_args:
@ -302,7 +306,10 @@ class BootLoaderInstallGrub2(BootLoaderInstallBase):
self.root_mount = MountManager(
device=self.custom_args['root_device']
)
self.root_mount.mount()
custom_root_mount_args = []
if self.root_volume_name and self.root_volume_name != '/':
custom_root_mount_args += [f'subvol={self.root_volume_name}']
self.root_mount.mount(options=custom_root_mount_args)
if self.boot_mount is None:
if 's390' in self.arch:

View File

@ -1537,7 +1537,12 @@ class DiskBuilder:
if self.volume_manager_name:
system.umount_volumes()
custom_install_arguments.update(
{'system_volumes': system.get_volumes()}
{
'system_volumes': system.get_volumes(),
'system_root_volume':
system.get_root_volume_name()
if self.volume_manager_name == 'btrfs' else None
}
)
if self.bootloader != 'custom':

View File

@ -397,7 +397,7 @@ class TestBootLoaderConfigBase:
'volume_options': 'subvol=@/boot/grub2',
'volume_device': 'device'
}
}
}, root_volume_name='root'
)
assert mock_MountManager.call_args_list == [
call(device='rootdev'),
@ -409,7 +409,9 @@ class TestBootLoaderConfigBase:
call(device='/proc', mountpoint='root_mount_point/proc'),
call(device='/sys', mountpoint='root_mount_point/sys')
]
root_mount.mount.assert_called_once_with()
root_mount.mount.assert_called_once_with(
options=['subvol=root']
)
boot_mount.mount.assert_called_once_with()
efi_mount.mount.assert_called_once_with()
volume_mount.mount.assert_called_once_with(

View File

@ -955,7 +955,7 @@ class TestBootLoaderConfigGrub2:
}
)
mock_mount_system.assert_called_once_with(
'rootdev', 'bootdev', None, None
'rootdev', 'bootdev', None, None, None
)
assert mock_Command_run.call_args_list == [
call(

View File

@ -29,6 +29,7 @@ class TestBootLoaderInstallGrub2:
'root_device': '/dev/mapper/loop0p1',
'efi_device': '/dev/mapper/loop0p3',
'prep_device': '/dev/mapper/loop0p2',
'system_root_volume': 'root',
'system_volumes': {'boot/grub2': {
'volume_options': 'subvol=@/boot/grub2',
'volume_device': 'device'
@ -167,7 +168,9 @@ class TestBootLoaderInstallGrub2:
mock_mount_manager.side_effect = side_effect
self.bootloader.install()
self.bootloader.root_mount.mount.assert_called_once_with()
self.bootloader.root_mount.mount.assert_called_once_with(
options=['subvol=root']
)
self.bootloader.boot_mount.mount.assert_called_once_with()
mock_glob.assert_called_once_with(
'tmp_root/boot/*/grubenv'
@ -213,7 +216,9 @@ class TestBootLoaderInstallGrub2:
mock_mount_manager.side_effect = side_effect
self.bootloader.install()
self.bootloader.root_mount.mount.assert_called_once_with()
self.bootloader.root_mount.mount.assert_called_once_with(
options=['subvol=root']
)
self.bootloader.boot_mount.mount.assert_called_once_with()
assert mock_command.call_args_list == [
call(
@ -258,7 +263,9 @@ class TestBootLoaderInstallGrub2:
mock_mount_manager.side_effect = side_effect
self.bootloader.install()
self.bootloader.root_mount.mount.assert_called_once_with()
self.bootloader.root_mount.mount.assert_called_once_with(
options=['subvol=root']
)
self.bootloader.boot_mount.mount.assert_called_once_with()
mock_wipe.assert_called_once_with(
'tmp_root/boot/grub2/grubenv'
@ -297,7 +304,9 @@ class TestBootLoaderInstallGrub2:
mock_mount_manager.side_effect = side_effect
self.bootloader.install()
self.bootloader.root_mount.mount.assert_called_once_with()
self.bootloader.root_mount.mount.assert_called_once_with(
options=['subvol=root']
)
self.bootloader.boot_mount.mount.assert_called_once_with()
mock_wipe.assert_called_once_with(
'tmp_root/boot/grub2/grubenv'
@ -338,7 +347,9 @@ class TestBootLoaderInstallGrub2:
self.bootloader.target_removable = True
self.bootloader.install()
self.root_mount.mount.assert_called_once_with()
self.root_mount.mount.assert_called_once_with(
options=['subvol=root']
)
self.volume_mount.mount.assert_called_once_with(
options=['subvol=@/boot/grub2']
)
@ -398,7 +409,9 @@ class TestBootLoaderInstallGrub2:
'/usr/sbin/grub2-install'
])
]
self.root_mount.mount.assert_called_once_with()
self.root_mount.mount.assert_called_once_with(
options=['subvol=root']
)
self.volume_mount.mount.assert_called_once_with(
options=['subvol=@/boot/grub2']
)
@ -421,7 +434,9 @@ class TestBootLoaderInstallGrub2:
mock_mount_manager.side_effect = side_effect
self.bootloader.secure_boot_install()
self.root_mount.mount.assert_called_once_with()
self.root_mount.mount.assert_called_once_with(
options=['subvol=root']
)
self.volume_mount.mount.assert_called_once_with(
options=['subvol=@/boot/grub2']
)