Macbook Air SSD換装: いよいよ480GB SSDの復元パーティション設定

「Macbook Air SSD換装」の話題、第7回目です。

注意: 下に書いたことも正確ではないことがわかりました。 「インターネット復元」でも、たしかにFilevault2が利用できる状態に復元パーティションを作成できますが、それはLionのクリーンインストールを行った場合のみです。 つまり、復元画面で「MacOS Xを再インストール」を選択した場合のみ、復元パーティションが作成されます。 復元画面のメニューから「Time Machineバックアップから復元」を選んだ場合は、たとえ元のシステムでFileVault2を利用していたとしても、復元時にFileVault2の実行に必要な隠しパーティションが削除されてしまいます(これはバグといってもいい問題点だと思います)。そのため、Time Machineから復元しつつFileVault2を利用するには、一旦「MacOS Xを再インストール」でLionをクリーンインストールし(ユーザ名は普段使っているのとは別の一時的な名前でインストールする)、その後「移行アシスタント」などを用いてTime Machineからデータをリストアし、一時的なユーザを削除するという手順をとる必要があります(あるいはインストーラの最後の方でTime Machineからの移行を選択する)。これについては後日まとめます。 (2012/06/15 追記)

注意: いろいろ長く書いていますが、筆者のFileVault2の実装への理解に間違いがあり、 このような面倒な手段を行わなくても、 「インターネット復元」でFilevault2が利用できる状態に復元パーティションを作成できるようです。(補足:これは正確ではありません。上に追記した「注意」をお読みください)なーんだ。 まあ、その作業を手動でやった記録として、 こちらのページは良かったら読んでみてくださいませ(トホホ)。 なお、ハードウェア的な問題については、 もしかしたら一部の人に意味があるかも知れません。(2011/11/17 追記)

Macbook Air (mid 2011, 11-inch)のSSDを換装しつつ、 Lion復元パーティションを新しいSSDに作成し、 FileVault2による暗号化を可能とすることに挑戦。 HDDでの試行錯誤も終了し、 検証では成功したか失敗したかが不明なまま、 とりあえず一か八か本番ディスクを設定して、内蔵してみることに。

さて、今までなんとなくそこそこスムーズに進行しているようですが、 その裏ではいろいろな隠れた試行錯誤があったりするのです。 ブロック数の計算だって、実際は手書きメモに電卓で計算してますよ。 こんな感じで。

[image]

汚い字だなー(笑)。というわけで、本番のSSDの設定に入ります。その前にもう一度… (ちょっと書き換えた)。

警告

今回は具体的な本番作業内容を記述していますが、 これは以前の試行錯誤の結果を元にしています。 以前の試行錯誤の内容への理解が不十分な場合、 想定外の事態が生じた際に対応は難しくなると思います。 ここを参考にして換装に挑戦する前に、確実に以前の内容を理解するようにしてください。

また、デバイス名(/dev/disk*)は、すべての環境で番号が同一に振られるとは限りません。 間違えた番号に対して操作を行った場合、現在利用しているパーティションだけではなく、通常の手順では復元不能な、内蔵起動ドライブの「復元パーティション」を破壊してしまう可能性もあります。

ここに記述された内容のコマンドを実行する場合は、 自分が何をしようとしているのか確実に理解した上で、 必要があれば適切なデバイス番号などに読み替えて実行するようにしてください。

作業を行う前は、かならず十分なバックアップを行い、またLion復旧ディスクアシスタントでUSBメモリから起動可能な復旧ディスクを作成しておいてください。 また、以前の試行錯誤のページで最初で解説した、復元パーティションのバックアップを必ず作成し、これも安全な場所に保存しておいてください。

なお、この記事の内容を参考に操作を行い、システムに何らかの問題が生じたとしても、 筆者は一切の責任を負いません。

さて、Macbook Air用480GB SSD OWCSSDAPAE480を、 専用のUSB箱OWCSSDAPOTGU3に入れた状態(あとでどうせ換装するので、 蓋は閉じる必要はない)で用意しておきます。 まずはディスクユーティリティでディスクの消去を行い、 全体を「Macintosh HD 2」という名前の1パーティションで初期化しておきます。

