简体   繁体   English

如何擦除硬盘驱动器

[英]How to erase a Hard Disk Drive

This is an odd question, but here it goes. 这是一个奇怪的问题,但在这里。 I would like to write a program to flash my external hard drive with 1s and then 0s to clean it completely so I can sell it. 我想写一个程序来闪存我的外部硬盘1s然后0s完全清理它所以我可以卖它。 Now, why do I want to write my own software instead of just using DBAN? 现在,为什么我要编写自己的软件而不是仅仅使用DBAN?

  1. From what I understand, DBAN deletes all hard drives it detects. 据我所知,DBAN删除了它检测到的所有硬盘。 I only want to clean my external. 我只想清理我的外部。

  2. DBAN flashes seven times. DBAN闪烁七次。 I feel this is a little excessive for my purposes, since my external contains no illegal material nor credit card information. 我认为这对我的目的有点过分,因为我的外部不包含非法材料或信用卡信息。

  3. To be honest, I actually am kind of curious as to how firmware works. 说实话,我实际上对固件如何工作很好奇。

Google didn't turn up too much (stupid Adobe Flash). 谷歌没有出现太多(愚蠢的Adobe Flash)。 I would prefer doing this in C/C++, but other languages work to, including assembly. 我更喜欢在C / C ++中这样做,但其他语言也适用,包括汇编。

Well, doing it in C is rather easy. 好吧,在C中做这件事很容易。 First, you open the appropriate device file in write mode: 首先,在写入模式下打开相应的设备文件:

int fd = open("/dev/sdc", O_WRONLY);

and you simply write() 512 byte chunks to it until you can write no more. 你只需write() 512字节块,直到你不能再写。 Newer disks use 4096 byte sectors instead, but the OS usually treats them as if they have 512 byte sectors, so 512 is the safest value. 较新的磁盘使用4096字节扇区,但操作系统通常将它们视为具有512字节扇区,因此512是最安全的值。 Here's a C program that does exactly this: 这是一个完成这个的C程序:

(Note: Be very careful to choose the correct /dev device file, or else you're going to wipe out the wrong disk!) (注意:要非常小心选择正确的/ dev设备文件,否则你要擦除错误的磁盘!)

#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

int main(void)
{
    int fd = open("/dev/sdd", O_WRONLY);
    if (fd < 0) {
        fprintf(stderr, "Error opening device file.\n");
        return EXIT_FAILURE;
    }

    // Write 0's all over the disk, in chunks of 512 bytes.
    char* zeros = calloc(1, 512);
    ssize_t written, total = 0;
    do {
        total += written = write(fd, zeros, 512);
        printf("\rBytes written: %ld", total);
    } while (written == 512);
    printf("\nDone!\n");

    close(fd);
    free(zeros);
    return 0;
}

You might get a speed-up if you remove the printf() , though it's kind of cool to see the progress as it happens. 如果你删除printf() ,你可能会获得加速,尽管看到进展发生时很酷。 You should probably also do additional error checking at the end (if written is -1, an error occurred, and you should check errno .) 您可能还应该在结尾处执行其他错误检查(如果written为-1,则发生错误,您应该检查errno 。)

Note that due to caching, the program might appear to hang at the end for a little while after it prints "Done". 请注意,由于缓存,程序在打印“完成”后可能会在结束时挂起一段时间。 It's not really hanging, it's only that the caching of the write operations is blocking it until they're all finished. 它并没有真正悬挂,只是写操作的缓存阻塞它,直到它们全部完成。

From what I understand, DBAN deletes all hard drives it detects. 据我所知,DBAN删除了它检测到的所有硬盘。 I only want to clean my external. 我只想清理我的外部。

It doesn't . 它没有

DBAN flashes seven times. DBAN闪烁七次。 I feel this is a little excessive for my purposes, since my external contains no illegal material nor credit card information. 我认为这对我的目的有点过分,因为我的外部不包含非法材料或信用卡信息。

But when you wake up in the morning, it's done, right? 但是当你早上醒来时,已经完成了,对吧? Also, it's apparently configurable . 此外,它显然是可配置的

To be honest, I actually am kind of curious as to how firmware works. 说实话,我实际上对固件如何工作很好奇。

IMO, this isn't the best place to start. IMO,这不是最好的起点。

As a note. 作为一个说明。 Your question seems to be about erasing data, aka shredding etc. 你的问题似乎是关于删除数据,也就是粉碎等。

Flashing a HDD would be to update the internal software. 闪存HDD将是更新内部软件。 As in: an HDD has its own firmware . 如: HDD有自己的固件 Under Linux you can do ie: 在Linux下你可以做到:

$ sudo hdparm -I /dev/sda

You will then get information such as: 然后,您将获得以下信息:

ATA device, with non-removable media
    Model Number:       ST31000524AS                            
    Serial Number:      XXXXXXX
    Firmware Revision:  JC4B    
    Transport:          Serial, SATA Rev 3.0

... ...

Tho this is the other way around, you can look at / search forensics. 反过来,你可以看看/搜索取证。 Ie FAU , Open Source Digital Forensics etc. to get more information. FAU开源数字取证等获取更多信息。

A bit more on wiping . 更多关于擦拭

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM