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

리눅스 VM의 루트 볼륨을 추가(증대)하기

by 3604 2023. 8. 9.
728x90

출처: VM의 루트 볼륨을 추가(증대)하기 (tistory.com)

#proxmox 호스트 머신
root@chainverse:~# qm config 112
boot: order=scsi0;ide2;net0
cores: 4
ide2: hdd:iso/CentOS-7-x86_64-Minimal-1908.iso,media=cdrom,size=942M
memory: 16384
meta: creation-qemu=7.2.0,ctime=1680057785
name: bc-node01
net0: virtio=C6:53:9B:89:EB:EC,bridge=vmbr0,firewall=1
numa: 0
ostype: l26
scsi0: hdd:107/vm-107-disk-0.qcow2,iothread=1,size=256G
scsihw: virtio-scsi-single
smbios1: uuid=12ccb4f8-a3d1-4b30-92a8-b36bbdb08765
sockets: 1
vmgenid: 1bad398c-8da4-480d-9e93-ff27552d684c
root@chainverse:~# qm resize 107 +2G
400 not enough arguments
qm disk resize <vmid> <disk> <size> [OPTIONS]
root@chainverse:~# qm resize 112 scsi0 +2G
root@chainverse:~# qm config 112
boot: order=scsi0;ide2;net0
cores: 4
ide2: hdd:iso/CentOS-7-x86_64-Minimal-1908.iso,media=cdrom,size=942M
memory: 16384
meta: creation-qemu=7.2.0,ctime=1680057785
name: bc-node01
net0: virtio=C6:53:9B:89:EB:EC,bridge=vmbr0,firewall=1
numa: 0
ostype: l26
scsi0: hdd:107/vm-107-disk-0.qcow2,iothread=1,size=258G
scsihw: virtio-scsi-single
smbios1: uuid=12ccb4f8-a3d1-4b30-92a8-b36bbdb08765
sockets: 1
vmgenid: 1bad398c-8da4-480d-9e93-ff27552d684c
root@chainverse:~#

#====== 위는 VM의 disk 크기를 증대하는 예시이다. 아래서부터는 용량을 추가한 VM에서 진행해야 한다. ==========





#1. == df -h ==

[coffee@localhost ~]$ df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             4.0M     0  4.0M   0% /dev
tmpfs                3.8G     0  3.8G   0% /dev/shm
tmpfs                1.6G  8.6M  1.5G   1% /run
/dev/mapper/rl-root   39G  1.8G   37G   5% /
/dev/sda1           1014M  217M  798M  22% /boot
/dev/mapper/rl-home   19G  165M   19G   1% /home
tmpfs                769M     0  769M   0% /run/user/0
tmpfs                769M     0  769M   0% /run/user/1000
[coffee@localhost ~]$

#2. == sudo fdisk -l ==

[coffee@localhost ~]$ sudo fdisk -l
[sudo] password for coffee:
Disk /dev/sda: 64 GiB, 68719476736 bytes, 134217728 sectors
Disk model: QEMU HARDDISK
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: 0x8316ce42

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


Disk /dev/mapper/rl-root: 38.03 GiB, 40831549440 bytes, 79749120 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/rl-swap: 6.4 GiB, 6874464256 bytes, 13426688 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/rl-home: 18.57 GiB, 19935526912 bytes, 38936576 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
[coffee@localhost ~]$

#3. == after qm resize scsi0 +2G ==

[coffee@localhost ~]$ sudo fdisk -l
Disk /dev/sda: 66 GiB, 70866960384 bytes, 138412032 sectors
Disk model: QEMU HARDDISK
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: 0x8316ce42

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


Disk /dev/mapper/rl-root: 38.03 GiB, 40831549440 bytes, 79749120 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/rl-swap: 6.4 GiB, 6874464256 bytes, 13426688 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/rl-home: 18.57 GiB, 19935526912 bytes, 38936576 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
[coffee@localhost ~]$

#4. == 블럭 디바이스 확인 ==
[coffee@localhost ~]$ lsblk -f
NAME        FSTYPE      FSVER            LABEL                UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1      xfs                                               997748d7-3f14-4b8d-ab24-0340ed496b88    797.5M    21% /boot
└─sda2      LVM2_member LVM2 001                              jWFSDI-Gc5U-6da0-TEoN-CxAL-o3AY-pYZWV9
  ├─rl-root xfs                                               9b26eaf3-a227-466b-9205-f1e37460a923     36.3G     4% /
  ├─rl-swap swap        1                                     245e34bf-ec63-4156-9faa-8b2032d158fc                  [SWAP]
  └─rl-home xfs                                               cc38ec94-adea-490d-b51c-d447665e0cdc     18.4G     1% /home
sr0         iso9660     Joliet Extension Rocky-9-1-x86_64-dvd 2022-11-19-03-31-31-00
[coffee@localhost ~]$

#지금의 인스턴스에는 디스크1개인 /dev/sda 1개로만 구성되어 있음을 확인 할 수 있다


#5. == growpart 설치 ==
[coffee@localhost ~]$ sudo yum install cloud-utils-growpart -y
[sudo] password for coffee:
Last metadata expiration check: 3:28:07 ago on Fri Apr 21 06:51:38 2023.
Dependencies resolved.
===========================================================================================================================================================================
 Package                                          Architecture                       Version                                   Repository                             Size