ここで、gdiskを用いてパーティションの状態を調べます。 USB箱の新SSDのデバイスは/dev/disk1であることを仮定します。 もし別の番号だった場合は適宜読み替えてください。

% gdisk /dev/disk1
GPT fdisk (gdisk) version 0.7.2
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/disk1: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): ********-****-****-****-************
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 8-sector boundaries
Total free space is 262157 sectors (128.0 MiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       937440903   446.8 GiB   AF00  Macintosh HD 2
Command (? for help): q

想定通り、EFI System PartitionとMacintosh HD 2の2つのパーティション。 ここで、Recovery HDを追加するに、試行錯誤の時と同じ計算をします。参考までに、もう一度元の内蔵SSDのパーティションテーブルの内容を載せておきます。

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI system partition
   2          409640       488965175   233.0 GiB   AF00  Macintosh HD
   3       488965176       490234711   619.9 MiB   AB00  Recovery HD

この双方を元に計算すると次のようになります。

  • 1番のEFI System Partitionはそのまま放置して良い。

  • 3番のRecovery HDは、サイズは現在の内蔵SSDのレイアウトから490234711+1-488965176を計算して、1269536ブロック。

    新しいSSDの現在の2番パーティションが409640番ブロックから937440903番ブロックなので、ここから3番パーティションの開始ブロックを計算すると、937440903+1-1269536で、936171368番ブロックとなる。

    終了位置は現在の2番パーティションの終了位置である937440903番ブロック。

  • 2番のファイルシステムは、開始位置は変わらず409640番ブロック。

    終了ブロックは3番パーティションの開始ブロック936171368番の1つ前の936171367番ブロック。

以上を完結にまとめると、次のようになります。これが先ほどの手書きメモの内容です。

番号タイプ開始ブロック終了ブロック名称
1EF0040409,639EFI System Partition
2AF00409,640936,171,367Macintosh HD 2
3AB00936,171,368937,440,903Recovery HD

では、このパーティションを作成しましょう。 まずは念のためもう一度パーティションテーブルを確認。

% gdisk /dev/disk1
GPT fdisk (gdisk) version 0.7.2
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/disk1: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): ********-****-****-****-************
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 8-sector boundaries
Total free space is 262157 sectors (128.0 MiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       937440903   446.8 GiB   AF00  Macintosh HD 2
Command (? for help): q

一旦、2番パーティションを削除します。

Command (? for help): d
Partition number (1-2): 2
Command (? for help): p
Disk /dev/disk1: 937703088 sectors, 447.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): ********-****-****-****-************
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 8-sector boundaries
Total free space is 937293421 sectors (446.9 GiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition

そして、新しい2番パーティションを作成します。

Command (? for help): n
Partition number (2-128, default 2): 2
First sector (34-937703054, default = 409640) or {+-}size{KMGTP}: 409640
Last sector (409640-937703054, default = 937703054) or {+-}size{KMGTP}: 936171367
Current type is 'Apple HFS/HFS+'
Hex code or GUID (L to show codes, Enter = AF00): af00
Changed type of partition to 'Apple HFS/HFS+'
Command (? for help): p
Disk /dev/disk1: 937703088 sectors, 447.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): ********-****-****-****-************
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 937703054
Partitions will be aligned on 8-sector boundaries
Total free space is 1531693 sectors (747.9 MiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       936171367   446.2 GiB   AF00  Apple HFS/HFS+

さらに、3番パーティションを作成します。

Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-937703054, default = 937703054) or {+-}size{KMGTP}: 936171368
Last sector (936171368-937703054, default = 937703054) or {+-}size{KMGTP}: 937440903
Current type is 'Apple HFS/HFS+'
Hex code or GUID (L to show codes, Enter = AF00): ab00
Changed type of partition to 'Apple boot'
Bogus UTF-16 name found in GPTPart::SetName()! Name not changed!
Command (? for help): p
Disk /dev/disk1: 937703088 sectors, 447.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): ********-****-****-****-************
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 937703054
Partitions will be aligned on 8-sector boundaries
Total free space is 262157 sectors (128.0 MiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       936171367   446.2 GiB   AF00  Apple HFS/HFS+
   3       936171368       937440903   619.9 MiB   AB00  

そして2番、3番パーティションに名前を付けます。

Command (? for help): c
Partition number (1-3): 2
Enter name: Macintosh HD 2
Command (? for help): c
Partition number (1-3): 3
Enter name: Recovery HD
Command (? for help): p
Disk /dev/disk1: 937703088 sectors, 447.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): ********-****-****-****-************
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 937703054
Partitions will be aligned on 8-sector boundaries
Total free space is 262157 sectors (128.0 MiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       936171367   446.2 GiB   AF00  Macintosh HD 2
   3       936171368       937440903   619.9 MiB   AB00  Recovery HD

問題なければ新SSDに書き込みます。

Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT).
Warning: The kernel may continue to use old or deleted partitions.
You should reboot or remove the drive.
The operation has completed successfully.

