diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index 8c233df6..92da5b5e 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -313,15 +313,14 @@ class FilesystemController(BaseController): # must be wiped or grub-install will fail wipe='zero', flag='prep') + self.model.grub_install_device = part elif bootloader == Bootloader.BIOS: log.debug('Adding grub_bios gpt partition first') part = self.create_partition( disk, dict(size=BIOS_GRUB_SIZE_BYTES, fstype=None, mount=None), flag='bios_grub') - # should _not_ specify grub device for prep - if bootloader != Bootloader.PREP: - disk.grub_device = True + self.model.grub_install_device = disk return part def create_raid(self, spec): @@ -472,7 +471,6 @@ class FilesystemController(BaseController): boot_disk = boot_partition.device full = boot_disk.free_for_partitions == 0 self.delete_partition(boot_partition) - boot_disk.grub_device = False if full: largest_part = max( boot_disk.partitions(), key=lambda p: p.size) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index c4263d65..6d479690 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -555,10 +555,17 @@ class Disk(_Device): lambda self: len(self._partitions) == 0 and self._constructed_device is None) _can_REMOVE = property(_generic_can_REMOVE) - _can_MAKE_BOOT = property( - lambda self: - not self.grub_device and self._fs is None - and self._constructed_device is None) + + @property + def _can_MAKE_BOOT(self): + install_dev = self._m.grub_install_device + if install_dev: + # For the PReP case, the install_device is the prep partition. + if install_dev.type == "partition": + install_dev = install_dev.device + if install_dev is self: + return False + return self._fs is None and self._constructed_device is None ok_for_raid = ok_for_lvm_vg = _can_FORMAT @@ -918,6 +925,7 @@ class FilesystemModel(object): def reset(self): self._actions = [ Disk.from_info(self, info) for info in self._disk_info] + self.grub_install_device = None def _render_actions(self): # The curtin storage config has the constraint that an action must be @@ -982,6 +990,15 @@ class FilesystemModel(object): } if not self._should_add_swapfile(): config['swap'] = {'size': 0} + if self.grub_install_device: + dev = self.grub_install_device + if dev.type == "partition": + devpath = "{}{}".format(dev.device.path, dev._number) + else: + devpath = dev.path + config['grub'] = { + 'install_devices': [devpath], + } return config def _get_system_mounted_disks(self): diff --git a/subiquity/ui/views/filesystem/tests/test_filesystem.py b/subiquity/ui/views/filesystem/tests/test_filesystem.py index 4acd1d02..5232acdd 100644 --- a/subiquity/ui/views/filesystem/tests/test_filesystem.py +++ b/subiquity/ui/views/filesystem/tests/test_filesystem.py @@ -25,6 +25,7 @@ class FilesystemViewTests(unittest.TestCase): controller = mock.create_autospec(spec=FilesystemController) controller.ui = mock.Mock() model.all_devices.return_value = devices + model.grub_install_device = None return FilesystemView(model, controller) def test_simple(self):