리눅스 / LVM / 만드는 방법, 수정하는 방법, 삭제하는 방법

1TB 디스크와 2TB 디스크를 추가했다고 하자. 디스크 크기에 맞게 그대로 사용할 수도 있지만, 3TB 하나인 것처럼 사용하거나 1.5TB 두 개인 것처럼 사용하고 싶을 수도 있다. 즉, 물리적인 디스크 크기와 무관하게 자유롭게 볼륨을 만들고 싶은 것이다.

이럴 때 사용하는 것이 LVM(Logical Volume Manager)이다. 여러 개의 볼륨을 하나로 묶은 후 다시 배분하여 사용한다.(이렇게 만든 볼륨을 논리적 볼륨이라고 한다.)

LVM을 이용하여 논리적 볼륨을 만들고, 수정하고, 삭제하는 방법을 알아본다.

LVM 만들기

LVM으로 볼륨을 만드는 순서는 다음과 같다.

  1. 물리적 볼륨을 만든다.
  2. 물리적 볼륨을 묶어서 볼륨 그룹을 만든다.
  3. 볼륨 그룹에 논리적 볼륨을 만든다.

간단한 예로 어떻게 구성하는지 알아보자. 목표는 100GB 디스크과 200GB 디스크로 50GB, 80GB, 170GB 볼륨을 만드는 것이다.

파티션 만들기

  • 현재 상태는 다음과 같다. 디스크 두 개를 추가해서 /dev/sdb와 /dev/sdc가 생겼고, /dev/sdb의 크기는 100GB, /dev/sdc의 크기는 200GB이다.
# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sdb  /dev/sdc
  • fdisk로 파티션을 만든다. 주의할 점은 타입을 8e로 해야 한다는 것이다.
# fdisk /dev/sdb

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 0xa066b799.

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-209715199, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199):

Created a new partition 1 of type 'Linux' and of size 100 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): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
  • 파티션을 만든 후의 상태는 다음과 같다.
# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sdb  /dev/sdb1  /dev/sdc  /dev/sdc1

물리적 볼륨 만들기

  • /dev/sdb1과 /dev/sdc1로 물리적 볼륨(Physical Volume)을 만든다.
# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
root@ubuntu-2004-s-02:~# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.

볼륨 그룹 만들기

  • /dev/sdb1과 /dev/sdc1를 볼륨 그룹으로 만든다.
  • VG-01은 볼륨 그룹의 이름으로, 다른 것으로 만들어도 된다.
# vgcreate VG-01 /dev/sdb1 /dev/sdc1
  Volume group "VG-01" successfully created

논리적 볼륨 만들기

  • VG-01 볼륨 그룹에 50GB 크기의 논리적 볼륨(Logical Volume)을 만든다.
  • LG-01은 논리적 볼륨의 이름으로, 다른 것으로 만들어도 된다.
# lvcreate --size 50G --name LG-01 VG-01
  Logical volume "LG-01" created.
  • LG-02라는 이름의 80GB 크기의 논리적 볼륨을 만든다.
# lvcreate --size 80G --name LG-02 VG-01
  Logical volume "LG-02" created.
  • 나머지 공간을 다 사용하는 LG-03이라는 이름의 논리적 볼륨을 만든다.
# lvcreate --extents 100%FREE --name LG-03 VG-01
  Logical volume "LG-03" created.

포맷하고 마운트하기

  • 논리적 볼륨을 포맷한다. 아래는 LG-01을 EXT4 형식으로 포맷한 것이다.
# mkfs.ext4 /dev/VG-01/LG-01
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 13107200 4k blocks and 3276800 inodes
Filesystem UUID: ee2a0e20-db9f-4e38-b3d1-d46f00ccc215
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424

Allocating group tables: done
Writing inode tables: done
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done
  • 적당한 이름의 폴더를 만들고 마운트한다.
