Skip to content

Commit

Permalink
Support partitioning of hybrid boot disks
Browse files Browse the repository at this point in the history
Anaconda needs to be able to create hybrid boot disks. For example:

  clearpart --all --initlabel --disklabel=gpt
  part prepboot  --size=4    --fstype=prepboot
  part biosboot  --size=1    --fstype=biosboot
  part /boot/efi --size=100  --fstype=efi
  part /boot     --size=1000 --fstype=ext4 --label=boot
  part /         --grow      --fstype xfs

However, this kickstart snippet is not working with two or more disks.
The bootloader-related partitions should be all created on the disk
the computer will boot from, but Blivet does that only for platform
-specific partitions. The rest of them are created on any disk with
enough space.

It looks like this can be easily fixed by setting the same weight
to all of these partitions regardless of the current platform.

See: rhinstaller/anaconda#5298
  • Loading branch information
poncovka committed Nov 24, 2023
1 parent 793ec72 commit b39e390
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
40 changes: 18 additions & 22 deletions blivet/devices/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,28 +452,24 @@ def _get_weight(self):
if isinstance(self.req_base_weight, int):
return self.req_base_weight

# now we have the weights for varying mountpoints and fstypes by platform
weight = 0
if self.format.mountable and self.format.mountpoint == "/boot":
weight = 2000
elif (self.format.mountable and
self.format.mountpoint == "/boot/efi" and
self.format.type in ("efi", "macefi") and
arch.is_efi()):
weight = 5000
elif arch.is_x86() and self.format.type == "biosboot" and not arch.is_efi():
weight = 5000
elif self.format.mountable and arch.is_arm():
# On ARM images '/' must be the last partition.
if self.format.mountpoint == "/":
weight = -100
elif arch.is_ppc():
if arch.is_pmac() and self.format.type == "appleboot":
weight = 5000
elif arch.is_ipseries() and self.format.type == "prepboot":
weight = 5000

return weight
# Now we have the weights for varying mountpoints and fstypes by platform.
mountpoint = self.format.mountpoint if self.format.mountable else None
format_type = self.format.type

if mountpoint == "/boot":
return 2000

if mountpoint == "/boot/efi" and format_type in ("efi", "macefi"):
return 5000

if format_type in ("biosboot", "appleboot", "prepboot"):
return 5000

# On ARM images '/' must be the last partition.
if mountpoint == "/" and arch.is_arm():
return -100

return 0

def _set_weight(self, weight):
self.req_base_weight = weight
Expand Down
23 changes: 15 additions & 8 deletions tests/unit_tests/devices_test/partition_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ def test_weight_1(self, *patches):

# weights for / and /boot are not platform-specific (except for arm)
fmt.mountpoint = "/"
fmt.type = "xfs"
self.assertEqual(dev.weight, 0)

fmt.mountpoint = "/boot"
fmt.type = "ext4"
self.assertEqual(dev.weight, 2000)

#
Expand All @@ -92,7 +94,7 @@ def test_weight_1(self, *patches):

fmt.mountpoint = "/boot/efi"
fmt.type = "efi"
self.assertEqual(dev.weight, 0)
self.assertEqual(dev.weight, 5000)

#
# UEFI
Expand All @@ -102,9 +104,10 @@ def test_weight_1(self, *patches):
self.assertEqual(dev.weight, 5000)

fmt.type = "biosboot"
self.assertEqual(dev.weight, 0)
self.assertEqual(dev.weight, 5000)

fmt.mountpoint = "/"
fmt.type = "xfs"
self.assertEqual(dev.weight, 0)

#
Expand All @@ -115,6 +118,7 @@ def test_weight_1(self, *patches):
arch.is_arm.return_value = True

fmt.mountpoint = "/"
fmt.type = "xfs"
self.assertEqual(dev.weight, -100)

#
Expand All @@ -126,38 +130,41 @@ def test_weight_1(self, *patches):
arch.is_ipseries.return_value = False

fmt.mountpoint = "/"
fmt.type = "xfs"
self.assertEqual(dev.weight, 0)

fmt.type = "prepboot"
self.assertEqual(dev.weight, 0)
self.assertEqual(dev.weight, 5000)

fmt.type = "appleboot"
self.assertEqual(dev.weight, 0)
self.assertEqual(dev.weight, 5000)

arch.is_pmac.return_value = True
self.assertEqual(dev.weight, 5000)

fmt.type = "prepboot"
self.assertEqual(dev.weight, 0)
self.assertEqual(dev.weight, 5000)

arch.is_pmac.return_value = False
arch.is_ipseries.return_value = True
self.assertEqual(dev.weight, 5000)

fmt.type = "appleboot"
self.assertEqual(dev.weight, 0)
self.assertEqual(dev.weight, 5000)

fmt.mountpoint = "/boot/efi"
fmt.type = "efi"
self.assertEqual(dev.weight, 0)
self.assertEqual(dev.weight, 5000)

fmt.type = "biosboot"
self.assertEqual(dev.weight, 0)
self.assertEqual(dev.weight, 5000)

fmt.mountpoint = "/"
fmt.type = "xfs"
self.assertEqual(dev.weight, 0)

fmt.mountpoint = "/boot"
fmt.type = "ext4"
self.assertEqual(dev.weight, 2000)

def test_weight_2(self):
Expand Down

0 comments on commit b39e390

Please sign in to comment.