Linux / UNIX: Create Large 1GB Binary Image File With dd Command

by Vivek Gite on June 2, 2008 · 6 comments

How do I create 1 GB or 10 GB image file instantly with dd command under UNIX / Linux / BSD operating systems using a shell prompt?

You can use dd command to create image files for network or file system testing. First, make sure you've sufficient disk space to create a image file using dd:
$ df -H
To create 1MB file (1024kb), enter:
$ dd if=/dev/zero of=test.img bs=1024 count=0 seek=1024
To create 10MB file , enter:
$ dd if=/dev/zero of=test.img bs=1024 count=0 seek=$[1024*10]
To create 100MB file , enter:
$ dd if=/dev/zero of=test.img bs=1024 count=0 seek=$[1024*100]
$ ls -lh test.img

To create 10GB, file:
$ dd if=/dev/zero of=10g.img bs=1000 count=0 seek=$[1000*1000*10]
Sample output:

0+0 records in
0+0 records out
0 bytes transferred in 0.000014 secs (0 bytes/sec)

Verify file size (note bs factor in original dd command):
$ ls -lh 10g
-rw-r--r-- 1 root wheel 9.3G Jun 2 12:07 10g.img

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 6 comments… read them below or add one }

1 JW June 17, 2009

I don’t think this works correctly unless the “count” argument is changed to something greater than 0.

Try something like this:

dd if=/dev/zero of=10Gtest bs=1M count=10000

Reply

2 Diane Girard June 24, 2009

can I supress the output of dd command?

Reply

3 Vivek Gite June 25, 2009

Yes, send it to /dev/null.

dd args >/dev/null
OR
dd args >/dev/null 2>&1

Reply

4 Indie December 26, 2010

Slightly easier version is to use a suffix for the size instead of trying to do the maths.

dd if=/dev/zero of=disk.img bs=1 count=0 seek=1G

to create a 1G file.

Reply

5 jayaram Prasad August 26, 2011

Yes this is work but there is concern !!!

When do ls -lh disk.img file its showing as 1G size but when u run the command

du -h disk.img it shows 0 bytes of size…..

Which one we can believe…i dont know…please clarify if you know about this…

Jai

Reply

6 Indie August 26, 2011

The ls command will tell you the size of the file while du will tell you the Disk Usage. When you create the empty disk image with the above command it doesn’t write any data so it doesn’t actually allocate any blocks to the file.

If you type “stat disk.img” you’ll see that it’s using 0 blocks and thus no disk space is being consumed by the file, it’s only when you then write data to it that the blocks will then be allocated.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 7 + 14 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: