Linux에서 LVM 사용
LVM(Logical Volume Manager)는 OS 커널단에서 스토리지 레이어에 대해서 논리적인 구조로 사용하기 편하게 하기 위한 관리용 모듈이다.
현재 최근 리눅스에는 LVM2 버전이 사용되고 있으면 LVM1과 몇몇 기능을 제외하고 하위 호환이 가능하다.
예로 LVM을 사용하지 않을 경우 스토리지 하드웨어에 파일 시스템을 구성해 장치마다 구분해서 쓰는 방식이라면
LVM을 사용할 경우 스토리지 하드웨어를 관리자 편의로 묶어 가상의 그룹을 구성해 편의에 맞게 나누거나 묶어서 사용할 수 있게 된다.
LVM을 사용할 경우 개별적인 하드웨어를 사용하는 것 보다 유연한 구조로 사용 가능하며 여러 기능 및 관리의 편의성을 갖게 된다.
0. 신규 추가한 H/W Disk 확인 및 파티션 작업
300G 사이즈로 추가한 HDD를 확인한다.
[root@kwanst ~]# fdisk -l ... Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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
물리 디스크의 경우 파티션 작업으로 여러개로 쪼갤 수 있으나 하나의 파티션으로 사용하고자 한다.
아래와 같이 파티션 생성 작업을 수행한다. LVM 타입으로 사용할 수 있게 system id 변경 작업을 반드시 해줘야 한다.
[root@kwanst ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x2aa9fb92. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-629145599, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599): Using default value 629145599 Partition 1 of type Linux and of size 300 GiB is set Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table 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 Selected partition 1 Hex code (type L to list all codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT 1e Hidden W95 FAT1 80 Old Minix Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@kwanst ~]#
1. pv 생성
LVM이 사용할 수 있도록 블럭 디바이스나 파티션을 PV(Physical Volume)으로 초기화 해줘야 한다.
[root@kwanst ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. [root@kwanst ~]# pvdisplay ... --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size <300.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID ZKu9en-Zw0d-Dxg8-62bX-ndO1-mLOV-3Use9j [root@kwanst ~]# pvscan PV /dev/sda2 VG centos_kwanst lvm2 [<29.00 GiB / 0 free] PV /dev/sdb1 lvm2 [<300.00 GiB] Total: 2 [<329.00 GiB] / in use: 1 [<29.00 GiB] / in no VG: 1 [<300.00 GiB] [root@kwanst ~]#
2. vg 생성
하나이상의 PV들을 묶어 VG(Volume Group)으로 구성해 일종의 스토리지 풀을 구성한다.
LVM은 VG를 원하는 사이즈로 쪼개서 명칭을 달아 LV(Logical Volume)으로 만든다.
[root@kwanst ~]# vgcreate vgrac /dev/sdb1 Volume group "vgrac" successfully created [root@kwanst ~]# vgdisplay --- Volume group --- VG Name vgrac System ID Format lvm2 Metadata Areas 1 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 1 Act PV 1 VG Size <300.00 GiB PE Size 4.00 MiB Total PE 76799 Alloc PE / Size 0 / 0 Free PE / Size 76799 / <300.00 GiB VG UUID j9XGxq-qXM1-0qTo-9oCa-Wbhd-R002-fxOkp9 ... [root@kwanst ~]# vgscan Reading volume groups from cache. Found volume group "vgrac" using metadata type lvm2 Found volume group "centos_kwanst" using metadata type lvm2 [root@kwanst ~]#
3. lv 생성
[root@kwanst ~]# lvcreate -n crs1 -L 5GB vgrac Logical volume "crs1" created. [root@kwanst ~]# lvcreate -n crs2 -L 5GB vgrac Logical volume "crs2" created. [root@kwanst ~]# lvcreate -n crs3 -L 5GB vgrac Logical volume "crs3" created. [root@kwanst ~]# lvcreate -n fra -L 50GB vgrac Logical volume "fra" created. [root@kwanst ~]# lvcreate -n data -L 50GB vgrac Logical volume "data" created. [root@kwanst ~]# lvdisplay --- Logical volume --- LV Path /dev/vgrac/crs1 LV Name crs1 VG Name vgrac LV UUID VAU8MQ-Ja0c-okZ6-QxF0-nMRD-fcwg-f0acKq LV Write Access read/write LV Creation host, time kwanst.localdomain, 2020-11-02 17:44:09 +0900 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 --- Logical volume --- LV Path /dev/vgrac/crs2 LV Name crs2 VG Name vgrac LV UUID neSUU2-BWKf-kcRv-5oG5-sx5u-nd1D-a7TBGd LV Write Access read/write LV Creation host, time kwanst.localdomain, 2020-11-02 17:44:17 +0900 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3 --- Logical volume --- LV Path /dev/vgrac/crs3 LV Name crs3 VG Name vgrac LV UUID z54ff0-RaWm-lfzk-glij-VmDG-Hk1Y-D7M2jk LV Write Access read/write LV Creation host, time kwanst.localdomain, 2020-11-02 17:44:23 +0900 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:4 --- Logical volume --- LV Path /dev/vgrac/fra LV Name fra VG Name vgrac LV UUID 6Y62qu-cjp8-dFvE-pPd1-VFBr-1nUO-Ijlqfi LV Write Access read/write LV Creation host, time kwanst.localdomain, 2020-11-02 17:44:56 +0900 LV Status available # open 0 LV Size 50.00 GiB Current LE 12800 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:5 --- Logical volume --- LV Path /dev/vgrac/data LV Name data VG Name vgrac LV UUID LLw8Ls-1oUK-VIxN-GAPL-iTHA-epJL-pgcUix LV Write Access read/write LV Creation host, time kwanst.localdomain, 2020-11-02 17:45:02 +0900 LV Status available # open 0 LV Size 50.00 GiB Current LE 12800 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:6 ... [root@kwanst ~]# lvscan ACTIVE '/dev/vgrac/crs1' [5.00 GiB] inherit ACTIVE '/dev/vgrac/crs2' [5.00 GiB] inherit ACTIVE '/dev/vgrac/crs3' [5.00 GiB] inherit ACTIVE '/dev/vgrac/fra' [50.00 GiB] inherit ACTIVE '/dev/vgrac/data' [50.00 GiB] inherit ... [root@kwanst ~]#
4. Lv 삭제 방법
정확한 작업을 위해 먼저 lv 확인. 삭제하고자 하는 lv가 정확히 확인되면 삭제 수행
[root@lnxtest ~]# lvscan ACTIVE '/dev/vgrac/crs1' [5.00 GiB] inherit ACTIVE '/dev/vgrac/crs2' [5.00 GiB] inherit ACTIVE '/dev/vgrac/crs3' [5.00 GiB] inherit ACTIVE '/dev/vgrac/fra' [30.00 GiB] inherit ACTIVE '/dev/vgrac/data' [30.00 GiB] inherit ... [root@lnxtest ~]# lvremove /dev/vgrac/crs1 Do you really want to remove active logical volume vgrac/crs1? [y/n]: y Logical volume "crs1" successfully removed [root@lnxtest ~]# lvremove /dev/vgrac/crs2 Do you really want to remove active logical volume vgrac/crs2? [y/n]: y Logical volume "crs2" successfully removed Do you really want to remove active logical volume vgrac/crs3? [y/n]: y Logical volume "crs3" successfully removed [root@lnxtest ~]# lvremove /dev/vgrac/fra Do you really want to remove active logical volume vgrac/fra? [y/n]: y Logical volume "fra" successfully removed [root@lnxtest ~]# lvremove /dev/vgrac/data Do you really want to remove active logical volume vgrac/data? [y/n]: y Logical volume "data" successfully removed [root@lnxtest ~]# lvscan ... [root@lnxtest ~]#
5. VG 삭제
[root@lnxtest ~]# vgscan Found volume group "vgrac" using metadata type lvm2 ... [root@lnxtest ~]# vgdisplay --- Volume group --- VG Name vgrac System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 11 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size <200.00 GiB PE Size 4.00 MiB Total PE 51199 Alloc PE / Size 0 / 0 Free PE / Size 51199 / <200.00 GiB VG UUID O1850N-vFCo-q3bb-6oZA-mre0-GLeQ-lIJ77R ... [root@lnxtest ~]# vgremove /dev/vgrac Volume group "vgrac" successfully removed [root@lnxtest ~]# vgscan ... [root@lnxtest ~]#
6. Disk 삭제
[root@lnxtest ~]# fdisk -l ... Disk /dev/sdb: 200 GiB, 214748364800 bytes, 419430400 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 Disklabel type: dos Disk identifier: 0x1e84843e Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 419430399 419428352 200G 83 Linux ... [root@lnxtest ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.32.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): p Disk /dev/sdb: 200 GiB, 214748364800 bytes, 419430400 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 Disklabel type: dos Disk identifier: 0x1e84843e Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@lnxtest ~]# fdisk -l ... Disk /dev/sdb: 200 GiB, 214748364800 bytes, 419430400 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 Disklabel type: dos Disk identifier: 0x1e84843e [root@lnxtest ~]#