summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/partition.py
diff options
context:
space:
mode:
authorMaciej Borzecki <maciej.borzecki@rndity.com>2016-12-19 12:20:58 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-12-22 08:50:16 +0000
commit1988bae5bfed203ddf889a7def2a49422e5d5e60 (patch)
tree7ea3490a77b1e5cd854480609956a0a489d22339 /scripts/lib/wic/partition.py
parent5903182484276fec4d9ccbe7ad2c859e9588e5ba (diff)
downloadpoky-1988bae5bfed203ddf889a7def2a49422e5d5e60.tar.gz
wic: add --fixed-size wks option
Added new option --fixed-size to wks. The option can be used to indicate the exact size of a partition. The option cannot be added together with --size, in which case an error will be raised. Other options that influence automatic partition size (--extra-space, --overhead-factor), if specifiec along with --fixed-size, will raise an error. If it partition data is larger than the amount of space specified with --fixed-size option wic will raise an error. (From OE-Core rev: fdd217ba874bd480e0180830fe2e6bd54dde19d9) Signed-off-by: Maciej Borzecki <maciej.borzecki@rndity.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/partition.py')
-rw-r--r--scripts/lib/wic/partition.py88
1 files changed, 55 insertions, 33 deletions
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index b191cdee54..aa8f8a7948 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -54,6 +54,7 @@ class Partition():
54 self.part_type = args.part_type 54 self.part_type = args.part_type
55 self.rootfs_dir = args.rootfs_dir 55 self.rootfs_dir = args.rootfs_dir
56 self.size = args.size 56 self.size = args.size
57 self.fixed_size = args.fixed_size
57 self.source = args.source 58 self.source = args.source
58 self.sourceparams = args.sourceparams 59 self.sourceparams = args.sourceparams
59 self.system_id = args.system_id 60 self.system_id = args.system_id
@@ -87,6 +88,41 @@ class Partition():
87 else: 88 else:
88 return 0 89 return 0
89 90
91 def get_rootfs_size(self, actual_rootfs_size=0):
92 """
93 Calculate the required size of rootfs taking into consideration
94 --size/--fixed-size flags as well as overhead and extra space, as
95 specified in kickstart file. Raises an error if the
96 `actual_rootfs_size` is larger than fixed-size rootfs.
97
98 """
99 if self.fixed_size:
100 rootfs_size = self.fixed_size
101 if actual_rootfs_size > rootfs_size:
102 msger.error("Actual rootfs size (%d kB) is larger than allowed size %d kB" \
103 %(actual_rootfs_size, rootfs_size))
104 else:
105 extra_blocks = self.get_extra_block_count(actual_rootfs_size)
106 if extra_blocks < self.extra_space:
107 extra_blocks = self.extra_space
108
109 rootfs_size = actual_rootfs_size + extra_blocks
110 rootfs_size *= self.overhead_factor
111
112 msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
113 (extra_blocks, self.mountpoint, rootfs_size))
114
115 return rootfs_size
116
117 @property
118 def disk_size(self):
119 """
120 Obtain on-disk size of partition taking into consideration
121 --size/--fixed-size options.
122
123 """
124 return self.fixed_size if self.fixed_size else self.size
125
90 def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir, 126 def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir,
91 bootimg_dir, kernel_dir, native_sysroot): 127 bootimg_dir, kernel_dir, native_sysroot):
92 """ 128 """
@@ -97,9 +133,9 @@ class Partition():
97 self.sourceparams_dict = parse_sourceparams(self.sourceparams) 133 self.sourceparams_dict = parse_sourceparams(self.sourceparams)
98 134
99 if not self.source: 135 if not self.source:
100 if not self.size: 136 if not self.size and not self.fixed_size:
101 msger.error("The %s partition has a size of zero. Please " 137 msger.error("The %s partition has a size of zero. Please "
102 "specify a non-zero --size for that partition." % \ 138 "specify a non-zero --size/--fixed-size for that partition." % \
103 self.mountpoint) 139 self.mountpoint)
104 if self.fstype and self.fstype == "swap": 140 if self.fstype and self.fstype == "swap":
105 self.prepare_swap_partition(cr_workdir, oe_builddir, 141 self.prepare_swap_partition(cr_workdir, oe_builddir,
@@ -146,6 +182,7 @@ class Partition():
146 oe_builddir, 182 oe_builddir,
147 bootimg_dir, kernel_dir, rootfs_dir, 183 bootimg_dir, kernel_dir, rootfs_dir,
148 native_sysroot) 184 native_sysroot)
185
149 # further processing required Partition.size to be an integer, make 186 # further processing required Partition.size to be an integer, make
150 # sure that it is one 187 # sure that it is one
151 if type(self.size) is not int: 188 if type(self.size) is not int:
@@ -153,6 +190,12 @@ class Partition():
153 "This a bug in source plugin %s and needs to be fixed." \ 190 "This a bug in source plugin %s and needs to be fixed." \
154 % (self.mountpoint, self.source)) 191 % (self.mountpoint, self.source))
155 192
193 if self.fixed_size and self.size > self.fixed_size:
194 msger.error("File system image of partition %s is larger (%d kB) than its"\
195 "allowed size %d kB" % (self.mountpoint,
196 self.size, self.fixed_size))
197
198
156 def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir, 199 def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
157 rootfs_dir): 200 rootfs_dir):
158 """ 201 """
@@ -228,15 +271,7 @@ class Partition():
228 out = exec_cmd(du_cmd) 271 out = exec_cmd(du_cmd)
229 actual_rootfs_size = int(out.split()[0]) 272 actual_rootfs_size = int(out.split()[0])
230 273
231 extra_blocks = self.get_extra_block_count(actual_rootfs_size) 274 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
232 if extra_blocks < self.extra_space:
233 extra_blocks = self.extra_space
234
235 rootfs_size = actual_rootfs_size + extra_blocks
236 rootfs_size *= self.overhead_factor
237
238 msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
239 (extra_blocks, self.mountpoint, rootfs_size))
240 275
241 with open(rootfs, 'w') as sparse: 276 with open(rootfs, 'w') as sparse:
242 os.ftruncate(sparse.fileno(), rootfs_size * 1024) 277 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
@@ -262,15 +297,7 @@ class Partition():
262 out = exec_cmd(du_cmd) 297 out = exec_cmd(du_cmd)
263 actual_rootfs_size = int(out.split()[0]) 298 actual_rootfs_size = int(out.split()[0])
264 299
265 extra_blocks = self.get_extra_block_count(actual_rootfs_size) 300 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
266 if extra_blocks < self.extra_space:
267 extra_blocks = self.extra_space
268
269 rootfs_size = actual_rootfs_size + extra_blocks
270 rootfs_size *= self.overhead_factor
271
272 msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
273 (extra_blocks, self.mountpoint, rootfs_size))
274 301
275 with open(rootfs, 'w') as sparse: 302 with open(rootfs, 'w') as sparse:
276 os.ftruncate(sparse.fileno(), rootfs_size * 1024) 303 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
@@ -292,20 +319,13 @@ class Partition():
292 out = exec_cmd(du_cmd) 319 out = exec_cmd(du_cmd)
293 blocks = int(out.split()[0]) 320 blocks = int(out.split()[0])
294 321
295 extra_blocks = self.get_extra_block_count(blocks) 322 rootfs_size = self.get_rootfs_size(blocks)
296 if extra_blocks < self.extra_space:
297 extra_blocks = self.extra_space
298
299 blocks += extra_blocks
300
301 msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
302 (extra_blocks, self.mountpoint, blocks))
303 323
304 label_str = "-n boot" 324 label_str = "-n boot"
305 if self.label: 325 if self.label:
306 label_str = "-n %s" % self.label 326 label_str = "-n %s" % self.label
307 327
308 dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks) 328 dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, rootfs_size)
309 exec_native_cmd(dosfs_cmd, native_sysroot) 329 exec_native_cmd(dosfs_cmd, native_sysroot)
310 330
311 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir) 331 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
@@ -328,8 +348,9 @@ class Partition():
328 """ 348 """
329 Prepare an empty ext2/3/4 partition. 349 Prepare an empty ext2/3/4 partition.
330 """ 350 """
351 size = self.disk_size
331 with open(rootfs, 'w') as sparse: 352 with open(rootfs, 'w') as sparse:
332 os.ftruncate(sparse.fileno(), self.size * 1024) 353 os.ftruncate(sparse.fileno(), size * 1024)
333 354
334 extra_imagecmd = "-i 8192" 355 extra_imagecmd = "-i 8192"
335 356
@@ -346,8 +367,9 @@ class Partition():
346 """ 367 """
347 Prepare an empty btrfs partition. 368 Prepare an empty btrfs partition.
348 """ 369 """
370 size = self.disk_size
349 with open(rootfs, 'w') as sparse: 371 with open(rootfs, 'w') as sparse:
350 os.ftruncate(sparse.fileno(), self.size * 1024) 372 os.ftruncate(sparse.fileno(), size * 1024)
351 373
352 label_str = "" 374 label_str = ""
353 if self.label: 375 if self.label:
@@ -362,7 +384,7 @@ class Partition():
362 """ 384 """
363 Prepare an empty vfat partition. 385 Prepare an empty vfat partition.
364 """ 386 """
365 blocks = self.size 387 blocks = self.disk_size
366 388
367 label_str = "-n boot" 389 label_str = "-n boot"
368 if self.label: 390 if self.label: