오늘 개발PC에 cetos7을 설치했다.

 

아래와 같이
/home 을 볼륨그룹(vg_data) 과 논리볼륨(lv_home)으로 이름을 지었고
/  를 vg_root/lv_root 로 만들었다.

SSD 500G를 사용하여 구성하였으며,
SSD 500G를 추가하여 mysql data만을 넣을 계획이다.

 

LVM 관련 파일 시스템 레이아웃을 아래와 같이 잡았다.

 

실행계획은 아래와 같다.

  1. 파티션 생성 ( fdisk /dev/sdb )
  2. 물리볼륨 생성  ( pvcreate /dev/sdb1 )
  3. 볼륨 그룹 생성 및 합치기  (  vgextend vg_data /dev/sdb1 )
  4. 논리볼륨 생성 및 크기 할당
  5. 파일 시스템으로 포맷 및 마운트

시작해보자.

 

1. 파티션 생성

* fdisk -l 하여 LVM 설정할 하드드라이브 (디스크)의 디바이스명을 확인한다.

 ]# fdisk -l

Disk /dev/sdb: 512.1 GB, 512110190592 bytes, 1000215216 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

 

* fdisk를 사용하여 LVM 타입으로 파티션을 생성한다

]#  fdisk /dev/sdb

  n 엔터 (새 파티션 추가)
  -> p 엔터 (primary partition (1-4)) ; 주파티션이면 p, 확장파티션이면 e
  -> 1 엔터 (파티션 넘버 입력)
  -> 엔터 (First cylinder 1-1792, default 1:)
  -> 엔터 (last cylinder)
  -> t 엔터 (change a partition's system id)
  -> l 엔터 (type L to list codes)
  -> 8e (linux LVM이 8e다)
  -> w 엔터 (write table to disk and exit)

 

 * fdisk -l 하여 LVM 타입으로 파티션이 설정되었음을 확인한다.

]# fdisk -l

 

2. 물리볼륨 생성 

1) 물리볼륨 확인한다.

]# pvdisplay

--- Physical volume ---
   PV Name               /dev/sda2
   VG Name               vg_data
   PV Size               100.00 GiB / not usable 0  
   Allocatable           yes (but full)
   PE Size               4.00 MiB
   Total PE              25600
   Free PE               0
   Allocated PE          25600
   PV UUID               YhNY50-00VY-xeBq-AYme-HESf-E7wO-1VMto0
   
   --- Physical volume ---
   PV Name               /dev/sda5
   VG Name               vg_root
   PV Size               380.05 GiB / not usable 3.00 MiB
   Allocatable           yes (but full)
   PE Size               4.00 MiB
   Total PE              97291
   Free PE               0
   Allocated PE          97291
   PV UUID               KmZAPe-zlCs-WYC3-KvTi-4YvG-ZJta-2nA9NK

 

2) pvcreate 로 물리볼륨을 생성한다.

]# pvcreate /dev/sdb1

Physical volume "/dev/sdb1" successfully created

 

3) pvdisplay하여 물리볼륨 확인한다.

]# pvdisplay

 --- Physical volume ---
   PV Name               /dev/sda2
   VG Name               vg_data
   PV Size               100.00 GiB / not usable 0  
   Allocatable           yes (but full)
   PE Size               4.00 MiB
   Total PE              25600
   Free PE               0
   Allocated PE          25600
   PV UUID               YhNY50-00VY-xeBq-AYme-HESf-E7wO-1VMto0
   
   --- Physical volume ---
   PV Name               /dev/sda5
   VG Name               vg_root
   PV Size               380.05 GiB / not usable 3.00 MiB
   Allocatable           yes (but full)
   PE Size               4.00 MiB
   Total PE              97291
   Free PE               0
   Allocated PE          97291
   PV UUID               KmZAPe-zlCs-WYC3-KvTi-4YvG-ZJta-2nA9NK
   
   "/dev/sdb1" is a new physical volume of "476.94 GiB"
   --- NEW Physical volume ---
   PV Name               /dev/sdb1
   VG Name              
   PV Size               476.94 GiB
   Allocatable           NO
   PE Size               0  
   Total PE              0
   Free PE               0
   Allocated PE          0
   PV UUID               vac0dh-KLml-y4Dh-VNU4-nPHm-cSGo-s50ZAd

 

 

3. 볼륨그룹 생성 및 합치기

1) 볼륨 그룹 확인한다.

]# vgdisplay

--- Volume group ---
VG Name               vg_data
System ID            
Format                lvm2
Metadata Areas        1
Metadata Sequence No  2
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                1
Act PV                1
VG Size               100.00 GiB
PE Size               4.00 MiB
Total PE              25600
Alloc PE / Size       25600 / 100.00 GiB
Free  PE / Size       0 / 0  
VG UUID               XIpogB-ssdt-rpNj-jPcB-Efxe-j3bb-0cDiDe

--- Volume group ---
VG Name               vg_root
System ID            
Format                lvm2
Metadata Areas        1
Metadata Sequence No  2
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                1
Act PV                1
VG Size               380.04 GiB
PE Size               4.00 MiB
Total PE              97291
Alloc PE / Size       97291 / 380.04 GiB
Free  PE / Size       0 / 0  
VG UUID               bBsk8F-XqLz-zMm9-Kolh-VdGS-YPda-GCvbsJ

 

