cancel
Showing results for 
Search instead for 
Did you mean: 

Create DAT file

SOLVED
Go to solution
'chris'
Super Advisor

Create DAT file

hi

Howto compress files to *.dat file?

For example, I can decompress files from a ramdisk.dat using 7-Zip, but howto compress back to *.dat after changes?
16 REPLIES
Matti_Kurkela
Honored Contributor
Solution

Re: Create DAT file

".dat" is a very generic file extension, meaning something like "some special data, only the appropriate tools are expected to make sense of this". So it would be kind of important to know more about the context: where exactly did you get this file from?

Since you placed this question into Linux section of this forum, I assume this might be something Linux-related. In this case, the name "ramdisk.dat" suggests this might be a Linux boot-time initrd or initramfs (INITial Ram Disk/ RAM File System), or something else.

Initrd and initramfs are similar in purpose, but very different in structure. Initrd is a GZIP compressed disk image that contains a filesystem of some type: the type must match what's available in the kernel that is going to use it.

Depending on the type of the filesystem, you might be able to uncompress the file with gunzip and then mount it as a disk image in Linux: that would allow making changes to the disk image, sort of like if it was an USB stick or other removable media.

Some special-purpose (high-compression) filesystems won't allow write access: these filesystems must be "built" using a special tool, similar to creating .ISO images with the mkisofs/genisoimage command.

So if it's an initrd-style file, it will be necessary to identify the filesystem type, or find some documentation that lists the correct type.

Initramfs, on the other hand, is simply a GZIP compressed "cpio" archive. One reason for its design was to avoid the complexity of initrd.

The Linux kernel documentation includes the procedures for extracting initramfs files and creating new ones:
http://www.mjmwired.net/kernel/Documentation/filesystems/ramfs-rootfs-initramfs.txt

Googling for "ramdisk.dat" finds various targets, like Acronis TrueImage or Ultimate Boot CD. If your question is related to customizing one of these for your environment, please say so: we can neither read your mind nor take a peek into your system to find out what you're doing.

MK
MK
dirk dierickx
Honored Contributor

Re: Create DAT file

if you use the command 'file ' it will tell you what the actual format of that file is, so you can then recreate the file using the same compression method as the 'file' command told you it was.
'chris'
Super Advisor

Re: Create DAT file

# file -s ramdisk.dat
ramdisk.dat: gzip compressed data, was "ramdisk.dat.initrd", from FAT filesystem (MS-DOS, OS/2, NT), last modified: Mon Nov 10 02:00:20 2008

# file -i ramdisk.dat
ramdisk.dat: application/x-gzip

I've tried first to uncompress under linux using gzip, but it doesn't work:

# gzip -d ramdisk.dat
gzip: ramdisk.dat: unknown suffix -- ignored
Steven Schweda
Honored Contributor

Re: Create DAT file

> # gzip -d ramdisk.dat
> gzip: ramdisk.dat: unknown suffix -- ignored

man gzip

You could rename the file, or you could feed
it in from stdin.

gzip -dc < ramdisk.dat > ramdisk2.dat
'chris'
Super Advisor

Re: Create DAT file

Thx, but howto decompress files from ramdisk2.dat or mount it?
Steven Schweda
Honored Contributor

Re: Create DAT file

> Thx, but howto decompress files from
> ramdisk2.dat or mount it?

How did you make the thing? How should we
know more about what's in it than you do?

"mount -o loop [...]"?
'chris'
Super Advisor

Re: Create DAT file

I've done what u suggested:

# gzip -dc < ramdisk.dat > ramdisk2.dat

and I'd like to get (mount) all files from ramdisk2.dat.
Matti_Kurkela
Honored Contributor

Re: Create DAT file

Please run "file ramdisk2.dat" to try and identify the content inside the compression.

If it says just "data", that means the "file" command cannot identify it. If it says something like "cpio archive", it's most likely an initramfs: it cannot be mounted, but you can use the "cpio" command to extract (and later re-package) it: see my previous answer for a link to instructions.

If your Linux distribution has "fstyp" or "fsstat" available, you can try these commands too:

fstyp ramdisk2.dat
fsstat -t ramdisk2.dat

If the ramdisk2.dat is a filesystem image, either of these commands might be able to identify the filesystem type used in the image. That would help a lot in selecting the proper tools for modifying/rebuilding the file.

If it is a filesystem image, it can be mounted like this if the filesystem type is supported by your current Linux kernel:

mkdir -p /mnt/ramdisk
mount -o loop,rw ramdisk2.dat /mnt/ramdisk

If the filesystem won't support read-write access (cramfs, squashfs or similar), the mount command may fail. You may have to mount it read-only instead:

mount -o loop,ro ramdisk2.dat /mnt/ramdisk

If the mount command is successful, then you can view /proc/mounts to identify the filesystem type.

MK
MK
'chris'
Super Advisor

Re: Create DAT file

thx,

# fstyp ramdisk2.dat
#

# fstat ramdisk2.dat
USER CMD PID FD MOUNT INUM MODE SZ|DV R/W NAME

# mkdir -p /mnt/ramdisk
# mount -o loop,rw ramdisk2.dat /mnt/ramdisk
mount: you must specify the filesystem type

# mount -o loop,ro ramdisk2.dat /mnt/ramdisk
mount: you must specify the filesystem type
'chris'
Super Advisor

Re: Create DAT file

using tar seems to work well:

# tar xvzf ramdisk.dat -C /mnt/ramdisk

# ls -l /mnt/ramdisk
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


'chris'
Super Advisor

Re: Create DAT file

It's quite interesting that tar with this file works only under freeBSD, it doesn't work under linux:

# tar xvzf ramdisk.dat -C /mnt/ramdisk
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Error exit delayed from previous errors
Steven Schweda
Honored Contributor

Re: Create DAT file

> It's quite interesting that tar with this
> file works only under freeBSD, it doesn't
> work under linux:

It _might_ be interesting if we knew which
"tar" programs were involved.

tar --version

(And if we knew that you were working with
the same data in both cases.)

> # tar xvzf ramdisk.dat -C /mnt/ramdisk

Probably not where I'd put something other
than a mount point for a file system, but
it's your system.
'chris'
Super Advisor

Re: Create DAT file

There is exact the same file and mount points on both systems are OK.

freeBSD:
# tar --version
bsdtar 2.2.5 - libarchive 2.2.4

Debian Lenny:
# tar --version
tar (GNU tar) 1.20
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by John Gilmore and Jay Fenlason.
Stuart Browne
Honored Contributor

Re: Create DAT file

That's because it's a CPIO image..

initrd / ramdisk images are gzip'd CPIO files.

To extract 'ramdisk.dat':

tmp]# mkdir image; cd image
image]# gzip -cd ../ramdisk.dat | cpio -vidum

To re-create the ramdisk image:

image]# find . -print | cpio -ocv | gzip -9 > ../ramdisk-new.dat
One long-haired git at your service...
'chris'
Super Advisor

Re: Create DAT file

I've done what u suggested:

linux:/tmp# mkdir image; cd image
linux:/tmp/image# gzip -cd /home/ramdisk/ramdisk.dat | cpio -vidum

and the linux server doesn't start anymore.
Steven Schweda
Honored Contributor

Re: Create DAT file

> and the linux server doesn't start anymore.

I don't recall having been shown the contents
of this cpio archive ("cpio -tv"), so I know
nothing, but if it contained absolute paths
instead of relative paths, then restoring it
(with "-u") might have overwritten a
directory like, say, "/dev", with
inappropriate data, and that could make a
system unusable.