CentOS Stream 10
Sponsored Link

LVM : 論理ボリュームの操作2024/12/27

 

論理ボリュームの基本的な操作方法です。
事前にボリュームグループを作成しておく必要があります

[1] 論理ボリュームを作成する。
# 論理ボリューム [lv_data] を ボリュームグループ [vg_dlp] に [30G] の容量で作成

[root@dlp ~]#
lvcreate -L 30G -n lv_data vg_dlp

  Logical volume "lv_data" created.

# 空き容量を全て割り当てる場合は以下のように指定

[root@dlp ~]#
lvcreate -l 100%FREE -n lv_data vg_dlp

  Logical volume "lv_data" created
[2] 論理ボリュームを表示する。
[root@dlp ~]#
lvdisplay /dev/vg_dlp/lv_data

  --- Logical volume ---
  LV Path                /dev/vg_dlp/lv_data
  LV Name                lv_data
  VG Name                vg_dlp
  LV UUID                n3MJsW-tL2e-o7yS-MVLs-s0CR-11zf-ZrJCvw
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2024-12-27 09:31:38 +0900
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
[3] 論理ボリュームの名前を変更する。
# [lv_data] から [lv_storage] に変更

[root@dlp ~]#
lvrename vg_dlp lv_data lv_storage

  Renamed "lv_data" to "lv_storage" in volume group "vg_dlp"

[root@dlp ~]#
lvdisplay /dev/vg_dlp/lv_storage

  --- Logical volume ---
  LV Path                /dev/vg_dlp/lv_storage
  LV Name                lv_storage
  VG Name                vg_dlp
  LV UUID                n3MJsW-tL2e-o7yS-MVLs-s0CR-11zf-ZrJCvw
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2024-12-27 09:31:38 +0900
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
[4] 論理ボリュームのレポートを出力する。
[root@dlp ~]#
lvs

  LV         VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home       cs     -wi-ao---- <23.34g
  root       cs     -wi-ao----  47.79g
  swap       cs     -wi-ao----  <7.87g
  lv_storage vg_dlp -wi-a-----  30.00g
[5] 論理ボリュームをスキャンする。
[root@dlp ~]#
lvscan

  ACTIVE            '/dev/cs/swap' [<7.87 GiB] inherit
  ACTIVE            '/dev/cs/home' [<23.34 GiB] inherit
  ACTIVE            '/dev/cs/root' [47.79 GiB] inherit
  ACTIVE            '/dev/vg_dlp/lv_storage' [30.00 GiB] inherit
[6] 論理ボリュームのスナップショットを取得する。
# [lv_storage] のスナップショットを [snap-lv_storage] という名前で作成

[root@dlp ~]#
lvcreate -s -L 30G -n snap-lv_storage /dev/vg_dlp/lv_storage

  Logical volume "snap-lv_storage" created.

[root@dlp ~]#
lvdisplay /dev/vg_dlp/lv_storage /dev/vg_dlp/snap-lv_storage

  --- Logical volume ---
  LV Path                /dev/vg_dlp/lv_storage
  LV Name                lv_storage
  VG Name                vg_dlp
  LV UUID                n3MJsW-tL2e-o7yS-MVLs-s0CR-11zf-ZrJCvw
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2024-12-27 09:31:38 +0900
  LV snapshot status     source of
                         snap-lv_storage [active]
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

  --- Logical volume ---
  LV Path                /dev/vg_dlp/snap-lv_storage
  LV Name                snap-lv_storage
  VG Name                vg_dlp
  LV UUID                yb1udq-7ba2-TJAd-Pitk-fYlV-3mVz-zRsgkT
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2024-12-27 09:40:00 +0900
  LV snapshot status     active destination for lv_storage
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  COW-table size         30.00 GiB
  COW-table LE           7680
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:6
[7] 論理ボリュームを拡張する。
運用中にマウントしたまま実行可能です。
[root@dlp ~]#
lvextend -L 50G /dev/vg_dlp/lv_storage

  Size of logical volume vg_dlp/lv_storage changed from 30.00 GiB (7680 extents) to 50.00 GiB (12800 extents).
  Logical volume vg_dlp/lv_storage successfully resized.

[root@dlp ~]#
lvdisplay /dev/vg_dlp/lv_storage

  --- Logical volume ---
  LV Path                /dev/vg_dlp/lv_storage
  LV Name                lv_storage
  VG Name                vg_dlp
  LV UUID                n3MJsW-tL2e-o7yS-MVLs-s0CR-11zf-ZrJCvw
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2024-12-27 09:31:38 +0900
  LV Status              available
  # open                 0
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

# ファイルシステムが存在している場合はサイズ拡張 (マウントポイントを指定)
# [xfs] ファイルシステムの場合

[root@dlp ~]#
xfs_growfs /mnt

meta-data=/dev/mapper/vg_dlp-lv_storage isize=512    agcount=4, agsize=1966080 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=1
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=1
         =                       exchange=0
data     =                       bsize=4096   blocks=7864320, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1, parent=0
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 7864320 to 13107200
[8] 論理ボリュームを縮小する。
対象デバイスをマウントしている場合は事前にマウント解除しておく。
対象の論理ボリュームに [xfs] ファイルシステムを作成している場合の縮小は不可です。
縮小したい場合は論理ボリュームを 削除 ⇒ 再作成 の流れになります。
# [ext4] の場合はファイルシステムをチェック

[root@dlp ~]#
e2fsck -f /dev/vg_dlp/lv_storage

e2fsck 1.47.1 (20-May-2024)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg_dlp/lv_storage: 11/3276800 files (0.0% non-contiguous), 251751/13107200 blocks

# [ext4] の場合はファイルシステムを縮小

[root@dlp ~]#
resize2fs /dev/vg_dlp/lv_storage 30G

resize2fs 1.47.1 (20-May-2024)
Resizing the filesystem on /dev/vg_dlp/lv_storage to 7864320 (4k) blocks.
The filesystem on /dev/vg_dlp/lv_storage is now 7864320 (4k) blocks long.

# 論理ボリュームを縮小

[root@dlp ~]#
lvreduce -L 30G /dev/vg_dlp/lv_storage

  File system ext4 found on vg_dlp/lv_storage.
  File system size (30.00 GiB) is equal to the requested size (30.00 GiB).
  File system reduce is not needed, skipping.
  Size of logical volume vg_dlp/lv_storage changed from 50.00 GiB (12800 extents) to 30.00 GiB (7680 extents).
  Logical volume vg_dlp/lv_storage successfully resized.
[9] 論理ボリュームを削除する。
マウント解除 ⇒ 対象論理ボリューム停止 ⇒ 削除 の流れで実行する。
[root@dlp ~]#
lvchange -an /dev/vg_dlp/lv_storage

[root@dlp ~]#
lvremove /dev/vg_dlp/lv_storage

  Logical volume "lv_storage" successfully removed
関連コンテンツ