-   Linux - Software (
-   -   dd empty space question (

ygloo 09-22-2006 10:27 AM

dd empty space question
i made image of hda1...
there is some empty space on it...
how to make image without that empty space??

dd if=/dev/hda1 of=/home/image bs=4096 conv=notrunc,noerror

stress_junkie 09-22-2006 10:33 AM

I believe that you cannot realistically do that because you cannot count on all of the free space being contiguous.

You can mount the partition and use dd if=<mount point> but then I doubt that it is any better than using tar.

ygloo 09-22-2006 10:40 AM

does tar copy all data...??
tar -cpf image.tar /dev/hda1 ??

stress_junkie 09-22-2006 10:44 AM

tar won't copy to or from an unmounted disk partition but it will copy all of the files in a mounted file system.

What I meant was that if you want to dump a disk partition then you probably can't get rid of the free space.

Matir 09-22-2006 10:45 AM

dd makes a bitwise copy of the drive (i.e., an image). The image must contain all data present on the original disk. tar, OTOH, works on the filesystem and you can create a tar file that contains all the files on the filesystem, but it will not be an 'exact copy' in the sense of an image.

ygloo 09-22-2006 10:52 AM

howto to archive all dirs in "/" using tar
except "/home"?

Matir 09-22-2006 10:57 AM

Use tar with the --exclude option to avoid /home. But you'll also want to avoid /sys, /dev, and /proc. You may also want to explore tar's 'l' option.

ygloo 09-22-2006 11:00 AM

tar -cpf tt.tar * --exclude comics/
not working...

tar -cpfl image.tar /
how to exclude /sys, /dev, and /proc?

Denes 09-22-2006 11:50 AM

I would suggest using partimage. You can download a live cd such as SystemRescueCD which has that on it already. That app ignores all empty space and does compression for you. I have used it to clone a linux hd. In fact I use it in an embedded application to clone linux from a compact flash so that reinstallation is not necessary. It is very fast compared with doing a dd.

marozsas 09-22-2006 11:56 AM

compress the image

Originally Posted by ygloo
i made image of hda1...
there is some empty space on it...
how to make image without that empty space??

dd if=/dev/hda1 of=/home/image bs=4096 conv=notrunc,noerror


I use this method here in the work to deal with MS_Windows images.
The images are good for a fast restore of a windows machine.

To deal with the large empty space in the image, I store the image in compressed mode with gzip. For a typical 40Gbytes image of an entire hard disk, the compressed image is just about 3G! I have a dozen of compressed images for several kinds of hardware and applications pre-loaded.

ygloo 09-22-2006 12:02 PM

!! 10 fold compression...
any1 knows how to exclude dirs using tar?

ygloo 09-22-2006 01:00 PM

dd copies MBR??
tar copies MBR??

Matir 09-22-2006 01:06 PM


Originally Posted by ygloo
dd copies MBR??

Depends on how you use it.

Originally Posted by ygloo
tar copies MBR??

No. The MBR is not a file.

ygloo 09-22-2006 01:09 PM

how to copy MBR with dd?

Denes 09-22-2006 01:15 PM

dd does copy the mbr.
dd if=/hda of=hda.mbr bs=512 count=1 will copy it to the file hda.mbr.

Here is a sample script for backing up and restoring using partimage but you can use dd instead if you like.

# Backup master boot record (MBR)
echo "Backing up master boot record"
dd if=/dev/hda of=Image.mbr count=1 bs=512

# Backup partition table
echo "Backing up partition table"
/sbin/sfdisk -d /dev/hda > Image.sf

# Create image
echo "Backing up first partition"
/usr/sbin/partimage -z1 -c -d -o -b save /dev/hda1 ImageP0
echo "Backing up second partition"
/usr/sbin/partimage -z1 -c -d -o -b save /dev/hda2 ImageP1
echo "Backing up third partition"
/usr/sbin/partimage -z1 -c -d -o -b save /dev/hda3 ImageP2
echo "Backup complete!"

Here is another one for restore

# Write master boot record (MBR)
echo "Writing master boot record"
dd if=Image.mbr of=/dev/hda count=1 bs=512

# Write partition table
echo "Writing parition table"
/sbin/sfdisk /dev/hda < Image.sf

# Write images
echo "Writing first partition"
/usr/sbin/partimage -b restore /dev/hda1 ImageP0.000
echo "Writing second parition"
/usr/sbin/partimage -b restore /dev/hda2 ImageP1.000
echo "Writing third partition"
/usr/sbin/partimage -b restore /dev/hda3 ImageP2.000
echo "Clone complete!"

All times are GMT -5. The time now is 02:19 AM.