OS/Linux

[Linux] LVM 생성

dalgong 2023. 12. 4. 14:17
반응형

Linux에서 LVM 생성 후 마운트 하는 방법을 공유드리겠습니다.

 

1. 디스크 추가 후 확인

[root@dalgong ~]# fdisk -l

Disk /dev/xvda: 53.7 GB, 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 label type: dos
Disk identifier: 0x000ac8f2

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048     2099199     1048576   83  Linux
/dev/xvda2         2099200   104857599    51379200   83  Linux

Disk /dev/xvdb: 10.7 GB, 10737418240 bytes, 20971520 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

 

2. 파티션 나누기

[root@dalgong ~]# fdisk /dev/xvdb
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 0x25d6f06d.

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-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): 
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

 

3. PV 생성 및 확인

[root@dalgong ~]# pvcreate /dev/xvdb1 
  Physical volume "/dev/xvdb1" successfully created.

[root@dalgong ~]# pvs
  PV         VG Fmt  Attr PSize   PFree  
  /dev/xvdb1    lvm2 ---  <10.00g <10.00g

 

4. VG 생성 및 확인

[root@dalgong ~]# vgcreate testvg /dev/xvdb1
  Volume group "testvg" successfully created
[root@dalgong ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  testvg   1   0   0 wz--n- <10.00g <10.00g

 

5. LV 생성 및 확인

[root@dalgong ~]# lvcreate -n testlv -l 100%FREE testvg
  Logical volume "testlv" created.
[root@dalgong ~]# lvs
  LV     VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- <10.00g

 

6. 디스크 포맷

[root@dalgong ~]# mkfs.xfs /dev/testvg/testlv 
meta-data=/dev/testvg/testlv     isize=512    agcount=4, agsize=655104 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2620416, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

 

7. 마운트 및 확인

[root@dalgong home]# mount /dev/testvg/testlv /home/dalgong/
[root@dalgong home]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   3.8G     0  3.8G   0% /dev
tmpfs                      3.9G     0  3.9G   0% /dev/shm
tmpfs                      3.9G  9.0M  3.9G   1% /run
tmpfs                      3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/xvda2                  49G  2.5G   47G   5% /
/dev/xvda1                1014M  183M  832M  18% /boot
tmpfs                      781M     0  781M   0% /run/user/0
/dev/mapper/testvg-testlv   10G   33M   10G   1% /home/dalgong

 

8. fstab 등록

#
# /etc/fstab
# Created by anaconda on Mon Aug 31 14:44:01 2020
#
# 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=0692fdb8-bb3c------83f0-fe95-------- /                       xfs     defaults        0 0
UUID=f95bed0a-11af------bfcc-4af--------- /boot                   xfs     defaults        0 0
/dev/testvg/testlv                        /home/dalgong/          xfs     defaults        0 0
반응형

'OS > Linux' 카테고리의 다른 글

[Linux] Linux에서 Slack으로 디스크 사용량 알림  (0) 2024.09.04
[Linux] E212: Can't open file for writing 해결법  (0) 2023.12.11
[Linux] NAS란?  (0) 2023.11.27
[Linux] Open SSH 업데이트  (0) 2023.07.23
[Linux] root 권한 부여  (0) 2023.06.18