From d03cbac7960c8f39019f2f428647e8100ddc5da0 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Thu, 28 Apr 2016 13:58:04 +0300 Subject: 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 Signed-off-by: Richard Purdie --- scripts/lib/wic/partition.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'scripts/lib/wic/partition.py') 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): msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, rootfs_size)) - dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ - (rootfs, rootfs_size) - exec_cmd(dd_cmd) + exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024)) extra_imagecmd = "-i 8192" @@ -255,9 +253,7 @@ class Partition(object): msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, rootfs_size)) - dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ - (rootfs, rootfs_size) - exec_cmd(dd_cmd) + exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024)) label_str = "" if self.label: @@ -320,9 +316,7 @@ class Partition(object): """ Prepare an empty ext2/3/4 partition. """ - dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ - (rootfs, self.size) - exec_cmd(dd_cmd) + exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024)) extra_imagecmd = "-i 8192" @@ -339,9 +333,7 @@ class Partition(object): """ Prepare an empty btrfs partition. """ - dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ - (rootfs, self.size) - exec_cmd(dd_cmd) + exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024)) label_str = "" if self.label: @@ -402,9 +394,7 @@ class Partition(object): """ path = "%s/fs.%s" % (cr_workdir, self.fstype) - dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \ - (path, self.size) - exec_cmd(dd_cmd) + exec_cmd("truncate %s -s %d" % (path, self.size * 1024)) import uuid label_str = "" -- cgit 1.2.3-korg