# mkdir /LG-01
# mount /dev/VG-01/LG-01 /LG-01
  • 다음은 세 개의 논리적 볼륨을 포맷하고 마운트한 결과이다. 제일 아래 세 줄에 논리적 볼륨이 추가된 것을 확인할 수 있다.
# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               1.9G     0  1.9G   0% /dev
tmpfs                              394M  1.4M  393M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  196G  8.8G  178G   5% /
tmpfs                              2.0G     0  2.0G   0% /dev/shm
tmpfs                              5.0M  4.0K  5.0M   1% /run/lock
tmpfs                              2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/loop1                          62M   62M     0 100% /snap/core20/1169
/dev/loop2                          71M   71M     0 100% /snap/lxd/21029
/dev/loop3                          68M   68M     0 100% /snap/lxd/21545
/dev/sda2                          976M  112M  798M  13% /boot
/dev/loop4                          56M   56M     0 100% /snap/core18/2128
/dev/loop5                          33M   33M     0 100% /snap/snapd/13170
/dev/loop0                          62M   62M     0 100% /snap/core20/1081
/dev/loop6                          33M   33M     0 100% /snap/snapd/12704
tmpfs                              394M   36K  394M   1% /run/user/128
tmpfs                              394M     0  394M   0% /run/user/0
/dev/mapper/VG--01-LG--01           49G   53M   47G   1% /LG-01
/dev/mapper/VG--01-LG--02           79G   57M   75G   1% /LG-02
/dev/mapper/VG--01-LG--03          167G   61M  158G   1% /LG-03

LVM 수정하기

볼륨 추가

볼륨 그룹에 볼륨을 추가하여 전체 공간을 확장할 수 있다. 위 예제에 이어 200GB 하드 디스크를 추가로 장착했다고 하면...

  • 디스크를 추가하면 아래와 같은 상태가 된다. /dev/sdd가 추가한 디스크이다.
# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sdb  /dev/sdb1  /dev/sdc  /dev/sdc1  /dev/sdd
  • Linux LVM 파티션을 만든다.
# fdisk /dev/sdd

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 0x8aa237e3.

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-419430399, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-419430399, default 419430399):

Created a new partition 1 of type 'Linux' and of size 200 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): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
  • 물리적 볼륨을 만든다.
# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created.
  • VG-01 볼륨 그룹에 추가한다.
# vgextend VG-01 /dev/sdd1
  Volume group "VG-01" successfully extended
  • 200GB의 여유 공간이 생긴다.
# vgdisplay VG-01
  --- Volume group ---
  VG Name               VG-01
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  9
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               <499.99 GiB
  PE Size               4.00 MiB
  Total PE              127997
  Alloc PE / Size       76798 / 299.99 GiB
  Free  PE / Size       51199 / <200.00 GiB
  VG UUID               YLV2F1-x00c-4CZt-LsCh-3q9O-iE3L-Ynx2vG

확장된 공간에 새로운 논리적 볼륨을 만들거나, 기존 논리적 볼륨의 크기를 늘릴 수 있다.

논리적 볼륨 확장하기

  • lvextend 명령어로 논리적 볼륨의 크기를 확장한다. 아래는 /dev/VG-01/LG-01의 크기를 1GB 늘리는 것.
# lvextend -L+1G /dev/VG-01/LG-01
  Size of logical volume VG-01/LG-01 changed from 50.00 GiB (12800 extents) to 51.00 GiB (13056 extents).
  Logical volume VG-01/LG-01 successfully resized.
  • resize2fs 명령어로 파일 시스템의 크기를 확장해야 반영된다.
# resize2fs /dev/VG-01/LG-01
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/VG-01/LG-01 is mounted on /LG-01; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 7
The filesystem on /dev/VG-01/LG-01 is now 13369344 (4k) blocks long.
  • 아래는 /dev/VG-01/LG-01의 크기를 60GB로 늘리는 것. 마찬가지로 resize2fs 명령으로 파일 시스템 크기를 확장한다.
