[ubuntu] lvm 구성
테스트 환경
Ubuntu 20.04.4 LTS
1. 서버 디스크 현황
brightforest-ubuntu 서버
/dev/vda - 루트 디스크 50GB
/dev/vdb - 추가 디스크 50GB
/dev/vdc - 추가 디스크 60GB
/dev/vdd - 추가 디스크 70GB
*물리 디스크가 아니라 가상 디스크이기 때문에 sda가 아닌 vda 형태로 표시
root@brightforest-ubuntu:~# fdisk -l
...
Disk /dev/vdb: 50 GiB, 53687091200 bytes, 104857600 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/vdc: 60 GiB, 64424509440 bytes, 125829120 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/vdd: 70 GiB, 75161927680 bytes, 146800640 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
물리볼륨 (PV, Physical Volume)
- 실제로 나눈 파티션 (/dev/sda1, /dev/vdb1 등)
볼륨그룹(VG, Volume Group)
- 물리적 볼륨이 모여서 하나의 볼륨그룹을 이룬다.
논리적볼륨(LV, Logical Volume)
- 서버에 마운트하여 사용하는 파티션 형태
1. 추가 디스크 LVM 타입으로 파티션 생성
(1) fdisk /dev/vdb ~ vdd까지 수행
root@brightforest-ubuntu:~# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.34).
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 0x7558c0e3.
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-104857599, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-104857599, default 104857599):
Created a new partition 1 of type 'Linux' and of size 50 GiB.
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 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
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.
(2) 파티션 확인
root@brightforest-ubuntu:~# fdisk -l
...
Disk /dev/vdb: 50 GiB, 53687091200 bytes, 104857600 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: 0x7558c0e3
Device Boot Start End Sectors Size Id Type
/dev/vdb1 2048 104857599 104855552 50G 8e Linux LVM
Disk /dev/vdc: 60 GiB, 64424509440 bytes, 125829120 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: 0x0fa7eae4
Device Boot Start End Sectors Size Id Type
/dev/vdc1 2048 125829119 125827072 60G 8e Linux LVM
Disk /dev/vdd: 70 GiB, 75161927680 bytes, 146800640 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: 0xce0b4588
Device Boot Start End Sectors Size Id Type
/dev/vdd1 2048 146800639 146798592 70G 8e Linux LVM
2. 물리볼륨 생성
root@brightforest-ubuntu:~# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
root@brightforest-ubuntu:~# pvcreate /dev/vdc1
Physical volume "/dev/vdc1" successfully created.
root@brightforest-ubuntu:~# pvcreate /dev/vdd1
Physical volume "/dev/vdd1" successfully created.
root@brightforest-ubuntu:~# pvdisplay
"/dev/vdb1" is a new physical volume of "<50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size <50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID wP5pKr-2kNV-aXIb-5E2F-Wv8w-3aHc-Vns37O
"/dev/vdc1" is a new physical volume of "<60.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdc1
VG Name
PV Size <60.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID r01RIY-mPPb-850G-DyYX-go5j-VjlQ-4C2vJU
"/dev/vdd1" is a new physical volume of "<70.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdd1
VG Name
PV Size <70.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID DXuL0f-apwh-BLPP-4wvG-jIjc-J3dX-ieNgsi
3. 볼륨그룹 생성
root@brightforest-ubuntu:~# vgcreate brightforest-vg /dev/vdb1 /dev/vdc1 /dev/vdd1
Volume group "brightforest-vg" successfully created
root@brightforest-ubuntu:~# vgdisplay
--- Volume group ---
VG Name brightforest-vg
System ID
Format lvm2
Metadata Areas 3
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 3
Act PV 3
VG Size <179.99 GiB
PE Size 4.00 MiB
Total PE 46077
Alloc PE / Size 0 / 0
Free PE / Size 46077 / <179.99 GiB
VG UUID Es9ha0-Vc1M-xspN-WVcn-JBco-3nor-BgzRdZ
4. 논리볼륨 생성
- 100GB, 80GB(나머지) Logical Volume 생성
root@brightforest-ubuntu:~# lvcreate -n bf-lv01 -L 100GB brightforest-vg
Logical volume "bf-lv01" created.
root@brightforest-ubuntu:~# lvcreate -n bf-lv02 -l 100%FREE brightforest-vg
Logical volume "bf-lv02" created.
root@brightforest-ubuntu:~# lvdisplay
--- Logical volume ---
LV Path /dev/brightforest-vg/bf-lv01
LV Name bf-lv01
VG Name brightforest-vg
LV UUID NpQpoL-8wKY-KbXB-Tqo8-5pUq-Kur4-sefnw0
LV Write Access read/write
LV Creation host, time brightforest-ubuntu, 2022-10-13 06:45:37 +0000
LV Status available
# open 0
LV Size 100.00 GiB
Current LE 25600
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/brightforest-vg/bf-lv02
LV Name bf-lv02
VG Name brightforest-vg
LV UUID 5Zc6zq-EkD4-U78O-4AcT-Sz0T-24jm-d2wo8U
LV Write Access read/write
LV Creation host, time brightforest-ubuntu, 2022-10-13 06:46:32 +0000
LV Status available
# open 0
LV Size <79.99 GiB
Current LE 20477
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
5. 파일시스템 포맷 및 마운트
(1) ext3 타입으로 포맷
root@brightforest-ubuntu:~# mkfs.ext3 /dev/brightforest-vg/bf-lv01
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done
Creating filesystem with 26214400 4k blocks and 6553600 inodes
Filesystem UUID: 1030fa17-c484-4251-bda0-d1c20dcc8835
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done
root@brightforest-ubuntu:~# mkfs.ext3 /dev/brightforest-vg/bf-lv02
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done
Creating filesystem with 20968448 4k blocks and 5242880 inodes
Filesystem UUID: 6e6cb512-9602-4dde-8293-3c84ae688ec6
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000
Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done
(2) 마운트
#마운트 할 폴더 생성
root@brightforest-ubuntu:~# mkdir -p /mnt/bf01
root@brightforest-ubuntu:~# mkdir -p /mnt/bf02
#마운트
root@brightforest-ubuntu:~# mount -t ext3 /dev/brightforest-vg/bf-lv01 /mnt/bf01
root@brightforest-ubuntu:~# mount -t ext3 /dev/brightforest-vg/bf-lv02 /mnt/bf02
#확인
root@brightforest-ubuntu:~# df -h
Filesystem Size Used Avail Use% Mounted on
...
/dev/mapper/brightforest--vg-bf--lv01 98G 61M 93G 1% /mnt/bf01
/dev/mapper/brightforest--vg-bf--lv02 79G 57M 75G 1% /mnt/bf02
(3) /etc/fstab 등록
...
/dev/brightforest-vg/bf-lv01 /mnt/bf01 ext3 defaults 0 0
/dev/brightforest-vg/bf-lv02 /mnt/bf02 ext3 defaults 0 0
6. 결론
- 50G, 60G, 70G 디스크를 하나의 180G VG으로 묶은 후 각각 100G, 80G LV로 생성
- 마운트 후에는 각각 93G, 75G로 실사용 용량이 7% 감소.
돌려줘..
참고사이트)