if only 1/3 of a 300GB hard disk is used. Is it possible to use dd to clone the drive (but only the 100GB that is used)?

dd if=/dev/sda of=clone.img

  • What do you mean by used, exactly? Are you saying you have a 100GB partition on the drive, or a 300GB partition with 100GB of data on it? – ChemicalRascal Sep 10 '14 at 0:57
  • ChemicalRascal - I mean a 300GB particition (C Drive on Windows) with 100 gig of data on it. – yoshiserry Sep 10 '14 at 1:01
  • Why exactly do you need to use dd? – Volker Siegel Sep 10 '14 at 1:26
  • I see an interesting solution from here. serverfault.com/a/439149 – Ramesh Sep 10 '14 at 1:29
  • @Ramesh That's brilliant indeed! – Volker Siegel Sep 10 '14 at 1:40

Can not dd parts of filesystem

You can use dd to copy a whole partition, which could be only a part of the harddisk.

You are asking whether you can use dd to copy part of a partition.

In the general case, that can not work:
It would mean you copy only a part of a file system. There is no reason the actual data should be at the start of the available space. And even if it was, there will still be relevant information in other parts in general.

It something like this would work - possibly with a different tool than dd, that tool would need to understand how the data is structured on the partition - that is, it needs to understand the filesystem.

It sounds more useful to let the normal filesystem driver understand how the data is arranged on the disk, and use tar or similar to pack up that data to put it somewhere else.

Resize filesystem, use dd then

One way to do something similar to what you ask for would be to resize the partition.

In a first step, resize the 300GB partition that is only filled to one third to a partition of slightly above 100GB which is almost full.

gparted, a GNOME-focused GUI front-end for the libparted library, is a commonly recommended partitioning manager, but the parted CLI front-end also exists (and is actually the reference implementation for libparted). cfdisk, fdisk and the like are also CLI options, and while I'd say they're less friendly than gparted most Linux distros should have them as part of the core utilities package.

After resizing, you can use dd in the standard way on a complete partition, containing a complete file system.

Filesystem archive tool

Depending on what you want to do, this may also be helpful:

fsarchiver is a tool that creates custom images from filesystems in a compressed format, that need to be unpacked with the same tool.

I would not recommend the tool in general to create images because of the custom format, but as an intermediate state it may make sense. You would create an image of the existing partition, that will not need space for the empty part of the file system. Then, you can use it to unpack it to a different partition and a different file system. The filesystem is generated by fsarchiver as part of the unpacking.

| improve this answer | |

partclone (from the same authors as CloneZilla) can do that. It does not seem to use a DD compatible image format though.

partimage can also do that, with less supported filesystems.

You should be able to convert the images to DD compatible format by restoring the images to a file. (You might want to convert it to sparse file as well)

You won't be able to restore the image to a smaller disk, since it is still a block image, but it uses knowledge of the filesystem to skipped the unused parts.

Exact commands needs more info, like the source filesystem, since partimage comes in filesystem-specific versions.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.