# lvextend -L60G /dev/VG-01/LG-01
  Size of logical volume VG-01/LG-01 changed from 51.00 GiB (13056 extents) to 60.00 GiB (15360 extents).
  Logical volume VG-01/LG-01 successfully resized.
# resize2fs /dev/VG-01/LG-01
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/VG-01/LG-01 is mounted on /LG-01; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 8
The filesystem on /dev/VG-01/LG-01 is now 15728640 (4k) blocks long.

LVM 삭제하기

LVM 삭제는 LVM 생성의 역순으로 진행한다.

논리적 볼륨 삭제하기

lvremove 명령어로 논리적 볼륨을 삭제한다. 아래는 /dev/VG-01/LG-03를 삭제하는 것.

# lvremove /dev/VG-01/LG-03
Do you really want to remove and DISCARD active logical volume VG-01/LG-03? [y/n]: y
  Logical volume "LG-03" successfully removed

볼륨 그룹 삭제하기

vgremove 명령어로 볼륨 그룹을 삭제한다. 아래는 VG-01을 삭제하는 것으로, 볼륨 그룹 안에 논리적 볼륨이 남아 있으면 삭제할 것인지 묻는다.

# vgremove VG-01
Do you really want to remove volume group "VG-01" containing 2 logical volumes? [y/n]: y
Do you really want to remove and DISCARD active logical volume VG-01/LG-01? [y/n]: y
  Logical volume "LG-01" successfully removed
Do you really want to remove and DISCARD active logical volume VG-01/LG-02? [y/n]: y
  Logical volume "LG-02" successfully removed
  Volume group "VG-01" successfully removed

물리적 볼륨 삭제하기

pvremove 명령어로 물리적 볼륨을 삭제한다. 아래는 /dev/sdd1을 삭제하는 것.

# pvremove /dev/sdd1
  Labels on physical volume "/dev/sdd1" successfully wiped.
같은 카테고리의 다른 글
CentOS / 설치용 부팅 USB 만드는 방법

CentOS / 설치용 부팅 USB 만드는 방법

CentOS를 설치하려면 다운로드 받은 ISO 파일을 부팅 가능한 CD 또는 USB로 만들어야 한다. ISO를 부팅 가능한 미디어로 만들어주는 프로그램은 여러 가지가 있는데, 그 중 많이 사용되는 것은 Rufus다. Rufus 다운로드 https://rufus.ie/에서 밑으로 내려가면 다운로드할 수 있는 링크가 있다. Rufus Portable은 설치가 필요 없는 실행 파일이다. 개인적으로 Portable 버전을 선호한다. CentOS 부팅 USB 만들기 Rufus를 실행한다. 다음과 ...

Ubuntu 20.04 / 글꼴 설치하는 방법

Ubuntu 20.04 / 글꼴 설치하는 방법

Ubuntu 20.04 Desktop 설치하려는 글꼴을 더블 클릭하거나, 글꼴 선택 후 엔터키를 누르거나, 마우스 우클릭 후 를 클릭합니다. 상단에 있는 를 클릭합니다. 설치가 완료되면 으로 바뀝니다. 글꼴이 잘 설치되었는지 확인합니다.

리눅스 / 게이트웨이(gateway) 확인하는 방법

리눅스에서 네트워크 정보는 주로 ifconfig, ip addr 명령어로 확인한다. 그런데, gateway 정보는 나오지 않는다. 만약 gateway 정보가 필요하다면 route 명령어를 사용한다. Ubuntu애서 명령어가 없다고 나오면 net-tools를 설치한다. apt install net-tools

리눅스 / CPU 이름, 코어 수, 스레드 수 확인하는 방법

리눅스에서 lscpu 명령으로 CPU의 정보를 확인할 수 있습니다. 출력하는 내용 중에 CPU 이름, 코어 수, 스레드 수가 있습니다. 아래는 lscpu 명령을 내린 결과 예시입니다. # lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: ...

CentOS / 버전 확인하는 방법

CentOS / 버전 확인하는 방법

