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 3 years have passed since last update.

LVMによるディスク拡張

Last updated at Posted at 2020-04-09

よくやることなのですが、シビアの作業ですし私流のやり方をまとめます
いろんな人が本件について記事書いていますので参考にさせていただいています。

環境

  • CentOS 7.7
  • Vmware vSphere 6.5

大まかな流れ

  1. fdiskによる現状の確認
  2. vmwareでディスク容量変更
  3. リブート(いらない場合もある)
  4. パーティションの再作成
  5. 物理ディスク領域の拡張(pv)
  6. 論理ボリュームの拡張(lv)
  7. ファイルシステムの拡張

ルートディレクトリも拡張できますが、その場合OSは別のところから起動して拡張します。

fdiskで最初に確認する

セクタ数とか初めに覚えておき、Vmware上で増やしたときに認識しているか確認します

# df
/dev/mapper/VolGroup00-lv    40G   35G  5.6G   87% /var/lib

# fdisk -l /dev/sdb
Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xf18db91f
# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <40.00 GiB
  PE Size               4.00 MiB
  Total PE              10239
  Alloc PE / Size       10239 / <40.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               iHNhqq-rSIc-vqFd-QZ7f-PYzq-rwQm-ahM0DC

Vmware でディスクの拡張

省略

  • シンプロビジョニングでないといけないのかもしれない

fdiskで確認し、容量とセクタが増えていることを確認する

# fdisk -l /dev/sdb
Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xf18db91f

パーティションの再作成

デカイディスクの場合partdを使用すること
Linux LVM であることも確認。
慎重に

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.


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

Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xf18db91f
デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048    83886079    41942016   8e  Linux LVM

コマンド (m でヘルプ): d
Selected partition 1
Partition 1 is deleted

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

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

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

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

コマンド (m でヘルプ): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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

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

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048   167772159    83885056   8e  Linux LVM

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

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

WARNING: Re-reading the partition table failed with error 16: デバイスもしくはリソースがビジー状態です.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
ディスクを同期しています。

使っているとWARNINGが出る。 メッセージによると partprobe、kpartxでもいいみたいだが、今回は停止できるのでリブートする

物理ディスク領域の拡張

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               VolGroup00
  PV Size               <40.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              10239
  Free PE               0
  Allocated PE          10239
  PV UUID               HW1JuI-q9uI-j8P4-SpFQ-D6rr-qN6x-nutLne

# pvresize /dev/sdb1
  Physical volume "/dev/sdb1" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               VolGroup00
  PV Size               <80.00 GiB / not usable 2.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              20479
  Free PE               10240
  Allocated PE          10239
  PV UUID               HW1JuI-q9uI-j8P4-SpFQ-D6rr-qN6x-nutLne

論理ボリュームの拡張

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup00/lv
  LV Name                lv
  VG Name                VolGroup00
  LV UUID                LOk62t-BiPS-p33o-wa8F-q3yT-akTO-xUNTQ0
  LV Write Access        read/write
  LV Creation host, time hostname, 2019-11-07 14:48:12 +0900
  LV Status              available
  # open                 1
  LV Size                <40.00 GiB
  Current LE             10239
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

# lvextend -l +100%FREE /dev/VolGroup00/lv
  Size of logical volume VolGroup00/lv changed from <40.00 GiB (10239 extents) to <80.00 GiB (20479 extents).
  Logical volume VolGroup00/lv successfully resized.

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup00/lv
  LV Name                lv
  VG Name                VolGroup00
  LV UUID                LOk62t-BiPS-p33o-wa8F-q3yT-akTO-xUNTQ0
  LV Write Access        read/write
  LV Creation host, time hostname, 2019-11-07 14:48:12 +0900
  LV Status              available
  # open                 1
  LV Size                <80.00 GiB
  Current LE             20479
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

# df -h
ファイルシス                       サイズ  使用  残り 使用% マウント位置
/dev/mapper/VolGroup00-lv    40G   35G  5.6G   87% /var/lib

ファイルシステムの拡張

# xfs_growfs /var/lib
meta-data=/dev/mapper/VolGroup00-lv isize=512    agcount=4, agsize=2621184 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=10484736, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=5119, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 10484736 to 20970496
# df -h
ファイルシス                       サイズ  使用  残り 使用% マウント位置
/dev/mapper/VolGroup00-lv    80G   35G   46G   44% /var/lib

ext3ファイルシステムの場合
e2fsck を行ってから resize2fsを行う

# e2fsck /dev/sdc1
# resize2fs /dev/sdc1

参考URL等

みなさまのWebの記事

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?