Mount installer root and ESP using their known filesystem types

This commit is contained in:
Codex
2026-10-13 22:29:56 +03:00
parent a77006a05f
commit 3c15890823
2 changed files with 25 additions and 4 deletions
+4 -4
View File
@@ -509,10 +509,10 @@ def render_plan(request, target, root):
['mount', '-t', 'btrfs', '-o', 'subvol=@home', part, str(Path(root) / 'home')], ['mount', '-t', 'btrfs', '-o', 'subvol=@home', part, str(Path(root) / 'home')],
['mount', '-t', 'btrfs', '-o', 'subvol=@snapshots', part, str(Path(root) / '.snapshots')]]) ['mount', '-t', 'btrfs', '-o', 'subvol=@snapshots', part, str(Path(root) / '.snapshots')]])
else: else:
commands.append(['mount', part, str(root)]) commands.append(['mount', '-t', 'ext4', part, str(root)])
commands += [ commands += [
['unsquashfs', '-f', '-d', str(root), request.payload], ['unsquashfs', '-f', '-d', str(root), request.payload],
['mount', esp, str(Path(root) / 'boot/efi')], ['mount', '-t', 'vfat', esp, str(Path(root) / 'boot/efi')],
['blkid', '-s', 'UUID', '-o', 'value', part], ['blkid', '-s', 'UUID', '-o', 'value', part],
['blkid', '-s', 'UUID', '-o', 'value', esp], ['blkid', '-s', 'UUID', '-o', 'value', esp],
['mount', '--rbind', '/dev', str(Path(root) / 'dev')], ['mount', '--rbind', '/dev', str(Path(root) / 'dev')],
@@ -744,7 +744,7 @@ def install(request, runner, probe, root, password, log: TextIO):
(root / directory).mkdir() (root / directory).mkdir()
mount(['mount', '-t', 'btrfs', '-o', 'subvol=' + subvolume, part, str(root / directory)], root / directory) mount(['mount', '-t', 'btrfs', '-o', 'subvol=' + subvolume, part, str(root / directory)], root / directory)
else: else:
mount(['mount', part, str(root)], root) mount(['mount', '-t', 'ext4', part, str(root)], root)
run(['unsquashfs', '-f', '-d', str(root), request.payload]) run(['unsquashfs', '-f', '-d', str(root), request.payload])
kernel = select_kernel(root, request.kernel) kernel = select_kernel(root, request.kernel)
remove_live_files(root) remove_live_files(root)
@@ -753,7 +753,7 @@ def install(request, runner, probe, root, password, log: TextIO):
raise InstallError('Timezone does not exist in payload: ' + request.timezone) raise InstallError('Timezone does not exist in payload: ' + request.timezone)
for folder in ('boot/efi', 'dev', 'proc', 'sys'): for folder in ('boot/efi', 'dev', 'proc', 'sys'):
target_path(root, folder).mkdir(parents=True, exist_ok=True) target_path(root, folder).mkdir(parents=True, exist_ok=True)
mount(['mount', esp, str(root / 'boot/efi')], root / 'boot/efi') mount(['mount', '-t', 'vfat', esp, str(root / 'boot/efi')], root / 'boot/efi')
root_uuid = run(['blkid', '-s', 'UUID', '-o', 'value', part]).strip() root_uuid = run(['blkid', '-s', 'UUID', '-o', 'value', part]).strip()
esp_uuid = run(['blkid', '-s', 'UUID', '-o', 'value', esp]).strip() esp_uuid = run(['blkid', '-s', 'UUID', '-o', 'value', esp]).strip()
if any(not re.fullmatch(r'[A-Fa-f0-9-]+', value) for value in (root_uuid, esp_uuid)): if any(not re.fullmatch(r'[A-Fa-f0-9-]+', value) for value in (root_uuid, esp_uuid)):
+21
View File
@@ -187,6 +187,17 @@ class PartitionGuardTests(unittest.TestCase):
self.assertIn('/dev/vda3',topo.parents['/dev/loop0']) self.assertIn('/dev/vda3',topo.parents['/dev/loop0'])
self.assertEqual(i.validate_request(partition_request(),probe),'/dev/vda2') self.assertEqual(i.validate_request(partition_request(),probe),'/dev/vda2')
def test_dry_run_mounts_use_requested_root_and_validated_esp_types(self):
for request in (i.Request('/dev/vda', 'emil'), partition_request()):
with self.subTest(mode='disk' if request.disk else 'partitions'):
target='/dev/vda' if request.disk else '/dev/vda2'
plan=i.render_plan(request,target,'/mnt/target')
self.assertIn('mount -t ext4 /dev/vda2 /mnt/target',plan)
self.assertIn('mount -t vfat /dev/vda1 /mnt/target/boot/efi',plan)
btrfs_plan=i.render_plan(partition_request(root_fs='btrfs'),'/dev/vda2','/mnt/target')
self.assertIn('mount -t btrfs -o subvol=@root /dev/vda2 /mnt/target',btrfs_plan)
self.assertIn('mount -t vfat /dev/vda1 /mnt/target/boot/efi',btrfs_plan)
def test_partition_plan_formats_only_root_and_preserves_efi(self): def test_partition_plan_formats_only_root_and_preserves_efi(self):
req = partition_request() req = partition_request()
plan = i.render_plan(req, '/dev/vda2', '/mnt/target') plan = i.render_plan(req, '/dev/vda2', '/mnt/target')
@@ -279,6 +290,11 @@ class PartitionPipelineTests(unittest.TestCase):
self.assertEqual(runner.calls, []) self.assertEqual(runner.calls, [])
self.assertFalse((self.root/'etc/fstab').exists()) self.assertFalse((self.root/'etc/fstab').exists())
def test_partition_execution_mounts_known_filesystem_types_explicitly(self):
runner=FakeRunner(self.root); self.install(runner)
self.assertIn(['mount','-t','ext4','/dev/vda2',str(self.root)],runner.calls)
self.assertIn(['mount','-t','vfat','/dev/vda1',str(self.root/'boot/efi')],runner.calls)
def test_existing_mode_formats_root_only_and_records_owned_layout(self): def test_existing_mode_formats_root_only_and_records_owned_layout(self):
runner = FakeRunner(self.root) runner = FakeRunner(self.root)
self.install(runner) self.install(runner)
@@ -518,6 +534,11 @@ class PipelineTests(unittest.TestCase):
self.assertIn('6.12.1', dracut) self.assertIn('6.12.1', dracut)
self.assertEqual(runner.calls[-1], ['umount', str(self.root)]) self.assertEqual(runner.calls[-1], ['umount', str(self.root)])
def test_whole_disk_execution_mounts_created_filesystem_types_explicitly(self):
runner=FakeRunner(self.root); self.install(runner)
self.assertIn(['mount','-t','ext4','/dev/vda2',str(self.root)],runner.calls)
self.assertIn(['mount','-t','vfat','/dev/vda1',str(self.root/'boot/efi')],runner.calls)
def test_whole_disk_installs_owned_loader_and_fallback(self): def test_whole_disk_installs_owned_loader_and_fallback(self):
runner=FakeRunner(self.root); self.install(runner) runner=FakeRunner(self.root); self.install(runner)
boot_commands=[c for c in runner.calls if 'grub-install' in c] boot_commands=[c for c in runner.calls if 'grub-install' in c]