「ディスクの完全消去」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
109行目: 109行目:
 
Sector size (logical/physical): 512 bytes / 4096 bytes
 
Sector size (logical/physical): 512 bytes / 4096 bytes
   
To get size in the physical sectors you will need the known disk size in bytes divided with physical sectors {{ic|echo $((2000398934016 / 4096))}}, you can get size of the storage device or partition on it even with the {{ic|blockdev --getsize64 /dev/sdX(Y)}} command.
+
To get disk size in the physical sectors you will need the known disk size in bytes divided with size of a single physical sector {{ic|echo $((2000398934016 / 4096))}}, you can get size of the storage device or partition on it even with the {{ic|blockdev --getsize64 /dev/sd"XY"}} command.
   
  +
{{Note|
{{Note|In the examples below we will use the logical sector size.}}
 
  +
* In the examples below we will use the logical sector size.
  +
* You can even wipe unallocated disk space with a {{ic|dd}} command by calculating the difference between the end of one and start of the next partition.
  +
}}
   
 
To wipe partition {{ic|/dev/sdXA}} the example parameters with logical sectors would be used like this:
 
To wipe partition {{ic|/dev/sdXA}} the example parameters with logical sectors would be used like this:
123行目: 126行目:
 
# dd if=''data_source'' of=/dev/sd"X" bs=${BytesInSector} count=${End} seek=${Start}
 
# dd if=''data_source'' of=/dev/sd"X" bs=${BytesInSector} count=${End} seek=${Start}
   
  +
パーティションの名前を使用:
By using the partitions name:
 
   
 
{{bc|1=LogicalSectors=3839709184}}
 
{{bc|1=LogicalSectors=3839709184}}
129行目: 132行目:
 
# dd if=''data_source'' of=/dev/sd"XA" bs=${BytesInSector} count=${LogicalSectors}
 
# dd if=''data_source'' of=/dev/sd"XA" bs=${BytesInSector} count=${LogicalSectors}
   
  +
もしくは、ディスク全体を消去するには:
Or, to wipe the whole disk:
 
   
 
