From 0ac03f464cc0c2b7aff013024527089095c91497 Mon Sep 17 00:00:00 2001 From: Rahman Ajibade Date: Sat, 17 Oct 2026 01:46:41 +0000 Subject: [PATCH] Pass -t to mount() call when filesystem type is known or can be determined This allows mounting not to depend on probe order, on libblkid's result or on whether the device happens to be mounted elsewhere already. Fixes #3093 --- kiwi/mount_manager.py | 7 ++++++- test/unit/builder/disk_test.py | 4 +++- test/unit/mount_manager_test.py | 17 ++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/kiwi/mount_manager.py b/kiwi/mount_manager.py index 2517fc93955..98ab905fb33 100644 --- a/kiwi/mount_manager.py +++ b/kiwi/mount_manager.py @@ -28,6 +28,7 @@ from kiwi.utils.temporary import Temporary from kiwi.command import Command from kiwi.exceptions import KiwiCommandError, KiwiUmountBusyError +from kiwi.utils.block import BlockID log = logging.getLogger('kiwi') @@ -119,8 +120,12 @@ def mount(self, options: List[str] = []) -> None: option_list = [] if options: option_list = ['-o'] + options + type_list = [] + filesystem = BlockID(self.device).get_filesystem() + if filesystem: + type_list = ['-t', filesystem] Command.run( - ['mount'] + option_list + [self.device, self.mountpoint] + ['mount'] + type_list + option_list + [self.device, self.mountpoint] ) def umount_lazy(self) -> None: diff --git a/test/unit/builder/disk_test.py b/test/unit/builder/disk_test.py index a22fd1a3580..c6afd075393 100644 --- a/test/unit/builder/disk_test.py +++ b/test/unit/builder/disk_test.py @@ -1305,14 +1305,16 @@ def test_create_disk_standard_root_no_hypervisor_found( with raises(KiwiDiskBootImageError): self.disk_builder.create_disk() + @patch('kiwi.mount_manager.BlockID') @patch('kiwi.builder.disk.Disk') @patch('kiwi.builder.disk.create_boot_loader_config') @patch('kiwi.builder.disk.FileSystem.new') @patch('kiwi.builder.disk.Command.run') def test_create_disk_standard_root_xen_server_boot( self, mock_command, mock_fs, mock_create_boot_loader_config, - mock_Disk + mock_Disk, mock_BlockID ): + mock_BlockID.return_value.get_filesystem.return_value = 'xfs' bootloader_config = Mock() bootloader_config.get_boot_cmdline = Mock( return_value='boot_cmdline' diff --git a/test/unit/mount_manager_test.py b/test/unit/mount_manager_test.py index a119fdbf48b..a39137d1706 100644 --- a/test/unit/mount_manager_test.py +++ b/test/unit/mount_manager_test.py @@ -70,11 +70,26 @@ def test_tmpfs_mount(self, mock_mounted, mock_command): ['mount', '-t', 'tmpfs', 'tmpfs', '/some/mountpoint'] ) + @patch('kiwi.mount_manager.BlockID') @patch('kiwi.mount_manager.Command.run') @patch('kiwi.mount_manager.MountManager.is_mounted') - def test_mount(self, mock_mounted, mock_command): + def test_mount(self, mock_mounted, mock_command, mock_BlockID): mock_mounted.return_value = False + mock_BlockID.return_value.get_filesystem.return_value = 'vfat' self.mount_manager.mount(['options']) + mock_BlockID.assert_called_once_with('/dev/some-device') + mock_command.assert_called_once_with( + ['mount', '-t', 'vfat', '-o', 'options', '/dev/some-device', '/some/mountpoint'] + ) + + @patch('kiwi.mount_manager.BlockID') + @patch('kiwi.mount_manager.Command.run') + @patch('kiwi.mount_manager.MountManager.is_mounted') + def test_mount_unknown_filesystem(self, mock_mounted, mock_command, mock_BlockID): + mock_mounted.return_value = False + mock_BlockID.return_value.get_filesystem.return_value = '' + self.mount_manager.mount(['options']) + mock_BlockID.assert_called_once_with('/dev/some-device') mock_command.assert_called_once_with( ['mount', '-o', 'options', '/dev/some-device', '/some/mountpoint'] )