Linux - HardwareThis forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?
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.
Quite a common occurrence to those of us who use SD cards instead of hard drives (Raspberry Pi, etc.). They mostly only last a couple years at most.
I used to work with failing floppy disks a lot and got in the habit of copying all the sectors off to something else at the start as a backup. If the physical drive is failing your problems are only going to get worse. Once you've backed it up you can write it back out to another drive or do a loop mount and tinker with salvaging stuff, knowing it's stable and not going to get worse. So I'm doing
dd if=/dev/sda2 of=stuff.dat bs=1M status=progress
which will take at least a few hours. Assuming I can edit this I'll update it.
Quite a common occurrence to those of us who use SD cards instead of hard drives (Raspberry Pi, etc.). They mostly only last a couple years at most.
I used to work with failing floppy disks a lot and got in the habit of copying all the sectors off to something else at the start as a backup. If the physical drive is failing your problems are only going to get worse. Once you've backed it up you can write it back out to another drive or do a loop mount and tinker with salvaging stuff, knowing it's stable and not going to get worse. So I'm doing
dd if=/dev/sda2 of=stuff.dat bs=1M status=progress
which will take at least a few hours. Assuming I can edit this I'll update it.
Using dd might also fail if there actually is a bad block. dd also does a bit for bit copy so any errors on the original will be in the copy even if it completes.
I seem to recall that someone used a utility called photorec to recover from a situation such as yours although I have not seen nor tried that. Apparently photorec only copies/recovers the actual data that is readable without the errors that exist in the original so it does not have the size requirements nor error copying problems associated with using dd to copy a disk partition that has errors.
It worked somewhat. I copied stuff.dat (made by dd) to another file as another backup level. Then mke2fs -n stuff.dat &> superblocks.txt. Then fsck.ext4 -y -b 32768 stuff.dat and ignored what fsck said basically because there was a ton of it. Then mount -o loop stuff.dat /mnt and looked around /mnt with mc. All the files were in a subdir of lost+found so I copied them out into a regular dir on my SSD and umounted /mnt.
They're close enough, I can ignore some errors in them. They're just wav files from a night's nature recordings, they don't matter that much. I still have the backup file from when I copied before I ran fsck, plus the original SD but I probably won't bother with them. This was a 32 GB SD and I have a mostly empty 2 TB SSD to play with. I could have done a dd to another SD if I'd needed the space. But my first priority was always preserving the original data untouched.
I wonder how big a superblock is? If you could read all the ones that mke2fs finds and compare them, leave out the outliers and use the biggest block where they're all the same. Sort of a voting process. If a bunch agree they're probably right, then you could pick any of those. A programming project that's about my speed. Run mke2fs in a pipe and catch the numbers it feeds back, then read all of those into arrays and compare.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.