cp fails to copy with errors "cp: error reading 'file': Input/output error" and "cp: failed to extend 'file': Input/output error

96,570

Solution 1

If this is not a "disk" inside a virtualbox, but the real physical disk where the vm images are stored on, that looks pretty bad.

There were read errors, on /dev/sda.
There is an automatic handling by marking a disk block as bad block forever, and use a different one instead.
For this to work, the harddisk needs to read the data one single more time, maybe trying a couple of hundred reads.
But the disk gave up on this:

"Add. Sense: Unrecovered read error - auto reallocate failed"

There are really bad errors on the disk - it's just not yet clear whether they are in one location only, or spread, and whether they increase with time.

The harddisk may fail very soon,
like "just now".
Or next week, or not at all.

If it does ok on a e2fsck test, you cann still not use it for anything important.

As soon as e2fsck confirms there are medium errors, best is to just replace it.

Otherwise, make backups as soon as possible,
boot a live CD or so (or find a way to unmount/not mount /home),
and check for bad blocks, like by

sudo e2fsck -c -v /dev/sdXN

Take into account that on a larger mechanical hard disk, checking for bad blocks may take lots of time, between hours and maybe a day or two. That is in part because the program needs to check each disk block separately, and take care of problems separately too. But also, if the disk is giving errors when reading, there are lots of retries on multiple levels before e2fsck even knows there is a problem. For each disk block.

It may be the right thing to just run e2fsck in auto-repair mode and leave the computer alone for a while:

sudo e2fsck -p -c -v /dev/sdXN

See ubuntuforums: Random freeze and "Unrecovered read error" in /var/log/messages for details.

Solution 2

For me, I got this error when trying to copy disk images that totaled something like 128GB. cp was trying to load the whole thing in memory in order to rewrite it back out and that obviously won't work, so it has to be done in chunks. The best way I've found to chunk the file is to force it through ssh.

scp user@localhost:/path/to/source /path/to/dest

You have to use user@localhost; omitting it will revert to cp-like behavior.

Solution 3

The sectors of your hard disk got corrupted. DRDY ERR - Device Ready Check Error. UNC - Uncorrectable.

Due to various reasons such as abrupt shut down during extensive write, High temperature, Read write operations carried out and the quality of hard disk plays a major role in this case.

Once a sector got corrupted and if the kernel tries to access those sectors then you will get this error.

You can use seatools, to recover from this error temporarily. But will not be to fix this issue forever, It may occur again some times later.

If you are lucky, then it will not reoccur for several days.

Better backup the data to a new hard disk and replace the hard disk.

Share:
96,570

Related videos on Youtube

Dmitry Koroliov
Author by

Dmitry Koroliov

Updated on September 18, 2022

