지난번에 이어 LVM시스템에 디스크(볼륨)를 추가 확장 하는 방법을 해보겠습니다.
볼륨(20G) 추가하여 현재 /home 파티션(70G)을 확장 하는 방법을 알아 보겠습니다.

1. 기존 디스크 확장

물리장치(sdb) 또는 볼륨 추가 후 표시 용량이 설정한(20G) 용량으로 표시되어야 합니다. 용량에 변화가 변화가 없으면 재부팅 합니다.

# lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0                     2:0    1    4K  0 disk
sda                     8:0    0  100G  0 disk
sda1                  8:1    0    1G  0 part /boot
sda2                  8:2    0   30G  0 part /
sda3                  8:3    0   69G  0 part
vg--home-lv--home 253:0    0   69G  0 lvm  /home
sdb                     8:16   0   20G  0 disk

2. 파티션 생성

/dev/sdb에 sdb1파트션을 만들고 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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x49a98a24.
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.

Command (m for help):
Command (m for help): n
Partition type:

   p   primary (0 primary, 0 extended, 4 free)
   e   extended
   
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos
Disk identifier: 0x49a98a24

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    41943039    20970496   83  Linux

Command (m for help):
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos
Disk identifier: 0x49a98a24

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    41943039    20970496   8e  Linux LVM

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

3. PV 생성

pvcreate 로 물리 볼륨 생성 및 pvdisplay 으로 확인 합니다.
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.

[root@localhost ~]# pvdisplay

  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               vg-home
  PV Size               <69.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              17663
  Free PE               0
  Allocated PE          17663
  PV UUID               dFUFjg-ETp6-aCkV-UHpw-HpP7-e40T-7L00p3
  "/dev/sdb1" is a new physical volume of "<20.00 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sdb1
  VG Name              
  PV Size               <20.00 GiB
  Allocatable           NO
  PE Size               0  
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               VjYTMM-ECCZ-GWrd-WpNS-OxMI-qYns-pnEr9x

4. VG 확장

기존 볼륨 그룸 확인 하고 vgextend로 볼륨 그룹을 확장합니다.
볼륨 정보 확인

# vgdisplay

  --- Volume group ---

  VG Name               vg-home
  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               <69.00 GiB
  PE Size               4.00 MiB
  Total PE              17663
  Alloc PE / Size       17663 / <69.00 GiB
  Free  PE / Size       0 / 0 
  VG UUID               MESw3F-j0gs-yzOo-bwR9-34nn-u0dP-qHOHEC

추가 볼륨을 확장

[root@localhost ~]# vgextend vg-home /dev/sdb1

  Volume group "vg-home" successfully extended

볼륨확장 후 정보 확인

[root@localhost ~]# vgdisplay

  --- Volume group ---

  VG Name               vg-home
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               88.99 GiB
  PE Size               4.00 MiB
  Total PE              22782
  Alloc PE / Size       17663 / <69.00 GiB
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               MESw3F-j0gs-yzOo-bwR9-34nn-u0dP-qHOHEC

5. LV 확장 (lvextend)

lvdisplay로 물리 볼륨을 확인한다.

# lvdisplay

  --- Logical volume ---

  LV Path                /dev/vg-home/lv-home
  LV Name                lv-home
  VG Name                vg-home
  LV UUID                AY0b7g-L0pN-DrTm-Lhgb-vqU5-T2W1-0cFe4e
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2022-05-11 16:20:59 +0900
  LV Status              available
  # open                 1
  LV Size                <69.00 GiB
  Current LE             17663
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

6. 리사이즈 (resize2fs )

작업전 용량 확인

[root@localhost ~]# df -h
Filesystem                     Size  Used Avail Use% Mounted on

/dev/sda2                       30G  1.3G   29G   5% /
devtmpfs                       484M     0  484M   0% /dev
tmpfs                          493M     0  493M   0% /dev/shm
tmpfs                          493M   19M  474M   4% /run
tmpfs                          493M     0  493M   0% /sys/fs/cgroup
/dev/sda1                     1014M  140M  875M  14% /boot
/dev/mapper/vg--home-lv--home   68G   55M   65G   1% /home

현재 작업하는 파티션 파일시스템 종류 확인 해보고 맞는 것으로 진행 하면 됩니다.

xfs인 경우 -> xfs_growfs
ext4 인 경우 -> resize2fs

파일시스템 종류 확인

[root@localhost ~]# blkid /dev/vg-home/lv-home

/dev/vg-home/lv-home: UUID="c29e7a45-dc2f-46b0-9f9a-62aa7e17ad07" TYPE="ext4"

[root@localhost ~]# resize2fs /dev/vg-home/lv-home

resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg-home/lv-home is mounted on /home; on-line resizing required
old_desc_blocks = 9, new_desc_blocks = 12
The filesystem on /dev/vg-home/lv-home is now 23328768 blocks long.

[root@localhost ~]# resize2fs /dev/vg-home/lv-home

resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg-home/lv-home is mounted on /home; on-line resizing required
old_desc_blocks = 9, new_desc_blocks = 12
The filesystem on /dev/vg-home/lv-home is now 23328768 blocks long.

7. 용량 확인

# /home 파티션에 추가된 용량 확인 됩니다.

[root@localhost ~]# df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/sda2                       30G  1.3G   29G   5% /
devtmpfs                       484M     0  484M   0% /dev
tmpfs                          493M     0  493M   0% /dev/shm
tmpfs                          493M   19M  474M   4% /run
tmpfs                          493M     0  493M   0% /sys/fs/cgroup
/dev/sda1                     1014M  140M  875M  14% /boot
/dev/mapper/vg--home-lv--home   88G   59M   84G   1% /home
image_print

호스트웨이 시스템 팀

호스트웨이 시스템1팀