OS/CentOS

CentOS Online LVM resize / LVM 기존 디스크 온라인 증설 (+VMware)

Lawmin 2024. 1. 10. 11:06

1. 기존 파일 시스템 용량 확인 (/dev/sda 안에 LVM 구성된 /dev/mapper/centos-root가 18G)

[root@centos7 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   25M  1.9G   2% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   18G  1.8G   17G  10% /
/dev/sda1                497M  125M  373M  26% /boot
tmpfs                    379M     0  379M   0% /run/user/0

 

2. 디스크 증설 (/dev/sda)

vSphere 에서 20GB→22GB로 증설 중

 

3. lsblk 확인 시 증설 분이 적용되지 않음 (/dev/sda가 20G, centos-root 가 있는 /dev/sda1가 19.5G)

[root@centos7 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0 19.5G  0 part 
  ├─centos-root 253:0    0 17.9G  0 lvm  /
  └─centos-swap 253:1    0  1.6G  0 lvm  [SWAP]
sr0              11:0    1 1024M  0 rom

 

4. Online 중 변경 사항 반영

[root@centos7 ~]# echo 1 > /sys/block/sda/device/rescan

 

5. lsblk 로 확인 시 증설 분 반영됨 (/dev/sda SIZE : 20G → 22G)

 

[root@centos7 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   22G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0 19.5G  0 part 
  ├─centos-root 253:0    0 17.9G  0 lvm  /
  └─centos-swap 253:1    0  1.6G  0 lvm  [SWAP]
sr0              11:0    1 1024M  0 rom

 

6. 증설할 파티션의 여유공간 확인

[root@centos7 ~]# parted -s -a opt /dev/sda "print free"
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 23.6GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  525MB   524MB   primary  xfs          boot
 2      525MB   21.5GB  20.9GB  primary               lvm
        21.5GB  23.6GB  2147MB           Free Space


7. 파티션 증설 및 여유공간이 사라진 것을 확인

[root@centos7 ~]# parted -s -a opt /dev/sda "resizepart 2 100%" "print free"
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 23.6GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  525MB   524MB   primary  xfs          boot
 2      525MB   23.6GB  23.1GB  primary               lvm


8. Physical volume 증설

[root@centos7 ~]# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

 

9. Logical volume 증설

[root@centos7 ~]# lvextend -r -l+100%FREE /dev/mapper/centos-root
  Size of logical volume centos/root changed from <17.91 GiB (4584 extents) to <19.91 GiB (5096 extents).
  Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=256    agcount=6, agsize=908800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4694016, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 4694016 to 5218304

 

10. 최종 파일 시스템 용량 확인  (/dev/mapper/centos-root가 20G로 변경됨)

[root@centos7 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   25M  1.9G   2% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   20G  1.8G   19G   9% /
/dev/sda1                497M  125M  373M  26% /boot
tmpfs                    379M     0  379M   0% /run/user/0