티스토리 뷰

운영체제/Ubuntu Tip

LVM 기반 Ubuntu Disk 확장

청년정신 2019. 2. 27. 18:21
Written By whchoi / 2018-04-23

1.LVM 볼륨 확인

df를 통한 확인
root@Ubuntuv16Repo19:~# df -h
Filesystem                                   Size  Used Avail Use% Mounted on
udev                                         3.9G     0  3.9G   0% /dev
tmpfs                                        799M  9.0M  790M   2% /run
/dev/mapper/Ubuntu--v16--64bit--VM--vg-root   78G  2.1G   72G   3% /
tmpfs                                        3.9G     0  3.9G   0% /dev/shm
tmpfs                                        5.0M     0  5.0M   0% /run/lock
tmpfs                                        3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                                    472M   58M  390M  13% /boot
tmpfs                                        799M     0  799M   0% /run/user/1000
# 현재 80GB 할당 중.

fdisk를 통한 확인.
root@Ubuntuv16Repo19:~# fdisk /dev/sda

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

Command (m for help): p
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 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: 0x79a815f8

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048    999423    997376  487M 83 Linux
/dev/sda2       1001470 167770111 166768642 79.5G  5 Extended
/dev/sda5       1001472 167770111 166768640 79.5G 8e Linux LVM
# 300GB 할당 디스크 가운데 , 현재 LVM을 통해 80GB만 할당되어 있음


2.Volume Group 확인
vgs를 통한 확인
root@Ubuntuv16Repo19:~# vgs
VG                     #PV #LV #SN Attr   VSize  VFree
Ubuntu-v16-64bit-VM-vg   1   2   0 wz--n- 79.52g    0

root@Ubuntuv16Repo19:~# vgdisplay
--- Volume group ---
VG Name               Ubuntu-v16-64bit-VM-vg
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               1
Max PV                0
Cur PV                1
Act PV                1
VG Size               79.52 GiB
PE Size               4.00 MiB
Total PE              20357
Alloc PE / Size       20357 / 79.52 GiB
Free  PE / Size       0 / 0   
VG UUID               QYkJFz-milF-G9Ez-e1CN-V0aB-pzII-JDkFBH
# VG Name "Ubuntu-v16-64bit-VM-vg" 으로 80GB 할당되어 있음


3.현재 볼륨 구성확인 
pvs (Physical Volume) 를 통한 확인
root@Ubuntuv16Repo19:~# pvs
PV         VG                     Fmt  Attr PSize  PFree
/dev/sda5  Ubuntu-v16-64bit-VM-vg lvm2 a--  79.52g    0

root@Ubuntuv16Repo19:~# pvdisplay
--- Physical volume ---
PV Name               /dev/sda5
VG Name               Ubuntu-v16-64bit-VM-vg
PV Size               79.52 GiB / not usable 2.00 MiB
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              20357
Free PE               0
Allocated PE          20357
PV UUID               fNsS81-hOFx-jCBV-QL30-VjIG-g0Yh-J7ij3S
# pvs 는 /dev/sad5 할당, VG는 ""Ubuntu-v16-64bit-VM-vg"로 할당되어 있음.

lvs(Logical Volume) 를 통한 확인
root@Ubuntuv16Repo19:~# lvs
LV     VG                     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert  root   Ubuntu-v16-64bit-VM-vg -wi-ao----  78.56g                                                 
swap_1 Ubuntu-v16-64bit-VM-vg -wi-a----- 980.00m                                                    

