LoginSignup
4
3

More than 3 years have passed since last update.

CentOS7でのディスク増設手順

Posted at

物理的にディスクを増設し、OSを起動したところからスタート

増設前の確認

既存のディスク(sda)が16G

[root@localhost ~]# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
devtmpfs         486M     0  486M    0% /dev
tmpfs            496M     0  496M    0% /dev/shm
tmpfs            496M  6.8M  489M    2% /run
tmpfs            496M     0  496M    0% /sys/fs/cgroup
/dev/sda3         15G  1.2G   14G    9% /
/dev/sda1        197M  109M   88M   56% /boot
tmpfs            100M     0  100M    0% /run/user/0

ディスクの認識を確認

増設ディスクがsdbとして認識していることを確認

[root@localhost ~]# fdisk -l

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

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     2508799     1048576   82  Linux swap / Solaris
/dev/sda3         2508800    33554431    15522816   83  Linux

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

ディスクのサイズが下記のように17.2GBとなっているが、
17179869184/1024/1024/1024=16GBとなる

Disk /dev/sdb: 17.2 GB, 17179869184 bytes, 33554432 sectors

パーティションの作成

[root@localhost ~]# 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 0xdc93160c.

コマンド (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 でヘルプ): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
パーティション番号 (1-4, default 1):
最初 sector (2048-33554431, 初期値 2048):
初期値 2048 を使います
Last sector, +sectors or +size{K,M,G} (2048-33554431, 初期値 33554431):
初期値 33554431 を使います
Partition 1 of type Linux and of size 16 GiB is set

コマンド (m でヘルプ): P

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

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

コマンド (m でヘルプ): w
パーティションテーブルは変更されました!

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

sdb用のパーティションが作成された事の確認

[root@localhost ~]# fdisk -l

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

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     2508799     1048576   82  Linux swap / Solaris
/dev/sda3         2508800    33554431    15522816   83  Linux

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

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

既存ディスクのフォーマット形式の確認

xfsである事を確認
因みに、CentOS7のデフォルトのフォーマット形式はxfs

[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Wed Jul 15 22:04:37 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=22611ecb-1d51-4bdd-9d81-4e3eb20972e8 /                       xfs     defaults        0 0
UUID=fd962e03-db59-4ac5-a09f-0e0f64a18e43 /boot                   xfs     defaults        0 0
UUID=a17d811c-b321-4ffc-950a-93f5a7f19b15 swap                    swap    defaults        0 0

ディスクをフォーマット

[root@localhost ~]# mkfs -t xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=1048512 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=4194048, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

手動でディスクをマウント

/newdiskとしてマウントする

[root@localhost ~]# mkdir /newdisk
[root@localhost ~]# mount /dev/sdb1 /newdisk
[root@localhost ~]# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
devtmpfs         486M     0  486M    0% /dev
tmpfs            496M     0  496M    0% /dev/shm
tmpfs            496M  6.8M  489M    2% /run
tmpfs            496M     0  496M    0% /sys/fs/cgroup
/dev/sda3         15G  1.2G   14G    9% /
/dev/sda1        197M  109M   88M   56% /boot
tmpfs            100M     0  100M    0% /run/user/0
/dev/sdb1         16G   33M   16G    1% /newdisk

UUIDの取得

OS起動時に自動でマウントするために/etc/fstabに設定を追記する必要がある
そのために、予めUUIDを確認する

[root@localhost ~]# blkid /dev/sdb1
/dev/sdb1: UUID="2fb71a67-4d60-45cf-a5bf-8eebe731f24f" TYPE="xfs"

OS起動時の自動マウント設定

/etc/fstabに設定を追記する
第1フィールド:デバイス名またはUUID
第2フィールド:マウントポイント
第3フィールド:ファイルシステム
第4フィールド:マウントオプション
第5フィールド:ファイルシステムをdumpするか否かの指定
第6フィールド:システム起動時にfsckチェックを行うか否かの指定
/etc/fstabに記述されている数字の意味


#
# /etc/fstab
# Created by anaconda on Wed Jul 15 22:04:37 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=22611ecb-1d51-4bdd-9d81-4e3eb20972e8 /                       xfs     defaults        0 0
UUID=fd962e03-db59-4ac5-a09f-0e0f64a18e43 /boot                   xfs     defaults        0 0
UUID=a17d811c-b321-4ffc-950a-93f5a7f19b15 swap                    swap    defaults        0 0
UUID=2fb71a67-4d60-45cf-a5bf-8eebe731f24f /newdisk                xfs     defaults        1 2

OS再起動前の自動マウント確認

ここまで上から順番にコマンドを実行していた場合、
マウント済みなので一度アンマウントしてマウントし直す

[root@localhost ~]# umount /newdisk
[root@localhost ~]# mount -a
[root@localhost ~]# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
devtmpfs         486M     0  486M    0% /dev
tmpfs            496M     0  496M    0% /dev/shm
tmpfs            496M  6.8M  489M    2% /run
tmpfs            496M     0  496M    0% /sys/fs/cgroup
/dev/sda3         15G  1.2G   14G    9% /
/dev/sda1        197M  109M   88M   56% /boot
tmpfs            100M     0  100M    0% /run/user/0
/dev/sdb1         16G   33M   16G    1% /newdisk

実際にOSを再起動して自動マウントを確認

[root@localhost ~]# reboot

[root@localhost ~]# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
devtmpfs         486M     0  486M    0% /dev
tmpfs            496M     0  496M    0% /dev/shm
tmpfs            496M  6.8M  489M    2% /run
tmpfs            496M     0  496M    0% /sys/fs/cgroup
/dev/sda3         15G  1.2G   14G    9% /
/dev/sdb1         16G   33M   16G    1% /newdisk
/dev/sda1        197M  109M   88M   56% /boot
tmpfs            100M     0  100M    0% /run/user/0
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3