===========================================================================================================================================================================
Installing:
 cloud-utils-growpart                             x86_64                             0.31-10.el9                               appstream                              31 k

Transaction Summary
===========================================================================================================================================================================
Install  1 Package

Total download size: 31 k
Installed size: 63 k
Downloading Packages:
cloud-utils-growpart-0.31-10.el9.x86_64.rpm                                                                                                266 kB/s |  31 kB     00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                       44 kB/s |  31 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                   1/1
  Installing       : cloud-utils-growpart-0.31-10.el9.x86_64                                                                                                           1/1
  Running scriptlet: cloud-utils-growpart-0.31-10.el9.x86_64                                                                                                           1/1
  Verifying        : cloud-utils-growpart-0.31-10.el9.x86_64                                                                                                           1/1

Installed:
  cloud-utils-growpart-0.31-10.el9.x86_64

Complete!
[coffee@localhost ~]$


#6. == ROOT(/)가 포함되어 있는 파티션에 용량추가==
[coffee@localhost ~]$ lsblk -f
NAME        FSTYPE      FSVER            LABEL                UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1      xfs                                               997748d7-3f14-4b8d-ab24-0340ed496b88    797.5M    21% /boot
└─sda2      LVM2_member LVM2 001                              jWFSDI-Gc5U-6da0-TEoN-CxAL-o3AY-pYZWV9
  ├─rl-root xfs                                               9b26eaf3-a227-466b-9205-f1e37460a923     36.3G     4% /
  ├─rl-swap swap        1                                     245e34bf-ec63-4156-9faa-8b2032d158fc                  [SWAP]
  └─rl-home xfs                                               cc38ec94-adea-490d-b51c-d447665e0cdc     18.4G     1% /home
sr0         iso9660     Joliet Extension Rocky-9-1-x86_64-dvd 2022-11-19-03-31-31-00
[coffee@localhost ~]$

#여기서 루트 볼륨은 rl-root 이다. 따라서 sda2에 추가해 줘야 한다.

[coffee@localhost ~]$ sudo growpart /dev/sda 2 #띄어쓰기 주의
CHANGED: partition=2 start=2099200 old: size=132118528 end=134217728 new: size=136312799 end=138411999
[coffee@localhost ~]$

#7. == 볼륨그룹 확인 ==
[coffee@localhost ~]$ sudo vgdisplay
  --- Volume group ---
  VG Name               rl
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <63.00 GiB
  PE Size               4.00 MiB
  Total PE              16127
  Alloc PE / Size       16127 / <63.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               s76JwD-iKfE-nugY-UOQA-sceH-E8Ry-q1BvMZ

[coffee@localhost ~]$
#물리파티션에 용량을 추가했지만 할당하지 않아 여유 공간이 없다.

#8. == 물리파이션에 추가한 용량을 파티션에 할당 ==
[coffee@localhost ~]$ sudo pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[coffee@localhost ~]$

[coffee@localhost ~]$ sudo vgdisplay
  --- Volume group ---
  VG Name               rl
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <65.00 GiB
  PE Size               4.00 MiB
  Total PE              16639
  Alloc PE / Size       16127 / <63.00 GiB
  Free  PE / Size       512 / 2.00 GiB
  VG UUID               s76JwD-iKfE-nugY-UOQA-sceH-E8Ry-q1BvMZ

[coffee@localhost ~]$
#2.00 GiB가 추가된 것을 확인할 수 있다.

#9. == 논리볼륨(논리 파티션) 용량 확장 ==
#할당된 용량 2GB를 논리파티션 rl-root에 증설 

[coffee@localhost mapper]$ sudo lvextend -r -l +100%FREE /dev/mapper/rl-root
  Size of logical volume rl/root changed from <38.03 GiB (9735 extents) to <40.03 GiB (10247 extents).
  Logical volume rl/root successfully resized.
meta-data=/dev/mapper/rl-root    isize=512    agcount=4, agsize=2492160 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1
data     =                       bsize=4096   blocks=9968640, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=4867, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 9968640 to 10492928
[coffee@localhost mapper]$

#10. == 증설 확인 ==

[coffee@localhost mapper]$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   66G  0 disk
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   65G  0 part
  ├─rl-root 253:0    0   40G  0 lvm  /
  ├─rl-swap 253:1    0  6.4G  0 lvm  [SWAP]
  └─rl-home 253:2    0 18.6G  0 lvm  /home
sr0          11:0    1  1.5G  0 rom
[coffee@localhost mapper]$

[coffee@localhost mapper]$ df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             4.0M     0  4.0M   0% /dev
tmpfs                3.8G     0  3.8G   0% /dev/shm
tmpfs                1.6G  8.6M  1.5G   1% /run
/dev/mapper/rl-root   41G  1.8G   39G   5% /
/dev/sda1           1014M  217M  798M  22% /boot
/dev/mapper/rl-home   19G  165M   19G   1% /home
tmpfs                769M     0  769M   0% /run/user/0
tmpfs                769M     0  769M   0% /run/user/1000
[coffee@localhost mapper]$

728x90