cat /etc/redhat-release # cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) cat /etc/*release* # cat /etc/*release* CentOS Linux release 7.4.1708 (Core) Derived from Red Hat Enterprise Linux 7.4 (Source) NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" CentOS Linux release 7.4.1708 (Core) CentOS Linux release 7.4.1708 (Core) cpe:/o:centos:centos:7

리눅스 / 명령어 / alias / 명령어 별칭 만들기

긴 명령어 또는 복잡한 명령어를 자주 사용한다면 alias를 사용하자. 시간을 많이 절약할 수 있다. alias 목록 보기 alias를 실행하면 현재 등록된 alias를 출력한다. alias 예를 들어 ll을 실행한다는 것은 ls -alF를 실행하는 것과 같다. alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l='ls -CF' alias la='ls -A' alias ll='ls -alF' alias ls='ls --color=auto' alias 만들기 alias는 다음과 같이 만든다. abc를 실행하는 ...

Ubuntu 24.04 Server / root 계정으로 로그인할 수 있게, ssh 접속할 수 있게 설정하는 방법

Ubuntu는 설치할 때 일반 사용자 계정만 만들고, 관리자 권한이 필요할 때는 sudo를 이용한다. 만약 보안에 문제가 없는 경우라면 root 계정으로 로그인하는 게 작업하는 게 편하다. root 계정으로 로그인할 수 있게 설정하는 방법 일반 사용자 계정으로 로그인한다. 다음과 같이 명령하여 root 계정의 비밀번호를 만들면 root 계정으로 로그인할 수 있다. # sudo passwd root root 계정으로 ssh ...

Ubuntu 16.04 / phpMyAdmin / 특정 IP에서만 접속 가능하게 만드는 방법

우분투 16.04에서 phpMyAdmin을 패키지로 설치했을 때, 기본 설정은 모든 IP에서 접속 가능입니다. 만약 특정 IP에서만 접속 가능하게 하려면 /etc/apache2/conf-available/phpmyadmin.conf에 다음 코드를 추가합니다. <Directory /usr/share/phpmyadmin> Order deny,allow Deny from all Allow from xxx.xxx.xxx.xxx </Directory> xxx.xxx.xxx.xxx는 접속하려는 IP로 바꿉니다. 여러 IP를 설정하고 싶을 때는 띄어쓰기로 구분합니다. <Directory /usr/share/phpmyadmin> Order deny,allow Deny from all ...

리눅스 / 명령어 / which, whereis, locate / 명령어 위치 찾기

