Logical Volume Management
LVM은 물리적 하드디스크를 논리 볼륨으로 관리 할수 있도록 해주는 녀석입니다.
기존의 데이터를 보존하면서 더 큰 용량을 확보 하고자 할 경우에 사용 합니다.

아래 예제에서는 용량 2TB의 하드디스크 2개를 가지고 LVM을 만들어 보았습니다.

1. Linux LVM 파티션 생성
fdisk로 새로 추가한 하드디스크 디바이스명 /dev/sdb, /dev/sdc에 LVM 파티션을 생성 합니다.
(fdisk -l 명령어로 미리 디바이스명을 찾아 주시길 바랍니다.)

[root@ruo91 ~]# fdisk /dev/sdc

첫번째 파티션을 생성 하기 위해 n을 누르고 첫번째 파티션에 모든 용량을 할당 하도록 합니다.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-267349, default 1): [Enter]
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-267349, default 267349): [Enter]
Using default value 267349

Linux LVM 파티션 Hex 코드 8e를 입력 해줍니다.
(코드 목록을 보려면 L을 눌러 확인 하시면 됩니다.)

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

LVM 파티션으로 지정 되었는지 확인 합니다.

Command (m for help): p
Disk /dev/sdb: 2199.0 GB, 2199022206976 bytes
255 heads, 63 sectors/track, 267349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c37dc
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      267349  2147480811   8e  Linux LVM

문제 없다면 설정값을 반영합니다.

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

나머지 /dev/sbc도 이와 마찬가지로 LVM 파티션을 만들면 됩니다.

두개 모두 LVM 파티션으로 지정 되었는지 확인 해봅니다.

[root@ruo91 ~]# fdisk -l /dev/sd{b,c}
Disk /dev/sdb: 2199.0 GB, 2199022206976 bytes
255 heads, 63 sectors/track, 267349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c37dc
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      267349  2147480811   8e  Linux LVM
Disk /dev/sdc: 2199.0 GB, 2199022206976 bytes
255 heads, 63 sectors/track, 267349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00063f17
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1      267349  2147480811   8e  Linux LVM

 2. LVM 생성
– PV (Physical Volume) 생성
두개의 하드디스크를 물리 볼륨으로 생성 합니다.

[root@ruo91 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created

[root@ruo91 ~]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created

– VG (Volume Group) 생성
논리 그룹으로 storage_vg라는 이름으로 생성합니다.

[root@ruo91 ~]# vgcreate storage_vg /dev/sdb /dev/sdc
  Volume group "storage_vg" successfully created

생성 확인

[root@ruo91 ~]# vgscan | grep storage_vg
  Found volume group "storage_vg" using metadata type lvm2

storage_vg 활성화

[root@ruo91 ~]# vgchange -a y
  0 logical volume(s) in volume group "storage_vg" now active

용량 확인 (2TB + 2TB = 4TB)

[root@ruo91 ~]# vgdisplay storage_vg
  --- Volume group ---
  VG Name               storage_vg
  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               4.00 TiB
  PE Size               4.00 MiB
  Total PE              1048574
  Alloc PE / Size       0 / 0
  Free  PE / Size       1048574 / 4.00 TiB
  VG UUID               ifSz7x-3Lp0-ZFGI-5J8O-TtYF-JPsR-clm6fg

– LV (Logical Volume) 생성
vgdisplay 시 나온 정보중에 VG Size와 Total PE를 뺀 값이 LV 생성시 사용될 용량입니다.

  4194302000000
-       1048574
----------------
  4194302951426 Byte = 3.81TB

LV를 storage 라는 이름으로 생성 합니다.

[root@ruo91 ~]# lvcreate -L 3.81T -n storage storage_vg
  Rounding up size to full physical extent 3.81 TiB
  Logical volume "storage" created

옵션 설명

-L : Volume Group 크기
-n : Logical Volume 이름

 3. 파일시스템 포멧 및 마운트
VG에서 만들었던 storage_vg 디렉토리 안에 storage라는 LV가 생성 되었습니다.

[root@ruo91 ~]# ls -al /dev/storage_vg
total 0
drwxr-xr-x  2 root root   60 Jan 22 22:50 .
drwxr-xr-x 19 root root 3760 Jan 22 22:50 ..
lrwxrwxrwx  1 root root    7 Jan 22 22:50 storage -> ../dm-3

– 포멧
적절한 파일 시스템으로 포멧을 합니다.

[root@ruo91 ~]# mkfs.ext4 /dev/storage_vg/storage

– 마운트
마운트로 사용 될 디렉토리를 생성 후 마운트하여 사용 하면 됩니다.

[root@ruo91 ~]# mkdir /storage
[root@ruo91 ~]# mount /dev/storage_vg/storage /storage