LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Create image of HDD to smaller HDD, using dd or similar. (https://www.linuxquestions.org/questions/linux-general-1/create-image-of-hdd-to-smaller-hdd-using-dd-or-similar-821428/)

Jezzalien 07-22-2010 04:12 AM

Create image of HDD to smaller HDD, using dd or similar.
 
Is it possible to copy the contents of a hard drive to a smaller hard drive. It should be assumed that the source drive is operational and fault-free, whereas the target drive is also fault-free but has no operating system or partition(s). The OS is Redhat. The source drive is by no means "full" or contain data exceeding the size of the target drive.

I've been using dd to copy to equal/larger-sized drives with success, but have noticed that there are some dd command options to limit the "amount" of sectors copied. Can these options be used to limit the copy-process to just the "used" portion of the source drive, so that only the data is copied, and the remainder left untouched?

On a similar vein, can the source filesystem/data be re-arranged so that the data is moved to the "beginning" of the drive?

Regards,
Jezzalien.

unSpawn 07-22-2010 04:22 AM

If the partitions on the source drive are not completely in use then maybe this could better be done by creating a partition table on the destination disk with deflated sizes, mounting partitions and then rsyncing data?

syg00 07-22-2010 04:59 AM

Rule #1: Never use dd to image a filesystem except for forensics.
Rule #2: there is only one rule.

Even were you could to get all the data to the "front" of the filesystem, the filesystem metadata has an inode table that describes the entire f/s. Chopping some portion off it is unlikely to be appreciated by fsck.
dd does an appalling job of resolving errors on the source. As per unSpawn, use a filesystem aware tool - rsync, cp, tar, ....

jefro 07-22-2010 03:04 PM

You can attempt that but dd usually works best if equal or greater. Since this is RH you really have other options. We use dd on some OS's that difficult to clone.

One way to condense a partition may be to tar it to some external and then copy back. I belive tar is supposed to take file by file even if fragmented. Since it was such an old command I believe it still works that way.

phil.d.g 07-22-2010 04:49 PM

You could resize the source filesystem, then the source partition, then create a partition on the target drive of equal or greater size and then dd across...

...but you'd want to make backups before doing any of that. By far the easiest way is to create a partition and filesystem on the target and use tar or rsync.

If this is partition contains an OS, and you are worried that the target drive won't boot after, we can guide you through installing the boot loader on the target drive after you've tar'ed/rsync'ed the files across.

Jezzalien 07-23-2010 12:31 AM

Thanks everyone,

Plenty of options to choose from. I particularly like the sound of "create new partitions and tar/rsync"-styled options. I'll look into doing this soon, but don't hold your breath...

Thanks again,
Jezzalien.


All times are GMT -5. The time now is 06:38 AM.