GPT fdisk

提供: ArchWiki
2022年7月29日 (金) 11:25時点におけるAshMyzk (トーク | 投稿記録)による版 (ページの作成:「Category:ファイルシステム Category:システムリカバリ Category:コマンド de:GPT#Partitionieren_mit_gdisk en:GPT fdisk [[es:GPT fdisk]…」)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

関連記事

GPT fdisk は、Rod Smith 氏により作成されたテキストモードパーティショニングツールのセットです。gdiskcgdisksgdisk、そして fixparts から成ります。これらのツールは、(かつて一般的であった)Master Boot Record (MBR) パーティションテーブルではなく、Globally Unique Identifier (GUID) Partition Table (GPT) のディスク上で動作します。

gdiskcgdisk、そして sgdisk はすべて同じ機能を持っていますが、異なるユーザインターフェイスを提供します。gdisk はテキストモードで対話的に動作し、sgdisk はコマンドライン、cgdiskCurses ベースのインターフェイスです。この記事では、gdisk(8)sgdisk(8) ユーティリティについて説明します。

ヒント:
  • テキストユーザインターフェイスで基本的なパーティショニング機能を使いたい場合は、cgdisk(8) を使用できます。
  • GPT fdisk のウェブサイトには gdiskcgdisksgdisk、そして FixParts の詳細なチュートリアルがあります。

インストール

gptfdisk パッケージをインストールしてください。

パーティションの一覧表示

ブロックデバイス上のパーティションテーブルとパーティションを一覧表示するには、以下のコマンドを実行してください(デバイスは /dev/sda/dev/nvme0n1/dev/mmcblk0 のような名前です):

# gdisk -l /dev/sda

あるいは、sgdisk を使って同じことができます:

# sgdisk -p /dev/sda

パーティションテーブルのバックアップとリストア

ディスクに変更を加える前に、ドライブのパーティションテーブルとパーティションスキームをバックアップしておくと良いでしょう。また、バックアップを利用して、同じパーティションレイアウトを多数のドライブにコピーすることもできます。

sgdisk を使えば、protective MBR、メイン GPT ヘッダ、バックアップ GPT ヘッダ、そしてパーティションテーブルのコピーからなるバイナリバックアップを作成できます。以下の例では、/dev/sda のパーティションテーブルをファイル sgdisk-sda.bin へ保存します:

# sgdisk -b=sgdisk-sda.bin /dev/sda

以下を実行することで、バックアップから復元できます:

# sgdisk -l=sgdisk-sda.bin /dev/sda

現在のデバイスのパーティションレイアウト(ここでは /dev/sda)を他のドライブ(ここでは /dev/sdc)にクローンしたい場合、以下を実行してください:

# sgdisk -R=/dev/sdc /dev/sda

両方のドライブが同じコンピュータに搭載される予定であるならば、クローン先のディスクとパーティションの GUID を乱数にする必要があります:

# sgdisk -G /dev/sdc

パーティションテーブルとパーティションの作成

パーティショニングする際の最初のステップは、パーティションテーブルの作成です。その後、望ましいパーティションスキームにあわせてパーティションを作成します。

最初に、パーティションテーブルとレイアウトをバックアップすることを推奨します。

以下のセクションでは、gdisk を使用してパーティションテーブルとパーティションを作成する方法を説明しています。curses ベースの cgdisk を使うこともできますが、操作は以下と異なります。cgdisk の使用方法は cgdisk(8) を参照してください。

gdisk は、2048 512バイトセクタ(1 MiB)ブロックサイズベースで自動的にパーティションアライメントを行います。これは、すべての Advanced Format HDD と、全てではないにしても大半の SSD と互換性があるはずです。

gdisk を使用するには、変更/編集したいブロックデバイスの名前を渡して gdisk プログラムを実行してください。以下の例では、/dev/sda に対して実行します:

# gdisk /dev/sda

新しいテーブルの作成

警告: データが含まれているディスクに新しいパーティションテーブルを作成すると、ディスク上の全てのデータが消去されます。注意して実行してください。

新しい GUID パーティションテーブルを作成して既存のパーティションデータを全て消去するには、プロンプトに o と入力します。既存のテーブルを使用する場合は次に進んで下さい。

パーティションの作成

n コマンドで新しいパーティションを作成します。ここで入力する必要のある情報は、パーティション番号、先頭のセクタ、最後のセクタ、そしてパーティションタイプです。

ノート: パーティションのサイズや場所に関する考慮事項は パーティショニング#パーティション形態 を見てください。

パーティション番号

パーティション番号とは、パーティションに割り当てられる番号です。例えば、ディスク /dev/sda 上の番号1が割り当てられたパーティションは /dev/sda1 となります。パーティション番号は、ディスク上のパーティションの順番と必ずしも一致しているとは限りません。この場合、パーティションをソートすることができます。

パーティション番号は、gdisk によって提案されたデフォルトの番号を使うことをおすすめします。

先頭と末尾のセクタ

パーティションの先頭と末尾のセクタは、セクタ番号で、あるいはキビバイト(K)、メビバイト(M)、ギビバイト(G)、テビバイト(T)、ペビバイト(P)単位で指定することができます。

パーティションの位置の指定方法は以下の2通りあります:

  • ディスクの先頭からの絶対値。例えば、先頭のセクタとして 40M を指定すると、ディスクの先頭から 40 MiB の位置となります。
  • +size-size のように、サイズの前に +/- を付けると相対値を指定できます。例えば、デフォルトの先頭セクタから 2 GiB の点を指定するには +2G、利用可能な末尾のセクタから 200 MiB の点を指定するには -200M

何も入力しないで Enter キーを押すと、先頭セクタの一番広いブロックから末尾セクタと同じブロックの終末までが指定されます。

ヒント:
  • パーティショニング時に +size{M,G,T,P} 記法による相対値を使ってパーティションサイズを指定し、常に 1 MiB 以上のサイズを使うと良いでしょう。このようにサイズを指定すれば、パーティションは常にデバイスの特性に従ってアライメントされます。
  • BIOS ブートパーティションを作成する必要がある場合、ディスクの先頭 2 TiB のどこかに 1 MiB の空き領域を作成してください(例えば、パーティションの最初のセクタとして +1M を使う)。

パーティションタイプ

Select the partition's type by entering gdisk's internal type code or specifying the partition type GUID manually. The default, Linux filesystem (GUID 0FC63DAF-8483-4772-8E79-3D69D8477DE4, gdisk's internal code 8300), should be fine for most use cases.

ヒント:
Common partition types
Partition type Mountpoint gdisk's
code
Partition type GUID
Linux filesystem Any 8300 0FC63DAF-8483-4772-8E79-3D69D8477DE4
EFI system partition Any1 ef00 C12A7328-F81F-11D2-BA4B-00A0C93EC93B
BIOS boot partition None ef02 21686148-6449-6E6F-744E-656564454649
Linux x86-64 root (/) / 8304 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
Linux swap [SWAP] 8200 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
Linux /home /home 8302 933AC7E1-2EB4-4F13-B844-0E14E2AEF915
Linux /srv /srv 8306 3B8F8425-20E0-4F3B-907F-1A25A76F98E8
Linux /var /var1 8310 4D21B016-B534-45C2-A9FB-5C16E091FD2D
Linux /var/tmp /var/tmp1 8311 7EC6F557-3BC5-4ACA-B293-16EF5DF639D1
Linux LVM Any 8e00 E6D6D379-F507-44C2-A23C-238F2A3DF928
Linux RAID Any fd00 A19D880F-05FC-4D3B-A006-743F0F84911E
Linux LUKS Any 8309 CA7D7CCB-63ED-4C53-861C-1742536059CC
Linux dm-crypt Any 8308 7FFEC5C9-2D00-49B7-8941-3EA10A5586B7
  1. systemd-gpt-auto-generator(8) will only automount the partition if specific conditions are met. See systemd#GPT partition automounting for details.

Repeat this procedure until you have the partitions you desire.

ディスクに変更を書き込む

ヒント: Use the command c to change a partition's name (PARTLABEL) for easy distinguishing.

Write the table to disk and exit via the w command.

ヒントとテクニック

MBR と GPT の変換

ヒント: Read Rod Smith's Converting to or from GPT for more detailed information and walktrough.

gdisk, sgdisk and cgdisk have the ability to convert MBR and BSD disklabels to GPT without data loss. Upon conversion, all the MBR primary partitions and the logical partitions become GPT partitions with the correct partition type GUIDs and Unique partition GUIDs created for each partition.

After conversion, the boot loader will need to be reinstalled to configure it to boot from GPT.

警告:
  • GPT stores a secondary table at the end of disk. This data structure consumes 33 512-byte sectors (16.5 KiB) by default. MBR does not have a similar data structure at its end, which means that the last partition on an MBR disk sometimes extends to the very end of the disk and prevents complete conversion. If this happens to you, you must abandon the conversion and resize the final partition.
この記事またはセクションは加筆を必要としています。
理由: Provide a reference to the issue. (議論: トーク:GPT fdisk#)
  • There are known corruption issues with the backup GPT on laptops that are Intel chipset based, and run in RAID mode. The solution is to use AHCI instead of RAID, if possible.

To convert an MBR partition table to GPT using sgdisk, use the -g/--mbrtogpt option:

# sgdisk -g /dev/sda

To convert GPT to MBR use the -m/--gpttombr option. Note that it is not possible to convert more than four partitions from GPT to MBR.

# sgdisk -m /dev/sda

パーティションの並び替え

This applies for when a new partition is created in the space between two partitions or a partition is deleted. /dev/sda is used in this example.

# sgdisk -s /dev/sda

After sorting the partitions if you are not using Persistent block device naming, it might be required to adjust the /etc/fstab and/or the /etc/crypttab configuration files.

ノート: The kernel must read the new partition table for the partitions (e.g. /dev/sda1) to be usable. Reboot the system or tell the kernel to reread the partition table.

GPT ヘッダのリカバリ

メイン GPT ヘッダ、あるいはバックアップ GPT ヘッダが破損した場合、gdisk を使うことでどちらか片方からもう片方を復元できます。以下の例では /dev/sda となっています。

# gdisk /dev/sda

リカバリと変換のオプションである r を選択してください(上級者のみ)。そして、以下のどちらかを選択してください:

  • b: バックアップ GPT ヘッダを使う (メイン GPT ヘッダを再生成)
  • d: メイン GPT ヘッダを使う (バックアップ GPT ヘッダを再生成)

リカバリが完了したらディスクにテーブルを書き込んで w コマンドで終了してください。

GPT ディスクの拡張

After enlarging a disk (e.g. in hardware RAID or a virtual machine disk) the newly added free space will not be immediately usable since GPT keeps data at the end of the disk. You must relocate the backup GPT header to the new end of the disk.

Run sgdisk with the option -e/--move-second-header, e.g.:

# sgdisk -e /dev/sda

Afterwards print the partition table; the total free space should now be increased.

GPT パーティションの自動マウントを防ぐ

systemd-gpt-auto-generator(8) will automount partitions following the Discoverable Partitions Specification. Sometimes that may not be desirable.

The automounting can be disabled by setting the partition attribute 63 "do not automount" on the partition.

Start gdisk, e.g.:

# gdisk /dev/sda

Press p to print the partition table and take note of the partition number(s) of the for which you want to disable automounting.

Press x extra functionality (experts only).

Press a set attributes. Input the partition number and set the attribute 63. Under Set fields are: it should now show 63 (do not automount). Press Enter to end attribute changing. Repeat this for all partitions you want to prevent from automounting.

When done write the table to disk and exit via the w command.

Alternatively using sgdisk, the attribute can be set using the -A/--attributes= option; see sgdisk(8) for usage. For example, to set partition attribute 63 "do not automount" on /dev/sda2 run:

# sgdisk -A 2:set:63 /dev/sda

gdisk EFI アプリケーション

EFI バージョンの gdisk パッケージはありませんが、Rod Smith 氏がビルド済みの gdisk EFI バイナリを SourceForge にて配布しています。gdisk-efi-*.zip をダウンロードしてアーカイブを展開してください。使用方法は gdisk_x64.efiEFI システムパーティションにコピーしてブートローダーUEFI シェルから起動してください。

gdisk_x64.efi を使えばオペレーティングシステムが起動する前でもパーティションテーブルを編集できるようになります。使用方法は Linux での gdisk バイナリと変わりません。

ノート: gdisk_x64.efi はファイルシステムにアクセスできません。ゆえにパーティションテーブルをファイルにバックアップしたり、バックアップファイルからパーティションテーブルを復活させたりはできません。

さらなる情報については README-efi.txt をご覧ください。

参照