diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2016-04-28 13:58:04 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-06 10:31:12 +0100 |
commit | d03cbac7960c8f39019f2f428647e8100ddc5da0 (patch) | |
tree | 7015264912dc51b07ca6819dd25f0d48c547d97e /scripts | |
parent | e93254b482c09aba884160ea6fea3756702cb1e8 (diff) | |
download | poky-d03cbac7960c8f39019f2f428647e8100ddc5da0.tar.gz |
wic: use truncate utility to create sparse files
Used truncate instead of dd to create wic images for the
following reasons:
- dd doesn't preserve sparseness
- truncate syntax is much more clear
- dd requires additional calculations of the image size
in blocks
- the way dd was used in the code is not always correct.
In some cases it was writing one block to the file which makes
it not 100% sparse.
[YOCTO #9099]
(From OE-Core rev: d2d0d18dfd3922411d856b98ab6ba5d64c9c1c9f)
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/wic/partition.py | 20 | ||||
-rw-r--r-- | scripts/lib/wic/utils/fs_related.py | 12 |
2 files changed, 8 insertions, 24 deletions
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py index 227b685137..6d21193902 100644 --- a/scripts/lib/wic/partition.py +++ b/scripts/lib/wic/partition.py | |||
@@ -220,9 +220,7 @@ class Partition(object): | |||
220 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ | 220 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ |
221 | (extra_blocks, self.mountpoint, rootfs_size)) | 221 | (extra_blocks, self.mountpoint, rootfs_size)) |
222 | 222 | ||
223 | dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ | 223 | exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024)) |
224 | (rootfs, rootfs_size) | ||
225 | exec_cmd(dd_cmd) | ||
226 | 224 | ||
227 | extra_imagecmd = "-i 8192" | 225 | extra_imagecmd = "-i 8192" |
228 | 226 | ||
@@ -255,9 +253,7 @@ class Partition(object): | |||
255 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ | 253 | msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ |
256 | (extra_blocks, self.mountpoint, rootfs_size)) | 254 | (extra_blocks, self.mountpoint, rootfs_size)) |
257 | 255 | ||
258 | dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ | 256 | exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024)) |
259 | (rootfs, rootfs_size) | ||
260 | exec_cmd(dd_cmd) | ||
261 | 257 | ||
262 | label_str = "" | 258 | label_str = "" |
263 | if self.label: | 259 | if self.label: |
@@ -320,9 +316,7 @@ class Partition(object): | |||
320 | """ | 316 | """ |
321 | Prepare an empty ext2/3/4 partition. | 317 | Prepare an empty ext2/3/4 partition. |
322 | """ | 318 | """ |
323 | dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ | 319 | exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024)) |
324 | (rootfs, self.size) | ||
325 | exec_cmd(dd_cmd) | ||
326 | 320 | ||
327 | extra_imagecmd = "-i 8192" | 321 | extra_imagecmd = "-i 8192" |
328 | 322 | ||
@@ -339,9 +333,7 @@ class Partition(object): | |||
339 | """ | 333 | """ |
340 | Prepare an empty btrfs partition. | 334 | Prepare an empty btrfs partition. |
341 | """ | 335 | """ |
342 | dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ | 336 | exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024)) |
343 | (rootfs, self.size) | ||
344 | exec_cmd(dd_cmd) | ||
345 | 337 | ||
346 | label_str = "" | 338 | label_str = "" |
347 | if self.label: | 339 | if self.label: |
@@ -402,9 +394,7 @@ class Partition(object): | |||
402 | """ | 394 | """ |
403 | path = "%s/fs.%s" % (cr_workdir, self.fstype) | 395 | path = "%s/fs.%s" % (cr_workdir, self.fstype) |
404 | 396 | ||
405 | dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ | 397 | exec_cmd("truncate %s -s %d" % (path, self.size * 1024)) |
406 | (path, self.size) | ||
407 | exec_cmd(dd_cmd) | ||
408 | 398 | ||
409 | import uuid | 399 | import uuid |
410 | label_str = "" | 400 | label_str = "" |
diff --git a/scripts/lib/wic/utils/fs_related.py b/scripts/lib/wic/utils/fs_related.py index 2e74461a40..2658dcfc20 100644 --- a/scripts/lib/wic/utils/fs_related.py +++ b/scripts/lib/wic/utils/fs_related.py | |||
@@ -71,14 +71,8 @@ class DiskImage(Disk): | |||
71 | def create(self): | 71 | def create(self): |
72 | if self.device is not None: | 72 | if self.device is not None: |
73 | return | 73 | return |
74 | 74 | # create sparse disk image | |
75 | blocks = self.size / 1024 | 75 | cmd = "truncate %s -s %s" % (self.image_file, self.size) |
76 | if self.size - blocks * 1024: | 76 | exec_cmd(cmd) |
77 | blocks += 1 | ||
78 | |||
79 | # create disk image | ||
80 | dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=1" % \ | ||
81 | (self.image_file, blocks) | ||
82 | exec_cmd(dd_cmd) | ||
83 | 77 | ||
84 | self.device = self.image_file | 78 | self.device = self.image_file |