root@Ubuntuv16Repo19:~# lvdisplay
--- Logical volume ---
LV Path                /dev/Ubuntu-v16-64bit-VM-vg/root
LV Name                root
VG Name                Ubuntu-v16-64bit-VM-vg
LV UUID                qCvyzI-rjAM-V8ie-Y6UR-iLlS-5Gl7-tt9FCr
LV Write Access        read/write
LV Creation host, time Ubuntu-v16-64bit-VM, 2018-04-20 23:48:41 +0900
LV Status              available
# open                 1
LV Size                78.56 GiB
Current LE             20112
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           252:0
--- Logical volume ---
LV Path                /dev/Ubuntu-v16-64bit-VM-vg/swap_1
LV Name                swap_1
VG Name                Ubuntu-v16-64bit-VM-vg
LV UUID                ZFIHe8-xHsG-zjIc-T0kL-JQ9x-41Pc-TIkqeL
LV Write Access        read/write
LV Creation host, time Ubuntu-v16-64bit-VM, 2018-04-20 23:48:41 +0900
LV Status              available
# open                 0
LV Size                980.00 MiB
Current LE             245
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           252:1
# LVS 내부에는 root와 swap_1 로 2개의 LV가 할당되어 있음.
# root는 78.56GB, swap은 980MB가 할당되어 있음.

VGS (Volume Group) 확인
root@Ubuntuv16Repo19:~# vgs
  VG                     #PV #LV #SN Attr   VSize  VFree
  Ubuntu-v16-64bit-VM-vg   1   2   0 wz--n- 79.52g    0
root@Ubuntuv16Repo19:~# vgdisplay
  --- Volume group ---
  VG Name               Ubuntu-v16-64bit-VM-vg
  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               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               79.52 GiB
  PE Size               4.00 MiB
  Total PE              20357
  Alloc PE / Size       20357 / 79.52 GiB
  Free  PE / Size       0 / 0   
  VG UUID               QYkJFz-milF-G9Ez-e1CN-V0aB-pzII-JDkFBH
# VGS에서도 위의 PV,LV 등의 내용을 확인 가능함.

fdisk를 통한 현재 볼륨 구성 확인
root@Ubuntuv16Repo19:~# fdisk /dev/sda

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


Command (m for help): p
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 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: 0x79a815f8

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048    999423    997376  487M 83 Linux
/dev/sda2       1001470 167770111 166768642 79.5G  5 Extended
/dev/sda5       1001472 167770111 166768640 79.5G 8e Linux LVM
# fdisk를 통해 현재 LVM 구성 확인.                                                 


4.새로운 Physical Partition 생성   

fdisk 기반 신규 Partition 생성
root@Ubuntuv16Repo19:~# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 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: 0x79a815f8

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048    999423    997376  487M 83 Linux
/dev/sda2       1001470 167770111 166768642 79.5G  5 Extended
/dev/sda5       1001472 167770111 166768640 79.5G 8e Linux LVM

Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): p
Partition number (3,4, default 3):
First sector (999424-629145599, default 999424): 167770111

Sector 167770111 is already allocated.
First sector (167770112-629145599, default 167770112): 167770112  
Last sector, +sectors or +size{K,M,G,T,P} (167770112-629145599, default 629145599):
# 현재 /dev/sda5 LVM의 End Sector 값의 다음을 설정

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

Command (m for help): t
Partition number (1-3,5, default 5): 3
Partition type (type L to list all types): L

8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         

Partition type (type L to list all types): 8e

Changed type of partition 'Linux' to 'Linux LVM'.
# 파티션을 Linux에서 LVM으로 변경

Command (m for help): p
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 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: 0x79a815f8

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048    999423    997376  487M 83 Linux
/dev/sda2         1001470 167770111 166768642 79.5G  5 Extended
/dev/sda3       167770112 629145599 461375488  220G 8e Linux LVM
/dev/sda5         1001472 167770111 166768640 79.5G 8e Linux LVM

Partition table entries are not in disk order.
# 추가된 LVM 확인 (파티션 번호 '3'으로 추가)
Command (m for help): w
# fdisk 변경 값 저장

init 6
# System Rebooting

5.LVM 기반 PV(Physical Volume) 생성

Physical Volume 생성
root@Ubuntuv16Repo19:~# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
# 신규 생성된 /dev/sd3 볼륨을 PV로 생성 

