0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7にアタッチしたボリュームをマウントする

Last updated at Posted at 2020-05-05

CentOS7に新規ボリュームをマウントする手順です。
/var/lib/testに別ボリュームをマウントします。

目次

0. 導入環境

  • CentOS 7.7(minimal)
$ cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
  • ルートボリューム:/dev/sda
  • アタッチしたボリューム:/dev/sdb

今回は/dev/sdbをOSにマウントさせます。
df -h/dev/sdbがOSにマウントされていないことを確認します。

$ df -h
ファイルシス            サイズ  使用  残り 使用% マウント位置
devtmpfs                  452M     0  452M    0% /dev
tmpfs                     464M     0  464M    0% /dev/shm
tmpfs                     464M  6.8M  457M    2% /run
tmpfs                     464M     0  464M    0% /sys/fs/cgroup
/dev/mapper/centos-root    14G  1.2G   13G    9% /
/dev/sda1                1014M  136M  879M   14% /boot
tmpfs                      93M     0   93M    0% /run/user/0
tmpfs                      93M     0   93M    0% /run/user/1000

以下のコマンドでマウントするボリュームの確認をします。

$ sudo fdisk -l

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


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

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

Disk /dev/mapper/centos-root: 14.4 GB, 14382268416 bytes, 28090368 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト


Disk /dev/mapper/centos-swap: 1719 MB, 1719664640 bytes, 3358720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト

1. パーティションの追加

以下コマンドでパーティションの追加を行います。

$ sudo 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 0xcd0e06ca.

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

コマンド (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)

今回は新たにパーティションを切るので、nと入力します。

コマンド (m でヘルプ): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended

pと入力します。

Select (default p): p

新規でパーティションを切るため、1と入力します。

パーティション番号 (1-4, default 1): 1

パーティションの開始位置を指定します。特に指定がなければ、何も入力せずEnterを押してください。

最初 sector (2048-20971519, 初期値 2048):
初期値 2048 を使います

パーティションの終了位置を指定します。特に指定がなければ、何も入力せずEnterを押してください。

Last sector, +sectors or +size{K,M,G} (2048-20971519, 初期値 20971519):
初期値 20971519 を使います
Partition 1 of type Linux and of size 10 GiB is set

設定を保存して終了します。

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

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

パーティションが追加されているか確認します。

$ sudo fdisk -l

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

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

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

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

Disk /dev/mapper/centos-root: 14.4 GB, 14382268416 bytes, 28090368 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト


Disk /dev/mapper/centos-swap: 1719 MB, 1719664640 bytes, 3358720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト

2. ボリュームのフォーマット

以下コマンドでフォーマットします。

sudo mkfs -t xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=655296 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621184, 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=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

3. マウント先のフォルダの作成

マウント先のファルダを作成します。
今回は/var/lib/testを作成します。

$ sudo mkdir /var/lib/test

4. マウントの設定

以下コマンドでsdb1のUUIDを確認してください。

$ sudo blkid
/dev/sdb1: UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="xfs"  # /dev/sdb1のUUIDをコピーする
/dev/sda1: UUID="yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" TYPE="xfs"
/dev/sda2: UUID="wwwwwwww-wwww-wwww-wwww-wwwwwwwwwwww" TYPE="LVM2_member"
/dev/mapper/centos-root: UUID="zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz" TYPE="xfs"
/dev/mapper/centos-swap: UUID="vvvvvvvv-vvvv-vvvv-vvvv-vvvvvvvvvvvv" TYPE="swap"

/etc/fstabにコピーしたUUIDをコピーする。

$ sudo vi /etc/fstab

変更前

#
# /etc/fstab
# Created by anaconda on Tue May  5 11:42:35 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
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy /boot                   xfs     defaults        0 0  # ここの行をコピー
/dev/mapper/centos-swap swap                    swap    defaults        0 0

変更後

#
# /etc/fstab
# Created by anaconda on Tue May  5 11:42:35 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
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy /boot                   xfs     defaults        0 0
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /var/lib/test           xfs     defaults        0 0  # ここを追加
/dev/mapper/centos-swap swap                    swap    defaults        0 0

マウントされるか確認します。

$ sudo mount -a

正常に設定されていない場合、以下が表示されます。/etc/fstabの設定を再確認してください。

$ sudo mount -a
mount: can't find UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

マウントされているか確認します。

$ df -h
ファイルシス            サイズ  使用  残り 使用% マウント位置
devtmpfs                  452M     0  452M    0% /dev
tmpfs                     464M     0  464M    0% /dev/shm
tmpfs                     464M  6.8M  457M    2% /run
tmpfs                     464M     0  464M    0% /sys/fs/cgroup
/dev/mapper/centos-root    14G  1.2G   13G    9% /
/dev/sda1                1014M  136M  879M   14% /boot
tmpfs                      93M     0   93M    0% /run/user/1000
/dev/sdb1                  10G   33M   10G    1% /var/lib/test

マウントの設定の手順は以上になります。

参考URL

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?