메뉴 닫기

lvm으로 DISK 그룹화.

LVM으로 물리적인 여러개의 disk를 1개처럼 사용 해봅시다.

※ 설치한 OS는 Ubuntu 14.04이며 그룹화할 disk는 sda3, sdb3 입니다.

1. fdisk로 파티션 생성

root@block1:~# fdisk /dev/sda

Command (m for help): p         -- 현재 디스크 확인

Disk /dev/sda: 256.1 GB, 256060514304 bytes
255 heads, 63 sectors/track, 31130 cylinders, total 500118192 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 identifier: 0x000369e6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    15624191     7811072   fd  Linux raid autodetect
/dev/sda2        15624192    54685695    19530752   fd  Linux raid autodetect

Command (m for help): n         -- 디스크 파티션 추가
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (1-4, default 3): 3         - 3번째 파티션 생성
First sector (54685696-500118191, default 54685696): 
Using default value 54685696
Last sector, +sectors or +size{K,M,G} (54685696-500118191, default 500118191): 
Using default value 500118191

Command (m for help): t         -- 파티션 시스템 아이디 변경
Partition number (1-4): 3
Hex code (type L to list codes): 8e        -- LVM 아이디 8e 입력
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sda: 256.1 GB, 256060514304 bytes
255 heads, 63 sectors/track, 31130 cylinders, total 500118192 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 identifier: 0x000369e6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    15624191     7811072   fd  Linux raid autodetect
/dev/sda2        15624192    54685695    19530752   fd  Linux raid autodetect
/dev/sda3        54685696   500118191   222716248   8e  Linux LVM         -- 생성 확인

Command (m for help): w         -- 저장
The partition table has been altered!

Calling ioctl() to re-read partition table.

# 추가할 디스크 동일하게 작업한다.

2. lvm2 패키지 설치

root@block1:~# apt-get install lvm2
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다       
상태 정보를 읽는 중입니다... 완료
다음 패키지를 더 설치할 것입니다:
  libdevmapper-event1.02.1 watershed
제안하는 패키지:
  thin-provisioning-tools
다음 새 패키지를 설치할 것입니다:
  libdevmapper-event1.02.1 lvm2 watershed
0개 업그레이드, 3개 새로 설치, 0개 제거 및 193개 업그레이드 안 함.
492 k바이트 아카이브를 받아야 합니다.
이 작업 후 1,427 k바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까? [Y/n] y

3. 물리적인 볼륨 생성

root@block1:~# pvcreate /dev/sda3
  Device /dev/sda3 not found (or ignored by filtering).
root@block1:~# pvcreate /dev/sdb3
  Device /dev/sdb3 not found (or ignored by filtering).
# 위에 같은 에러 메시지가 출력된다면 리부팅을 진행하자.

root@block1:~# pvcreate /dev/sda3         --> 물리적인 볼륨 생성
  Physical volume "/dev/sda3" successfully created

root@block1:~# pvcreate /dev/sdb3         --> 물리적인 볼륨 생성
  Physical volume "/dev/sdb3" successfully created

root@block1:~# pvdisplay 
  "/dev/sda3" is a new physical volume of "212.40 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               212.40 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               6lVYW0-oKQX-mVtN-FyVC-IZzk-Ncpu-KIWNV2
   
  "/dev/sdb3" is a new physical volume of "212.40 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb3
  VG Name               
  PV Size               212.40 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               heFKxa-pwXP-eV7f-YK1g-E4Gc-wMxe-ySA006

root@block1:~# pvs
  PV         VG       Fmt  Attr PSize   PFree  
  /dev/sda3     lvm2   a--  212.39g 
  /dev/sdb3     lvm2   a--  212.39g 

4. 물리적인 볼륨을 하나로 그룹화

root@block1:~# vgcreate jyh_test /dev/sda3 /dev/sdb3
  Volume group "jyh_test" successfully created

root@block1:~# vgdisplay 
  --- Volume group ---
  VG Name               jyh_test            --> 그룹 이름을 jyh_test로 생성
  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               424.79 GiB
  PE Size               4.00 MiB
  Total PE              108746
  Alloc PE / Size       0 / 0   
  Free  PE / Size       108746 / 424.79 GiB
  VG UUID               yQiSis-DaPj-hcS1-fJYC-nB46-NS7w-rGzxon

5. 논리적인 볼륨 생성

root@block1:~# lvcreate -L 10GB -n data jyh_test              ---> L 옵션은 사이즈, n 옵션은 볼륨 이름
  Logical volume "data" created 

root@block1:~# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/jyh_test/data
  LV Name                data
  VG Name                jyh_test
  LV UUID                8sxEHr-m6vK-Ww02-wxPM-zthy-AIIw-VGZSJs
  LV Write Access        read/write
  LV Creation host, time block1, 2015-12-07 16:56:13 +0900
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
   
root@block1:~# lvs
  LV   VG       Attr      LSize  Pool Origin Data%  Move Log Copy%  Convert
  data jyh_test -wi-a---- 10.00g

root@block1:~# cd /dev/jyh_test/
root@block1:/dev/jyh_test# ls
data         --> 생성 확인
root@block1:/dev/jyh_test#
root@block1:/dev/jyh_test# ll
total 0
drwxr-xr-x  2 root root   60 Dec  7 16:56 ./
drwxr-xr-x 16 root root 4240 Dec  7 16:56 ../
lrwxrwxrwx  1 root root    7 Dec  7 16:56 data -> ../dm-0

root@block1:/dev/jyh_test# fdisk -l
..
..
..
Disk /dev/mapper/jyh_test-data: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 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 identifier: 0x00000000

Disk /dev/mapper/jyh_test-data doesn't contain a valid partition table

root@block1:/dev/jyh_test# ll /dev/mapper/jyh_test-data
lrwxrwxrwx 1 root root 7 Dec  7 16:56 /dev/mapper/jyh_test-data -> ../dm-0

6. 생성된 볼륨 포맷, 마운트

root@block1:/dev/jyh_test# mkfs.ext4 /dev/jyh_test/data      
mke2fs 1.42.9 (4-Feb-2014)
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

root@block1:~# mkdir /root/mount_dir
root@block1:~# mount /dev/jyh_test/data /root/mount_dir/

root@block1:~# df -Th
Filesystem                Type      Size  Used Avail Use% Mounted on
..
..
..
/dev/mapper/jyh_test-data ext4      9.8G   23M  9.2G   1% /root/mount_dir

# 리부팅후에도 마운트 유지할려면 fstab도 수정 해주자.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 항목은 *(으)로 표시합니다