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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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.
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).
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.
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.
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 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.