Linux/설정 및 명령어

CentOS에서 LVM 설정하기

gunner_77 2016. 11. 28. 17:10




LVM 설정하기





CentOS 6.8 기준


[root@localhost ~]# fdisk -l

...

Disk /dev/sdc: 19.3 GB, 19321150464 bytes

64 heads, 32 sectors/track, 18426 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

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

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

Disk identifier: 0x00000000


## 위와 같이 sdc를 lvm으로 설정
fdisk 명령어나, parted 명령어를 통해 파티션 생성

## 구축을 끝내고 나면


[root@localhost ~]# fdisk -l
Disk /dev/sdc: 19.3 GB, 19321150464 bytes
255 heads, 63 sectors/track, 2348 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: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2349    18868310+  ee  GPT


PV 생성 (Physical Volume)

[root@localhost ~]# pvcreate /dev/sdc1

##아래 두 명령어로 생성된 것을 확인할 수 있다.
[root@localhost ~]# pvdisplay
  "/dev/sdc1" is a new physical volume of "17.99 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name
  PV Size               17.99 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               1AdP7j-mT1I-tseY-Fu5P-4U5B-7TOb-dZFL1T

[root@localhost ~]# pvscan
  PV /dev/sda2   VG VolGroup        lvm2 [19.51 GiB / 0    free]
  PV /dev/sdc1                      lvm2 [17.99 GiB]
  Total: 2 [37.50 GiB] / in use: 1 [19.51 GiB] / in no VG: 1 [17.99 GiB]



VG 생성 (Volume Group)

## vgcreate vg생성이름 /장치경로
[root@localhost /]# vgcreate vg_test /dev/sdc1
  Volume group "vg_test" successfully created

[root@localhost /]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg_test" using metadata type lvm2
  Found volume group "VolGroup" using metadata type lvm2

[root@localhost /]# vgdisplay
...
  --- Volume group ---
  VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.51 GiB
  PE Size               4.00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               nVwGFt-0Dsg-qmAN-R7Fe-WcyR-wxyP-ALDhsa


LV 생성 (Logical Volume)

lvcreate -n lv이름 -L 할당용량 vg선택

[root@localhost /]# lvcreate -n lv_test -L 18GB vg_test

또는

-l 옵션을 통해 % 지정

lvcreate -n lv_test -l 100%FREE vg_test

  Logical volume "lv_test" created.
[root@localhost /]# lvscan
  ACTIVE            '/dev/vg_test/lv_test' [17.99 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_root' [17.51 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_swap' [2.00 GiB] inherit

[root@localhost /]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_test/lv_test
  LV Name                lv_test
  VG Name                vg_test
  LV UUID                LkeVpj-EX0R-o4LR-FNEP-qjl9-1TVx-F76pTd
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-11-29 02:10:43 +0900
  LV Status              available
  # open                 0
  LV Size                17.99 GiB
  Current LE             4606
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
...


파일시스템 포맷 및 마운트


[root@localhost ~]# fdisk -l

...

Disk /dev/sdc: 19.3 GB, 19321150464 bytes

255 heads, 63 sectors/track, 2348 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: 0x00000000


   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        2349    18868310+  ee  GPT


Disk /dev/mapper/vg_test-lv_test: 19.3 GB, 19318964224 bytes

255 heads, 63 sectors/track, 2348 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: 0x00000000



[root@localhost ~]# mkfs.xfs -f /dev/mapper/vg_test-lv_test

[root@localhost ~]# mkdir /test

[root@localhost /]# mount /dev/mapper/vg_test-lv_test /test

[root@localhost /]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

                       18G  1.8G   15G  11% /

tmpfs                 939M   23M  917M   3% /dev/shm

/dev/sda1             477M   39M  413M   9% /boot

/dev/mapper/vg_test-lv_test

                       18G   33M   18G   1% /test