Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 06-07-2016, 10:34 AM   #1
Ned Radd
LQ Newbie
Registered: Apr 2016
Posts: 20

Rep: Reputation: Disabled
What Program(s) Allow Read/Write To HDD or Flash Sectors?

I have a situation where I need to wipe out the content os some of the sectors on several drives. With those sectors as they are, I have a real problem on my hands. But format, erase, delete no longer overwrite the whole drive or any partition, so I am unable to go that route. Since I know which sectors are causing me problems, if I could change their content, that should be enough, and much faster to boot. But how to do this at the bash level, where I don't have to become a coding expert myself?

My searches online suggest that dd, ddrescue, gddrescue, and gnurescue are possible tools for the job. I find I have dd and ddrescue available in my system. But the available --Help, man, and info data does not venture in this area at all. Yet some mention from online gurus say they are up to the job, even dispute which is better and/or faster. Only there the focus was on dealing with bad sectors.

There was somw C code found and one article on getting it done in Windows. I'm not a C coder and have no interest in Windows. I'd rather use tested code than try to write my own anyway.

Any clues, any help, and detailed instructions would be of great value to me.
Old 06-07-2016, 05:43 PM   #2
Registered: Mar 2008
Posts: 21,240

Rep: Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451
Not sure I fully understand the issue here. Normally it is a file issue rather than a direct drive location issue. You may need to explain this more.

I used to use debug in dos. Freedos may have it. I've never tried gdb but it is reported to be similar. Debug was able to access any memory location and edit it almost.

dd can possibly write to areas. It is a very unforgiving program so you'd better test it and learn it before working on production systems.

There are binary editors that may get some areas of the drive.

If I recall from python you could write a small program but since I haven't worked on python I tend to forget stuff. But many if not all of the modern programming tools can access low level parts of the system. Assembly would indeed access it.

Last edited by jefro; 06-07-2016 at 05:46 PM.
Old 06-07-2016, 08:14 PM   #3
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
With dd it should be possible, it can seek n block size (given with "seek") from the start of output file (destination disk), then copy into it n block size (given by "count") from this point. As jefro says, you'll need some learning to be sure you'll know what to do before proceed.

edit: some usage examples here:

Last edited by keefaz; 06-07-2016 at 08:23 PM.
Old 06-09-2016, 12:42 PM   #4
Ned Radd
LQ Newbie
Registered: Apr 2016
Posts: 20

Original Poster
Rep: Reputation: Disabled
Idon't mind learning, but I don't know where to learn it from. This is an extreme use of dd and not covered in the normal help sources. As to python, that is on my billboard of future study topics, but my need is now.

As to why, here goes. You won't believe me, and in all likelihood because it wasn't suppose to happen, but my large drives are all poisoned by loose superblocks that never got deleted when the partitions were removed. Testdisk and gparted are going crazy as a result.

gpart is able to effect a data rescue if the partitions don't overlap each other, but somewhere a maverick program is butting in and trying to make the partition table reflect what it reads from the superblocks, and then is is like a double exposure film in spades, where the partition table actually reports more disk space than the drive has built in.

The way I figure it, qhen full partition formatting was the norm, there was nothing left of the old formats to deal with going forward. But when drives got bigger, a full rormat too too long, so thet moved to quick format instead. Quick format does not actually overwrite the old data,it only deletes references to it. The data remains as it was.

Superblocks are a special kind of record that reflect the setup of the partition when it is formatted. Ehe superblocks are written into specific sectors at precise intervals from the start of each partition. That means they are relatively addressed, not absolutely addressed.

This is the heart of the problem. Delete a partiton, move a partition, add a partition whose head is at a different absolute address, the relative addresses of the series of superblocks will be different, and instead ov overwriting the original superblocks you create s string of new superblocks in addition to the old superblocks. Sounds crazy, right? Well, it is enough to make you crazy.

If it is what I say it is, why hasn't this been reported as a problem before? Why aren't more people effected? I can propose some likely answers to those questions:

(1) How many people format their hard drive eveb once? If you do, how many people partition it more than once? If you do, how many people change partition size or location so that any new partition has a different start from what the old one(s) had?

