fdiskコマンドはハードディスク領域を分割して複数のパーティションを作成したり編集したりできるコマンドですが、運用マシンではなかなか実行する機会の少ない fdisk コマンドを RHEL7 の環境で実行の流れを学びます。fdisk コマンドは、RHEL(Red Hat Enterprise Linux)のコアの資格である、RHCSA(Red Hat Certified System Administrator)の資格取得にも必要な知識ですので、資格取得されたい方は実際に実行して確認してみましょう。
パーティションとは、ハードディスク内の分割した領域をあらわします。
ファイルシステムはパーティション単位で作成するため、バックアップやメンテナンスが行いやすくなります。
fdisk コマンドで指定できるパーティションは「基本パーティション」「拡張パーティション」「論理パーティション」の3つありますが、今回は、fdisk コマンドの基本操作となる「基本パーティション」の作成の流れを紹介します。
今回、fdiskを実行するRed Hatのバージョンとカーネルは以下の通りです。
# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.0 (Maipo) # # uname -r 3.10.0-123.el7.x86_64
使用するマシンのディスクは fdisk コマンドの -l オプションで確認します。
この検証環境では、Red Hatが提供しているKVMという仮想化環境で試しているため、/dev/vdX となります。Xはaが1本目、bが2本目をあらわします。
/dev/vdaは起動ディスクで使用中であり、/dev/vdbはパーティションもなく未使用のディスクです。
# fdisk -l Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk label type: dos ディスク識別子: 0x00013f3e デバイス ブート 始点 終点 ブロック Id システム /dev/vda1 * 2048 20970332 10484142+ 83 Linux Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
/dev/vdbに対し、早速パーティション編集をしていきましょう。
パーティション編集は、fdisk デバイス名 と実行します。
# fdisk /dev/vdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x301b335b. コマンド (m でヘルプ):
fdiskは対話的なコマンドです。
次に入力するコマンドは、m と入力するとヘルプがでますので、まずは m と入力しましょう。
コマンド (m でヘルプ): m コマンドの動作 a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table 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) コマンド (m でヘルプ):
現在のパーティションテーブルを見るには、p と実行します。
コマンド (m でヘルプ): p Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk label type: dos ディスク識別子: 0x301b335b デバイス ブート 始点 終点 ブロック Id システム コマンド (m でヘルプ):
新しいパーティションを作成するには、n と入力します。
p と入力し、今回は基本パーティションを作成していきます。
パーティション番号は1、パーティション開始セクタはデフォルト値で進めます。サイズは+100Mと指定します。
コマンド (m でヘルプ): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p パーティション番号 (1-4, default 1): 1 最初 sector (2048-20971519, 初期値 2048): 初期値 2048 を使います Last sector, +sectors or +size{K,M,G} (2048-20971519, 初期値 20971519): +100M Partition 1 of type Linux and of size 100 MiB is set
作成したパーティションができているか、もう一度、p と入力し、確認します。
コマンド (m でヘルプ): p Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk label type: dos ディスク識別子: 0x301b335b デバイス ブート 始点 終点 ブロック Id システム /dev/vdb1 2048 206847 102400 83 Linux
保存は、w コマンドです。以下のメッセージが出力されれば作成完了です。
コマンド (m でヘルプ): w パーティションテーブルは変更されました! ioctl() を呼び出してパーティションテーブルを再読込みします。 ディスクを同期しています。 #
fdisk コマンドで作成したパーティションには、ファイルシステムを作成したり、swapとして使用するなどさまざまな使用用途があります。これら全ての一通りの流れを実機を通して確認できるトレーニングもありますので、体系的にfdiskを学びたい、サポートを受けながら実機操作をしたい、という方、ぜひチェックしてみてください。
記事は、予告なく変更または削除される場合があります。
記載された情報は、執筆・公開された時点のものであり、予告なく変更されている場合があります。
また、社名、製品名、サービス名などは、各社の商標または登録商標の場合があります。