Re: Script to set up sparse device for testing

Erik Mouw <[email protected]>
Newsgroups gmane.comp.file-systems.ext2.devel
Organization Harddisk-recovery.com
Message-ID <[email protected]>
On Thu, Jul 06, 2006 at 01:05:14AM +0100, Stephen C. Tweedie wrote:
> Attached is a script from Heinz Mauelshagen to set up a sparse device
> for testing purposes, allowing a given amount of storage to act as a
> test bed for a much larger filesystem --- as long as you don't actually
> write to all that data. :)   It basically creates a snapshot of the
> empty zero device, and fills it in using the backing store you give it
> for snapshot storage.

Here's another way I always use: create a file, truncate it to the
desired size and use it as a loop mount. Requires a small program
called "truncate":

/* truncate.c: truncate files
 * compile with: gcc -Wall -O2 -D_GNU_SOURCE -o truncate truncate.c
 */

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int main (int argc, char **argv)
{
  int i;
  long long l;

  if(argc < 3) {
          printf("Truncates one or more files.\n");
          printf("Usage: %s size file [file ...]\n", argv[0]);
          return 0;
  }
  sscanf (argv[1], "%lli", &l);

  for (i=2;i < argc;i++) {
    if (truncate64 (argv[i], l) < 0) {
      perror (argv[i]);
    }
  }
  exit (0);
}

(IIRC truncate() isn't required to work this way according to
POSIX/SUSv3, but it works under Linux).

Example: create a 1 GB ext3 filesystem:

touch foobar
truncate 1073741824 foobar
mke2fs -j foobar
losetup /dev/loop0 foobar
mount -t ext3 /dev/loop0 /mnt


Erik

-- 
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.