Loose/orphaned/abandoned superblocks, whatever you want to name them, might be a bit of a hazard to navigstion, but they would not cause problems if they were left undisturbed. But some piece of code in at least one OS, Ubuntu, is revising the paertition table based on the content of one or more of those blocks. Maybe it tracks back to Debian, or even the kernel. There is not enough info at hand to do more than guess. Since Linux is small in terms of general use, and the group of repeat partitioners even smaller, it would not be an obvious problem.

But there is another factor: The problem involves writes where a partition is gradually filled. I can't see reads as really playing a part. With fewer writes and fewer files, there is less chance of overwrites at some point. And less used space to be overwritten.

But here is my final point on why is isn't a known problem: there is no guidebook to help you. I had multiple drives getting corrupted for no known reason, and I had to find a cause and a cure. Gparted was my principal tool, but told me little. Adding gpart helprd me rescue data, but I was losing ground.

Then I tried testdisk, and that was the breakthrough. Now I was shown superblocks being listed as all over the drive and mass confusion as to what might work with what when placed together in a possible revision to the partition table. But while testdisk showed me enough, it did not do enough, at least for someone in my shoes. I could not flag a group of superblocks to just go away, and the log entries do not report the superblock locations by address or how it is actually laid out as to content.

But if I could do raw reads and writes simply enough, I should be able to go from there, I hope.

So as simply as I can put it, that's the whole of it. Testdisk is free, as is gparted and gpart, along with dd. you can corrupt a stick drive in the manner I described, then check your results as well. Testdisk may do more than I think it does, but I've no way to judge what it can do, as this is not something that teaches as it goes from one task to the next.

A final reason this may have slipped notic is what prople might do after a dtive or partition corrupts. They may assume a hardware error occurred and replace the drive as their means of effecting a repair. But 8 drives cdon't all go bad on you as happened in my case, si I began with knowing it was not a problem with the drives themselves.The failyes involved 3 different computers, so it was not hardware elated at all. That left just the software.
Old 06-09-2016, 07:50 PM   #5
Registered: Mar 2008
Posts: 21,240

Rep: Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451Reputation: 3451
This is how I view what you have. Not sure you can do what you want. Not sure why you have overlapping partitions. The tools like fdisk that were doing that 20 years ago have been corrected. Most modern tools won't create them.

So, I suspect that you can only try testdisk to get data off. You would need to rebuild and monitor the saved data before returning. All your data on this disk is suspect. It is even further suspect till you discover the reason it happened.

edit. If it is failing on 3 computers and multiple drives then I'd have to agree that it can't be the hardware. I didn't fully read your reply.
I'd use tools such as the OEM hard drive diags to see what it says about the disk. Never hurts to run memtest for a few days. Some people run it for 10 minutes and call it good. I wouldn't assume much till I found some problem. I would buy a new larger drive maybe since it gives me an excuse.

It is entirely possible that you used some tricks to try to work on the drive that caused this. Things like dd to different sized drive could cause it.

Used to use Ranish to fix some of these issues but it hasn't been updated in a long time. Guess you could try it. Unless you have a backup or copy of the geometry then no amount of guessing usually works.

Last edited by jefro; 06-09-2016 at 08:58 PM.
Old 06-09-2016, 08:25 PM   #6
Senior Member
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian Stable and Unstable
Posts: 1,943

Rep: Reputation: 537Reputation: 537Reputation: 537Reputation: 537Reputation: 537Reputation: 537
A common cause of this type problem is having remnants of a gpt partition table with MBR also on it. Gdisk can take care of this by removing the gpt remnants.


hdd, read, sectors, stick, write

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How do I read disk sectors from a C program? stf92 Programming 5 07-21-2014 12:32 PM
Program to read total read/write cycles for compact flash card timetraveler Linux - Hardware 0 05-06-2010 10:49 PM
What r the functions used to read data from the all the sectors of hdd nutanj Programming 2 10-30-2006 12:03 PM
No read/write perms for HDD duryodhan Slackware 3 10-19-2006 05:15 PM
firewire hdd will not stay read-write solemar Mandriva 4 07-04-2005 07:46 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:40 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration