[Trilug-ontopic] I need to create a 2 gb file using Linux

Sean Myers smyers at americanri.com
Fri Dec 21 13:16:19 EST 2007


Continuing the line of tricks, once you've used dd to create a file of arbitrary
size, you can use the mkfs tools on it to write a filesystem to the file, and
then you can mount it like a normal partition using the 'loop' option during the
mount. The mount manpage has some more insight on loop devices and what they're
all about.

--
Sean Myers
System Administrator
American Research Institute
(919) 228-4961


Alan Porter wrote:
>> Yeah, thanks, it worked great.  Created a one gig file but it wasn't 
>> long before I got the file size I wanted.  Thanks again!!!
> 
> Another trick... you can create a so-called "sparse" file by doing this:
> 
> dd if=/dev/zero of=/home/alan/myfile bs=1 count=0 seek=2G
> 
> That takes something like a millisecond to create.  It does not waste 
> time copying 2 billion bytes to a file.
> 
> The space for the file is not actually allocated on the disk until some 
> actual data is written to it, and even then it is only allocated as 
> needed.  If you read the file, it would look like all zeros.
> 
> This is useful if you just want to create an image for something without 
> waiting (for example, create an image and then immediately cover it up 
> with a filesystem or something).  However, this method is NOT useful 
> when you're trying to test what happens when a disk is full, since it 
> does not actually fill up the disk.
> 
> Something neat to add to the toolbox...
> 
> Alan
> 
> 
> 
> 
> 
> 
> .
> 
> 
> 
> _______________________________________________
> Trilug-ontopic mailing list
> Trilug-ontopic at trilug.org
> http://www.trilug.org/mailman/listinfo/trilug-ontopic


More information about the Trilug-ontopic mailing list