[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

LVMを使ってCentOS7にディスクを追加する

こんにちは。
開発チームのワイルド担当、まんだいです。

vSphere上に作った開発サーバーのディスクが足りなくなったので、LVMでディスク拡張する作業をしてみました。

(検索すればすぐに見つかるので)fdiskを使った作業の先を重点的に書いています。

 

vSphere上で割り当てるディスクサイズを変更

まず、vSphereで割り当てのディスク割り当てをする必要があります。

VMの設定画面から、設定の編集をクリックしていきます。

VMの設定画面

ポップアップされた画面の左側からハードディスクの項目を選び、プロビジョニング済みサイズを調整します。

ディスクサイズの設定

仮想マシンの再構成が実行され、完了すればマシンに新しいディスクを繋いだ状態になります。
とりあえずここで、VMを再起動しておきます。

 

新しいパーティションを作成する

先の作業で追加したディスクにパーティションを作成していきます。

パーティションの作り方はこちらの通りに進めていくとよろしいかと。
こちらのページは、今回の作業と同じ内容なので、こちらを参考にしていただいても支障ないですが、LVMに追加する辺りがあっさりしているので、私が次の項でこってり書きたいとおもいます。

 

LVMを利用して拡張する

初めてディスク追加した場合、/dev/sda3というパーティションが作成されていると思いますので、今回LVMに拡張したいパーティションは/dev/sda3ということにします。
こちらは環境に依存するので、適宜読み替えてください。

まずは、pvcreateコマンドで追加したパーティションをLVMを物理ボリュームとして初期化します。

# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created

 

続いて、pvdisplayコマンドで、追加するボリュームグループ(VG)を確認します。

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               cl
  PV Size               15.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              3839
  Free PE               0
  Allocated PE          3839
  PV UUID               N2FEPJ-GjMb-D3OM-8sAE-CeHW-SKHu-KdlyWe

 

「VG Name」という項目が空き容量を増やしたいVGの名前になります。
この例では、「cl」というのがVGの名前になります。

次に、vgextendコマンドでclに/dev/sda3を追加して拡張します。

# vgextend cl /dev/sda3
  Volume group "cl" successfully extended

 

これでclに/dev/sda3が追加されました。
ですが、この時点で利用できるディスク容量が増えた訳ではないので、lvextendコマンドで論理ボリュームを拡張します。

lvdisplayコマンドで拡張する論理ボリューム(LV)の確認を行います。

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                yroqAX-k0kh-6NyT-IUaZ-50v3-nZjX-7thw7Y
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-10-05 00:02:04 +0900
  LV Status              available
  # open                 1
  LV Size                13.39 GiB
  Current LE             3429
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                0Eh5Ss-mFH1-GVME-rfJl-mGR6-hNed-AtHfxo
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-10-05 00:02:11 +0900
  LV Status              available
  # open                 2
  LV Size                1.60 GiB
  Current LE             410
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

 

システム上に存在するLVが全て表示されますので、容量を増やしたいLVを探します。
今回は、rootというLVの容量を増やしてみます。

それでは改めてlvextendコマンドを流してみます。

# lvextend -l +100%FREE /dev/cl/root
  Size of logical volume cl/root changed from 13.39 GiB (3429 extents) to 97.39 GiB (24932 extents).
  Logical volume cl/root successfully resized.

 

lvextendコマンドは、-Lオプションで拡張するサイズを指定できます。
今回のように、LVに登録されたVGをすべて拡張する場合は、「-l +100%FREE」とします。

最後にファイルシステムの拡張ですが、CentOS7の場合は、xfs_growfsコマンドを使って拡張します。

# xfs_growfs /dev/cl/root
meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=877824 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=3511296, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 3511296 to 25530368

 

lvmdiskscanコマンドでうまくいったか確認します。

# lvmdiskscan
  /dev/cl/root [      97.39 GiB]
  /dev/sda1    [       1.00 GiB]
  /dev/cl/swap [       1.60 GiB]
  /dev/sda2    [      15.00 GiB] LVM physical volume
  /dev/sda3    [      84.00 GiB] LVM physical volume
  2 disks
  1 partition
  0 LVM physical volume whole disks
  2 LVM physical volumes

 

/dev/cl/rootが今回の作業対象LVですが、うまく拡張できているようです。

以上で、ディスク追加が完了しました。
dfコマンドで空き容量を確認してみると、

# df -h
ファイルシス        サイズ  使用  残り 使用% マウント位置
/dev/mapper/cl-root    98G   14G   85G   14% /
devtmpfs              486M     0  486M    0% /dev
tmpfs                 497M     0  497M    0% /dev/shm
tmpfs                 497M  6.7M  490M    2% /run
tmpfs                 497M     0  497M    0% /sys/fs/cgroup
/dev/sda1            1014M  139M  876M   14% /boot
tmpfs                 100M     0  100M    0% /run/user/0
tmpfs                 100M     0  100M    0% /run/user/1000

 

となっており、無事増えているのがわかります。

 

まとめ

今回は、LVMを使った仮想ディスクの追加作業でしたが、これが物理ディスクだったとしても、作業内容は変わりません。
今回の記事は、作業自体は検索すればすぐに出てくる内容ですが、pvdisplay、vgdisplay、lvdisplayの見た目の区別が付かなかった自分(そろそろ老眼なのか、な...)に対する戒めのようなものです。

 
以上です。

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
0
読み込み中...
0 票, 平均: 0.00 / 10
6,558
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Yoichi Bandai

My main job is developing web APIs for social games, but I'm also fortunate to be able to do a lot of other work, including marketing.
Furthermore, my portrait rights in Beyond are treated as CC0 by him.