1833904 Members
1838 Online
110063 Solutions
New Discussion

Creating a large file.

 
SOLVED
Go to solution
Prasad Joshi
Regular Advisor

Creating a large file.

Hi All,

How can I create a file of size 3GB+?

Thanks & regards,
Prasad.
8 REPLIES 8
Chan 007
Honored Contributor

Re: Creating a large file.

Hi Prasan,

you can do while creating

mkfs -F vxfs -o largefiles /dev//rlv

or

fsadm -F vxfs -o largefiles ...

Chan
DRAXLER, Markus
Occasional Advisor
Solution

Re: Creating a large file.

dd if=/dev/zero of=/var/tmp/three_gig+ bs=1024 count=$((3*1024*1024+1))
Peter Godron
Honored Contributor

Re: Creating a large file.

Prasad,
see
man prealloc


prealloc testfile 3221225473
Chan 007
Honored Contributor

Re: Creating a large file.

Mark "0" for this

man newfs, mkfs, fsadm

My prev reply should be read as newfs not mkfs.

Chan
Arunvijai_4
Honored Contributor

Re: Creating a large file.

Hi Prasad,

Do you want to create file larger than 3 GB ? If yes, you can try this program,


/*
* Assuming this is named largetest.c, build with:
* cc -o largetest largetest.c
*/
#include
#include
#include
#include
#include
#include
#include
#include

#define ERROR(x,y) { if ( (x) == -1) { perror(y); exit(errno); } }

int main(int argn, char **argv)
{
const char *file;
int fd, len;
long long count;
ssize_t result;
long long offset;
struct timeval start, end, dif;

if (argn < 2)
file = "largefile.junk";
else
file = argv[1];

gettimeofday(&start, NULL);

fd = open(file, O_CREAT | O_TRUNC | O_RDWR , 00644);
ERROR(fd, "Failed to open file");

printf("Creating 3GB test file...\n");
count = (3*1024*1024*1024) - 1;
offset = lseek(fd, count, SEEK_CUR);
ERROR(offset, "Failed to set current offset");

printf("Writting at 3GB...\n");
result = write(fd, "b", 1); /* Write data at 3GB point */
ERROR(result, "Failed to write at 3 GB mark");

printf("Closing file...\n");
result = close(fd);
ERROR(result, "Failed to close file");

gettimeofday(&end, NULL);

timersub(&end, &start, &dif);
printf("Task took %ld.%ld sec to run.\n", dif.tv_sec, dif.tv_usec);

printf("Done. Large file created.\n");
}

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Ninad_1
Honored Contributor

Re: Creating a large file.

Prasad,

If you want to create a file greater than 2Gb then you need the largefiles option on your filesystem when it was created and then while mounting it. Chan has already given you the commands.
I think thats the info you are looking for. But when you say you want to create a file of size 3GB+, if you mean how you can reserve some space for a file - then you can do a prealloc filename size(in bytes)
to reserver that much space for a file. This essentially creates a file with nulls making it the size you specified - But I am not sure if this is waht you want.

Regards,
Ninad
Prasad Joshi
Regular Advisor

Re: Creating a large file.

Hi All,

I have created file system with largefile support and also mounted with large file support.

I wanted to create some largefiles on them for testing purpose.

Thanks for your help.

Thanks & regards,
Prasad.
Prasad Joshi
Regular Advisor

Re: Creating a large file.

Thanks