본문 바로가기
OS/Linux

[ubuntu] LVM 구성 - 신규 LVM 구성

by KEI NETWORK 2019. 7. 18.
728x90

[Linux] LVM 구성 - 신규 LVM 구성

 

LVM 구성 환경


LVM과 Linux 설치 시 LVM 구성은 "[Linux] LVM (Logical Volume Management) - Linux 설치 시 생성" 포스팅을 참조 부탁드립니다.

본 포스팅은 GCP(Google Cloud Platform)의 CentOS 6.x를 기준으로 포스팅하였습니다.

 

기존 운영하고 있는 System에 신규  디스크를 추가하여 LVM을 구성할 수 있습니다.

 

 

LVM 생성


LVM을 생성할 Disk 추가 후 디스크 정보를 확인합니다.

•fdisk -l 명령어로 디스크 정보를 확인할 수 있습니다.

•새로 설치된 sdb / sdc는 현재  파티션 정보가 없습니다. 

$> sudo fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Disk identifier: 0x0003a892

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1        3916    31454246   83  Linux

 

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

64 heads, 32 sectors/track, 10240 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

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

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

Disk identifier: 0x00000000

 

Disk /dev/sdc: 10.7 GB, 10737418240 bytes

64 heads, 32 sectors/track, 10240 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

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

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

Disk identifier: 0x00000000

 

 

fdisk를 통해 신규로 추가된 Disk를 파티션 합니다.

•sudo fdisk /dev/sdb(장치명)

$> sudo fdisk /dev/sdb  # 파티션 할 장치명을 입력합니다.

 

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x5c960643.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

The device presents a logical sector size that is smaller than

the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

         switch off the mode (command 'c') and change display units to

         sectors (command 'u').

Command (m for help): m  # m 입력하여 메뉴를 확인합니다.

 

 

 

'p'를 입력하여 현재의 파티션 정보를 확인할 수 있습니다.

생성된 파티션이 없는 것을 다시 한번 확인 후 파티션 생성을 진행합니다.

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partition's system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)

 

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

64 heads, 32 sectors/track, 10240 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

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

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

 

Disk identifier: 0x5c960643

   Device Boot      Start         End      Blocks   Id  System

 

 

 

'n'을 입력하면 파티션을 생성할 수 있습니다.

 

'p'는 파티션의 속성입니다. 주 파티션 또는 확장 파티션 중에 선택할 수 있습니다.

 

파티션 번호에는 첫번째 파티션을 생성함에 따라 1번을 선택했습니다.

 

파티션의 크기는 용량으로 나오지 않고 Cylinder의 시작점과 끝점을 선택하게 됩니다.

•Cylinder의 시작점을 1, 끝점을 5000으로 지정할 경우 약 5GB를 파티션 합니다.

•Cylinder의 시작점을 1, 끝점을 10240으로 지정할 경우 10GB를 파티션 합니다.

Command (m for help): n                    # 파티션을 생성합니다.

Command action                             # 파티션의 속성을 선택합니다.

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1                  # 파티션의 번호를 선택합니다.

First cylinder (1-10240, default 1): 1     # Cylinder의 시작점을 선택합니다.

Last cylinder, +cylinders or +size{K,M,G} (1-10240, default 10240): 10240  # Cylinder의 끝점을 선택합니다.

 

 

'p'를 입력하여 파티션이 정상적으로 생성되었는지 확인합니다.

Command (m for help): p

 

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

64 heads, 32 sectors/track, 10240 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

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

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

Disk identifier: 0xd833bf9d

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1       10240    10485744   83  Linux

 

 

파티션이 정상적으로 생성되었다면 't'를 입력하여 파티션 System ID를 변경합니다.

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partition's system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)

 

Command (m for help): t

 

 

'list'를 입력하여 파티션 System ID 리스트를 확인합니다.

Linux LVM을 구성 할 예정이기 때문에 '8e'를 입력합니다.

Hex code (type L to list codes): list

 

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        

 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-

 2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-

 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-

 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx         

 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data    

 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP// CTOS / .

 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility   

 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt         

 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     

 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        

 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor      

 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        

 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT            

 f  W95 Ext'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/

10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b

11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor      

12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor      

14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary  

16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS    

17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 

18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto

1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep        

1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT            

1e  Hidden W95 FAT1

 

Hex code (type L to list codes): 8e  

 

 

 

 

파티션 System ID가 Linux LVM으로 정상적으로 변경되었으면 'w'를 입력하여 저장합니다.

Changed system type of partition 1 to 8e (Linux LVM)

 

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partitions system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)

Command (m for help): w

 

 

'/dev/sdb'에 대한 파티션 정보가 정상적으로 생성되었는지 확인합니다.

'/dev/sdc'도 sdb와 같이 동일하게 파티션을 생성합니다.

$> sudo fdisk -l

 

Disk /dev/sda: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Disk identifier: 0x0003a892

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1        3916    31454246   83  Linux

 

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

64 heads, 32 sectors/track, 10240 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

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

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

Disk identifier: 0xd833bf9d

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1       10240    10485744   8e  Linux LVM

 

Disk /dev/sdc: 10.7 GB, 10737418240 bytes

64 heads, 32 sectors/track, 10240 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

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

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

Disk identifier: 0xc6a84646

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1       10240    10485744   8e  Linux LVM

 

LVM으로 구성할 신규 Disk의 파티션 설정이 완료 되었다면 Physical Volumes을 생성합니다.
•pvcreate /dev/장치명

$> pvcreate /dev/sdb1

  Physical volume "/dev/sdb1" successfully created

 

$> pvcreate /dev/sdc1

  Physical volume "/dev/sdc1" successfully created

 

 

