一般在送修、轉售電腦時,會使用格式化以抹除硬碟裡的隱密資料。可內行人都知道只有這樣是不夠的,真的想清除乾淨,還得加上資料銷毀的程序才行 (本文同步發佈於 凍仁的筆記)。
過去在 GNU/Linux 裡,凍仁會使用 dd [1] ,此指令會將資料填零而達到抹除磁碟的功用,但就算這樣還是有被專業人士還原的風險;現在凍仁都改用 shred [2] 指令來完成這項任務,此指令是專門用來撕碎資料的。
將 /dev/sdX 裝置填零。
dd if=/dev/zero of=/dev/sdX bs=1M
2.1. 開始 shred 之前,您必須先安裝 coreutils 套件。
$ sudo aptitude install coreutils
# -v 顯示進度。
# -f 強制寫入,必要時允許變更權限寫入。
# -z 用零覆寫並撕碎。
# -n 指定覆寫次數。
2.2. 銷毀 (抹除) 硬碟。
$ sudo shred -vfz -n 10 /dev/sdX
shred: /dev/sdX:11 次之第 1 次 (random)...
shred: /dev/sdX:11 次之第 1 次 (random)...471MiB/932GiB 0%
shred: /dev/sdX:11 次之第 1 次 (random)...472MiB/932GiB 0%
shred: /dev/sdX:11 次之第 1 次 (random)...949MiB/932GiB 0%
......
2.3. 銷毀 (抹除) 檔案。
$ shred -vu -n 10 hello-sherd.txt
shred: hello-sherd.txt: pass 1/3 (random)...
shred: hello-sherd.txt: pass 2/3 (random)...
shred: hello-sherd.txt: pass 3/3 (random)...
shred: hello-sherd.txt: removing
shred: hello-sherd.txt: renamed to 000000000000000
shred: 000000000000000: renamed to 00000000000000
shred: 00000000000000: renamed to 0000000000000
shred: 0000000000000: renamed to 000000000000
shred: 000000000000: renamed to 00000000000
shred: 00000000000: renamed to 0000000000
shred: 0000000000: renamed to 000000000
shred: 000000000: renamed to 00000000
shred: 00000000: renamed to 0000000
shred: 0000000: renamed to 000000
shred: 000000: renamed to 00000
shred: 00000: renamed to 0000
shred: 0000: renamed to 000
shred: 000: renamed to 00
shred: 00: renamed to 0
shred: hello-sherd.txt: removed
※ shred 在 ext3, ext4 這類的日誌檔案系統上運作時可能無法完整清除,若真不放心可以試試 hdparm。