본문 바로가기
컴퓨터 활용(한글, 오피스 등)/50_2.운영체제_리눅스

LVM으로 구성된 ROOT 디스크 확장

by 3604 2023. 8. 9.
728x90

테스트 환경

CentOS 7.6 64bit

사용 방안

- 만약 ROOT 디스크 용량이 부족한 경우 다른 디스크를 추가하고

해당 설정을 통해 ROOT 디스크 확장이 가능합니다.

사전 준비

- ROOT Disk가 LVM으로 구성된 서버

- ROOT Disk 증설을 위한 데이터 디스크

LVM으로 구성된 ROOT 디스크 확장

- 디스크가 LVM의 형태로 구성되있는지 확인하기 위해 아래 명령을 통해 파일 시스템을 확인합니다.

- 일반적으로 LVM으로 구성되지 않은 경우 해당 디스크의 위치를 FileSystem으로 나타냅니다.

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 1.9G 16G 11% /

- 자신의 파일 시스템 경로를 복사하여 마운트 포인트와 포맷 형식을 확인합니다.

# mount | grep /dev/mapper/centos-root
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)

- 해당 마운트 포인트가 해당하고 있는 Logical Volume이 어느 것인지 아래 명령을 통해 확인합니다.

# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID cVnLK8-dIxO-oZ5x-lZ5c-VDgg-Qki0-IdcvJL
LV Write Access read/write
LV Creation host, time localhost, 2019-03-12 16:59:23 +0900
LV Status available
# open 1
LV Size <17.20 GiB
Current LE 4404
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

- 해당 명령을 통해 자신이 마운트한 디스크가 어떤 형태인지 확인합니다. (xvda2 디스크가 Linux LVM 형태로 되있습니다.)

- 저는 미리 100GB 디스크를 준비하여 확장을 준비한 상태로 사진 상에 /dev/xvdb 경로에 디스크가 상주된 것을 확인할 수 있습니다.

# fdisk -l
Disk /dev/xvda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b2185
Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 1953791 975872 83 Linux
/dev/xvda2 1953792 41943039 19994624 8e Linux LVM
Disk /dev/mapper/centos-root: 125.8 GB, 125841702912 bytes, 245784576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 2000 MB, 2000683008 bytes, 3907584 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/xvdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

- fdisk에서 디스크의 파티션을 설정한 뒤 디스크 타입을 Linux에서 Linux LVM으로 변경 후 저장합니다.

# fdisk /dev/xvdb
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 0x9eb0f2e7.
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): 1 <= 입력
First sector (2048-209715199, default 2048): <= Enter 입력
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): <= Enter 입력
Partition 1 of type Linux and of size 100 GiB is set
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): w <= 입력
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

- 위에서 파티셔닝된 디스크를 물리 볼륨으로 선언해줍니다.

# pvcreate /dev/xvdb1

- 물리 볼륨으로 정상적으로 선언됐는지 확인합니다.

# pvscan

-현재 볼륨 그룹이 어떤 구성으로 설정되있는지 확인합니다.

# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <19.07 GiB
PE Size 4.00 MiB
Total PE 4881
Alloc PE / Size 4881 / <19.07 GiB
Free PE / Size 0 / 0
VG UUID oXZj4O-pKmL-PWqm-BFID-doSQ-oWiw-82eGaU

- 위에서 확인한 ROOT 디스크가 위치한 볼륨 그룹에 ROOT 디스크를 증설하기 위해 추가한 디스크를 추가합니다.

# vgextend centos /dev/xvdb1

- 볼륨 그룹에 정상적으로 디스크가 추가됐는지 확인합니다. (가장 큰 변화는 용량의 변화입니다.)

# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <119.06 GiB
PE Size 4.00 MiB
Total PE 4881
Alloc PE / Size 4881 / <19.07 GiB
Free PE / Size 25599 / <100.00 GiB​
Free PE / Size 0 / 0
VG UUID oXZj4O-pKmL-PWqm-BFID-doSQ-oWiw-82eGaU

- 논리 볼륨에 해당 디스크의 남은 공간을 추가해줍니다.

- 중간에 내용은 초반에 확인하였던 df -h에서 확인된 LVM 디스크의 경로를 입력합니다.

- vgdisplay를 통해 확인한 Free PE를 + 값에 입력합니다. (저는 25599로 해당 값을 추가합니다.)

- 여기서 추가되더라도 아직 실제 용량에는 정상 적용이 되지 않은 상태입니다.

# lvextend /dev/centos/root -l +25599
Size of logical volume centos/root changed from 17.20 GiB (4404 extents) to <117.20 GiB (30003 extents).
Logical volume centos/root successfully resized.

- 저는 xfs 포맷으로 디스크가 설정되있으므로 xfs_growfs 명령을 통해 resize 하겠습니다.

# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1127424 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4509696, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
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 4509696 to 30723072
※ 만약 디스크 포맷이 xfs 포맷이 아니라 ext4 포맷이라면 다른 명령을 통해 진행해야합니다.
해당 명령은 아래와 같은 resize를 진행할 때 참고하여 작업 부탁드립니다.
# resize2fs [해당 디스크 위치]

- 정상적으로 reisizing이 됐다면 위와 같이 디스크 용량이 확장되어 표기 및 사용 가능합니다.

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 118G 1.9G 116G 2% /
728x90