Lionがまた新しく出来たMacintosh HD 2パーティションをマウントしてしまいますが、 すぐにFinderから取り出しボタンで再度アンマウントしておきましょう。 そして、もう一度gdiskコマンドで、確実にパーティションが書きこまれていることを確認します。

% gdisk /dev/disk1
GPT fdisk (gdisk) version 0.7.2
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/disk1: 937703088 sectors, 447.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): ********-****-****-****-************
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 937703054
Partitions will be aligned on 8-sector boundaries
Total free space is 262157 sectors (128.0 MiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       936171367   446.2 GiB   AF00  Macintosh HD 2
   3       936171368       937440903   619.9 MiB   AB00  Recovery HD
Command (? for help): q

そして、パーティション2番をHFS+で再フォーマットします。

% diskutil eraseVolume HFS+ "Macintosh HD 2" /dev/disk1s2
Started erase on disk1s2 Macintosh HD 2
Unmounting disk
Erasing
Initialized /dev/rdisk1s2 as a 446 GB HFS Plus volume
Mounting disk
Finished erase on disk1s2 Macintosh HD 2

3番パーティションを再作成して、再度パーティションテーブルを書き込みます。

% gdisk /dev/disk1
GPT fdisk (gdisk) version 0.7.2
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/disk1: 937703088 sectors, 447.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): ********-****-****-****-************
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 937703054
Partitions will be aligned on 8-sector boundaries
Total free space is 1531693 sectors (747.9 MiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       936171367   446.2 GiB   AF00  Macintosh HD 2
Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-937703054, default = 937703054) or {+-}size{KMGTP}: 936171368
Last sector (936171368-937703054, default = 937703054) or {+-}size{KMGTP}: 937440903
Current type is 'Apple HFS/HFS+'
Hex code or GUID (L to show codes, Enter = AF00): ab00
Changed type of partition to 'Apple boot'
Bogus UTF-16 name found in GPTPart::SetName()! Name not changed!
Command (? for help): c
Partition number (1-3): 3
Enter name: Recovery HD
Command (? for help): p
Disk /dev/disk1: 937703088 sectors, 447.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): ********-****-****-****-************
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 937703054
Partitions will be aligned on 8-sector boundaries
Total free space is 262157 sectors (128.0 MiB)
Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       936171367   446.2 GiB   AF00  Macintosh HD 2
   3       936171368       937440903   619.9 MiB   AB00  Recovery HD
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT).
Warning: The kernel may continue to use old or deleted partitions.
You should reboot or remove the drive.
The operation has completed successfully.

そして、復元パーティションの内容を新しいSSDにコピーします。

% sudo dd if=/dev/disk0s3 of=/dev/disk1s3
Password:
1269536+0 records in
1269536+0 records out
650002432 bytes transferred in 21.853469 secs (29743673 bytes/sec)

さて、これでコピーは出来たはず。 これで、設定したSSDをMacbook Airに内蔵し、 先ほどの一か八かの賭け、

「Macbook AirのEFIは、外付けのUSBにRecovery HDが存在することを仮定していない」
「旧Macbook AirのEFIは、Recovery HDに対応していない」

に双方に勝っていれば、問題なく新しいSSD上の復元パーティションから、 Macintosh HD 2上にシステムをインストールすることが可能なはずです。

……と思ったのですが…。まさかそんなところに思いもしなかった罠が待ち構えていたとは…。

…と、思わせぶりに続きますが、その前に腹も減ったなぁ…。