-
LINUX LVM(Logical Volume Managemant) 구성하는 방법System of Infra/Linux System 2022. 4. 26. 21:43반응형
LINUX LVM(Logical Volume Managemant) 구성하는 방법
[root@localhost ~]# fdisk -l Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 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: 0xbe61492f Device Boot Start End Sectors Size Id Type /dev/sda1 2048 8390655 8388608 4G 82 Linux swap / Solaris /dev/sda2 * 8390656 167772159 159381504 76G 83 Linux Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 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 Disk /dev/sdc: 3 GiB, 3221225472 bytes, 6291456 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 테스트를 위해서 Rootvg(80G)를 제외하고 추가로 2 GiB,3 GiB를 서버에 할당해주도록 합니다.
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 80G 0 disk ├─sda1 8:1 0 4G 0 part [SWAP] └─sda2 8:2 0 76G 0 part / sdb 8:16 0 2G 0 disk sdc 8:32 0 3G 0 disk sr0 11:0 1 6.7G 0 rom /run/media/root/CentOS-8-BaseOS-x86_64
▶ lsblk의 명령어를 통해서 확인 했을때 2GB(sdb), 3GB(sdc)의 디스크로 할당된 것을 확인할 수 있습니다.
[root@localhost /]# 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. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x3651dfce. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-4194303, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): Created a new partition 1 of type 'Linux' and of size 2 GiB. Command (m for help): 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 or 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 ea Rufus alignment e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT 10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/ 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto 1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep 1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'. Command (m for help): p Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 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: 0x3651dfce Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 4194303 4192256 2G 8e Linux LVM Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
▶ /dev/sdb의 디스크를 생성해주도록 합니다. 생성시 Type을 Linux LVM 형태로 생성해주도록 합니다.
[root@localhost /]# fdisk /dev/sdc 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. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0xe4bbff94. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-6291455, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-6291455, default 6291455): Created a new partition 1 of type 'Linux' and of size 3 GiB. Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'. Command (m for help): p Disk /dev/sdc: 3 GiB, 3221225472 bytes, 6291456 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: 0xe4bbff94 Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 6291455 6289408 3G 8e Linux LVM Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
▶ /deb/sdc도 동일하게 Type을 Linux LVM 형태의 타입으로 생성을 해주도록 합니다.
[root@localhost /]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 80G 0 disk ├─sda1 8:1 0 4G 0 part [SWAP] └─sda2 8:2 0 76G 0 part / sdb 8:16 0 2G 0 disk └─sdb1 8:17 0 2G 0 part sdc 8:32 0 3G 0 disk └─sdc1 8:33 0 3G 0 part sr0 11:0 1 6.7G 0 rom /run/media/root/CentOS-8-BaseOS-x86_64
▶ /dev/sdb의 디스크에 논리적으로 sdb1이 생성되었고 /deb/sdc의 디스크에 논리적으로 sdc1이 생성된 것을 확인할 수 있습니다.
[root@localhost /]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. [root@localhost /]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created.
▶ PV(Physical Volume)을 생성해주기 위해서 /dev/sdb1,/dev/sdc1을 각각 pvcreate를 통해서 생성해주도록 합니다.
[root@localhost /]# vgcreate datavg /dev/sdb1 /dev/sdc1 Volume group "datavg" successfully created [root@localhost /]# vgdisplay --- Volume group --- VG Name datavg 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 4.99 GiB PE Size 4.00 MiB Total PE 1278 Alloc PE / Size 0 / 0 Free PE / Size 1278 / 4.99 GiB VG UUID YMff2H-FuQh-EUHd-qfAC-naic-0NUN-GFU8nx
▶ VG(Volume Group)를 생성해주기 위해서 /dev/sdb1과 /dev/sdc1을 합하여 datavg라는 VG를 생성해주도록 합니다.
[root@localhost /]# lvcreate --size 1G --name datalv datavg Logical volume "datalv" created. [root@localhost /]# lvcreate --size 3G --name datalv2 datavg Logical volume "datalv2" created. [root@localhost /]# lvcreate --extents 100%FREE --name datalv3 datavg Logical volume "datalv3" created.
▶ LV(Logical Volume)을 생성해주기 위해서 datavg안에 1GB의 datalv를 생성하고 3GB의 datalv2를 생성합니다. 이때 할당한 PV의 잔여용량을 모두 datalv3로 생성하겠다면 extents 100% FREE를 사용하여 나머지를 모두 할당하면 됩니다.
[root@localhost /]# ls -ltr /dev/datavg lrwxrwxrwx 1 root root 7 4월 19 23:29 datalv -> ../dm-0 lrwxrwxrwx 1 root root 7 4월 19 23:29 datalv2 -> ../dm-1 lrwxrwxrwx 1 root root 7 4월 19 23:30 datalv3 -> ../dm-2
▶ 생성된 datavg안에는 논리적으로 datalv,datalv2,datalv3가 존재하며 각각의 디스크는 dm-0, dm-1, dm-2의 디스크를 사용한 것을 확인할 수 있습니다.
[root@localhost /]# cd /sys/block/dm-0/slaves [root@localhost slaves]# ls -ltr lrwxrwxrwx 1 root root 0 4월 19 23:33 sdb1 -> ../../../../pci0000:00/0000:00:10.0/host2/target2:0:1/2:0:1:0/block/sdb/sdb1 [root@localhost /]# cd /sys/block/dm-1/slaves lrwxrwxrwx 1 root root 0 4월 19 23:35 sdc1 -> ../../../../pci0000:00/0000:00:10.0/host2/target2:0:2/2:0:2:0/block/sdc/sdc1 lrwxrwxrwx 1 root root 0 4월 19 23:35 sdb1 -> ../../../../pci0000:00/0000:00:10.0/host2/target2:0:1/2:0:1:0/block/sdb/sdb1 [root@localhost /]# cd /sys/block/dm-2/slaves [root@localhost slaves]# ls -ltr lrwxrwxrwx 1 root root 0 4월 19 23:37 sdb1 -> ../../../../pci0000:00/0000:00:10.0/host2/target2:0:1/2:0:1:0/block/sdb/sdb1
▶ 생성된 디스크에 대한 물리적인 디스크가 어떤것을 사용했는지 확인하기 위해서 /sys/block/dm-N/slaves의 경로를 통해서 pci 번호를 비교하며 어떤 디스크로 생성이 되었는지 확인을 할 수 있습니다.
[root@localhost /]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert datalv datavg -wi-a----- 1.00g datalv2 datavg -wi-a----- 3.00g datalv3 datavg -wi-a----- 1016.00m
▶ lvs 명령어를 통해서 LV가 3개로 생성이 된것을 확인하고 구축 당시 1GB, 3GB, 나머지 할당에 대한 Lsize를 확인할 수 있습니다.
[root@localhost /]# mkfs.ext4 /dev/datavg/datalv mke2fs 1.44.3 (10-July-2018) Creating filesystem with 262144 4k blocks and 65536 inodes Filesystem UUID: 9e652093-81bf-410a-b49e-e79c6ba71159 Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done [root@localhost /]# mkfs.ext4 /dev/datavg/datalv2 mke2fs 1.44.3 (10-July-2018) Creating filesystem with 786432 4k blocks and 196608 inodes Filesystem UUID: 5d481425-e39c-44d0-926f-faaedfa51c1e Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done [root@localhost /]# mkfs.ext4 /dev/datavg/datalv3 mke2fs 1.44.3 (10-July-2018) Creating filesystem with 260096 4k blocks and 65024 inodes Filesystem UUID: 1464b8e4-e5dd-4541-8b19-eb232783f645 Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done
▶ 생성된 LV의 Type을 mkfs.ext4 명령어를 통해서 ext4의 Type으로 포맷해주도록 합니다.
[root@localhost /]# mkdir lvm lvm2 lvm3 [root@localhost /]# mount /dev/datavg/datalv lvm [root@localhost /]# mount /dev/datavg/datalv2 lvm2 [root@localhost /]# mount /dev/datavg/datalv3 lvm3 [root@localhost /]# df -Th | grep lvm /dev/mapper/datavg-datalv ext4 976M 2.6M 907M 1% /lvm /dev/mapper/datavg-datalv2 ext4 2.9G 9.0M 2.8G 1% /lvm2 /dev/mapper/datavg-datalv3 ext4 985M 2.5M 915M 1% /lvm3
▶ 생성된 LV에 파일시스템 마운트 디렉터리를 마운트 하기 위해서 마운트 포인트 할 디렉터리를 만들어 줍니다. 생성 후 마운트를 하게 되면 할당된 용량만큼 파일 시스템이 생성된 것을 확인할 수 있습니다.(lvm, lvm2, lvm3)
[root@localhost /]# vi /etc/fstab # /etc/fstab # Created by anaconda on Mon Feb 28 20:48:23 2022 # # 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. # # After editing this file, run 'systemctl daemon-reload' to update systemd # units generated from this file. # UUID=6d75a782-7d9b-4e9e-a338-fa882a919ada / xfs defaults 0 0 UUID=ae9aeae5-2577-49e3-86d9-63db631bc9d8 swap swap defaults 0 0 /dev/datavg/datalv /lvm ext4 defaults 0 0 /dev/datavg/datalv /lvm2 ext4 defaults 0 0 /dev/datavg/datalv /lvm3 ext4 defaults 0 0
▶ 시스템 재부팅 후에도 마운트가 유지되기 위해서 /etc/fstab에 생성된 파일 시스템을 만들어 주도록 합니다.
2022.03.21 - [System of Infra/LINUX] - LINUX DISK 추가를 통한 파티션 생성하는 방법(1편)
2022.03.23 - [System of Infra/LINUX] - LINUX DISK 추가를 통한 파티션 생성하는 방법(2편)
PS. 포스팅의 내용은 제 기준으로 작성한 것이기 때문에 참고해서 보시면 감사하겠습니다.
포스팅 과정의 오류 및 오타 그리고 궁금한 점에 대해서는 댓글 남겨주세요.
반응형'System of Infra > Linux System' 카테고리의 다른 글
LINUX Telnet 서버 구축 하는 방법 [원격지 서버 1편] (2) 2022.05.17 LINUX RAID1 디스크에 OS 설치하는 방법 (2) 2022.04.26 LINUX DISK RAID0 RAID1 RAID5 장애 긴급 복구 하는 방법 (4) 2022.04.07 LINUX DISK RAID0 RAID1 RAID5 구성하는 방법(2편) (4) 2022.04.05 LINUX DISK Linear RAID 구성하는 방법(1편) (0) 2022.03.30