$> sudo pvdisplay

  --- Physical volume ---

  PV Name               /dev/sdb1

  VG Name               vg001

  PV Size               10.00 GiB / not usable 3.98 MiB

  Allocatable           yes 

  PE Size               4.00 MiB

  Total PE              2559

  Free PE               2559

  Allocated PE          0

  PV UUID               tIgIGn-Uxzs-mpFl-jk3e-cGhc-c7pC-NZef9X

   

  --- Physical volume ---

  PV Name               /dev/sdc1

  VG Name               vg001

  PV Size               10.00 GiB / not usable 3.98 MiB

  Allocatable           yes 

  PE Size               4.00 MiB

  Total PE              2559

  Free PE               2559

  Allocated PE          0

  PV UUID               5g3syX-Nudm-96ib-oSco-Ghdh-Ajfk-mf8iBT

 

 

Physical Volumes 생성을 완료하였다면 Volume Groups을 생성합니다.

•vgcreate [볼륨이름] [볼륨에 포함될 장치명]

$> sudo vgcreate vg001 /dev/sdb1 /dev/sdc1

  Volume group "vg001" successfully created

 

 

$> sudo vgdisplay

  --- Volume group ---

  VG Name               vg001

  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               19.99 GiB

  PE Size               4.00 MiB

  Total PE              5118

  Alloc PE / Size       0 / 0   

  Free  PE / Size       5118 / 19.99 GiB

  VG UUID               fWzKCY-bQGC-Wd6z-n4eD-tpsy-A5wA-1Rglhm

   

 

 

Volumes Groups 생성을 완료하였다면 Logical Volumes을 생성합니다.

•lvcreate -L [LV 크기 지정] -n [LV 이름 지정] [ LV가 생성될 VG ]

•-L 옵션은 LV의 크기를 지정하는 옵션입니다. [ k, m, g, t ]를 사용가능합니다.

•-n 옵션은 LV의 이름을 지정하는 옵션입니다.

$> sudo lvcreate -L 19g -n lv001 vg001

  Logical volume "lv001" created.

 

 

$> sudo lvdisplay

  --- Logical volume ---

  LV Path                /dev/vg001/lv001

  LV Name                lv001

  VG Name                vg001

  LV UUID                xC5Vgy-LMFJ-4ddL-FE31-zYoz-w7Oh-fXHf6R

  LV Write Access        read/write

  LV Creation host, time test, 2017-11-14 03:46:42 +0000

  LV Status              available

  # open                 0

  LV Size                19.00 GiB

  Current LE             4864

  Segments               2

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0

 

 

 

Logical Volumes 생성을 완료하였다면 fdisk로 생성된  Logical Volumes을 확인합니다.

$> fdisk -l

 

Disk /dev/mapper/vg001-lv001: 20.4 GB, 20401094656 bytes

255 heads, 63 sectors/track, 2480 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Disk identifier: 0x00000000

 

 

생성된 Logical Volumes을 포맷합니다.

•mkfs.ext4 [ 장치명 ]

•포맷 방식은 ext3, ext4, xfs 등 원하는 File System으로 포맷 할 수 있습니다.

$> sudo mkfs.ext4 /dev/vg001/lv001

 

mke2fs 1.41.12 (17-May-2010)

Discarding device blocks: done                            

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=1 blocks, Stripe width=0 blocks

1245184 inodes, 4980736 blocks

249036 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

152 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks: 

        327689830416384022937629491281920088473616056322654208

        4096000

 

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 35 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

 

 

 

 

 

 

LVM Mount


Logical Volumes에 대한 File System 포맷이 완료되었다면 디렉토리를 생성하여 LV를 Mount 합니다.

$> sudo mkdir /data               # LV를 Mount할 디렉토리를 생성합니다.

$> sudo chmod 755 /data           # 디렉토리에 권한을 부여합니다.

$> mount /dev/vg001/lv001 /data   # 생성된 디렉토리에 LV를 Mount합니다.

 

 

LV가 디렉토리에 정상적으로 Mount 되었는지 확인합니다.

•df -l

$> sudo df -l

 

Filesystem           1K-blocks    Used Available Use% Mounted on

/dev/sda1             30829600 1335300  27921896   5/

tmpfs                  1832288       0   1832288   0/dev/shm

/dev/mapper/vg001-lv001

                      19479228   44992  18438092   1/data

 

 

 

 

LVM 부팅 시 자동 Mount


생성된 LVM을 부팅시에 자동으로 Mount 하려면 "/etc/fstab"에 Mount 정보를 등록해야 합니다.

$> sudo vi /etc/fstab

 

 

[ 장치명 ] / [ 마운트 위치 ] / [ 파일시스템 ] / [ defaults] / [ 0 ] / [ 0 ] 로 설정합니다.

Fstab에 대한 자세한 사항은 추후 포스팅 할 수 있도록 하겠습니다.

## /etc/fstab

# Created by anaconda on Wed Oct 25 19:09:59 2017

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=5a421796-b7f0-4b1e-8a35-706b49dff68d /                       ext4    defaults,barrier=1 1 1

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

dev/vg001/lv001         /data                   ext4    defaults        0 0

~                                                                               

 

 

시스템 재부팅 후 아래와 같이 정상적으로 마운트 되어 있다면 LVM 구성이 완료된 것입니다.

$> df -l

Filesystem           1K-blocks    Used Available Use% Mounted on

/dev/sda1             30829600 1423568  27833628   5/

tmpfs                  1832288       0   1832288   0/dev/shm

/dev/mapper/vg001-lv001

                      19479228   44992  18438092   1/data

 

 

728x90

댓글