# Decompress files from a single DAT file



## ccc (Dec 28, 2009)

Hi

Howto decompress (uncompress) files from a single DAT file?


----------



## SirDice (Dec 28, 2009)

What do you mean? You need an disk image you can load as a ramdisk? What should be in there? Most disk images aren't compressed but they can be.


----------



## ccc (Dec 28, 2009)

I'd like to decompress image .dat file, change some files 
and after changes compress back to a single .dat file.


----------



## graudeejs (Dec 28, 2009)

extension doesn't tell anything about actual file type....

try using `$ file -i [i]filename[/i]` and show output....
It may fail to determinate correct file type, but it's much better than file extensions

also it might be good idea to look at file with binary editor/viewer. editors/hte is my favourite


mostly Windows use file extensions to determinate file type.... I could rename some readme.txt to readme.png and many apps in windows would be confused...
That's why I dislike any File Managers that determinate file types by extensions

EDIT:
also what makes you think it's compressed?


----------



## ccc (Dec 28, 2009)

```
# file -i ramdisk.dat
ramdisk.dat: application/x-gzip
# file -s ramdisk.dat
ramdisk.dat: gzip compressed data, was "ramdisk.dat.initrd", from FAT filesystem (MS-DOS, OS/2, NT), last modified: Tue Jan 13 01:00:25 2009
```


----------



## ccc (Dec 31, 2009)

Howto decompress ramdisk.dat to get single files?


----------



## aragon (Dec 31, 2009)

If file is correct about what it is, you just need to decompress it with gunzip, create a vnode type md device from it with mdconfig(8), mount the md device as a msdos file system, modify the files, and then reverse.


```
gunzip -N ramdisk.dat
mdconfig -a -t vnode -f ramdisk.dat.inird
mount_msdosfs /dev/mdX /wherever
```


----------



## ccc (Dec 31, 2009)

Thx, but I'm getting this problem:
	
	



```
# gunzip -N ramdisk.dat
gunzip: ramdisk.dat: unknown suffix -- ignored
# gunzip -N ramdisk.dat > ramdisk.dat.inird
gunzip: ramdisk.dat: unknown suffix -- ignored
```

Perhaps:
	
	



```
# gunzip -dc ramdisk.dat > ramdisk.dat.inird
# mdconfig -a -t vnode -f ramdisk.dat.inird
md0
# mount_msdosfs /dev/md0 /tmp/cc
mount_msdosfs: /dev/md0: : Invalid argument
```


----------



## aragon (Dec 31, 2009)

I'm guessing it's not a compressed FAT file system image then.  So what is it?

If data can't be identified, it can't be used.  If you don't know what it is then you'll need to first try figure that out with hexdump(1).


----------



## graudeejs (Dec 31, 2009)

try running `$ file -i ...` on decompressed image
See what it tells you


----------



## fronclynne (Dec 31, 2009)

Might try `# mount_msdosfs /dev/md0s1 /tmp/cc` . . .


----------



## J65nko (Dec 31, 2009)

You use tar with the "-z" flag. From *man 1 tar*

```
-z      (c mode only) Compress the resulting archive with gzip(1).  In
             extract or list modes, this option is ignored.  Note that, unlike
             other tar implementations, this implementation recognizes gzip
             compression automatically when reading archives.
```
An example

```
$ tar cvzf alllogs.tgz *log

a mailman-port.log
a pkgadd.log
a postfix-postfix-2.5.9,2.tbz.log
a postfix-re-pkg_add.log

$ file alllogs.tgz 
alllogs.tgz: gzip compressed data, from Unix, last modified: Thu Dec 31 20:03:53 2009

$ tar xvzf alllogs.tgz -C /tmp

x mailman-port.log
x pkgadd.log
x postfix-postfix-2.5.9,2.tbz.log
x postfix-re-pkg_add.log

$ ls -l /tmp

total 1312
[snip]
-rw-r--r--  1 root  wheel     264919 Dec 25 03:36 mailman-port.log
-rw-r--r--  1 root  wheel     917943 Dec 23 23:43 pkgadd.log
-rw-r--r--  1 root  wheel      30240 Dec 24 01:10 postfix-postfix-2.5.9,2.tbz.log
-rw-r--r--  1 root  wheel      55429 Dec 24 00:13 postfix-re-pkg_add.log
```


----------



## ccc (Dec 31, 2009)

killasmurf86 said:
			
		

> try running `$ file -i ...` on decompressed image
> See what it tells you




```
# file -i ramdisk.dat.inird
ramdisk.dat.inird: application/x-empty
```


----------



## ccc (Dec 31, 2009)

fronclynne said:
			
		

> Might try `# mount_msdosfs /dev/md0s1 /tmp/cc` . . .




```
# mount_msdosfs /dev/md0s1 /tmp/cc
mount_msdosfs: /dev/md0s1: : No such file or directory
```


----------



## ccc (Dec 31, 2009)

J65nko said:
			
		

> You use tar with the "-z" flag. From *man 1 tar*
> 
> ```
> -z      (c mode only) Compress the resulting archive with gzip(1).  In
> ...



Thx, it works well!
	
	



```
# tar xvzf ramdisk.dat -C /tmp

# ls -l /tmp
total 24
drwxr-xr-x  2 root  <<<<<<< current   1024 Aug 15  2007 bin
drwxr-xr-x  2 root  <<<<<<< current    512 Aug 15  2007 dev
drwxr-xr-x  7 root  <<<<<<< current    512 Aug 15  2007 etc
-rwxr-xr-x  1 root  <<<<<<< current    272 Aug 14  2007 init
drwxr-xr-x  3 root  <<<<<<< current   2048 Aug 15  2007 lib
drwxr-xr-x  2 root  <<<<<<< current    512 Aug 15  2007 mnt
drwxr-xr-x  2 root  <<<<<<< current    512 Aug 15  2007 proc
drwxr-xr-x  2 root  <<<<<<< current    512 Aug 15  2007 sbin
drwxr-xr-x  2 root  <<<<<<< current    512 Aug 15  2007 sys
drwxrwxr-x  2 root  <<<<<<< current    512 Aug 15  2007 tmp
drwxr-xr-x  3 root  <<<<<<< current    512 Aug 15  2007 usr
drwxr-xr-x  2 root  <<<<<<< current    512 Aug 15  2007 var
```


----------



## aragon (Jan 1, 2010)

Surprised file(1) didn't detect that it was just a compressed tarball!  Well done.


----------

