LVM 활용하기

By | 2009년 10월 19일

리눅스에서 LVM을 활용하면 여러개의 물리적인 디스크를 하나의 디스크처럼 사용할 수 있다. 이 예에서는 각각 160G(/dev/sdb), 500G(/dev/sdc), 250G(/dev/sdd) 용량의 HDD 세 개를 /members 라는 하나의 마운트 포인트로 액세스 할 수 있도록 LVM을 설정해 보겠다.

먼저 fdisk를 이용 파티션을 나누고 파티션 ID를 8e (Linux LVM)으로 설정해야 한다. 아래 예는 두 번째 SATA 디스크(/dev/sdb) 전체를 하나의 LVM으로 파티션 하는 과정을 보여준다. 아래 예에서 밑줄 굵은 글씨가 사용자에 의해 입력되는 값이다. 그리고 이탤릭체로 된 (enter_key) 부분은 해당 키를 누르라는 의미이다. fdisk 프로그램에서 ‘m’을 누르면 도움말이 출력된다.
root@info3:~# fdisk /dev/sdb
The number of cylinders for this disk is set to 19457.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-19457, default 1): enter_key
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-19457, default 19457): enter_key
Using default value 19457
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)
Command (m for help): p
Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x5d754a5f
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       19457   156288321   8e  Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
root@info3:~#
위와 같은 방법으로 나머지 두 개의 디스크 /dev/sdc, /dev/sdd를 LVM 파티션으로 지정한다. 
나머지 디스크 모두 LVM으로 파티션 했으면 다음 단계로 pvcreate 명령을 이용 Physical Volume을 생성해야 한다.
root@info3:~# pvcreate /dev/sdb1
  Physical volume “/dev/sdb1” successfully created
root@info3:~# pvcreate /dev/sdc1
  Physical volume “/dev/sdc1” successfully created
root@info3:~# pvcreate /dev/sdd1
  Physical volume “/dev/sdd1” successfully created
root@info3:~#
이제 세 개의 Physical Volumes을 data라 불리는 하나의 Volume Group로 vgcreate 명령을 이용 묶는다.
root@info3:~# vgcreate data /dev/sdb1 /dev/sdc1 /dev/sdd1
  Volume group “data” successfully created
root@info3:~#
현재 Volume Group의 정보는 vgdisplay 명령으로 확인할 수 있다. 
root@info3:~# vgdisplay
  — Volume group —
  VG Name               data
  System ID             
  Format                lvm2
  Metadata Areas        3
  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                3
  Act PV                3
  VG Size               847.69 GB
  PE Size               4.00 MB
  Total PE              217008
  Alloc PE / Size       0 / 0   
  Free  PE / Size       217008 / 847.69 GB
  VG UUID               yPu2NU-dG4V-dPaf-zGDA-bM0O-S2Pi-LuEVDf
   
root@info3:~# 
위 내용을 보면 VG Size가 847.69 GB로 나타난다. 이제 이 모두를 lvcreate 명령을 이용 users란 이름의 Logical Volume을 생성할 것이다. 이 명령은 Volume Group 이름(data)을 -L, -n 옵션과 함께 주어 실행하는데, -L 옵션 뒤에는 Logical Volume의 크기를 -n 옵션 뒤에는 Logical Volume의 이름(users)을 준다.
root@info3:~# lvcreate -L 847G -n users data
  Logical volume “users” created
root@info3:~#
위 명령을 실행하면 /dev/data 디렉터리에 users 라는 Symbolic Link 파일이 생성되는데, 이 파일을 /dev/mapper/data-users에 링크돼 있다. 이제 마지막으로 파일시스템에서 액세스 가능하도록 Logical Volume을 포맷하고 마운트 하면 된다. 아래 예는 디렉터리 /members를 만들고 여기에 ext3 파일시스템으로 포맷한 Logical Volume users를 마운트 시킨다.
root@info3:/dev/data# mkfs.ext3 /dev/data/users
mke2fs 1.41.4 (27-Jan-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
55508992 inodes, 222035968 blocks
11101798 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
6776 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
102400000, 214990848
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
root@info3:/dev/data# mkdir /members
root@info3:/dev/data# mount /dev/data/users /members
root@info3:/dev/data# df
파일시스템           1K-블럭 사용됨 사용가능 사용% 마운트 됨
/dev/sda1            237405788   5874220 219471976   3% /
tmpfs                   513228         0    513228   0% /lib/init/rw
varrun                  513228       128    513100   1% /var/run
varlock                 513228         0    513228   0% /var/lock
udev                    513228       168    513060   1% /dev
tmpfs                   513228         0    513228   0% /dev/shm
lrm                     513228      2192    511036   1% /lib/modules/2.6.28-15-generic/volatile
/dev/mapper/data-users
                     874208312    205024 829596096   1% /members
root@info3:/dev/data# 

One thought on “LVM 활용하기

  1. 연금술사

    쉽고 간단하게 정리가 되어 있네요. 잘봤습니다. 새해 복 많이 받으십시요.

    Reply

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.