Writing raw bits to a drive.
I'm wondering if someone could help me figure out how to write raw bits to a drive.
What I need is some kind of direct memory access that will allow me to wipe an internal or external device. Being a newbie to linux, I'm wondering what linux has that can help me accomplish this task. I'm using ubuntu if that helps any. |
dd
For an article on how to do **everything** with this ultimate power tool, search here for member awesomemachine, and look in his sig. "man dd" for the basics. My normal "wiping" is to first write random data to the drive, and then all zeros. Secure wipe does something like, but several times. If you don't care about security, just writing all zeroes should be plenty. |
Thanks for the info on dd.
What I'm more interested in though is how to do this myself programmatically in C. Is there anything in the linux header files that helps with DMA access? Also, would Code:
FILE* fp=fopen("/dev/sda","w"); I've also read something about a KIO buffer although I haven't been able to find much info on it through google. |
Don't know, but why not try it? (Perhaps try READING first......;))
BTW, I think "DMA" normally refers to direct access to system memory---ie RAM, and not to block devices. |
If you want to wipe a drive run:
NOTE: This command is dangerous it will wipe all data, irreversibly from /dev/sdx !!! Code:
dd bs=4M if=/dev/zero of=/dev/sdx |
OK, just curious, how would one wipe a USB?
Also, where can I get the source to dd. |
* BUMP *
Ok, I understand that dev/hda, dev/sda, etc have to do with the hard drives in the computer. But where in the dev/ folder does it contain information about USB's plugged into the system. I'm trying to figure out how to use dd to wipe a usb. How could I find out the current, plugged in USB's 3 character name in the dev/ folder? I want to call something like: Code:
dd bs=4M if=/dev/zero of=/dev/usb |
There are 2 ways to find it, for example I just plugged in a USB stick, then you run:
Code:
bash-3.1$ dmesg | tail You can also check /dev/disk/by-id and it will be listed in there: Code:
bash-3.1$ ls -l /dev/disk/by-id/ |
Interesting...
Just curious, I know now that dd bs=4M if=/dev/zero of=/dev/sdx will write all zeros and dd bs=4M if=/dev/random of=/dev/sdx will write random bytes. But how does one write all 1's? |
Quote:
|
Quote:
Code:
dd if=/dev/zero | tr '\000' '\377' > /dev/sdx Code:
dd if=/dev/zero | tr '\000' '\377' | dd of=/dev/sdx |
Quote:
AND---to wipe a large disk, we're going to need a ***really big*** file of "1"s----where do you suggest we store it????? |
The thing is it would need to be something like a device node so you can read unlimited data from it, like /dev/one, and I think there's a kernel patch somewhere that implements it. You can also write a small C program to do it. Or you can use my solution above.
|
Maybe create a named pipe with mkfifo and use a loop to echo $char(or whatever) to the pipe and have dd use the other end of the pipe as input.
|
All times are GMT -5. The time now is 02:20 AM. |