리눅스

리눅스에서 LVM을 사용하여 하드 디스크를 증설하는 방법

변군이글루 2015. 4. 1. 10:29
반응형

리눅스에서 LVM(Logical Volume Manager)을 사용하여 하드 디스크를 증설하는 방법

LVM(Logical Volume Manager)은 리눅스 시스템에서 디스크 공간을 유연하게 관리할 수 있게 해주는 강력한 기능입니다.

기존 디스크 및 마운트 정보 확인

df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       38G   21G   15G  59% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/xvda1            485M   32M  429M   7% /boot
/dev/mapper/VolGroup-lv_home
                       36G  179M   34G   1% /home
/dev/xvdb1             99G   15G   80G  16% /data

1. 하드 디스크 추가하기

가상 머신(예: VMware, KVM, AWS) 또는 물리 서버에 새로운 하드디스크를 추가합니다.

fdisk –l
...
Disk /dev/xvdc: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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

2. 새 디스크에 파티션 생성

파티션 없이 디스크 전체를 LVM에 사용할 수도 있지만 파티션을 생성하는 것이 일반적입니다.

fdisk /dev/xvdc
  • n : 새 파티션 생성
  • p : 기본(primary)
  • 1 : 파티션 번호
  • (Enter) : 시작 섹터
  • (Enter) : 끝 섹터
  • t : 파티션 타입 변경
  • 8e : LVM 타입
  • w : 저장 후 종료
$ fdisk /dev/xvdc
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1): (Enter)
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): (Enter)
Using default value 13054
Command (m for help): p

Disk /dev/xvdc: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x64939e91

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdc1               1       13054   104856223+  83  Linux

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): w
The partition table has been altered!

결과 확인

fdisk –l
$ fdisk –l
…
Disk /dev/xvdc: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x64939e91

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdc1               1       13054   104856223+  8e  Linux LVM

3. Physical Volume(PV) 생성

pvscan
$ pvscan
  PV /dev/xvda2   VG VolGroup   lvm2 [79.51 GiB / 0    free]
Total: 1 [79.51 GiB] / in use: 1 [79.51 GiB] / in no VG: 0 [0   ]
sudo pvcreate /dev/sdb1  # 디스크 전체를 사용할 경우에는 /dev/sdb를 지정합니다.
$ pvcreate /dev/xvdc1
  Writing physical volume data to disk "/dev/xvdc1"
  Physical volume "/dev/xvdc1" successfully created

확인

pvdisplay
pvdisplay
  --- Physical volume ---
  PV Name               /dev/xvda2
  VG Name               VolGroup
  PV Size               79.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              20354
  Free PE               0
  Allocated PE          20354
  PV UUID               U6Zndd-VaQa-c0Ax-4xOZ-nYnu-DuxF-MU2QQe
  
    "/dev/xvdc1" is a new physical volume of "100.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/xvdc1
  VG Name
  PV Size               100.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Cz40bS-cIy6-rTDC-jGTE-l26a-GVCU-wEdF1e

4. Volume Group(VG) 확장 또는 생성

기존 VG에 추가 (예: VolGroup)

vgdisplay
$ vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               79.51 GiB
  PE Size               4.00 MiB
  Total PE              20354
  Alloc PE / Size       20354 / 79.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               qvHBC1-0JCQ-vF2N-CYl1-Lt3B-hmcA-ozy8Sf
sudo vgextend VolGroup /dev/xvdc1
$ vgextend VolGroup /dev/xvdc1
  Volume group "VolGroup" successfully extended

확인

vgdisplay
$ vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               179.50 GiB
  PE Size               4.00 MiB
  Total PE              45953
  Alloc PE / Size       20354 / 79.51 GiB
  Free  PE / Size       25599 / 100.00 GiB
VG UUID               qvHBC1-0JCQ-vF2N-CYl1-Lt3B-hmcA-ozy8Sf

기존 VG가 없고 새로운 VG를 만들려면 vgcreate 명령어로 VG를 생성합니다.

728x90

5. Logical Volume(LV) 확장

확장 전 확인

lvdisplay
$ lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                Ly6a7c-HZgZ-vwf8-RcJS-EGBQ-f6ZP-JZrnsE
  LV Write Access        read/write
  LV Creation host, time ,
  LV Status              available
  # open                 1
  LV Size                37.91 GiB
  Current LE             9704
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
...

확장

sudo lvextend -l +25599 /dev/VolGroup/lv_root
$ lvextend -l +25599 /dev/VolGroup/lv_root
  Extending logical volume lv_root to 137.90 GiB
Logical volume lv_root successfully resized

확인

lvdisplay
$ lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                Ly6a7c-HZgZ-vwf8-RcJS-EGBQ-f6ZP-JZrnsE
  LV Write Access        read/write
  LV Creation host, time ,
  LV Status              available
  # open                 1
  LV Size                137.90 GiB
  Current LE             35303
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
...

6. 파일 시스템 확장

ext4 파일 시스템

sudo mkfs.ext4 /dev/my_vg/my_lv
sudo resize2fs /dev/mapper/VolGroup-lv_root

7. 파일 시스템 크기 조정하기

resize2fs 명령어를 사용하여 파일 시스템 크기를 확장합니다. 확장할 LV의 디바이스 경로를 사용합니다.

$ resize2fs /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 9
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 36150272 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 36150272 blocks long.

8. 확인하기

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      136G   21G  109G  17% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/xvda1            485M   32M  429M   7% /boot
/dev/mapper/VolGroup-lv_home
                       36G  179M   34G   1% /home
/dev/xvdb1             99G   15G   80G  16% /data

 

이제 단계별로 따라가면서 CentOS 7.x에서 LVM을 사용하여 하드 디스크를 증설할 수 있습니다. LVM을 사용하면 유연하게 디스크 공간을 증설하고 관리할 수 있으므로, 서버 운영에 매우 유용합니다.

 

반응형