* [PATCH 1/2] wic/engine: fix errors when expanding partitions
@ 2018-07-12 2:05 Anuj Mittal
2018-07-12 2:05 ` [PATCH 2/2] wic/engine: use up all free space " Anuj Mittal
0 siblings, 1 reply; 2+ messages in thread
From: Anuj Mittal @ 2018-07-12 2:05 UTC (permalink / raw)
To: openembedded-core
The UEFI spec implies that GPT partitions should be assumed to be on a 2048
sector boundary (for a 512 byte sector) and the current logic just
divides the free sectors available by the number of partitions that need
re-sizing, which may or may not align and the final result might
overshoot the limits imposed after alignment.
Since we are expanding already aligned partitions, just divide up the
free space in multiples of 2048. Also use the exec_cmd wrapper instead
of the subprocess call directly.
Fixes [YOCTO #12840]
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
---
scripts/lib/wic/engine.py | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 94992365df..fe036f60e9 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -391,11 +391,8 @@ class Disk:
def write_ptable(parts, target):
with tempfile.NamedTemporaryFile(prefix="wic-sfdisk-", mode='w') as outf:
write_sfdisk_script(outf, parts)
- cmd = "{} --no-reread {} < {} 2>/dev/null".format(self.sfdisk, target, outf.name)
- try:
- subprocess.check_output(cmd, shell=True)
- except subprocess.CalledProcessError as err:
- raise WicError("Can't run '{}' command: {}".format(cmd, err))
+ cmd = "{} --no-reread {} < {} ".format(self.sfdisk, target, outf.name)
+ exec_cmd(cmd, as_shell=True)
if expand is None:
sparse_copy(self.imagepath, target)
@@ -412,6 +409,8 @@ class Disk:
for line in exec_cmd("{} -F {}".format(self.sfdisk, target)).splitlines():
if line.startswith("Unpartitioned space ") and line.endswith("sectors"):
free = int(line.split()[-2])
+ # Align free space to a 2048 sector boundary. YOCTO #12840.
+ free = free - (free % 2048)
if free is None:
raise WicError("Can't get size of unpartitioned space")
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] wic/engine: use up all free space when expanding partitions
2018-07-12 2:05 [PATCH 1/2] wic/engine: fix errors when expanding partitions Anuj Mittal
@ 2018-07-12 2:05 ` Anuj Mittal
0 siblings, 0 replies; 2+ messages in thread
From: Anuj Mittal @ 2018-07-12 2:05 UTC (permalink / raw)
To: openembedded-core
Currently we just divide up the free space by the number of partitions
that need to be re-sized. This leads to problems when a user has
explicitly specified a subset of partitions (but not all) that need
to re-sized along with the sizes. As an example, for an image with 3
partitions, if we use:
wic write image.wic /dev/sdb --expand 1:10G
This would lead to paritions 2 and 3 each being re-sized to one thirds
of the free space instead of half.
Change the behavior to use up all the free space.
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
---
scripts/lib/wic/engine.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index fe036f60e9..f0c5ff0aaf 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -416,6 +416,7 @@ class Disk:
# calculate expanded partitions sizes
sizes = {}
+ num_auto_resize = 0
for num, part in enumerate(parts['partitiontable']['partitions'], 1):
if num in expand:
if expand[num] != 0: # don't resize partition if size is set to 0
@@ -425,10 +426,11 @@ class Disk:
sizes[num] = sectors
elif part['type'] != 'f':
sizes[num] = -1
+ num_auto_resize += 1
for num, part in enumerate(parts['partitiontable']['partitions'], 1):
if sizes.get(num) == -1:
- part['size'] += free // len(sizes)
+ part['size'] += free // num_auto_resize
# write resized partition table to the target
write_ptable(parts, target)
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-12 2:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-12 2:05 [PATCH 1/2] wic/engine: fix errors when expanding partitions Anuj Mittal
2018-07-12 2:05 ` [PATCH 2/2] wic/engine: use up all free space " Anuj Mittal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox