본문 바로가기

Work/Linux(6.x)_centos

Linux LVM ( Logical Volume Manager )

@@@ 리눅스 LVM

1. VG

 : Volume Group ( 물리적 볼륨이 모여서 하나의 VG 를 생성 )

2. LV

  : Logical Volume ( 이 논리적 볼륨이 우리가 흔히 사용하는 일반적인 파티션 ) 

3. PV 

  : Physical Volume ( 실제로 나눈 파티션 /dev/sda1, /dev/sda2 ) 

4. PE

  : 일종의 블록 같은 것


5. fdisk /dev/sdf

/dev/sdf1               1         510     3905039   83  Linux

/dev/sdf2             511        1020     3905070   83  Linux


Command (m for help): m

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel


   t   change a partition's system id


   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)


Command (m for help): t

Partition number (1-4): 2

Hex code (type L to list codes): 8e

Changed system type of partition 2 to 8e (Linux LVM)


Command (m for help): p


Disk /dev/sdf: 8004 MB, 8004304896 bytes

247 heads, 62 sectors/track, 1020 cylinders

Units = cylinders of 15314 * 512 = 7840768 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x356f4383


   Device Boot      Start         End      Blocks   Id  System

/dev/sdf1               1         510     3905039   8e  Linux LVM

/dev/sdf2             511        1020     3905070   8e  Linux LVM



6. PV 생성


# pvcreate /dev/sdf1

# pvcreate /dev/sdf2



7. # pvscan

  PV /dev/sda2   VG vg_volume       lvm2 [465.27 GiB / 437.27 GiB free]

  PV /dev/sdf1                      lvm2 [3.72 GiB]

  PV /dev/sdf2                      lvm2 [3.72 GiB]

  Total: 3 [472.72 GiB] / in use: 1 [465.27 GiB] / in no VG: 2 [7.45 GiB]


( 생성한 PV 확인 ) 



8. VG 생성


# vgcreate vg0 /dev/sdf1 /dev/sdf2

  Volume group "vg0" successfully created


[root@test-linux ~]# vgscan

  Reading all physical volumes.  This may take a while...

  Found volume group "vg0" using metadata type lvm2

[root@test-linux ~]# vgs

  VG        #PV #LV #SN Attr   VSize   VFree

  vg0         2   0   0 wz--n-   7.45g   7.45g



@@ pv 확인

[root@test-linux ~]# pvdisplay

  --- Physical volume ---

  PV Name               /dev/sdf1

  VG Name               vg0

  PV Size               3.72 GiB / not usable 1.51 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE              953

  Free PE               953

  Allocated PE          0

  PV UUID               Zyzg1V-9oqJ-uTRN-mwyb-JqgO-Mu7d-MF9OcN


  --- Physical volume ---

  PV Name               /dev/sdf2

  VG Name               vg0

  PV Size               3.72 GiB / not usable 1.54 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE              953

  Free PE               953

  Allocated PE          0

  PV UUID               P20a1b-czgK-Kawh-jUzs-sEm4-wHqh-GEzCkI



@@ vg 확인 


[root@test-linux ~]# vgdisplay

  --- Volume group ---

  VG Name               vg0

  System ID

  Format                lvm2

  Metadata Areas        2

  Metadata Sequence No  1

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                0

  Open LV               0

  Max PV                0

  Cur PV                2

  Act PV                2

  VG Size               7.45 GiB

  PE Size               4.00 MiB

  Total PE              1906

  Alloc PE / Size       0 / 0

  Free  PE / Size       1906 / 7.45 GiB

  VG UUID               pBEceJ-9UB1-jzKf-XlnU-r2zJ-lbo1-LLTD2T



9. LV 생성


[root@test-linux ~]# lvcreate -L 1G -n usbvol1 vg0

  Logical volume "usbvol1" created


( -L 사이즈, -n 생성할 lv 이름, vg0 ( lv를 생성할 Volume Group )


@@@ max 사이즈

# lvcreate -n NAME -l 100%FREE vg0




[root@test-linux ~]# lvs

  LV       VG        Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  usbvol1  vg0       -wi-a-----  1.00g



[root@test-linux ~]# lvscan

  ACTIVE            '/dev/vg0/usbvol1' [1.00 GiB] inherit



LV 생성 위치 

/dev/vg0/usbvol1

( /dev 밑에 /Volumegroup 밑에 / 생성한 LV 이름 )



10. 생성한 LV 마운트 작업

  

  10-1. mkfs.ext4 /dev/vg0/usbvol1

  10-2. mount /dev/vg0/usbvol1 /마운트할디렉토리이름

  10-3. 마운트 확인


[root@test-linux /]# df -h

Filesystem                      Size  Used Avail Use% Mounted on

/dev/mapper/vg_volume-LogVol00   20G  9.3G  9.5G  50% /

tmpfs                           3.9G   72K  3.9G   1% /dev/shm

/dev/sda1                       485M   41M  420M   9% /boot

/dev/mapper/vg0-usbvol1        1008M   34M  924M   4% /voltest


   



11. LVM 삭제

[root@test-linux ~]# lvs

v  LV       VG        Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  vgmax    vg0       -wi-a-----  7.45g

  LogVol00 vg_volume -wi-ao---- 20.00g

  LogVol01 vg_volume -wi-ao----  8.00g


[root@test-linux ~]# vgs

  VG        #PV #LV #SN Attr   VSize   VFree

  vg0         2   1   0 wz--n-   7.45g      0

  vg_volume   1   2   0 wz--n- 465.27g 437.27g



[root@test-linux ~]# lvremove /dev/vg0/vgmax           ( LV 삭제 ) 

Do you really want to remove active logical volume vgmax? [y/n]: y

  Logical volume "vgmax" successfully removed


[root@test-linux ~]# lvs

  LV       VG        Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  LogVol00 vg_volume -wi-ao---- 20.00g

  LogVol01 vg_volume -wi-ao----  8.00g


[root@test-linux ~]# vgs

  VG        #PV #LV #SN Attr   VSize   VFree

  vg0         2   0   0 wz--n-   7.45g   7.45g

  vg_volume   1   2   0 wz--n- 465.27g 437.27g


[root@test-linux ~]# vgremove /dev/vg0                  ( VG 삭제 ) 

  Volume group "vg0" successfully removed

[root@test-linux ~]# vgs

  VG        #PV #LV #SN Attr   VSize   VFree

  vg_volume   1   2   0 wz--n- 465.27g 437.27g



@@@ VG 와 LV 가 있는 상태에서, VG 삭제 시도시, VG 에 포함된 LV 모두 삭제


[root@test-linux ~]# lvs

  LV       VG        Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  maxvg0   vg0       -wi-a-----  7.45g

  LogVol00 vg_volume -wi-ao---- 20.00g

  LogVol01 vg_volume -wi-ao----  8.00g

[root@test-linux ~]# vgs

  VG        #PV #LV #SN Attr   VSize   VFree

  vg0         2   1   0 wz--n-   7.45g      0

  vg_volume   1   2   0 wz--n- 465.27g 437.27g

[root@test-linux ~]# vgremove /dev/vg0

Do you really want to remove volume group "vg0" containing 1 logical volumes? [y/n]: y

Do you really want to remove active logical volume maxvg0? [y/n]: y

  Logical volume "maxvg0" successfully removed

  Volume group "vg0" successfully removed

[root@test-linux ~]# vgs

  VG        #PV #LV #SN Attr   VSize   VFree

  vg_volume   1   2   0 wz--n- 465.27g 437.27g

[root@test-linux ~]# lvs

  LV       VG        Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  LogVol00 vg_volume -wi-ao---- 20.00g

  LogVol01 vg_volume -wi-ao----  8.00g



12. LVM 용량 늘리기


[root@test-linux ~]# lvs

  LV       VG        Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  1gvol    vg0       -wi-a-----  1.00g

  2gvol    vg0       -wi-a-----  2.00g

  LogVol00 vg_volume -wi-ao---- 20.00g

  LogVol01 vg_volume -wi-ao----  8.00g


[root@test-linux ~]# lvextend -L2G /dev/vg0/1gvol  ( 1gvol1 의 사이즈를 2G 로 늘리기 ) 

  Extending logical volume 1gvol to 2.00 GiB

  Logical volume 1gvol successfully resized


[root@test-linux ~]# lvs

  LV       VG        Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  1gvol    vg0       -wi-a-----  2.00g

  2gvol    vg0       -wi-a-----  2.00g

  LogVol00 vg_volume -wi-ao---- 20.00g

  LogVol01 vg_volume -wi-ao----  8.00g



[root@test-linux ~]# lvextend -L+1G /dev/vg0/2gvol  ( 2gvol 의 사이즈에 +1G )

  Extending logical volume 2gvol to 3.00 GiB

  Logical volume 2gvol successfully resized

[root@test-linux ~]# lvs

  LV       VG        Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  1gvol    vg0       -wi-a-----  2.00g

  2gvol    vg0       -wi-a-----  3.00g

  LogVol00 vg_volume -wi-ao---- 20.00g

  LogVol01 vg_volume -wi-ao----  8.00g



[root@test-linux ~]# lvextend -l +100%FREE /dev/vg0/2gvol  ( 2gvol 의 사이즈를 해당 볼륨그룹의 모든 사이즈 할당 ) 

  Extending logical volume 2gvol to 5.45 GiB

  Logical volume 2gvol successfully resized

[root@test-linux ~]# lvs

  LV       VG        Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

  1gvol    vg0       -wi-a-----  2.00g

  2gvol    vg0       -wi-a-----  5.45g

  LogVol00 vg_volume -wi-ao---- 20.00g

  LogVol01 vg_volume -wi-ao----  8.00g

[root@test-linux ~]# vgs

  VG        #PV #LV #SN Attr   VSize   VFree

  vg0         2   2   0 wz--n-   7.45g      0

  vg_volume   1   2   0 wz--n- 465.27g 437.27g


!! 마운트된 파일시스템에 대해 적용시에

(예시. /test 파일시스템이 lvs 사용중이며, 사이즈를 늘릴려고 할때 )


[root@dk-test ~]# df -h

Filesystem                     Size  Used Avail Use% Mounted on

/dev/mapper/vg_dktest-lv_root   50G  2.5G   45G   6% /

tmpfs                          3.9G     0  3.9G   0% /dev/shm

/dev/sda1                      485M   40M  421M   9% /boot

/dev/mapper/vg_dktest-lv_home  402G  199M  381G   1% /home

/dev/mapper/vg_dktest-test     194M  5.6M  179M   3% /test

[root@dk-test ~]# lvs

  LV      VG        Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert

  lv_home vg_dktest -wi-ao---- 407.49g

  lv_root vg_dktest -wi-ao----  50.00g

  lv_swap vg_dktest -wi-ao----   7.00g

  test    vg_dktest -wi-ao---- 200.00m


[root@dk-test ~]# lvextend -L300m /dev/vg_dktest/test  ( test 볼륨을 300M 로 확장 )

  Extending logical volume test to 300.00 MiB

  Logical volume test successfully resized

[root@dk-test ~]# lvs

  LV      VG        Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert

  lv_home vg_dktest -wi-ao---- 407.49g

  lv_root vg_dktest -wi-ao----  50.00g

  lv_swap vg_dktest -wi-ao----   7.00g

  test    vg_dktest -wi-ao---- 300.00m

[root@dk-test ~]# df -h 

Filesystem                     Size  Used Avail Use% Mounted on

/dev/mapper/vg_dktest-lv_root   50G  2.5G   45G   6% /

tmpfs                          3.9G     0  3.9G   0% /dev/shm

/dev/sda1                      485M   40M  421M   9% /boot

/dev/mapper/vg_dktest-lv_home  402G  199M  381G   1% /home

/dev/mapper/vg_dktest-test     194M  5.6M  179M   3% /test  

( 마운트되어있는 볼륨은 사이즈 미적용 상태 ) 



[root@dk-test ~]#umount /test


[root@dk-test ~]#resize2fs /dev/vg_dktest/test 

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/vg_dktest/test is mounted on /test; on-line resizing required

old desc_blocks = 1, new_desc_blocks = 2

Performing an on-line resize of /dev/vg_dktest/test to 307200 (1k) blocks.

The filesystem on /dev/vg_dktest/test is now 307200 blocks long.


[root@dk-test ~]#mount /dev/vg_dktest/test /test


[root@dk-test ~]# df -h

Filesystem                     Size  Used Avail Use% Mounted on

/dev/mapper/vg_dktest-lv_root   50G  2.5G   45G   6% /

tmpfs                          3.9G     0  3.9G   0% /dev/shm

/dev/sda1                      485M   40M  421M   9% /boot

/dev/mapper/vg_dktest-lv_home  402G  199M  381G   1% /home

/dev/mapper/vg_dktest-test     291M  6.1M  271M   3% /test



*** lvm swap size 변경 ***

0. lvscan

  볼륨 경로 확인

  ex> /dev/vg-dktest/lv_swap

 

1. swapoff -v /dev/볼륨그룹/논리볼륨

 : swap disable

2. lvm lvresize /dev/볼륨그룹/논리볼륨 -L 16G

 : lvm swap 사이즈 변경(16G로 설정)

3. mkswap /dev/볼륨그룹/논리볼륨

 : swap space 포맷

4. swapon -va

 : swap enable

5. cat /proc/swaps

 : swap 사용 확인

 



'Work > Linux(6.x)_centos' 카테고리의 다른 글

보안설정  (0) 2014.07.06
리눅스에서 FAT32 포맷하기  (0) 2014.06.20
네트워크와 관련된 파라미터  (0) 2014.06.11
Local Yum 설정  (0) 2014.06.11
리눅스 xrdp 설정  (0) 2014.04.09