fdiskを使用したディスクのパーティション化
MBRを使用するハード・ディスクを作成および管理するには、fdiskコマンドを使用します。 または、fdiskのテキストベースのグラフィカル・バージョンであるcfdiskユーティリティを使用できます。
fdiskを実行する前に、まず次の要件を完了します。
-
ディスク上のマウントされているパーティションをすべてアンマウントします。
-
swapoffコマンドを使用して、スワップ領域として使用中のパーティションを無効にします。
-
構成するディスク上のデータをバックアップします。
fdiskは、対話型で使用することも、コマンドライン・オプションと引数を指定して直接使用することもできます。
ノート:
2つのモードは、特定のアクションの実行をサポートしているオプションによって異なる場合があります。 対話型モードでサポートされているオプションをリストするには、モードのプロンプトでmと入力します。 コマンドライン・モードでサポートされるオプションについては、次のように入力します。
fdisk -h
fdiskコマンドを対話型で実行するには、ディスク・デバイスの名前のみを引数として指定します。次に例を示します。
sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2) Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help):
次のコマンドは、パーティションの管理に役立ちます。
- p
-
現在のパーティション表を表示します。
- n
-
新しいパーティションを作成するプロセスを開始します。
- t
-
パーティション・タイプを変更します。
ヒント:
サポートされているすべてのパーティション・タイプをリストするには、lと入力します。
- w
-
パーティション表に加えた変更をコミットしてから、対話型セッションを終了します。
- q
-
行った構成変更を無視し、セッションを終了します。
- m
-
サポートされるすべてのコマンドを対話型モードで表示します。
詳細は、cfdisk(8)およびfdisk(8)の各マニュアル・ページを参照してください。
パーティション表の表示
パーティション表を表示するには、fdiskプロンプトでpと入力します。次に例を示します。
Command (m for help): p
Disk /dev/sda: 36.5 GiB, 39191576576 bytes, 76546048 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 Disklabel type: dos Disk identifier: 0x67fb0c7a Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 1026047 1024000 500M 83 Linux /dev/sda2 1026048 76546047 75520000 36G 8e Linux LVM Command (m for help):
出力には、ディスク・サイズやディスク・ラベル・タイプなどのデバイス情報のサマリー、およびパーティションの詳細が含まれます。 パーティションの詳細は、次のフィールド名で指定されます。
-
Device -
デバイスの現在のパーティションをリストします。
-
Boot -
ブート・パーティションをアスタリスク(
*)で識別します。 このパーティションには、GRUBブート・ローダーがシステムをブートするために必要なファイルが含まれています。 ブート可能にできるパーティションは1つのみです。 StartおよびEnd-
セクターの境界をマークするセクターの開始オフセットと終了オフセットをリストします。 すべてのパーティションは1MB境界に配置されます。
-
Sectors -
セクター・サイズを表示します。
-
Size -
パーティション・サイズを表示します。
IdおよびType-
代表番号と対応する代表番号のタイプを示します。
Oracle Linuxでは通常、次のタイプがサポートされています:
-
5 Extended -
最大4つの論理パーティションを含めることができる拡張パーティション。
-
82 Linux swap -
スワップ領域パーティション。
-
83 Linux -
LVMで管理されないファイル・システム用のLinuxパーティション。 これがデフォルトのパーティション・タイプです。
-
8e Linux LVM -
LVMで管理されるLinuxパーティション。
-
パーティションの作成
次の例では、様々なfdiskインタラクティブ・コマンドを使用してディスクをパーティション化する方法を示します。/dev/sdbに2つのパーティションが作成されます。 1番目のパーティションには2GBが割り当てられ、2番目のパーティションには残りのディスク領域がすべて使用されます。
sudo fdisk /dev/sdb
このコマンドでは、メニューベースのシステムが実行され、適切な応答を選択してパーティションを構成する必要があります。 入力例は次の対話型セッションに表示されます。
...
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-32767999, default 2048): <Enter>
Last sector, +sectors or +size{K,M,G,T,P} (2048-32767999, default 32767999): +2G
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (4196352-32767999, default 4196352): <Enter>
Last sector, +sectors or +size{K,M,G,T,P} (4196352-32767999, default 32767999): <Enter>
Created a new partition 2 of type 'Linux' and of size 13.6 GiB.
Command (m for help): p
Disk /dev/sdb: 15.6 GiB, 16777216000 bytes, 32768000 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
Disklabel type: dos
Disk identifier: 0x460247f0
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 4196351 4194304 2G 83 Linux
/dev/sdb2 4196352 32767999 28571648 13.6G 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.