명령어의 위치를 찾을 때 사용할 수 있는 명령어에는 which, whereis, locate가 있다. 명령어의 위치만 찾을 때는 which를 사용하고, 관련된 파일들의 위치까지 찾을 때는 whereis나 locate를 사용한다. which 명령어로 find 명령어를 찾는다. # which find /usr/bin/find whereis 명령어로 find 명령어를 찾는다. # whereis find find: /usr/bin/find /usr/share/man/man1/find.1.gz locate 명령어로 find 명령어를 찾는다. # locate find /usr/bin/find /usr/bin/find2perl /usr/bin/findmnt /usr/bin/nl-link-ifindex2name /usr/bin/nl-link-name2ifindex /usr/bin/oldfind /usr/lib64/python2.7/modulefinder.py /usr/lib64/python2.7/modulefinder.pyc /usr/lib64/python2.7/modulefinder.pyo /usr/sbin/btrfs-find-root /usr/sbin/findfs /usr/share/bash-completion/completions/findmnt /usr/share/doc/findutils-4.5.11 /usr/share/doc/findutils-4.5.11/AUTHORS /usr/share/doc/findutils-4.5.11/COPYING /usr/share/doc/findutils-4.5.11/ChangeLog /usr/share/doc/findutils-4.5.11/NEWS /usr/share/doc/findutils-4.5.11/README /usr/share/doc/findutils-4.5.11/THANKS /usr/share/doc/findutils-4.5.11/TODO /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_find.py /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_stop_find.py /usr/share/info/find-maint.info.gz /usr/share/info/find.info.gz /usr/share/locale/be/LC_MESSAGES/findutils.mo /usr/share/locale/bg/LC_MESSAGES/findutils.mo /usr/share/locale/ca/LC_MESSAGES/findutils.mo /usr/share/locale/cs/LC_MESSAGES/findutils.mo /usr/share/locale/da/LC_MESSAGES/findutils.mo /usr/share/locale/de/LC_MESSAGES/findutils.mo /usr/share/locale/el/LC_MESSAGES/findutils.mo /usr/share/locale/eo/LC_MESSAGES/findutils.mo /usr/share/locale/es/LC_MESSAGES/findutils.mo /usr/share/locale/et/LC_MESSAGES/findutils.mo /usr/share/locale/fi/LC_MESSAGES/findutils.mo /usr/share/locale/fr/LC_MESSAGES/findutils.mo /usr/share/locale/ga/LC_MESSAGES/findutils.mo /usr/share/locale/gl/LC_MESSAGES/findutils.mo /usr/share/locale/hr/LC_MESSAGES/findutils.mo /usr/share/locale/hu/LC_MESSAGES/findutils.mo /usr/share/locale/id/LC_MESSAGES/findutils.mo /usr/share/locale/it/LC_MESSAGES/findutils.mo /usr/share/locale/ja/LC_MESSAGES/findutils.mo /usr/share/locale/ko/LC_MESSAGES/findutils.mo /usr/share/locale/lg/LC_MESSAGES/findutils.mo /usr/share/locale/lt/LC_MESSAGES/findutils.mo /usr/share/locale/ms/LC_MESSAGES/findutils.mo /usr/share/locale/nl/LC_MESSAGES/findutils.mo /usr/share/locale/pl/LC_MESSAGES/findutils.mo /usr/share/locale/pt/LC_MESSAGES/findutils.mo /usr/share/locale/pt_BR/LC_MESSAGES/findutils.mo /usr/share/locale/ro/LC_MESSAGES/findutils.mo /usr/share/locale/ru/LC_MESSAGES/findutils.mo /usr/share/locale/rw/LC_MESSAGES/findutils.mo /usr/share/locale/sk/LC_MESSAGES/findutils.mo /usr/share/locale/sl/LC_MESSAGES/findutils.mo /usr/share/locale/sr/LC_MESSAGES/findutils.mo /usr/share/locale/sv/LC_MESSAGES/findutils.mo /usr/share/locale/tr/LC_MESSAGES/findutils.mo /usr/share/locale/uk/LC_MESSAGES/findutils.mo /usr/share/locale/vi/LC_MESSAGES/findutils.mo /usr/share/locale/zh_CN/LC_MESSAGES/findutils.mo /usr/share/locale/zh_TW/LC_MESSAGES/findutils.mo /usr/share/man/man1/find.1.gz /usr/share/man/man1/find2perl.1.gz /usr/share/man/man1/oldfind.1.gz /usr/share/man/man8/btrfs-find-root.8.gz /usr/share/man/man8/findfs.8.gz /usr/share/man/man8/findmnt.8.gz locate 명령어는 -n 옵션으로 출력 ...

Ubuntu 16.04 Server / 고정 IP 설정하는 방법

네트워크 설정 파일은 /etc/network/interfaces이다. 우분투를 DHCP로 설치했다면 설정 파일의 내용은 다음과 비슷하게 되어 있다. # The primary network interface auto enp0s3 iface enp0s3 inet dhcp 이를 다음처럼 변경하고 저장한다. xxx.xxx.xxx.xxx는 네트워크 환경에 맞게 수정한다. # The primary network interface auto enp0s3 iface enp0s3 inet static address xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx gateway xxx.xxx.xxx.xxx dns-nameservers xxx.xxx.xxx.xxx 다음과 같이 명령하여 네트워크를 재시작한다. systemctl restart networking.service 만약 위와 같이 해도 ...