1

My laptop's hard drive will fail soon (according to SMART), so I decided to clone the entire drive to another one:

sudo sh -c 'cat /dev/sda >/dev/sdc'

With the new hard drive the laptop shows these errors:

Failed to start File System Check on /dev/.../78c...b86
Dependency failed for /home
Dependency failed for Load File System
...
Cannot open access to console, the root account is locked

The UUID look equal on both drives:

> lsblk -f
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda                                                      
├─sda1 ntfs   XP    D6A46388A46369C7                     
├─sda3                                                   
├─sda5 ext4         f02a6d59-8411-4018-85da-bb6a521d91d0 /
├─sda6 swap         70bc8fb3-77e5-47e8-953f-63da54226679 [SWAP]
└─sda7 ext4         78c3867d-4382-4dff-ac7d-ed69c788db86 /home
sdc                                                      
├─sdc1 ntfs   XP    D6A46388A46369C7                     
├─sdc3                                                   
├─sdc5 ext4         f02a6d59-8411-4018-85da-bb6a521d91d0 
├─sdc6 swap         70bc8fb3-77e5-47e8-953f-63da54226679 
└─sdc7 ext4         78c3867d-4382-4dff-ac7d-ed69c788db86 

The drives are of different size and different physical sector size. However, I couldn't prove it is an issue in this case.

> sudo fdisk -l
Disk /dev/sda: 111.8 GiB, 120034123776 bytes, 234441648 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd961d961

Device     Boot    Start       End   Sectors  Size Id Type
/dev/sda1  *          63  43015687  43015625 20.5G  7 HPFS/NTFS/exFAT
/dev/sda3       43016190 215076863 172060674   82G  5 Extended
/dev/sda5       43016192  62545919  19529728  9.3G 83 Linux
/dev/sda6       62547968  68737023   6189056    3G 82 Linux swap / Solaris
/dev/sda7       68739072 215076863 146337792 69.8G 83 Linux

Disk /dev/sdc: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0xd961d961

Device     Boot    Start       End   Sectors  Size Id Type
/dev/sdc1  *          63  43015687  43015625 20.5G  7 HPFS/NTFS/exFAT
/dev/sdc3       43016190 215076863 172060674   82G  5 Extended
/dev/sdc5       43016192  62545919  19529728  9.3G 83 Linux
/dev/sdc6       62547968  68737023   6189056    3G 82 Linux swap / Solaris
/dev/sdc7       68739072 215076863 146337792 69.8G 83 Linux

Partition 1 does not start on physical sector boundary.
Partition 3 does not start on physical sector boundary.

The files /etc/fstab are equal, too.

The laptop has a broken screen, and I use an external monitor. This imposes some restrictions for tools which can be used, e.g. Clonezilla' Live CD shows no output.

What can be done in this case?

Update 1: Tried to accomplish the task with dd bs=1M if=/dev/sda of=/dev/sdc. Got the same errors. Have to say that the Windows boots from its partition properly with either cat or dd approach.

Update 2: The all bad blocks on the source hard drive are located in the /home partition /dev/sda7. The first LBA number is 127221317. I found about 300 bad blocks with the last LBA number 146938319, then stopped. Seems there are many of them further.

  • Can you clone with cat? I've only every done this with dd which works great but does require that the from and to are not mounted. – user1794469 Jan 19 at 19:08
  • Seems it doesn't matter what you use for block devices: unix.stackexchange.com/questions/144172/…. With cat the speed is optimized automatically; it took one hour for me (didn't try dd though). – Dmitry Jan 19 at 19:16
  • Have cloned with dd, takes 10 minutes less. – Dmitry Jan 19 at 22:26
  • 1
    You're trying to do this while the file system is mounted, you're in error. You should be booting from a live usb/cd and doing the cloning. I understand your screen is broken. Open the laptop and unplug the broken screen and plug one in on the external display port. That should fix the issue. I have done this all before. Make sure the external display is powered on before you switch the laptop on though. – Michael Prokopec Jan 20 at 4:05
  • Note the only bit that you need to copy is your home directory (if not already backed up). The OS can be re-installed. It is a 20 minute job, to get the basics, then you have to install the extra packages, and add custom configurations (they should be in etckeeper (if you installed it)). – ctrl-alt-delor Jan 20 at 12:08
