LoginSignup
17
19

More than 3 years have passed since last update.

LVMを使って複数のディスクを1つに統合する

Last updated at Posted at 2020-02-10

0. 概要

ここ最近、メディア機器の高機能化に伴い、画像や動画等容量の大きいものが増えてきている。
様々なHDDにデータを保存していると、どのHDDにどのデータがあるのか見つけにくくなってしまう問題がある。
そこで複数のHDDを束ねて、1つの大容量HDDとして、取り扱いたいと考える。
今回は、複数のHDDをLVMを用いて束ねる方法を説明する。

1. 前提条件

  • HDDは全てで5台

  • 各HDDは8TB

  • 2つのグループに容量を統合する

2. ディスクの統合

2.1. ディスクの確認

まず以下からディスク情報を調査して、統合するディスクの名前を確認する。

$ sudo fdisk -l

# ------------------------------------------------------------------ #
Disk /dev/sdf: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/sdg: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/sdh: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/sdd: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/sde: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
# ------------------------------------------------------------------ #

他のHDDと間違えていないか、製造番号の確認もしておく。

$ sudo smartctl -a /dev/sde | grep Model

# ------------------------------------------------------------------ #
Device Model:     ST8000VN004-2M2101
# ------------------------------------------------------------------ #

マウントされていないかも確認しておく。

$ df -h

もし、マウントされていたら以下で解除

$ umount <YOUR MOUNT POINT>

2.2. ディスクの初期化

ディスク5台を初期化

$ sudo pvcreate /dev/sdd
  WARNING: ext4 signature detected on /dev/sdd at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdd.
  Physical volume "/dev/sdd" successfully created.

同様にsde, sdf, sdg, sdhも行う。

2.3. ディスクの統合(グループ化)

次に初期化したディスクを統合していく。
今回はsdd, sde, sdf, sdg, sdh8TBディスク5枚
3枚で1つ2枚で1つ、すなわち24TB16TBの論理ドライブに
統合して構築する。

まず24TBの方から統合。

$ sudo vgcreate exthd1Group /dev/sdd /dev/sde /dev/sdf

# ------------------------------------------------------------------ #
Volume group "exthd1Group" successfully created
# ------------------------------------------------------------------ #

同様に、16TBの方も行う。

$ sudo vgcreate exthd2Group /dev/sdg /dev/sdh

2.4. ディスクの統合(ボリュームの作成)

次に、ロジカルボリュームを作成する。
上記で作成したHDDグループのexthd1Groupを指定して、ロジカルボリュームを作成する。

$ sudo lvcreate -l 100%FREE -n lv0 exthd1Group

# ------------------------------------------------------------------ #
  Logical volume "lv0" created.
# ------------------------------------------------------------------ #

同様に、exthd2Groupについても行う。

$ sudo lvcreate -l 100%FREE -n lv0 exthd2Group

なお、全ての容量を使い切らないのであれば、-l 100%FREE-L 8T等にすればよい。
lv0はロジカルボリュームの名前を指している。

2.5. ディスクの統合(ボリューム確認)

作成したボリュームを確認する。

$ sudo lvdisplay
# ------------------------------------------------------------------ #
  --- Logical volume ---
  LV Path                /dev/exthd2Group/lv0
  LV Name                lv0
  VG Name                exthd2Group
  LV UUID                
  LV Write Access        read/write
  LV Creation host, time N/A, 2020-02-10 14:09:41 +9999
  LV Status              available
  # open                 0
  LV Size                14.55 TiB
  Current LE             3815442
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

  --- Logical volume ---
  LV Path                /dev/exthd1Group/lv0
  LV Name                lv0
  VG Name                exthd1Group
  LV UUID                
  LV Write Access        read/write
  LV Creation host, time N/A, 2020-02-10 14:09:35 +9999
  LV Status              available
  # open                 0
  LV Size                21.83 TiB
  Current LE             5723163
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
# ------------------------------------------------------------------ #

後はフォーマットして使うだけである。

2.6. ディスクの統合(ボリュームの初期化)

各HDDグループのボリュームに対して、ext4でフォーマットする。まずexthd1Groupのボリュームに対して。

$ sudo mkfs -t ext4 /dev/exthd1Group/lv0

同様に、exthd2Groupのボリュームに対して。

$ sudo mkfs -t ext4 /dev/exthd2Group/lv0

2.7. ディスクの統合(マウント)

まずは作成し初期化したボリュームを確認する。

$ sudo fdisk -l

# ------------------------------------------------------------------ #
Disk /dev/mapper/exthd1Group-lv0: 21.9 TiB, 24004685463552 bytes, 46884151296 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/exthd2Group-lv0: 14.6 TiB, 16003123642368 bytes, 31256100864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
# ------------------------------------------------------------------ #

しっかり出来ている。では、これらをマウントする。

$ sudo mount   /dev/exthd1Group/lv0 ./hdd1
$ sudo mount   /dev/exthd2Group/lv0 ./hdd2

もし、起動時に自動マウントさせるなら各統合HDDグループのボリュームのUUIDを確認してfstabに記述する。
まず、UUIDの確認。

$ sudo blkid /dev/exthd1Group/lv0

# ------------------------------------------------------------------ #
/dev/exthd1Group/lv0: UUID="7ii63fbf-deed-4ff1-b4af-8156f" TYPE="ext4"
# ------------------------------------------------------------------ #

同様にexthd2Groupも確認。

$ sudo blkid /dev/exthd2Group/lv0

# ------------------------------------------------------------------ #
/dev/exthd2Group/lv0: UUID="8ii63fbf-deed-4ff1-b4af-8156f" TYPE="ext4"
# ------------------------------------------------------------------ #

最後にfstabに記述する。

$ sudo vim /etc/fstab

# ------------------------------------------------------------------ #
追記
UUID=7ii63fbf-deed-4ff1-b4af-8156f     /hdd1    ext4   defaults        0 3
UUID=8ii63fbf-deed-4ff1-b4af-8156f     /hdd2    ext4   defaults        0 3
# ------------------------------------------------------------------ #

99. グループ及びPVを削除する

pvcreateを行う際に既にLVMを使った痕跡がある場合は、

$ sudo pvdisplay

で既存のディスクを確認して、PV及びそのPVがどのグループに属しているかを見る。
もしUnkownになっている場合、グループを作った後に物理デバイスが抜かれた可能性が高い。

一貫性を持たせるために以下を実行してUnkownを削除する。

$ sudo vgreduce --removemissing <YOUR_GROUP>

次にグループを削除。

$ sudo vgremove <YOUR_GROUP>

PVを削除。

$ sudo pvremove <YOUR_PV>
17
19
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
17
19