Salvaging a “broken” hard drive

filesystemshard-diskreadonly

My girlfriend's macbook's hard drive failed, so I gave her a new one and reinstalled OSX on it. Works fine. However, I wanted to see if I could use her old hard drive for backups/fun.

I was able to wipe the partitions on the drive and make one single ext4 partition on it. I was then able to mount it and check it's size (~230G, perfect).

Then I tried backing up my home directory to the hardrive using sudo cp -r ~/* /media/tmp where /media/tmp is the mounted filesystem. My home directory is around 35G in size. I was able to get far into the copy, then I received this:

sudo cp -r ./* /media/tmp/
root's password:
cp: writing `/media/tmp/media/music/Neutral Milk Hotel/In the Airplane Over the Sea/09 Ghost.mp3': Read-only file system
cp: cannot create regular file `/media/tmp/media/music/Neutral Milk Hotel/In the Airplane Over the Sea/07 Communist Daughter.mp3': Read-only file system
cp: cannot create regular file `/media/tmp/media/music/Neutral Milk Hotel/In the Airplane Over the Sea/06 Holland, 1945.mp3': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Neutral Milk Hotel/Everything Is': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Neutral Milk Hotel/1996 - On Avery Island': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Neutral Milk Hotel/Beauty': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Neutral Milk Hotel/1998 - In the Aeroplane Over the Sea': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Neutral Milk Hotel/Invent Yourself A Shortcake': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Tim Minchin And The Heritage Orchestra': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Dethklok': Read-only file system
cp: cannot create directory `/media/tmp/media/music/The Tossers - Discography [77era]': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Porcupine Tree (All Studio Albums)': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Protest The Hero': Read-only file system
cp: cannot create directory `/media/tmp/media/music/Dream Theater': Read-only file system
cp: cannot create directory `/media/tmp/media/pictures': Read-only file system
cp: cannot create directory `/media/tmp/media/videos': Read-only file system
cp: cannot create directory `/media/tmp/misc': Read-only file system
cp: cannot create directory `/media/tmp/Monster Complete Series (Eng.-Dub)': Read-only file system
cp: cannot create directory `/media/tmp/repo': Read-only file system
c    p: cannot create directory `/media/tmp/web': Read-only file system

Message from syslogd@linux-vwzy at Dec 11 21:48:16 ...
 kernel:[950354.789962] journal commit I/O error

Pardon me for the personal files there, now you know what kind of music I listen to.

I'm not quite sure exactly what's happening here. Are there bad sectors on the hard drive? What does the kernel:[950354.789962] journal commit I/O error message mean?

Whatever the issue, is there a way I can fix this? What if I determine where the issue lies on the disk and never write up that sector, would that work?

Update So supposedly the os ran into too many errors while writing to the disk, and put it into read-only mode as a response. So I guess my only question is if there is a way around this? Is this problem directly related to the size of data I write on the disk (ie if I only write 1G will the data be safe as long as I don't touch those bad parts)?

Best Answer

Unmount the drive and run badblocks -n on it. This will rewrite every sector on the drive — read-then-write, so it's nondestructive — which forces the drive to swap in a fresh sector for every dodgy one found during the pass.

If badblocks can't fix it, you could step up to SpinRite which does that and more.

If either of those "fixes" the drive but you get more data errors later, you have a continual degradation going on, and no fix will be permanent.

Related Question