1

Did you run the clone operation on a partition that was in use? That is was it being used by the OS that did the clone?

If so then it will be corrupt, boot from a live CD/USB-storage-device, and try again.

  • Yes, I did. Do agree with you that some files can be corrupted, but I'm convinced they wouldn't be the ones related to the boot process. Will try what you've suggested now. – Dmitry Jan 19 at 22:51
  • It would probably corrupt files, and directory structures, so that files can not be located. – ctrl-alt-delor Jan 19 at 22:54
  • I've got another laptop, booted from live USB-device, and cloned the hard drive with dd. The errors described in the question persist. Next, I tried to clone it using Clonezilla. It fails trying to clone a partition with bad blocks. The Clonzilla also says that it makes changes in the partition table, in the very beginning of the cloning. I assumed that even without /home partition the system should start. It doesn't. No any output to the screen attempting to boot from the cloned drive. The cat and dd look having more sense so far. – Dmitry Jan 20 at 11:59
  • From your comment, I understand that you have not yet got it to work (and nothing else). Have you tried cloning from another device (live CD/USB). And where are the bad blocks? – ctrl-alt-delor Jan 20 at 12:06
  • Updated the answer with details about bad blocks. It's all at '/home'. Yes, it's not working. Tried live USB, and cloned using naive dd approach and 'smart' Clonezilla. – Dmitry Jan 20 at 12:45
0

Learned something new, cat and dd are indeed the same/binary transparent as ctrl-alt-delor stated. I must have done something wrong when I first tried cat to clone a disk or something else was amiss, could have even been the CD drive, as a result I wrongly decided cat was not the right tool for the job as I was use to dd already, I just went back to using it.

  • I standby the comment I made about not performing cloning operations on mounted drives on the question itself above.

  • I standby the method of coping the home directory over to a fresh install on a new disk as a solution for migrating from the copy that was made, as stated in my original post.

    "Or you could just copy the home directory on the drive you created to a 
    fresh install with all the same packages installed and all should be well."
    

    Like: Here

  • I standby this information (with the knowledge that cat will do the same):

    dd would have made it appear as if the drive was the exact same. All that 
    would have been needed would be to expand the partitions to fit, with gparted.
    Doing so would have also adjusted the partition table that was written while
    cloning with dd. So there would have been no need for messing with grub.
    dd copies every byte.
    
  • I retract my previous error ridden information below:

    Cat only copies the contents of files/known data structures on the drive. 
    

What caused me to think the way I did:

  • I have noticed this type of behavior of cat before in copying CD to USB. dd made the USB appear as a actual CD and cat made the file structure look the same, but it did not look like a actual CD to the OS. (happened years ago so no telling what I actually did wrong :( )

What I know now:

  • cat behaves the same as dd as it should and seems faster too.
  • 1
    Have just tried, no effect (updated the question) According to this post unix.stackexchange.com/questions/144172/…, the dd and cat do the same job for cloning. – Dmitry Jan 19 at 22:23
  • 2
    Note that the asker used cat on the block device; dd should not be doing anything different. I think this answer does not have the right idea. – dhag Jan 20 at 0:42
  • @dhag cat does do things differently, as I explained. Create a small disk cat the disk to iso and dd the same disk to iso the md5sums will be differant, meaning they are not the same. – Michael Prokopec Jan 20 at 3:49
  • 1
    Both cat and dd should be binary transparent, that is they should not interpret what they see. Do you have any evidence of this behaviour? – ctrl-alt-delor Jan 20 at 11:34
  • @ctrl-alt-delor I have had it happen twice the first time I tried to use cat to create an image about 6 or so years ago. Never used it again as I was and still am use to dd. I will try cat again and report back. As it happens I have to create a disk from a image for a friend anyway. – Michael Prokopec Jan 20 at 19:17
0

I fixed the problem by changing the /etc/fstab file for the /home mount point as follows:

Doesn't work (have no clue why):

UUID=78c3867d-4382-4dff-ac7d-ed69c788db86 /home ext4 defaults,errors=remount-ro 0 1

Works:

/dev/sda7 /home ext4 defaults,errors=remount-ro 0 1

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.