리눅스 가상머신 루트 볼륨 용량 증설

김건호·2024년 5월 8일

개요

테스트환경 VM / 가 100% 다 쓰고 있어서 증설을 한 번 해보겠습니다
가상머신 관리 페이지에서 디스크는 추가한 상태입니다
sda장치에는 200G로 늘어났지만 아직 / 에는 할당되지 않았습니다

➜  ~ lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0  200G  0 disk
├─sda1              8:1    0    1G  0 part /boot
└─sda2              8:2    0   99G  0 part
  └─prolinux-root 253:0    0   99G  0 lvm  /
sr0                11:0    1   10G  0 rom

fdisk -l로 보면 가용량이 200 GiB인 것을 확인할 수 있습니다

➜  ~ fdisk -l
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 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
Disklabel type: dos
Disk identifier: 0x3f9231de

Device     Boot   Start       End   Sectors Size Id Type
/dev/sda1  *       2048   2099199   2097152   1G 83 Linux
/dev/sda2       2099200 209715199 207616000  99G 8e Linux LVM


Disk /dev/mapper/prolinux-root: 99 GiB, 106296246272 bytes, 207609856 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

그치만 아직 /는 100G입니다

➜  ~ df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   7.8G     0  7.8G   0% /dev
tmpfs                      7.8G     0  7.8G   0% /dev/shm
tmpfs                      7.8G   17M  7.8G   1% /run
tmpfs                      7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/prolinux-root   99G   99G  168K 100% /

파티션 추가

➜  ~ fdisk /dev/sda

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 1
Value out of range.
Partition number (3,4, default 3): 3
First sector (209715200-419430399, default 209715200):
Last sector, +sectors or +size{K,M,G,T,P} (209715200-419430399, default 419430399):

Created a new partition 3 of type 'Linux' and of size 100 GiB.

Command (m for help): w
The partition table has been altered.
Syncing disks.

n : 파티션 추가
p : primary 파티션 추가
3 : 파티션 번호 ( sda3 )

파티션 확인

sda3가 추가 되었습니다

➜  ~ lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0  200G  0 disk
├─sda1              8:1    0    1G  0 part /boot
├─sda2              8:2    0   99G  0 part
│ └─prolinux-root 253:0    0   99G  0 lvm  /
└─sda3              8:3    0  100G  0 part
sr0                11:0    1   10G  0 rom

LVM 초기화

초기화를 위해 가상머신을 재기동합니다

물리 볼륨 추가

➜  ~ pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
➜  ~ pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               prolinux
  PV Size               <99.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              25343
  Free PE               0
  Allocated PE          25343
  PV UUID               4Ie3ld-r4MG-5BXG-cKZV-sqna-Z6AB-QwMi1E

  "/dev/sda3" is a new physical volume of "100.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name
  PV Size               100.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               uFf0F8-a7cb-Lp89-wSbe-1v3p-cA6i-EsS9ql
➜  ~ vgextend prolinux /dev/sda3
  Couldn't create temporary archive name.

루트 볼륨 그룹 확장

➜  ~ vgextend prolinux /dev/sda3
  Volume group "prolinux" successfully extended

루트 논리 볼륨 확장

➜  ~ lvextend --size +99GB --resizefs /dev/prolinux/root
  Size of logical volume prolinux/root changed from <99.00 GiB (25343 extents) to <198.00 GiB (50687 extents).
  Logical volume prolinux/root successfully resized.
meta-data=/dev/mapper/prolinux-root isize=512    agcount=4, agsize=6487808 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=25951232, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=12671, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 25951232 to 51903488

확장 및 파일 시스템 크기 변경

➜  ~ lvextend /dev/prolinux/root -l+100%FREE
  Size of logical volume prolinux/root changed from <198.00 GiB (50687 extents) to 198.99 GiB (50942 extents).
  Logical volume prolinux/root successfully resized.
➜  ~ lvextend -l+100%FREE --resize /dev/prolinux/root
  Size of logical volume prolinux/root unchanged from 198.99 GiB (50942 extents).
  Logical volume prolinux/root successfully resized.
meta-data=/dev/mapper/prolinux-root isize=512    agcount=9, agsize=6487808 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=51903488, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=12671, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 51903488 to 52164608

루트 디스크 용량 확인

➜  ~ df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   7.8G     0  7.8G   0% /dev
tmpfs                      7.8G     0  7.8G   0% /dev/shm
tmpfs                      7.8G   33M  7.7G   1% /run
tmpfs                      7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/prolinux-root  199G   66G  134G  34% /
/dev/sda1                 1014M  217M  798M  22% /boot
profile
네.. 뭐.. 김건호입니다...

0개의 댓글