2) vgcreate 하여 볼륨그룹 설정 (위에서 생성했던 물리볼륨들을)

]# vgextend vg_data /dev/sdb1

Volume group "vg_data" successfully extended

 

3) vgdisplay 하여 볼륨그룹을 확인한다..

]# vgdisplay


--- Volume group ---
VG Name               vg_data
System ID            
Format                lvm2
Metadata Areas        2
Metadata Sequence No  3
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                2
Act PV                2
VG Size               576.94 GiB
PE Size               4.00 MiB
Total PE              147696
Alloc PE / Size       25600 / 100.00 GiB
Free  PE / Size       122096 / 476.94 GiB            <= 프리공간476.94G 있다 (즉 논리볼륨 추가 시 이 숫자 적으며 됨)
VG UUID               XIpogB-ssdt-rpNj-jPcB-Efxe-j3bb-0cDiDe

--- Volume group ---
VG Name               vg_root
System ID            
Format                lvm2
Metadata Areas        1
Metadata Sequence No  2
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                1
Act PV                1
VG Size               380.04 GiB
PE Size               4.00 MiB
Total PE              97291
Alloc PE / Size       97291 / 380.04 GiB
Free  PE / Size       0 / 0  
VG UUID               bBsk8F-XqLz-zMm9-Kolh-VdGS-YPda-GCvbsJ

 

4) 활성화

]# vgchange -a y vg_data

1 logical volume(s) in volume group "vg_data" now active

 

 

4. 논리볼륨 생성 및 크기 할당

1) 논리볼륨 확인한다.

]# lvdisplay

--- Logical volume ---
LV Path                /dev/vg_data/lv_home
LV Name                lv_home
VG Name                vg_data
LV UUID                aSl3Dm-2TA5-xe1P-6O3u-6f21-KtXt-rymv4u
LV Write Access        read/write
LV Creation host, time bss2, 2017-10-24 18:36:54 +0900
LV Status              available
# open                 1
LV Size                100.00 GiB
Current LE             25600
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:1

--- Logical volume ---
LV Path                /dev/vg_root/lv_root
LV Name                lv_root
VG Name                vg_root
LV UUID                ZlEzuE-35ZU-9u58-rSTq-Vzfv-xOI7-hQffPF
LV Write Access        read/write
LV Creation host, time bss2, 2017-10-24 18:37:02 +0900
LV Status              available
# open                 1
LV Size                380.04 GiB
Current LE             97291
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

 

2) 논리볼륨 추가

]# lvcreate -n lv_mysql -l 100%FREE vg_data

 

3) 확인

]# lvdisplay

--- Logical volume ---
LV Path                /dev/vg_data/lv_home
LV Name                lv_home
VG Name                vg_data
LV UUID                aSl3Dm-2TA5-xe1P-6O3u-6f21-KtXt-rymv4u
LV Write Access        read/write
LV Creation host, time bss2, 2017-10-24 18:36:54 +0900
LV Status              available
# open                 1
LV Size                100.00 GiB
Current LE             25600
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:1

--- Logical volume ---
LV Path                /dev/vg_data/lv_mysql
LV Name                lv_mysql
VG Name                vg_data
LV UUID                HonjWk-zxLz-5OFS-yihm-a9q2-6k9b-02KAXa
LV Write Access        read/write
LV Creation host, time bss2, 2017-10-25 09:59:59 +0900
LV Status              available
# open                 0
LV Size                476.94 GiB
Current LE             122096
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:2

--- Logical volume ---
LV Path                /dev/vg_root/lv_root
LV Name                lv_root
VG Name                vg_root
LV UUID                ZlEzuE-35ZU-9u58-rSTq-Vzfv-xOI7-hQffPF
LV Write Access        read/write
LV Creation host, time bss2, 2017-10-24 18:37:02 +0900
LV Status              available
# open                 1
LV Size                380.04 GiB
Current LE             97291
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

 

 

5. 파일시스템 포맷 및 마운트

1) 생성된 논리볼륨을 파일시스템 포맷

]# mkfs.ext4 /dev/vg_data/lv_mysql

 

2) 마운트

]# mkdir /mysql_data
]# mount -t ext4 /dev/vg_data/lv_mysql /mysql_data

 

3) 확인

]# df -h

/dev/mapper/vg_data-lv_mysql  470G   73M  446G   1% /mysql_data

 

4) 부팅 시 자동으로 디스크 읽어줄수 있게 fstab 설정

]# vi /etc/fstab

/dev/vg_data/lv_mysql         /mysql_data         ext4      defaults     0    0

 

 

끝났다...

기회가 된다면 하드 하나를 더 축하여 lv_mysql 에 용량 추가하는 방법을 다뤄보겠다. (언제 한번 밥 먹자와 같은 말..... ;;;;;)
다음에는 mysql 데이터 경로를 생상한 /mysql_data로 옮기는 일을 할 차례이다.

 


본 글은 나의 다른 블로그(폐쇄예정) 에서 작성했던 포스팅입니다. (2017년 10월 25일 작성)