この広告は、90日以上更新していないブログに表示しています。
GPT は名前の通り、128ビットのGUIDによりディスクを識別できるのだが、実はMBR の場合でもディスク固有の値として32ビットの値がMBR(セクタ0)のオフセット 440 - 443 に書き込まれている。
fdisk コマンドでも「Disk identifier」として出力され、以下の例では「e64d8f76」がそれだ。
# fdisk -l /dev/sddDisk /dev/sdd: 1073 MB, 1073741824 bytes34 heads, 61 sectors/track, 1011 cylindersUnits = cylinders of 2074 * 512 = 1061888 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xe64d8f76 Device Boot Start End Blocks Id System/dev/sdd1 1 100 103669+ 83 Linux/dev/sdd2 101 200 103700 83 Linux
なお、確認に使用しているのはCentOS 6.4x86_64 である。
この Disk identifier だが、恥ずかしながら私はずっと「なにか適当な数字」ぐらいにしか思っていなかった。その理由はMBR の形式をずっと以下の図の通りと認識していたからだ。
実際に日本語のWikipediaにおける「マスターブートレコード」ではこの構造が記載されており、「0(先頭)〜445(446バイト)にブートストラップローダ、446〜509(64バイト)にパーティションテーブル、510〜511(2バイト)にブートシグニチャがある。」とも明言されている。これによれば Disk identifer などといういかにも永続的なものを書いておく余地などない。書いておくことができない永続的な情報があるわけがない、そう思っているから見えていなかったといってもよい(無いと思っているものは目の前にあっても見えない、とか言いますよね)。
ところが、英語のWikipediaにおける「Master boot record」では上記の図の形式を「Structure of aclassical genericMBR」だとして説明している。そして、「Structure ofmodern standardMBR」として以下の図の形式を説明している。つまり、現在の標準的な(といってもそのMBR自体がレガシーになっていくが)MBR の形式ではオフセット 440 - 445 の扱いが決定的に変わっているのである。そしてこの場所こそが Disk identifer が書き込まれている場所だ。
パーティションを削除したあとにディスクをクリアする(先頭64セクタのみ)。
# dd if=/dev/zero of=/dev/sdd bs=512 count=6464+0 records in64+0 records out32768 bytes (33 kB) copied, 0.0694129 s, 472 kB/s
パーティションテーブルもなく、Disk identifer は 00000000 になっている。
# fdisk -l /dev/sddDisk /dev/sdd: 1073 MB, 1073741824 bytes34 heads, 61 sectors/track, 1011 cylindersUnits = cylinders of 2074 * 512 = 1061888 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
fdisk を実行し、パーティションは作らずに保存する。
実行直後の p (print) で既に Disk identifier が表示されているのは、fdisk のメモリ上ではもうMBR(セクタ0) のイメージが生成済みだからだろう。
# fdisk /dev/sddDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x3907301d.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').Command (m for help): pDisk /dev/sdd: 1073 MB, 1073741824 bytes34 heads, 61 sectors/track, 1011 cylindersUnits = cylinders of 2074 * 512 = 1061888 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x3907301d Device Boot Start End Blocks Id SystemCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
fdisk -l で表示してみると、Disk identifer がしっかり書き込まれていることが確認できた。
dd でもちょうどオフセット 440 - 443 に書き込まれていることがわかる。何もパーティションを作成しない初期のMBR(セクタ0) のイメージはこの Disk identifer と末尾2バイトのブートシグニチャのみということのようだ。
# fdisk -l /dev/sddDisk /dev/sdd: 1073 MB, 1073741824 bytes34 heads, 61 sectors/track, 1011 cylindersUnits = cylinders of 2074 * 512 = 1061888 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x3907301d Device Boot Start End Blocks Id System# dd if=/dev/sdd bs=512 count=1 2>/dev/null | hexdump -C00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|*000001b0 00 00 00 00 00 00 00 00 1d 30 07 39 00 00 00 00 |.........0.9....|000001c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|*000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|00000200
fdisk にはエキスパートモードというものがあり、そのモードに切り替えるの Disk identifer を書き換えることができる。
ただし、Disk identifer の書き換えのみでは fdisk が変更として扱わず、MBR に実際に書き込みを行わないようである。そのため、適当なパーティションのシステム識別子を一旦書き換えて戻す(変更フラグを立てさせるだけ)という一見無駄なオペレーションも行う。もちろんパーティションの一時作成・削除でもよい。
元々の Disk identifer は「1c1f80db」である。
# fdisk -l /dev/sddDisk /dev/sdd: 1073 MB, 1073741824 bytes34 heads, 61 sectors/track, 1011 cylindersUnits = cylinders of 2074 * 512 = 1061888 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x1c1f80db Device Boot Start End Blocks Id System/dev/sdd1 1 100 103669+ 83 Linux
fdisk を起動し、エキスパートモードに入る。
# fdisk /dev/sddWARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').Command (m for help): mCommand action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)Command (m for help): xExpert command (m for help): mCommand action b move beginning of data in a partition c change number of cylinders d print the raw data in the partition table e list extended partitions f fix partition order g create an IRIX (SGI) partition table h change number of heads i change the disk identifier m print this menu p print the partition table q quit without saving changes r return to main menu s change number of sectors/track v verify the partition table w write table to disk and exit
Disk identifer の書き換えのため i を入力し、新しい Disk identifier として「0xe64d8f76」を入力する(ここでは16進数を表す0xを付ける必要がある)。
Expert command (m for help): iNew disk identifier (current 0x1c1f80db): 0xe64d8f76Disk identifier: 0xe64d8f76
r を入力し、エキスパートを終了する。p にて確認すると Disk identifier は変更されている(まだ fdisk のメモリ上のみ)。
ここで w で書き込みを要求しても書き込みをしてくれないので、パーティション1のシステム識別子を 83 → 8e → 83 に書き換えてから w を実行する。
Expert command (m for help): rCommand (m for help): pDisk /dev/sdd: 1073 MB, 1073741824 bytes34 heads, 61 sectors/track, 1011 cylindersUnits = cylinders of 2074 * 512 = 1061888 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xe64d8f76 Device Boot Start End Blocks Id System/dev/sdd1 1 100 103669+ 83 LinuxCommand (m for help): tSelected partition 1Hex code (type L to list codes): 8eChanged system type of partition 1 to 8e (Linux LVM)Command (m for help): tSelected partition 1Hex code (type L to list codes): 83Changed system type of partition 1 to 83 (Linux)Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
無事に Disk identifier が書き換えられた。
# fdisk -l /dev/sddDisk /dev/sdd: 1073 MB, 1073741824 bytes34 heads, 61 sectors/track, 1011 cylindersUnits = cylinders of 2074 * 512 = 1061888 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xe64d8f76 Device Boot Start End Blocks Id System/dev/sdd1 1 100 103669+ 83 Linux
引用をストックしました
引用するにはまずログインしてください
引用をストックできませんでした。再度お試しください
限定公開記事のため引用できません。