Skip to content

Commit

Permalink
Make sure btrfs root volume is used when needed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
schaefi committed Jul 27, 2023
1 parent 8d8c14c commit 2e88686
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 16 deletions.
8 changes: 6 additions & 2 deletions kiwi/bootloader/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ def get_gfxmode(self, target):
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
Expand All @@ -522,7 +523,10 @@ def _mount_system(
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()
Expand Down
8 changes: 6 additions & 2 deletions kiwi/bootloader/config/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,18 @@ def setup_disk_image_config(
'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(
[
Expand Down
9 changes: 8 additions & 1 deletion kiwi/bootloader/install/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def post_init(self, custom_args):
{
'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,
Expand All @@ -71,12 +72,15 @@ def post_init(self, custom_args):
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:
Expand Down Expand Up @@ -302,7 +306,10 @@ def _mount_device_and_volumes(self):
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:
Expand Down
7 changes: 6 additions & 1 deletion kiwi/builder/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,12 @@ def _install_bootloader(
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':
Expand Down
6 changes: 4 additions & 2 deletions test/unit/bootloader/config/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def mount_managers_effect(**args):
'volume_options': 'subvol=@/boot/grub2',
'volume_device': 'device'
}
}
}, root_volume_name='root'
)
assert mock_MountManager.call_args_list == [
call(device='rootdev'),
Expand All @@ -409,7 +409,9 @@ def mount_managers_effect(**args):
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(
Expand Down
2 changes: 1 addition & 1 deletion test/unit/bootloader/config/grub2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ def open_file(filename, mode=None):
}
)
mock_mount_system.assert_called_once_with(
'rootdev', 'bootdev', None, None
'rootdev', 'bootdev', None, None, None
)
assert mock_Command_run.call_args_list == [
call(
Expand Down
29 changes: 22 additions & 7 deletions test/unit/bootloader/install/grub2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setup(self):
'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'
Expand Down Expand Up @@ -167,7 +168,9 @@ def side_effect(device, mountpoint=None):
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'
Expand Down Expand Up @@ -213,7 +216,9 @@ def side_effect(device, mountpoint=None):
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(
Expand Down Expand Up @@ -258,7 +263,9 @@ def side_effect(device, mountpoint=None):
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'
Expand Down Expand Up @@ -297,7 +304,9 @@ def side_effect(device, mountpoint=None):
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'
Expand Down Expand Up @@ -338,7 +347,9 @@ def side_effect(device, mountpoint=None):
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']
)
Expand Down Expand Up @@ -398,7 +409,9 @@ def side_effect(device, mountpoint=None):
'/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']
)
Expand All @@ -421,7 +434,9 @@ def side_effect(device, mountpoint=None):
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']
)
Expand Down

0 comments on commit 2e88686

Please sign in to comment.