Create image of HDD to smaller HDD, using dd or similar.
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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?
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, ....
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.
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.
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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.