root@Ubuntuv16Repo19:~# pvs
  PV         VG                     Fmt  Attr PSize   PFree  
  /dev/sda3                         lvm2 ---  220.00g 220.00g
  /dev/sda5  Ubuntu-v16-64bit-VM-vg lvm2 a--   79.52g      0

root@Ubuntuv16Repo19:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               Ubuntu-v16-64bit-VM-vg
  PV Size               79.52 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              20357
  Free PE               0
  Allocated PE          20357
  PV UUID               fNsS81-hOFx-jCBV-QL30-VjIG-g0Yh-J7ij3S
   
  "/dev/sda3" is a new physical volume of "220.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               220.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               ZyALee-fVTR-w5lP-qjLY-LePd-8mfH-4hRR6f


6.LVM Volume Group 확장. 

vgextend를 통한 VG 확장 (VG는 "pvdisplay"를 통해 확인 가능)
root@Ubuntuv16Repo19:~# vgextend Ubuntu-v16-64bit-VM-vg /dev/sda3
  Volume group "Ubuntu-v16-64bit-VM-vg" successfully extended
# 80G로 구성된 "Ubuntu-v16-64bit-VM-vg" volume group을 Physical Volume /dev/sda3로 확장함.

root@Ubuntuv16Repo19:~# vgs
  VG                     #PV #LV #SN Attr   VSize   VFree  
  Ubuntu-v16-64bit-VM-vg   2   2   0 wz--n- 299.52g 220.00g

root@Ubuntuv16Repo19:~# vgdisplay
  --- Volume group ---
  VG Name               Ubuntu-v16-64bit-VM-vg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               299.52 GiB
  PE Size               4.00 MiB
  Total PE              76677
  Alloc PE / Size       20357 / 79.52 GiB
  Free  PE / Size       56320 / 220.00 GiB
  VG UUID               QYkJFz-milF-G9Ez-e1CN-V0aB-pzII-JDkFBH


7.LVM(Logical Volume)의 확장 

lvextend를 통해 Free Size "220GB"를 Physical Volume으로 확장
root@Ubuntuv16Repo19:~# lvextend -L+220G /dev/Ubuntu-v16-64bit-VM-vg/root /dev/sda3
  Size of logical volume Ubuntu-v16-64bit-VM-vg/root changed from 78.56 GiB (20112 extents) to 298.56 GiB (76432 extents).
  Logical volume root successfully resized.
# /dev/Ubuntu-v16-64bit-VM-vg/root를 Physical Volume /dev/sda3로 확장함.

root@Ubuntuv16Repo19:~# lvs
  LV     VG                     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root   Ubuntu-v16-64bit-VM-vg -wi-ao---- 298.56g                                                    
  swap_1 Ubuntu-v16-64bit-VM-vg -wi-ao---- 980.00m                   

root@Ubuntuv16Repo19:~# resize2fs /dev/Ubuntu-v16-64bit-VM-vg/root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/Ubuntu-v16-64bit-VM-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 19
The filesystem on /dev/Ubuntu-v16-64bit-VM-vg/root is now 78266368 (4k) blocks long.
# resize2fs를 통해 mount 및 on line resizing 구성.


8.최종 구성된 Volunme 확인 

root@Ubuntuv16Repo19:~# df -h
Filesystem                                   Size  Used Avail Use% Mounted on
udev                                         3.9G     0  3.9G   0% /dev
tmpfs                                        799M  9.0M  790M   2% /run
/dev/mapper/Ubuntu--v16--64bit--VM--vg-root  294G  2.1G  279G   1% /
tmpfs                                        3.9G     0  3.9G   0% /dev/shm
tmpfs                                        5.0M     0  5.0M   0% /run/lock
tmpfs                                        3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                                    472M   58M  390M  13% /boot
tmpfs                                        799M     0  799M   0% /run/user/1000




'운영체제 > Ubuntu Tip' 카테고리의 다른 글

samba 설정  (0) 2019.02.27
공지사항