dd vs. truncate for creating vkernel root images

Chris Turner c.turner at 199technologies.org
Wed Apr 11 16:33:23 PDT 2007

Nuno Antunes wrote:
> Hi all,
> Is there any advantage in using
> 'dd if=/dev/zero of=/var/vkernel/rootimg.01 bs=1m count=2048'
> over the much quicker
> 'truncate -s 2G /var/vkernel/rootimg.01'
> other than getting a root image filled with zeros?

not sure if the 'filled with zeros' counts as the same thing,
but the former will pre-allocate the storage whereas the latter
will not:

  $ truncate -s 100M ./foocate
  $ dd if=/dev/zero of=./ddcate bs=1m count=100
  $ ls -l *cate
  -rw-r--r--  1 foonicator  staff  104857600 Apr 11 19:26 ddcate
  -rw-r--r--  1 foonicator  staff  104857600 Apr 11 19:25 foocate
  $ du -sk *cate
  102448  ddcate
  48      foocate

so it depends on your preference if you want to pre-allocate or
defer allocation.

More information about the Users mailing list