このページで解説している内容は、以下の YouTube 動画の解説で見ることができます。

Linuxコマンド演習47

以下のコマンドの演習を行います。

実際にコマンド操作を行いながら、Linuxの操作に慣れていきましょう。

ここでは、増設した2台目ディスクにパーティションを作成していきます。

演習01:増設したディスクを確認する。

・増設したディスクのデバイス名を確認します。

 fdiskコマンドに「-l」オプションを指定して実行します。fdiskコマンドを実行するために、まず、rootユーザーに切り替えておきます。

$ su -
パスワード:
最終ログイン: 2024/02/10 (土) 13:15:22 JST日時 pts/0
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000a53d9

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
(省略)

 「Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors」の出力より、「/dev/sdb」として認識されていることが確認できます。

演習02:'/dev/sdb' ディスクに新しいパーティションを作成します。

・'/dev/sdb' ディスクに新しいパーティションを作成するために、「n」コマンドを使用します。

# fdisk /dev/sdb
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 0x21b8b685.

コマンド (m でヘルプ): n # 「n」で新規パーティションを作成
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p # 「p」で基本パーティションを作成
パーティション番号 (1-4, default 1): 1 # 「1」で第1パーティションを作成
最初 sector (2048-41943039, 初期値 2048):  # 「Enter」キーでデフォルトの開始セクタを指定
初期値 2048 を使います
Last sector, +sectors or +size{K,M,G} (2048-41943039, 初期値 41943039): +5G # 「+5G」でパーティションサイズを5GB
Partition 1 of type Linux and of size 5 GiB is set

コマンド (m でヘルプ): p # 「p」でハーティション一覧を表示

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x21b8b685

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048    10487807     5242880   83  Linux # 作成されたパーティション

コマンド (m でヘルプ): w # 「w」でパーティション操作を保存して終了
パーティションテーブルは変更されました!

ioctl() を呼び出してパーティションテーブルを再読込みします。
ディスクを同期しています。

演習03:作成したパーティションを確認する。

・作成したパーティションを確認します。

 パーティション作成時にも作成したパーティションを確認することができますが、fdiskコマンドに「-l」オプションを指定して再度実行します。

# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000a53d9

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x21b8b685

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048    10487807     5242880   83  Linux 

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectors
(省略)

「sdb」内に1番目の基本パーティションが作成されていることが確認できます。