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

by on June 2, 2008 · 10 comments· last updated at June 2, 2009

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



You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 10 comments… read them below or add one }

1 JW June 17, 2009 at 5:57 am

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 zzzplayer March 5, 2013 at 4:42 am

I don’t think you have read and tested this yourself.

If using “count=0″, as the article suggests, you will still have the file of the specified size.

However, the output will show something like “0+0 records in” and “0+0 records out”.

Then if you check the file size:

ls -al /path/to/test.img

it should show the proper size.

It’s even easier, using the format that the commenter Indie suggest:

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

Reply

3 Diane Girard June 24, 2009 at 9:48 pm

can I supress the output of dd command?

Reply

4 Vivek Gite June 25, 2009 at 8:05 am

Yes, send it to /dev/null.

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

Reply

5 Indie December 26, 2010 at 12:23 am

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

6 jayaram Prasad August 26, 2011 at 5:09 am

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

7 Indie August 26, 2011 at 3:02 pm

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

8 Jigar June 1, 2012 at 7:56 am

I have 2 tb harddrive and i want to clone only 1 tb to my other drive?

what command should i do

Reply

9 vsama June 2, 2012 at 11:52 pm

How to check if the created file is empty, is there a way to check that?

Reply

10 Bhanu November 6, 2012 at 12:01 pm

ls -l

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , , , ,

Previous Faq:

Next Faq: