0

I am pretty new to Linux and have run into some problems.

Goal: I have two machines running Debian 9 Stretch and I want to clone one of the machines onto the other.

First thing I did was connected an external harddrive into the first machine and used the following command to copy everything into it.

sudo dd if=/dev/sda1 of=/dev/sdb1 bs=10M && sync

I am still not sure if that was the right way to copy it or if was were to make the output equal to a .img.

Anyways, I connected the external harddrive into the second machine and executed the following dd command

sudo dd if=/dev/sdb1 of=/dev/sba1 bs=10M conv=noerror,sync

I kept getting errors saying something about I/O but eventually it went through and near the end it said it ran out of memory. It created new partitions and the internal drive got filled up.

I checked the /etc/rc.local file and it seemed to have been corrupted. I had rebooted and there were a bunch of lines popping up with rc.local as it was booting.

I decided to boot into recovery mode and for some reason it booted up like my first machine with the same directory and everything.

Looking back at my dd command, I felt that I should've entered in sda instead of sda1

I executed the dd command again and realized maybe I should change sdb1 to sdb as well.

I stopped the command about 30 seconds in and tried to correct the line.

When I re-executed the line, I got a reply saying segmentation fault.

Any command I entered afterward give me this reply.

A reboot was then perform and brought me to the EFI shell screen which now I am stuck at.

Is there anything I can do to resolve this problem?

2
  • 1
    avoid conv=noerror,sync it behaves in unexpected ways ( superuser.com/a/1075837/195171 ). regarding the other errors, did you boot off a live medium or did you overwrite the system you booted, thus corrupting the running system? also why clone it at all? two clean installs, no surprises. Nov 11 '20 at 18:56
  • 1
    Wait… Did you create a copy of sda1 when the filesystem existing on sda1 was mounted (as the root filesystem maybe?) and could change in the process? And did you copy the copy to sda1 of another computer, when the filesystem existing on its sda1 was mounted (as the root filesystem maybe?) at the time? And maybe this sda1 was too small? Or was it sba1? (your question is not coherent in this matter, a typo?). What were the I/O errors? With conv=noerror,sync they could mangle the data, the above comment is right. Nov 11 '20 at 19:40
1

This is not a good way to clone a system. If you copy /dev/sda1 to /dev/sdb1, you are copying the first partition of the sda drive to the first partition of the sdb drive. It doesn't copy the bootstrap, or anything else. It will also not do the right thing if the sdb drive doesn't actually have a partition table (or if the partitions on the sdb drive are not set up appropriately).

If the two drives are identical (or at least, if they're exactly the same size), and you really want to use dd, you want to copy /dev/sda to /dev/sdb.

If the two drives are not identical, I'd recommend using something like Clonezilla to clone the system. Clonezilla will handle the bootstrap and partition table correctly, and will account for differences in the size of the drives between the source and destination systems.

Also, you don't mention how, on the second system (that you want to copy to), you got into a position where you were able to dd the contents of the external drive on to the system's hard drive. If you attempted to do this by actually booting the second system and copying the external drive's contents on to the system's hard drive (while the system was running) - which, from your description, I fear that you may have done - that is definitely not going to work, and will destroy the filesystem on the second system, while the system is running. To do this successfully, you would need to boot the second system from some other source (such as a live Linux distro image on removable media) and do the dd while booted from that source.

2
  • 1
    You don't want to copy /dev/sda from a live system unless you've got some way of copying from a snapshot
    – roaima
    Nov 11 '20 at 19:57
  • 1
    You also do not want to copy partitions on gpt(GUID) partitioned drives. With gpt, the partition GUID is in the primary partition table, backup partition table & the partition. If they get out of sync, then you have major issues. new users really should not use dd and even as a bit more knowledgeable user I try to find any other way than dd.
    – oldfred
    Nov 11 '20 at 20:37

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.