Merge ~mwhudson/curtin:default-first-lba into curtin:master

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Dan Bungert
Approved revision: 02bc28d88d3556a292f9d0dad9368ba0f67b128b
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~mwhudson/curtin:default-first-lba
Merge into: curtin:master
Diff against target: 53 lines (+29/-2)
2 files modified
curtin/commands/block_meta_v2.py (+8/-2)
tests/integration/test_block_meta.py (+21/-0)
Reviewer Review Type Date Requested Status
Dan Bungert Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+433618@code.launchpad.net

Commit message

block_meta_v2: set first-lba if needed when creating a new GPT

sfdisk sets first-lba to 2048 by default, which fails if one of
the partitions has an start smaller than that. Having a
partition start so early in the disk is a bit strange but it
works if you are preserving a partition (because we preserve
first-lba) so it should probably work when creating one too.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Dan Bungert (dbungert) wrote :

This looks great. Would you add a test covering this case?
I did see sub-2048 values when playing with gpt preservation so this is quite worth doing.

~mwhudson/curtin:default-first-lba updated
02bc28d... by Michael Hudson-Doyle

add integration test

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Good point, added.

Revision history for this message
Dan Bungert (dbungert) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/curtin/commands/block_meta_v2.py b/curtin/commands/block_meta_v2.py
index 348bf89..3c6e1a5 100644
--- a/curtin/commands/block_meta_v2.py
+++ b/curtin/commands/block_meta_v2.py
@@ -227,8 +227,14 @@ class GPTPartTable(SFDiskPartTable):
227227
228 def _headers(self):228 def _headers(self):
229 r = []229 r = []
230 if self.first_lba is not None:230 first_lba = self.first_lba
231 r.extend(['first-lba: ' + str(self.first_lba)])231 if first_lba is None:
232 min_start = min(
233 [entry.start for entry in self.entries], default=2048)
234 if min_start < 2048:
235 first_lba = min_start
236 if first_lba is not None:
237 r.extend(['first-lba: ' + str(first_lba)])
232 if self.last_lba is not None:238 if self.last_lba is not None:
233 r.extend(['last-lba: ' + str(self.last_lba)])239 r.extend(['last-lba: ' + str(self.last_lba)])
234 if self.table_length is not None:240 if self.table_length is not None:
diff --git a/tests/integration/test_block_meta.py b/tests/integration/test_block_meta.py
index 5f7434f..ff3877a 100644
--- a/tests/integration/test_block_meta.py
+++ b/tests/integration/test_block_meta.py
@@ -350,6 +350,27 @@ class TestBlockMeta(IntegrationTestCase):
350 def test_specified_offsets_msdos_v2(self):350 def test_specified_offsets_msdos_v2(self):
351 self._test_specified_offsets('msdos', 2)351 self._test_specified_offsets('msdos', 2)
352352
353 def test_minimum_gpt_offset_v2(self):
354 # The default first-lba for a GPT is 2048 (i.e. one megabyte
355 # into the disk) but it is possible to create a GPT with a
356 # value as low as 34 and curtin shouldn't get in the way of
357 # you doing that.
358 psize = 20 << 20
359 offset = 34*512
360 img = self.tmp_path('image.img')
361 config = StorageConfigBuilder(version=2)
362 config.add_image(path=img, size='100M', ptable='gpt')
363 config.add_part(size=psize, number=1, offset=offset)
364 self.run_bm(config.render())
365
366 with loop_dev(img) as dev:
367 self.assertEqual(
368 summarize_partitions(dev), [
369 PartData(number=1, offset=offset, size=psize),
370 ])
371 config.set_preserve()
372 self.run_bm(config.render())
373
353 def _test_non_default_numbering(self, ptable, version):374 def _test_non_default_numbering(self, ptable, version):
354 psize = 40 << 20375 psize = 40 << 20
355 img = self.tmp_path('image.img')376 img = self.tmp_path('image.img')

Subscribers

People subscribed via source and target branches