{{bc|1=AllDiskPhysicalSectors=488378646
 
{{bc|1=AllDiskPhysicalSectors=488378646
145行目: 148行目:
   
 
For data that is not truly random your disk's writing speed should be the only limiting factor. If you need random data, the required system performance to generate it may extremely depend on what you choose as source of entropy.
 
For data that is not truly random your disk's writing speed should be the only limiting factor. If you need random data, the required system performance to generate it may extremely depend on what you choose as source of entropy.
 
{{Note|Everything regarding [[Benchmarking disk wipes]] should get merged there.}}
 
   
 
=== ランダムではないデータ ===
 
=== ランダムではないデータ ===
  +
大抵は {{ic|/dev/zero}} などのシンプルなパターンで上書きするので安全です。高速にディスク消去をしたい場合は十分でしょう。
Overwriting with {{ic|/dev/zero}} or simple patterns is considered secure in most resources. In the case of current HDD's it should be sufficient for fast disk wipes.
 
   
  +
{{Warning|異常に高速にドライブに書き込みが行われる場合、透過圧縮がされている可能性があります。この場合、全てのブロックが消去されるとは限りません。[[#フラッシュメモリ|フラッシュメモリ]]デバイスはこの"機能"を持っていることが多々あります。}}
{{Warning|A drive that is abnormally fast in writing patterns or zeroing could be doing transparent compression. It is obviously presumable not all blocks get wiped this way. Some [[#Flash memory]] devices do "feature" that.}}
 
   
 
==== パターン書き込みのテスト ====
 
==== パターン書き込みのテスト ====
  +
[[#Badblocks|Badblocks]] はシンプルなパターンをデバイスのブロックに書き込むことができ、壊れた領域がないか検索してチェックすることができます (memtest86* がメモリで行うのと同じようなテストです)。
[[#Badblocks]] can write simple patterns to every block of a device and then read and check them searching for damaged areas (just like memtest86* does with memory).
 
   
  +
アクセス可能なブロック全てにパターンが書き込まれるため、効率的にデバイスを消去することができます。
As the pattern is written to every accesible block this effectively wipes the device.
 
   
 
=== ランダムデータ ===
 
=== ランダムデータ ===
   
  +
ランダムまたは擬似的にランダムなデータをソースとして使う場合、[[乱数生成]]を見て下さい。
For differences between random and pseudorandom data as source, please see [[Random number generation]].
 
   
 
{{Note|Data that is hard to compress (random data) will get written slower, if the drive logic mentioned in the [[#Unrandom data]] warning tries compressing it. This should not lead to [[#Data remanence]] though. As maximum write-speed is not the performance-bottleneck it can get completely neglected while wiping disks with random data.}}
 
{{Note|Data that is hard to compress (random data) will get written slower, if the drive logic mentioned in the [[#Unrandom data]] warning tries compressing it. This should not lead to [[#Data remanence]] though. As maximum write-speed is not the performance-bottleneck it can get completely neglected while wiping disks with random data.}}
174行目: 175行目:
 
=== dd ===
 
=== dd ===
   
[[Core utilities#dd]] を参照してください。
+
[[Core Utilities#dd]] を参照してください。
   
 
{{Warning|There is no confirmation regarding the sanity of this command so '''repeatedly check''' that the correct drive or partition has been targeted. Make certain that the {{ic|<nowiki>of=...</nowiki>}} option points to the target drive and not to a system disk.}}
 
{{Warning|There is no confirmation regarding the sanity of this command so '''repeatedly check''' that the correct drive or partition has been targeted. Make certain that the {{ic|<nowiki>of=...</nowiki>}} option points to the target drive and not to a system disk.}}
206行目: 207行目:
 
=== shred ===
 
=== shred ===
   
[https://www.gnu.org/software/coreutils/manual/html_node/shred-invocation.html ''shred''] is a Unix command that can be used to securely delete [[#対象の上書き|individual files]] or full devices so that they can be recovered only with great difficulty with specialised hardware, if at all. ''shred'' uses three passes, writing [[Random number generation|pseudo-random data]] to the device during each pass. This can be reduced or increased.
+
[https://www.gnu.org/software/coreutils/manual/html_node/shred-invocation.html ''shred''] is a Unix command that can be used to securely delete [[#対象の上書き|individual files]] or full devices so that they can be recovered only with great difficulty with specialised hardware, if at all. ''shred'' uses three passes, writing [[乱数生成|pseudo-random data]] to the device during each pass. This can be reduced or increased.
   
 
The following command invokes shred with its default settings and displays the progress.
 
The following command invokes shred with its default settings and displays the progress.
250行目: 251行目:
 
If the data can get exactly located on the disk and was never copied anywhere else, wiping with random data can be thoroughgoing and impressively quick as long there is enough entropy in the pool.
 
If the data can get exactly located on the disk and was never copied anywhere else, wiping with random data can be thoroughgoing and impressively quick as long there is enough entropy in the pool.
   
  +
{{ic|/dev/urandom}} を使って [[Dm-crypt/デバイスの暗号化#キーの管理|LUKS キースロットを消去]]する cryptsetup が良い例です。
A good example is cryptsetup using {{ic|/dev/urandom}} for [[Dm-crypt/Device encryption#Keyslot_management|wiping the LUKS keyslots]].
 
   
 
=== ハードウェア特有の問題 ===
 
=== ハードウェア特有の問題 ===

2015年8月16日 (日) 17:17時点における版

関連記事

ディスクワイプを行うには全てのビットに新しいデータを書き込みます。

ノート: この記事における"ディスク"にはループバックデバイスも含めます。

一般的なユースケース

デバイス上に残っているデータを全て消去

デバイスを完全に、二度と復旧できないように消去する最も一般的な理由としては、デバイスを廃棄するまたは売り飛ばす場合が考えられます。デバイス上に (暗号化されていない) データが残っている可能性を考えると、簡単にデータをとり出される前に対処しておいたほうが良いでしょう。データを盗むことはファイルリカバリソフトウェアなどを使えば朝飯前です。

ディスク上の全てのデータを素早く消去したいという場合、/dev/zero のようなシンプルなパターンを使うのが一番効率がよく、それでいて十分なランダム性を確保できます。詳しくはデータの残留で説明しています。

ビットを全て上書きしてデータを消去すると通常のシステムの機能 (標準の ATA/SCSI コマンドなど) やハードウェアのインターフェイスでリカバリすることはできなくなります。上で述べたようなファイルリカバリソフトウェアがデータを復旧させようとしたら、プロプライエタリなストレージハードウェアの機能を使う必要が出てきます。

HDD の場合、ドキュメントになってないドライブコマンドが存在するとか、デバイスのコントローラやファームウェアを弄って再配置セクタ (S.M.A.R.T. が使用を止めた不良セクタ) を読み出すなどしないかぎり、データの復旧は不可能になります。

ディスク消去には物理ストレージの形式によって様々な問題が存在します。中でもフラッシュメモリデバイスや旧式の磁気ストレージ (古い HDD や、フロッピーディスク、テープなど) は注意する必要があります。

ブロックデバイス暗号化の準備

完全に消去した領域にディスク暗号化を設定したいという場合、暗号強度が高い乱数生成器 (Random Number Generator、以下 RNG と呼称します) による、ランダムデータを使用するべきでしょう。

Wikipedia:Random number generation を参照してください。

警告: If Block device encryption is mapped on a partition that contains anything else than random/encrypted data, disclosure of usage patterns on the encrypted drive is possible and weakens the encryption being comparable with filesystem-level-encryption. Never use /dev/zero, simple patterns (badblocks, eg.) or other unrandom data before setting up Block device encryption if you are serious about it!

対象の選択

ノート: Fdisk は GPT でフォーマットされたデバイスでは動作しません。代わりに gdisk (gptfdisk) を使って下さい。

fdisk を使うことでユーザーが読み取りアクセスできる全ての読み書きデバイスを見つけることができます。

/dev/sdX などのデバイスで始まる行の出力をチェックしてください。

以下は Linux システムを起動するようにフォーマットされた HDD の例です:

# fdisk -l
Disk /dev/sda: 250.1 GB, 250059350016 bytes, 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00ff784a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      206847      102400   83  Linux
/dev/sda2          206848   488397167   244095160   83  Linux

4GB USB メモリードライブに書き込まれた Arch のインストールメディアの例:

# fdisk -l
Disk /dev/sdb: 4075 MB, 4075290624 bytes, 7959552 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x526e236e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           0      802815      401408   17  Hidden HPFS/NTFS

If you are worried about unintentional damage of important data on the primary computer, consider using an isolated environment such as a virtual environment (VirtualBox, VMWare, QEMU, etc...) with direct connected disk drives to it or a single computer only with a storage disk(s) that need to be wiped booted from a Live Media (USB, CD, PXE, etc...).

ブロックサイズの選択

Wikipedia:Dd (Unix)#Block size, blocksize io-limits も見て下さい。

Advanced Format のハードドライブを使用している場合、ブロックサイズをデフォルトの512バイトよりも大きく指定することを推奨します。高速に書き換え処理を行うために、あなたの使用しているドライブの物理的なジオメトリにブロックサイズを合わせて下さい。dd コマンドにブロックサイズオプションを追加することで指定できます (例: 4KB の場合 bs=4096)。

fdisk は全てのディスクの物理セクタと論理セクタのサイズを出力します。

もしくは sysfs によっても情報を得ることができます:

/sys/block/sdX/size
/sys/block/sdX/queue/physical_block_size
/sys/block/sdX/queue/logical_block_size
/sys/block/sdX/sdXY/alignment_offset
/sys/block/sdX/sdXY/start
/sys/block/sdX/sdXY/size

消去するブロックを手動で計算

In the following the determination of the data area to wipe is done in an example.

A block storage devices contains sectors and a size of a single sector that can be used to calculate the whole size of device in bytes. You can do it by multiplying sectors with size of the sector.

As an example we use the parameters with the dd command to wipe a partition:

# dd if=data_source of=/dev/sdX bs=sector_size count=sector_number seek=partitions_start_sector

Here you will see only a part of output of fdisk -l /dev/sdX with root, showing the example partition information:

Device     Boot      Start        End         Sectors     Size  Id Type
/dev/sdXA            2048         3839711231  3839709184  1,8T  83 Linux
/dev/sdXB            3839711232   3907029167  67317936    32,1G  5 Extended

The first line of the fdisk output shows the disk size in bytes and logical sectors:

Disk /dev/sdX: 1,8 TiB, 2000398934016 bytes, 3907029168 sectors

To calculate size of a single logical sector use echo $((2000398934016 / 3907029168)) or use data from the second line of fdisk output:

Units: sectors of 1 * 512 = 512 bytes

To calculate physical sectors that will make it work faster we can use the third line:

Sector size (logical/physical): 512 bytes / 4096 bytes

To get disk size in the physical sectors you will need the known disk size in bytes divided with size of a single physical sector echo $((2000398934016 / 4096)), you can get size of the storage device or partition on it even with the blockdev --getsize64 /dev/sd"XY" command.

ノート:
  • In the examples below we will use the logical sector size.
  • You can even wipe unallocated disk space with a dd command by calculating the difference between the end of one and start of the next partition.

To wipe partition /dev/sdXA the example parameters with logical sectors would be used like this:

Start=2048
End=3839711231
BytesInSector=512

By using the starting address of the partition on the device by defining it in the seek= option:

# dd if=data_source of=/dev/sd"X" bs=${BytesInSector} count=${End} seek=${Start}

パーティションの名前を使用:

LogicalSectors=3839709184
# dd if=data_source of=/dev/sd"XA" bs=${BytesInSector} count=${LogicalSectors}

もしくは、ディスク全体を消去するには:

AllDiskPhysicalSectors=488378646
PhysicalSectorSizeBytes=4096
# dd if=data_source of=/dev/sd"X" bs=${PhysicalSectorSizeBytes} count=${AllDiskPhysicalSectors} seek=0
ノート: The count= option not necessary when wiping the physical limited area e.g. sd"XY" or sd"X" from begin to the end but will show an error about out of free space when will try to write outside of limits.

データソースの選択

先に述べた通り、重要なデータを消去したいときは、必要に応じて手段を選ぶことができます。

消去した後にブロックデバイスの暗号化をセットアップしたい場合、データソースとして暗号を使用して消去を行うべきでしょう。最低でも擬似乱数によるデータを使って下さい。

For data that is not truly random your disk's writing speed should be the only limiting factor. If you need random data, the required system performance to generate it may extremely depend on what you choose as source of entropy.

ランダムではないデータ

大抵は /dev/zero などのシンプルなパターンで上書きするので安全です。高速にディスク消去をしたい場合は十分でしょう。

警告: 異常に高速にドライブに書き込みが行われる場合、透過圧縮がされている可能性があります。この場合、全てのブロックが消去されるとは限りません。フラッシュメモリデバイスはこの"機能"を持っていることが多々あります。

パターン書き込みのテスト

Badblocks はシンプルなパターンをデバイスのブロックに書き込むことができ、壊れた領域がないか検索してチェックすることができます (memtest86* がメモリで行うのと同じようなテストです)。

アクセス可能なブロック全てにパターンが書き込まれるため、効率的にデバイスを消去することができます。

ランダムデータ

ランダムまたは擬似的にランダムなデータをソースとして使う場合、乱数生成を見て下さい。

ノート: Data that is hard to compress (random data) will get written slower, if the drive logic mentioned in the #Unrandom data warning tries compressing it. This should not lead to #Data remanence though. As maximum write-speed is not the performance-bottleneck it can get completely neglected while wiping disks with random data.

暗号データ

When preparing a drive for full-disk encryption, sourcing high quality entropy is usually not necessary. The alternative is to use an encrypted datastream. For example, if you will use AES for your encrypted partition, you would wipe it with an equivalent encryption cipher prior to creating the filesystem to make the empty space not distinguishable from the used space.

対象の上書き

選択したドライブをユーティリティを使って上書きします。都合に合わせて選択してください。単一のファイルだけ削除したい場合、ディスクの完全消去/Tips and tricks#単一ファイルの消去に以下で説明しているユーティリティの追加説明があります。

dd

Core Utilities#dd を参照してください。

警告: There is no confirmation regarding the sanity of this command so repeatedly check that the correct drive or partition has been targeted. Make certain that the of=... option points to the target drive and not to a system disk.

Zero-fill the disk by writing a zero byte to every addressable location on the disk using the /dev/zero stream. iflag and oflag as below will try to disable buffering, which is senseless for a constant stream.

# dd if=/dev/zero of=/dev/sdX iflag=nocache oflag=direct bs=4096

もしくは /dev/urandom ストリームを使用:

# dd if=/dev/urandom of=/dev/sdX bs=4096

dd が No space left on device と報告したら処理は完了です:

dd: writing to ‘/dev/sdb’: No space left on device
7959553+0 records in
7959552+0 records out
4075290624 bytes (4.1 GB) copied, 1247.7 s, 3.3 MB/s

巨大なドライブを高速に消去する方法は、以下を見て下さい:

wipe

ファイルの消去に特化しているツールで、arch のリポジトリからインストールできます。クイックワイプを実行するには以下のようなコマンドを使用します:

$ wipe -r -q /path/to/wipe

参照: man page

shred

shred is a Unix command that can be used to securely delete individual files or full devices so that they can be recovered only with great difficulty with specialised hardware, if at all. shred uses three passes, writing pseudo-random data to the device during each pass. This can be reduced or increased.

The following command invokes shred with its default settings and displays the progress.

# shred -v /dev/sdX

Alternatively, shred can be instructed to do only one pass, with entropy from e.g. /dev/urandom.

# shred --verbose --random-source=/dev/urandom -n1 /dev/sdX

Badblocks

badblocks でディスク消去を行うには、破壊的な read-write テストを実行します:

# badblocks -c <NUMBER_BLOCKS> -wsv /dev/<drive>

hdparm

hdparmATA Secure Erase をサポートしています。これはディスクをゼロで埋めるのと機能的には同一です。ただし、ハードドライブのファームウェアによって処理されるのが違っていて、"隠しデータ領域"も含まれます。そのため、今日における"ローレベルフォーマット"コマンドとして考えても良いでしょう。このコマンドを実行することで SSD ドライブは生産時のパフォーマンスを発揮することができると言われていますが、十分な消去とまでは言えない可能性もあります (#フラッシュメモリを参照)。

Some drives support Enhanced Secure Erase, which uses distinct patterns defined by the manufacturer. If the output of hdparm -I for the device indicates a manifold time advantage for the Enhanced erasure, the device probably has a hardware encryption feature and the wipe will be performed to the encryption keys only.

ATA Secure Erase の使用法に関する詳細は Linux ATA wiki を見て下さい。

secure-delete

AURsecure-deleteAUR パッケージには安全な消去のためのユーティリティが複数含まれています。例えば sfill は特定のマウントポイントの空き領域だけを消去します。例:

# sfill -v /

詳しくは ツールのリスト を見て下さい。

データの残留

Wikipedia:Data remanence を参照してください。

たとえデータの削除・消去を行った後でも、データが残留している可能性は存在します。

一回だけでなく複数回、繰り返しディスクに(ランダムな)データを書き込むことで残留データを消去できるかもしれませんが、複数回書き換えることでハードディスクドライブのデータを復元できる可能性が劇的に減るわけではありません。#残留磁気を見て下さい。

オペレーティングシステム、プログラム、ファイルシステム

The operating system, executed programs or journaling file systems may copy your unencrypted data throughout the block device. When writing to plain disks this should only be relevant in conjunction with one of the above.

If the data can get exactly located on the disk and was never copied anywhere else, wiping with random data can be thoroughgoing and impressively quick as long there is enough entropy in the pool.

/dev/urandom を使って LUKS キースロットを消去する cryptsetup が良い例です。

ハードウェア特有の問題

フラッシュメモリ

ライトアンプリフィケーションなどの機能があるために、フラッシュメモリを完全に消去するのは厄介です。デバイスのコントローラチップから見えるデータと、オペレーティングシステムから見えるデータの間には、透過的な抽象レイヤーが多数存在しており、データの書き込まれる場所が食い違っているために、特定のブロックやファイルを消去したとしても確実にデータが書き換えられているとは限りません。

(SandForce の全ての SSD に搭載されている) 透過圧縮などの"機能"は /dev/zero などのパターンストリームを圧縮してしまうことがあり、信じられないほど速く消去が終わってしまった場合、圧縮されてしまっている可能性があります。

Flash メモリデバイスを解体して、チップのハンダ付けを取り除き、中に入っているコントローラを使わずにデータの中身を解析することは 単純なハードウェア だけで簡単に行えてしまいます。データ復旧会社は安価にこれをしています。

詳細は次を参照: Reliably Erasing Data From Flash-Based Solid State Drives

不良セクタ

ハードドライブが不良セクタを認識すると、セクタへのアクセスが遮断され、ソフトウェアからはその領域に書き込みできなくなります。それによって、完全な書き換えがその領域にまで及ばない可能性があります。ただし、ブロックサイズから考えて、理論上、その領域からリカバリできるサイズはあくまで数 KB ほどしかありません。

残留磁気

A single, full overwrite with zeros or random data does not lead to any recoverable data on a modern high-density storage device.[1] Indications otherwise refer to single residual bits; reconstruction of byte patterns is generally not feasible.[2] See also [3], [4] and [5].

Overwriting old magnetic storage devices (e.g. floppy disks, magnetic tape, early-generation hard drives) only once can instead allow the wiped data to be reconstructed by analyzing the measured residual magnetics, due to much lower memory storage density. Such devices can get disassembled in a cleanroom and then analyzed with equipment like a magnetic force microscope. This method of data recovery requires however substantial financial resources. For this reason, it is advisable to overwrite old storage devices multiple times; degaussing is another practiced countermeasure, and to ensure that data has been completely erased, most resources even advise physical destruction.