Linux でパーティションを作成または管理するには、さまざまなオプションがあります – Parted その一つです。このノートでは、その使用法と、新しいパーティション テーブルを作成する際のユース ケースについて説明します。 parted を対話的に使用して、コマンドを 1 つずつ入力します。インタラクティブ モードを呼び出す引数としてデバイスのみを含めます。
parted を使用してパーティションを作成する
1.分割するハードディスクを選択
パーティションを作成するディスクを選択します。以下の例では /dev/sdb がパーティション化されています。以下の 2 つの方法でディスクを選択できます。
# parted /dev/sdb GNU Parted 3.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted)
または
# parted GNU Parted 3.1 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) select /dev/sdb Using /dev/sdb (parted)
「help」を実行すると、parted コマンドで提供されるさまざまなオプションを確認できます
2.パーティション テーブル タイプの設定
次の例では、mklabel コマンドを使用して新しいパーティション テーブルを作成します。ディスク ラベル タイプは、aix、amiga、bsd、dvh、gpt、mac、msdos、pc98、sun、または loop のいずれかでなければなりません。
(parted) help mklabel mklabel,mktable LABEL-TYPE create a new disklabel (partition table) LABEL-TYPE is one of: aix, amiga, bsd, dvh, gpt, mac, msdos, pc98, sun, loop
上記の出力では、さまざまな LABEL-TYPE が parted でサポートされていることがわかります。一般的な Linux では、msdos を LABEL-TYPE として使用する必要があることに注意してください。
(parted) mklabel msdos Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? Yes
3.空き容量と既存のパーティションを確認してください
ディスクの空き容量と既存のパーティションを確認するには、print を使用します サブコマンド。ご覧のとおり、ディスクには 21.5GB の空き容量があり、ディスクにはまだパーティションが作成されていません。
(parted) print free Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 32.3kB 21.5GB 21.5GB Free Space
(parted) print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags (parted)
4. mkpart を使用して、選択したディスクにプライマリまたは論理パーティションを作成する
mkpart コマンドを使用して、プライマリ パーティションまたは論理パーティションを作成できます。オプションは、それぞれプライマリおよび論理にすることができます。両方のオプションの例を以下に示します (プライマリ パーティションと論理パーティションとしてそれぞれ 200 MB の 2 つのパーティションを作成します)。
a.プライマリ パーティションの作成
(parted) mkpart primary File system type? [ext2]? ext4 Start? 0 End? 200MB Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? I
(parted) print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 512B 200MB 200MB primary
b.論理パーティションの作成
(parted) mkpart logical parted: invalid token: logical Partition type? primary/extended? extended Start? 201M End? 402M
(parted) print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 512B 200MB 200MB primary 2 201MB 402MB 200MB extended lba注意 :論理パーティションを作成する場合を除き、Parted はプライマリ パーティションの作成中に FS-Type を要求します。
rm コマンドを使用してパーティションを削除する
「rm」コマンドを使用して既存のパーティションを削除することもできます。以下の例に示すように、番号 1 と 2 の 2 つのパーティションがあります。
(parted) print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 512B 200MB 200MB primary 2 201MB 402MB 200MB extended lba
パーティション 2 を削除するには:
(parted) rm Partition number? 2
パーティション番号 1 のみが表示されることを確認してください。
(parted) print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 512B 200MB 200MB primary