Comments

  • Dmitry Koroliov
    Dmitry Koroliov almost 2 years

    I'm a user of Oracle Virtualbox on Ubuntu. And I used to copy vdi files as a kind of backup. Previously I did this (copying vdi file and then copying it back) many times without any problem.

    But today I experienced this error

    VirtualBox VMs/win_7$ cp ../../Bkps/win_7.vdi .
    cp: error reading ‘../../Bkps/win_7.vdi’: Input/output error
    cp: failed to extend ‘./win_7.vdi’: Input/output error
    

    I googled for this a little but from the advices on similar problems I undersood nothing unfortunately. Could anyone suggest how to solve this, please?

    The output from the dmesg is, (and I understand nothing from it)

    [ 2347.982876] ata1.00: exception Emask 0x0 SAct 0x1900406f SErr 0x0 action 0x0
    [ 2347.982887] ata1.00: irq_stat 0x40000008
    [ 2347.982895] ata1.00: failed command: READ FPDMA QUEUED
    [ 2347.982908] ata1.00: cmd 60/08:70:d0:da:f4/00:00:2e:00:00/40 tag 14 ncq 4096 in
    [ 2347.982908]          res 41/40:08:d0:da:f4/00:00:2e:00:00/00 Emask 0x409 (media error) <F>
    [ 2347.982915] ata1.00: status: { DRDY ERR }
    [ 2347.982919] ata1.00: error: { UNC }
    [ 2348.395657] ata1.00: configured for UDMA/133
    [ 2348.395727] sd 0:0:0:0: [sda] Unhandled sense code
    [ 2348.395733] sd 0:0:0:0: [sda]  
    [ 2348.395737] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
    [ 2348.395741] sd 0:0:0:0: [sda]  
    [ 2348.395745] Sense Key : Medium Error [current] [descriptor]
    [ 2348.395752] Descriptor sense data with sense descriptors (in hex):
    [ 2348.395764]         72 03 11 04 00 00 00 0c 00 0a 80 00 00 00 00 00 
    [ 2348.395770]         2e f4 da d0 
    [ 2348.395772] sd 0:0:0:0: [sda]  
    [ 2348.395774] Add. Sense: Unrecovered read error - auto reallocate failed
    [ 2348.395775] sd 0:0:0:0: [sda] CDB: 
    [ 2348.395776] Read(10): 28 00 2e f4 da d0 00 00 08 00
    [ 2348.395781] end_request: I/O error, dev sda, sector 787798736
    [ 2348.395792] ecryptfs_decrypt_page: Error attempting to read lower page; rc = [-5]
    [ 2348.395795] ata1: EH complete
    [ 2348.395797] ecryptfs_readpage: Error decrypting page; rc = [-5]
    [ 2351.264987] ata1.00: exception Emask 0x0 SAct 0x7f80400 SErr 0x0 action 0x0
    [ 2351.264998] ata1.00: irq_stat 0x40000008
    [ 2351.265005] ata1.00: failed command: READ FPDMA QUEUED
    [ 2351.265019] ata1.00: cmd 60/08:50:d0:da:f4/00:00:2e:00:00/40 tag 10 ncq 4096 in
    [ 2351.265019]          res 41/40:08:d0:da:f4/00:00:2e:00:00/00 Emask 0x409 (media error) <F>
    [ 2351.265025] ata1.00: status: { DRDY ERR }
    [ 2351.265029] ata1.00: error: { UNC }
    [ 2351.403371] ata1.00: configured for UDMA/133
    [ 2351.403425] sd 0:0:0:0: [sda] Unhandled sense code
    [ 2351.403426] sd 0:0:0:0: [sda]  
    [ 2351.403428] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
    [ 2351.403429] sd 0:0:0:0: [sda]  
    [ 2351.403430] Sense Key : Medium Error [current] [descriptor]
    [ 2351.403433] Descriptor sense data with sense descriptors (in hex):
    [ 2351.403434]         72 03 11 04 00 00 00 0c 00 0a 80 00 00 00 00 00 
    [ 2351.403439]         2e f4 da d0 
    [ 2351.403442] sd 0:0:0:0: [sda]  
    [ 2351.403444] Add. Sense: Unrecovered read error - auto reallocate failed
    [ 2351.403445] sd 0:0:0:0: [sda] CDB: 
    [ 2351.403446] Read(10): 28 00 2e f4 da d0 00 00 08 00
    [ 2351.403451] end_request: I/O error, dev sda, sector 787798736
    [ 2351.403463] ecryptfs_decrypt_page: Error attempting to read lower page; rc = [-5]
    [ 2351.403466] ecryptfs_readpage: Error decrypting page; rc = [-5]
    [ 2351.403470] ata1: EH complete
    

    Any help is greatly appreciated, thank you in advance

    • Volker Siegel
      Volker Siegel almost 10 years
      Maybe the disk the vdi file is on if full? Try df -h
    • Volker Siegel
      Volker Siegel almost 10 years
      Oh, wait - are you doing all this inside virtualbox, or outside?
    • Dmitry Koroliov
      Dmitry Koroliov almost 10 years
      @VolkerSiegel I do this outside, on my host system. The partition, where the copy is stored and where I try to make a copy has 280GB available, so it is more than enough, as I said I did this operation already many times. I suppose that this can be an error of the HDD
    • Volker Siegel
      Volker Siegel almost 10 years
      What is the filesystem on that partition of /dev/sda? (mount | grep /dev/sda)
    • Dmitry Koroliov
      Dmitry Koroliov almost 10 years
      @VolkerSiegel the output is /dev/sda5 on /home type ext4 (rw)
    • Volker Siegel
      Volker Siegel almost 10 years
      Oh..., so it's ext4, good; And it's your home partition, not so good :)
    • Volker Siegel
      Volker Siegel almost 10 years
      Do you still see errors in dmesg? You could run a less +F /var/log/syslog in a terminal. Theoretically, you could move your users home directory to a different harddisk, so you can unmount `/home', but that sounds a little fragile...
    • Dmitry Koroliov
      Dmitry Koroliov almost 10 years
      @VolkerSiegel I see errors in syslog file but they are related to some network problems, may be because I constantly use rdp-client, they look like Aug 11 17:13:05 dk-l kernel: [18669.464676] [UFW BLOCK] IN=wlan0 OUT= MAC=01:00:5e:00:00:01:f8:1a:67:7b:1f:ac:08:00 SRC=192.168.0.1 DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=0 DF PROTO=2
    • Volker Siegel
      Volker Siegel almost 10 years
      That's ok - so the disk seems to be alive for now ;)
    • Volker Siegel
      Volker Siegel almost 10 years
      I edited the answer a little regarding what to do next: boot a live CD... ;)
    • Eliah Kagan
      Eliah Kagan almost 10 years
  • Dmitry Koroliov
    Dmitry Koroliov almost 10 years
    I did not understand what did you mean with "the real physical disk". This is not a real disk, this is a file which is Virtualbox virtual drive
  • Volker Siegel
    Volker Siegel almost 10 years
    Ok, some questions to confirm, I may be wrong: The file win_7.vdi is a vm image, right? And it is outside any vms, right? I mean the file win_7.vdi is on a real disk - right? The dmesg output is from outside the vm, right? In this case, the errors in the dmesg log are on a real harddisk /dev/sda.
  • Dmitry Koroliov
    Dmitry Koroliov almost 10 years
    yes, "right" to all your questions
  • Volker Siegel
    Volker Siegel almost 10 years
    Good - but bad for the disk... can you just replace it? It may fail very soon, like "just now". Or next week, or not at all. If it does ok on a e2fsck test, you cann still not use it for anything important.
  • Dmitry Koroliov
    Dmitry Koroliov almost 10 years
    ok, thank you, now I'm at work so I will check your answer today, asap
  • Volker Siegel
    Volker Siegel almost 10 years
    And, by the way, is your /home encrypted?
  • Dmitry Koroliov
    Dmitry Koroliov almost 10 years
    yes, it is encrypted
  • Dmitry Koroliov
    Dmitry Koroliov almost 10 years
    thank you, I decided to replace the hard drive with an SSD soon
  • Volker Siegel
    Volker Siegel almost 10 years
    Hehe, My pleasure ;)
  • Jarad Downing
    Jarad Downing about 3 years
    This is actually a pretty nifty trick. I have a disk that's on the way out and I was getting Input/Output errors while trying to copy data off of it. scp saved the day.
  • myersjustinc
    myersjustinc over 2 years
    This is wonderful. Never would've come up with it on my own, but it worked on the first try for a 480 GB disk image I was having trouble with.
  • Admin
    Admin about 2 years
    This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review