CentOSを起動したままパーティションとlvmとfsを拡張

こんばんにちは

仮想マシンでのディスク容量拡張やVPSのスケールアップなどで,システムがブートしているファイルシステムをそのシステム上から拡張したくなることがあります.

以前,Ubuntuで同様のことを記事にしております.

今回は,CentOSでインストール時に標準で選択される論理ボリュームを使用した構成になります.

なお,swapのサイズは変更しません.

続きをどうぞ.

最初に

sakura3 ~ % cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)

※ 以下,関係ないディスク等はコマンド実行結果から省いています.

変更前

25GBのディスク

sakura3 ~ % df -h
ファイルシス                サイズ  使用  残り 使用% マウント位置
/dev/mapper/centos_***-root    23G   14G  8.9G   61% /
/dev/vda1                     497M  259M  238M   53% /boot

sakura3 ~ % sudo fdisk -l

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

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    52428799    25701376   83  Linux

Disk /dev/mapper/centos_***-root: 24.2 GB, 24167579648 bytes, 47202304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト


Disk /dev/mapper/centos_***-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト

sakura3 ~ % sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos_***/swap
  LV Name                swap
  VG Name                centos_***
  LV UUID                ******-****-****-****-****-****-******
  LV Write Access        read/write
  LV Creation host, time ********.**.**, 2018-01-12 13:23:40 +0900
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos_***/root
  LV Name                root
  VG Name                ***
  LV UUID                ******-****-****-****-****-****-******
  LV Write Access        read/write
  LV Creation host, time ********.**.**, 2018-01-12 13:23:41 +0900
  LV Status              available
  # open                 1
  LV Size                

パーティションのリサイズ

論理ボリュームが乗っている /dev/vda2 をディスクいっぱいまで拡張します.

sakura3 ~ % sudo parted /dev/vda
GNU Parted 3.1
/dev/vda を使用
GNU Parted へようこそ! コマンド一覧を見るには 'help' と入力してください。
(parted) print
モデル: Virtio Block Device (virtblk)
ディスク /dev/vda: 107GB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: msdos
ディスクフラグ:

番号  開始    終了    サイズ  タイプ   ファイルシステム  フラグ
 1    1049kB  525MB   524MB   primary  xfs               boot
 2    525MB   26.8GB  26.3GB  primary

(parted) resizepart 2
終了?  [26.8GB]? 100%
(parted) print
モデル: Virtio Block Device (virtblk)
ディスク /dev/vda: 107GB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: msdos
ディスクフラグ:

番号  開始    終了   サイズ  タイプ   ファイルシステム  フラグ
 1    1049kB  525MB  524MB   primary  xfs               boot
 2    525MB   107GB  107GB   primary

(parted) quit
通知: 必要であれば /etc/fstab を更新するのを忘れないようにしてください。

sakura3 ~ % sudo fdisk -l

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

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048   209715199   104344576   83  Linux

Disk /dev/mapper/centos_***-root: 24.2 GB, 24167579648 bytes, 47202304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト


Disk /dev/mapper/centos_***-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト

物理ボリュームのリサイズ

リサイズしたパーティションに合わせて物理ボリュームをリサイズします.

sakura3 ~ % sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda2
  VG Name               centos_***
  PV Size               

論理ボリュームとファイルシステムのリサイズ

論理ボリュームをリサイズします.同時にファイルシステムをリサイズすることが出来ます.

sakura3 ~ % sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos_***/swap
  LV Name                swap
  VG Name                centos_***
  LV UUID                ******-****-****-****-****-****-******
  LV Write Access        read/write
  LV Creation host, time ********.**.**, 2018-01-12 13:23:40 +0900
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos_***/root
  LV Name                root
  VG Name                centos_***
  LV UUID                ******-****-****-****-****-****-******
  LV Write Access        read/write
  LV Creation host, time ********.**.**, 2018-01-12 13:23:41 +0900
  LV Status              available
  # open                 1
  LV Size                

結果

sakura3 ~ % df -h
ファイルシス                サイズ  使用  残り 使用% マウント位置
/dev/mapper/centos_***-root    98G   14G   84G   15% /
/dev/vda1                     497M  259M  238M   53% /boot

まとめ

一度も再起動してないです.

簡単すぎて驚きました...

参考

【 lvextend 】コマンド――論理ボリュームのサイズを拡張する:Linux基本コマンドTips(343) - @IT

SNSでもご購読できます。

コメント

コメントを残す

*

モバイルバージョンを終了