March 28

Linux: Create 10 GB file instantly using dd

Make sure that you have enough free space on the partition

To find out how much is free you can use from command prompt:
df -h

The output will look like this:
Filesystem                   Size  Used Avail Use% Mounted on
/dev/hda2                453G  364G   67G  85% /
tmpfs                           7.8G  292M  7.6G   4% /dev/shm

This means that you have some 67 GB of unused space, so you can proceed with next command that will create 10 GB file:
dd if=/dev/zero of=myharddisk.img bs=1000 count=0 seek=$[1000*1000*10]

Caveats:

This trick will work on ext3, ext4 & reiserfs – but will NOT work on FAT32 partitions as they have maximum file size of 4 GiB.

Also because this file is null from within – some programs will fail working with it – such as mkswapfs & mkswapon. For absolute majority of utilities it will work.

By: A. Eremenko


Copyright 2021. All rights reserved.

Posted March 28, 2017 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B