[Linux] LVM 명령어 실습Linux2022. 2. 25. 19:50
Table of Contents
728x90
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
├─sdb2 8:18 0 4G 0 part
├─sdb3 8:19 0 6G 0 part
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]# pvcreate /dev/sdb[1-4]
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
Physical volume "/dev/sdb3" successfully created.
Physical volume "/dev/sdb4" successfully created.
[root@localhost ~]# pvdisplay /dev/sdb1
"/dev/sdb1" is a new physical volume of "4.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 4.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID l9fEc9-t823-i0F9-rSUn-9N5y-DLcF-CoYUL7
[root@localhost ~]# blkid
/dev/sda1: UUID="88f82736-89b0-49e6-88c5-165c88bcc5bf" TYPE="swap"
/dev/sda2: UUID="231c776b-3197-4e9f-a142-6b80be0ca930" TYPE="xfs"
/dev/sdb1: UUID="l9fEc9-t823-i0F9-rSUn-9N5y-DLcF-CoYUL7" TYPE="LVM2_member"
/dev/sdb2: UUID="DPrEjM-TASQ-8TWv-o846-hRTx-Anq2-PhrfF6" TYPE="LVM2_member"
/dev/sdb3: UUID="GGH9fu-DY5d-SGxH-WlPS-AzL6-cT76-zw9qqk" TYPE="LVM2_member"
/dev/sdb4: UUID="62ytZJ-T3T8-VB52-Le1a-ICRT-A10n-dKDJto" TYPE="LVM2_member"
[root@localhost ~]# vgcreate vg0 /dev/sdb[1-3]
Volume group "vg0" successfully created
[root@localhost ~]# vgdisplay vg0
--- Volume group ---
VG Name vg0
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 <13.99 GiB
PE Size 4.00 MiB
Total PE 3581
Alloc PE / Size 0 / 0
Free PE / Size 3581 / <13.99 GiB
VG UUID whMH0Q-fBOJ-dFC2-zIkf-xlht-iwXF-Y8XAHI
# PE Size 디폴트 값은 4이다.
[root@localhost ~]# vgcreate vg1 /dev/sdb[24] -s 8M
Volume group "vg1" successfully created
[root@localhost ~]# vgdisplay vg1
--- Volume group ---
VG Name vg1
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 9.98 GiB
PE Size 8.00 MiB
Total PE 1278
Alloc PE / Size 0 / 0
Free PE / Size 1278 / 9.98 GiB
VG UUID FmY6u5-fA8U-8QuG-Exqe-FsBA-9k6K-js5a2X
[root@localhost ~]# lvcreate vg0 -l 256 -n lv01
Logical volume "lv01" created.
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ └─vg0-lv01 253:0 0 1G 0 lvm
├─sdb2 8:18 0 4G 0 part
├─sdb3 8:19 0 6G 0 part
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# lvcreate vg0 -L 2G -n lv02
Logical volume "lv02" created.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ ├─vg0-lv01 253:0 0 1G 0 lvm
│ └─vg0-lv02 253:1 0 2G 0 lvm
├─sdb2 8:18 0 4G 0 part
├─sdb3 8:19 0 6G 0 part
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
# lv는 파티션을 만든 것과 비슷한 것이다.
# 파티션을 만들고 사용을 위해서는 포맷이 필요하다.
[root@localhost ~]# ls -l /dev/vg0/lv01 /dev/mapper/vg0-lv01 /dev/dm-0
brw-rw----. 1 root disk 253, 0 2월 25 16:03 /dev/dm-0
lrwxrwxrwx. 1 root root 7 2월 25 16:03 /dev/mapper/vg0-lv01 -> ../dm-0
lrwxrwxrwx. 1 root root 7 2월 25 16:03 /dev/vg0/lv01 -> ../dm-0
# 세가지 경로명을 사용할 수 있다. (심볼릭 링크되어있기 때문이다.)
# 우리가 사용할 때는 볼륨 그룹명과 lv명으로 하는 것이 편하다.
[root@localhost ~]# lvdisplay /dev/vg0/lv01
--- Logical volume ---
LV Path /dev/vg0/lv01
LV Name lv01
VG Name vg0
LV UUID PrHceW-gFgC-nXmH-tXYg-jhyi-gbAO-dhay55
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-02-25 16:03:14 +0900
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
# 리눅스 시스템에서 쓰는 경로는 mapper이다.
[root@localhost ~]# lvdisplay /dev/mapper/vg0-lv02
--- Logical volume ---
LV Path /dev/vg0/lv02
LV Name lv02
VG Name vg0
LV UUID iShdgX-6pLK-e2cA-d5i9-wU4L-MHmk-dZRAWb
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-02-25 16:03:49 +0900
LV Status available
# open 0
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
# 10G에서 1G, 2G를 사용하고 남은 7G를 사용하려고 하면 에러가 뜬다.
[root@localhost ~]# lvcreate vg0 -L 7G -n lv03
Volume group "vg0" has insufficient free space (1790 extents): 1792 required.
[root@localhost ~]# lvcreate vg0 -l 100%FREE -n lv03
Logical volume "lv03" created.
# 여유 공간 : 1790 필요 공간 : 1792
# 볼륨 그룹에 나머지 용량을 쏟아서 만들어줘야 한다.
[root@localhost ~]# lvdisplay /dev/vg0/lv03
--- Logical volume ---
LV Path /dev/vg0/lv03
LV Name lv03
VG Name vg0
LV UUID U91BeN-HbnL-UeAt-gmeG-vtst-Xb3m-JeuX9U
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-02-25 16:10:17 +0900
LV Status available
# open 0
LV Size 6.99 GiB
Current LE 1790
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ ├─vg0-lv01 253:0 0 1G 0 lvm
│ ├─vg0-lv02 253:1 0 2G 0 lvm
│ └─vg0-lv03 253:2 0 7G 0 lvm
├─sdb2 8:18 0 4G 0 part
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv03 253:2 0 7G 0 lvm
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
# 포맷 방법
[root@localhost ~]# mkfs -t xfs /dev/vg0/lv01
meta-data=/dev/vg0/lv01 isize=512 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, 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
[root@localhost ~]# mkfs.ext4 /dev/mapper/vg0-lv02
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
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 ~]# blkid
/dev/sda1: UUID="88f82736-89b0-49e6-88c5-165c88bcc5bf" TYPE="swap"
/dev/sda2: UUID="231c776b-3197-4e9f-a142-6b80be0ca930" TYPE="xfs"
/dev/sdb1: UUID="GkUEuY-FkCA-Wls2-5XUX-WyLe-Ncq9-nbCwmQ" TYPE="LVM2_member"
/dev/sdb2: UUID="lsq3bK-48VH-Hktg-0kI4-18iP-0KCs-oe943q" TYPE="LVM2_member"
/dev/sdb3: UUID="QezrqV-J3Jl-rL2K-vVIa-gKu1-Fv8y-W5JusJ" TYPE="LVM2_member"
/dev/sdb4: UUID="k9TheN-1fIM-Ze10-9tDD-SdNe-dhLd-TeX0mB" TYPE="LVM2_member"
/dev/mapper/vg0-lv01: UUID="c985c6c5-a4fe-4d24-bebb-271c869a3f63" TYPE="xfs"
/dev/mapper/vg0-lv02: UUID="54c4553f-eb40-4577-b103-41070b396c6c" TYPE="ext4"
[root@localhost ~]# mkdir /mnt/disk{1..3}
[root@localhost ~]# ls /mnt
disk1 disk2 disk3
[root@localhost ~]# mount /dev/vg0/lv01 /mnt/disk1
[root@localhost ~]# mount /dev/mapper/vg0-lv02 /mnt/disk2
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ ├─vg0-lv01 253:0 0 1G 0 lvm /mnt/disk1
│ ├─vg0-lv02 253:1 0 2G 0 lvm /mnt/disk2
│ └─vg0-lv03 253:2 0 7G 0 lvm
├─sdb2 8:18 0 4G 0 part
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv03 253:2 0 7G 0 lvm
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# lvremove /dev/vg0/lv01
Logical volume vg0/lv01 contains a filesystem in use.
# 이미 마운트해서 사용하고 있기 때문에 지울 수 없다.
# 지우기 위해서는 마운트를 해제해준다.
[root@localhost ~]# umount /mnt/disk1
[root@localhost ~]# umount /mnt/disk2
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ ├─vg0-lv01 253:0 0 1G 0 lvm
│ ├─vg0-lv02 253:1 0 2G 0 lvm
│ └─vg0-lv03 253:2 0 7G 0 lvm
├─sdb2 8:18 0 4G 0 part
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv03 253:2 0 7G 0 lvm
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# lvremove /dev/vg0/lv01
Do you really want to remove active logical volume vg0/lv01? [y/n]: y
Logical volume "lv01" successfully removed
[root@localhost ~]# lvremove /dev/mapper/vg0-lv0[23]
Do you really want to remove active logical volume vg0/lv02? [y/n]: y
Logical volume "lv02" successfully removed
Do you really want to remove active logical volume vg0/lv03? [y/n]: y
Logical volume "lv03" successfully removed
# 논리 볼륨이 정상적으로 지워지는 것을 확인할 수 있다.
[root@localhost ~]# vgremove vg0
Volume group "vg0" successfully removed
[root@localhost ~]# vgremove vg1
Volume group "vg1" successfully removed
[root@localhost ~]# pvremove /dev/sdb[1-4]
Labels on physical volume "/dev/sdb1" successfully wiped.
Labels on physical volume "/dev/sdb2" successfully wiped.
Labels on physical volume "/dev/sdb3" successfully wiped.
Labels on physical volume "/dev/sdb4" successfully wiped.
[root@localhost ~]# blkid
/dev/sda1: UUID="88f82736-89b0-49e6-88c5-165c88bcc5bf" TYPE="swap"
/dev/sda2: UUID="231c776b-3197-4e9f-a142-6b80be0ca930" TYPE="xfs"
# 정상적으로 지워진 것을 확인할 수 있다.
[root@localhost ~]# pvcreate /dev/sdb[1-4]
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
Physical volume "/dev/sdb3" successfully created.
Physical volume "/dev/sdb4" successfully created.
[root@localhost ~]# vgcreate vg0 /dev/sdb[13]
Volume group "vg0" successfully created
[root@localhost ~]# lvcreate vg0 -l 1024 -n lv01
Logical volume "lv01" created.
# 현재 볼륨 그룹의 PE size는 디폴드값인 4MB이다.
# 총 1024개이므로 4G가 됨을 확인할 수 있다.
[root@localhost ~]# lvdisplay /dev/vg0/lv01
--- Logical volume ---
LV Path /dev/vg0/lv01
LV Name lv01
VG Name vg0
LV UUID 11NR67-Auoc-Mdgu-gIeG-hnzq-qfc7-sqzNw3
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-02-25 16:20:21 +0900
LV Status available
# open 0
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@localhost ~]# lvcreate vg0 -L 3G -n lv02
WARNING: xfs signature detected on /dev/vg0/lv02 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/vg0/lv02.
Logical volume "lv02" created.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ └─vg0-lv02 253:1 0 3G 0 lvm
├─sdb2 8:18 0 4G 0 part
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv01 253:0 0 4G 0 lvm
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
# lv01, lv02의 위치 배정은 시스템의 임의적인 것이다.
[root@localhost ~]# mkfs.xfs /dev/vg0/lv01
meta-data=/dev/vg0/lv01 isize=512 agcount=4, agsize=262144 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1048576, 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
[root@localhost ~]# mkfs.ext4 /dev/vg0/lv02
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
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 ~]# mount /dev/vg0/lv01 /mnt/disk1
[root@localhost ~]# mount /dev/vg0/lv02 /mnt/disk2
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 xfs 56G 4.3G 52G 8% /
devtmpfs devtmpfs 985M 0 985M 0% /dev
tmpfs tmpfs 1000M 0 1000M 0% /dev/shm
tmpfs tmpfs 1000M 9.0M 991M 1% /run
tmpfs tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
tmpfs tmpfs 200M 0 200M 0% /run/user/0
/dev/mapper/vg0-lv01 xfs 4.0G 33M 4.0G 1% /mnt/disk1
/dev/mapper/vg0-lv02 ext4 2.9G 9.0M 2.8G 1% /mnt/disk2
# 볼륨 그룹에 대한 확장과 축소
[root@localhost ~]# vgdisplay vg0
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 9.99 GiB
PE Size 4.00 MiB
Total PE 2558
Alloc PE / Size 1792 / 7.00 GiB
Free PE / Size 766 / 2.99 GiB
VG UUID JjynoY-15Fn-6eAJ-hiF8-fssp-qplM-zWWGUT
[root@localhost ~]# vgextend vg0 /dev/sdb2
Volume group "vg0" successfully extended
[root@localhost ~]#
[root@localhost ~]# vgdisplay vg0
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size <13.99 GiB
PE Size 4.00 MiB
Total PE 3581
Alloc PE / Size 1792 / 7.00 GiB
Free PE / Size 1789 / <6.99 GiB
VG UUID JjynoY-15Fn-6eAJ-hiF8-fssp-qplM-zWWGUT
# vg0 /dev/sdb1 /dev/sdb2 /dev/sdb3 => 14G
# 기존에 sdb1, sdb3가 있었고 거기에 sdb2를 추가한 상태이다.
# 여기서 sdb1을 제거해보겠다.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ └─vg0-lv02 253:1 0 3G 0 lvm /mnt/disk2
├─sdb2 8:18 0 4G 0 part
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv01 253:0 0 4G 0 lvm /mnt/disk1
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# vgreduce vg0 /dev/sdb2
Removed "/dev/sdb2" from volume group "vg0"
[root@localhost ~]# vgdisplay vg0
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 9.99 GiB
PE Size 4.00 MiB
Total PE 2558
Alloc PE / Size 1792 / 7.00 GiB
Free PE / Size 766 / 2.99 GiB
VG UUID JjynoY-15Fn-6eAJ-hiF8-fssp-qplM-zWWGUT
# sdb2에는 마운트된 장치가 없어서 정상적으로 삭제되며
# 13.99 GB 에서 9.99GB로 축소된것을 확인할 수 있다.
[root@localhost ~]# vgextend vg0 /dev/sdb2
Volume group "vg0" successfully extended
[root@localhost ~]#
[root@localhost ~]# vgreduce vg0 /dev/sdb1
Physical volume "/dev/sdb1" still in use
# 다시 vg0에 sdb2를 확장하고 sdb1을 제거하려고하면 에러가 뜨는 것을 확인할 수 있다.
# 제거하기위해서는 sdb1에 있는 자료를 볼륨 그룹의 나머지 부분에 전부 옮겨야 가능하다.
[root@localhost ~]# pvmove /dev/sdb1
/dev/sdb1: Moved: 0.39%
/dev/sdb1: Moved: 100.00%
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
├─sdb2 8:18 0 4G 0 part
│ └─vg0-lv02 253:1 0 3G 0 lvm /mnt/disk2
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv01 253:0 0 4G 0 lvm /mnt/disk1
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
# 다시 확인해보면 sdb2 밑으로 장치가 옮겨진 것을 확인할 수 있다.
# 성공적으로 sdb1이 제거되었음을 확인 가능하다
[root@localhost ~]# vgreduce vg0 /dev/sdb1
Removed "/dev/sdb1" from volume group "vg0"
# 장치를 다시 추가한 뒤 확인하면 13.99GB를 이루는 것을 알 수 있다.
[root@localhost ~]# vgextend vg0 /dev/sdb1
Volume group "vg0" successfully extended
[root@localhost ~]# vgdisplay vg0
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 11
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size <13.99 GiB
PE Size 4.00 MiB
Total PE 3581
Alloc PE / Size 1792 / 7.00 GiB
Free PE / Size 1789 / <6.99 GiB
VG UUID JjynoY-15Fn-6eAJ-hiF8-fssp-qplM-zWWGUT
# lvextend는 만들고자하는 용량을 써줄 수도 있고 추가하고자 하는 용량을 써줄 수도 있다.
[root@localhost ~]# lvextend -L +2G /dev/vg0/lv01
Size of logical volume vg0/lv01 changed from 4.00 GiB (1024 extents) to 6.00 GiB (1536 extents).
Logical volume vg0/lv01 successfully resized.
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
├─sdb2 8:18 0 4G 0 part
│ ├─vg0-lv01 253:0 0 6G 0 lvm /mnt/disk1
│ └─vg0-lv02 253:1 0 3G 0 lvm /mnt/disk2
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv01 253:0 0 6G 0 lvm /mnt/disk1
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
# 기존의 4G에서 2G 추가되어 6G 된것을 확인할 수 있다.
[root@localhost ~]# lvextend -L 7G /dev/vg0/lv02
Size of logical volume vg0/lv02 changed from 3.00 GiB (768 extents) to 7.00 GiB (1792 extents).
Logical volume vg0/lv02 successfully resized.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ └─vg0-lv02 253:1 0 7G 0 lvm /mnt/disk2
├─sdb2 8:18 0 4G 0 part
│ ├─vg0-lv01 253:0 0 6G 0 lvm /mnt/disk1
│ └─vg0-lv02 253:1 0 7G 0 lvm /mnt/disk2
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv01 253:0 0 6G 0 lvm /mnt/disk1
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
# lvextend 시 주의 할 점 !
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 xfs 56G 4.4G 52G 8% /
devtmpfs devtmpfs 985M 0 985M 0% /dev
tmpfs tmpfs 1000M 0 1000M 0% /dev/shm
tmpfs tmpfs 1000M 9.0M 991M 1% /run
tmpfs tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
tmpfs tmpfs 200M 0 200M 0% /run/user/0
/dev/mapper/vg0-lv01 xfs 4.0G 33M 4.0G 1% /mnt/disk1
/dev/mapper/vg0-lv02 ext4 2.9G 9.0M 2.8G 1% /mnt/disk2
# 부여한 볼륨 크기는 7G, 6G인데 파일시스템의 크기는 커지지않고 그대로이다.
# why ?!!!
# 우리가 실제로 사용하는 공간은 "File System" 공간이다.
# 볼륨을 주고 file system 영역까지 확장하지 않으면 결국 사용할 수 있는 공간은 디폴트 공간이다.
# fs 확장 방법
# xfs 파일 시스템을 논리볼륨에서 확장
# xfs_growfs 마운트포인트
# ext4 파일시스템 논리볼륨에서 확장
# resize2fs 논리볼륨명
[root@localhost ~]# xfs_growfs /mnt/disk1
meta-data=/dev/mapper/vg0-lv01 isize=512 agcount=4, agsize=262144 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1048576, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1048576 to 1572864
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 xfs 56G 4.4G 52G 8% /
devtmpfs devtmpfs 985M 0 985M 0% /dev
tmpfs tmpfs 1000M 0 1000M 0% /dev/shm
tmpfs tmpfs 1000M 9.0M 991M 1% /run
tmpfs tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
tmpfs tmpfs 200M 0 200M 0% /run/user/0
/dev/mapper/vg0-lv01 xfs 6.0G 33M 6.0G 1% /mnt/disk1
/dev/mapper/vg0-lv02 ext4 2.9G 9.0M 2.8G 1% /mnt/disk2
# 기존의 용량과 비교해서 +2G 된것을 확인할 수 있다.
[root@localhost ~]# resize2fs /dev/vg0/lv02
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg0/lv02 is mounted on /mnt/disk2; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg0/lv02 is now 1835008 blocks long.
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 xfs 56G 4.4G 52G 8% /
devtmpfs devtmpfs 985M 0 985M 0% /dev
tmpfs tmpfs 1000M 0 1000M 0% /dev/shm
tmpfs tmpfs 1000M 9.0M 991M 1% /run
tmpfs tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
tmpfs tmpfs 200M 0 200M 0% /run/user/0
/dev/mapper/vg0-lv01 xfs 6.0G 33M 6.0G 1% /mnt/disk1
/dev/mapper/vg0-lv02 ext4 6.9G 14M 6.5G 1% /mnt/disk2
# 확장과 동시에 포맷도 같이하려면 -r 옵션을 사용한다.
[root@localhost ~]# lvextend -L +0.5G /dev/vg0/lv01 -r
Size of logical volume vg0/lv01 changed from 6.00 GiB (1536 extents) to 6.50 GiB (1664 extents).
Logical volume vg0/lv01 successfully resized.
meta-data=/dev/mapper/vg0-lv01 isize=512 agcount=6, agsize=262144 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1572864, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1572864 to 1703936
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ ├─vg0-lv01 253:0 0 6.5G 0 lvm /mnt/disk1
│ └─vg0-lv02 253:1 0 7G 0 lvm /mnt/disk2
├─sdb2 8:18 0 4G 0 part
│ ├─vg0-lv01 253:0 0 6.5G 0 lvm /mnt/disk1
│ └─vg0-lv02 253:1 0 7G 0 lvm /mnt/disk2
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv01 253:0 0 6.5G 0 lvm /mnt/disk1
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 xfs 56G 4.4G 52G 8% /
devtmpfs devtmpfs 985M 0 985M 0% /dev
tmpfs tmpfs 1000M 0 1000M 0% /dev/shm
tmpfs tmpfs 1000M 9.0M 991M 1% /run
tmpfs tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
tmpfs tmpfs 200M 0 200M 0% /run/user/0
/dev/mapper/vg0-lv01 xfs 6.5G 33M 6.5G 1% /mnt/disk1
/dev/mapper/vg0-lv02 ext4 6.9G 14M 6.5G 1% /mnt/disk2
[root@localhost ~]# lvextend -L +0.2G /dev/vg0/lv02 -r
Rounding size to boundary between physical extents: 208.00 MiB.
Size of logical volume vg0/lv02 changed from 7.00 GiB (1792 extents) to 7.20 GiB (1844 extents).
Logical volume vg0/lv02 successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg0-lv02 is mounted on /mnt/disk2; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/vg0-lv02 is now 1888256 blocks long.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ ├─vg0-lv01 253:0 0 6.5G 0 lvm /mnt/disk1
│ └─vg0-lv02 253:1 0 7.2G 0 lvm /mnt/disk2
├─sdb2 8:18 0 4G 0 part
│ ├─vg0-lv01 253:0 0 6.5G 0 lvm /mnt/disk1
│ └─vg0-lv02 253:1 0 7.2G 0 lvm /mnt/disk2
├─sdb3 8:19 0 6G 0 part
│ └─vg0-lv01 253:0 0 6.5G 0 lvm /mnt/disk1
└─sdb4 8:20 0 6G 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 xfs 56G 4.4G 52G 8% /
devtmpfs devtmpfs 985M 0 985M 0% /dev
tmpfs tmpfs 1000M 0 1000M 0% /dev/shm
tmpfs tmpfs 1000M 9.0M 991M 1% /run
tmpfs tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
tmpfs tmpfs 200M 0 200M 0% /run/user/0
/dev/mapper/vg0-lv01 xfs 6.5G 33M 6.5G 1% /mnt/disk1
/dev/mapper/vg0-lv02 ext4 7.1G 14M 6.7G 1% /mnt/disk2
# pvmove가 바로 되려면 볼륨 그룹의 나머지 영역에 여유 공간이 있어야 한다.
[root@localhost ~]# vgreduce vg0 /dev/sdb3
Physical volume "/dev/sdb3" still in use
[root@localhost ~]#
[root@localhost ~]# pvmove /dev/sdb3
Insufficient free space: 1535 extents needed, but only 73 available
Unable to allocate mirror extents for vg0/pvmove0.
Failed to convert pvmove LV to mirrored.
# 이럴 때는 기존의 것을 합쳐줘야 한다.
# sdb4를 추가해서 공간이 늘어나면 옮겨준다.
# 일반적으로 디스크 용량을 옮길 때 같거나 큰 용량의 디스크를 extend 해줘야 한다.
# 그래야 추가할 수 있다.
[root@localhost ~]# vgextend vg0 /dev/sdb4
Volume group "vg0" successfully extended
[root@localhost ~]#
[root@localhost ~]# pvmove /dev/sdb3
/dev/sdb3: Moved: 0.07%
/dev/sdb3: Moved: 100.00%
# 다만 pvmove할 때 sdb3가 이동하는 영역은 시스템이 알아서 선택하는 것이다. 사용자 지정 불가하다.
# sdb3에 있던 내용이 sdb4로 이동한 것을 확인할 수 있다.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 4G 0 part
│ ├─vg0-lv01 253:0 0 6.5G 0 lvm /mnt/disk1
│ └─vg0-lv02 253:1 0 7.2G 0 lvm /mnt/disk2
├─sdb2 8:18 0 4G 0 part
│ ├─vg0-lv01 253:0 0 6.5G 0 lvm /mnt/disk1
│ └─vg0-lv02 253:1 0 7.2G 0 lvm /mnt/disk2
├─sdb3 8:19 0 6G 0 part
└─sdb4 8:20 0 6G 0 part
└─vg0-lv01 253:0 0 6.5G 0 lvm /mnt/disk1
sr0 11:0 1 1024M 0 rom
# 이후 삭제하려고 하면 정상적으로 삭제되는 것을 확인할 수 있다.
[root@localhost ~]# vgreduce vg0 /dev/sdb3
Removed "/dev/sdb3" from volume group "vg0"
# Tip! 한번에 삭제하는 방법
[root@localhost ~]# vgremove vg0
Do you really want to remove volume group "vg0" containing 2 logical volumes? [y/n]: y
Logical volume vg0/lv01 contains a filesystem in use.
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# umount /mnt/*
umount: /mnt/disk3: not mounted
[root@localhost ~]# vgremove vg0
Do you really want to remove volume group "vg0" containing 2 logical volumes? [y/n]: y
Do you really want to remove active logical volume vg0/lv01? [y/n]: y
Logical volume "lv01" successfully removed
Do you really want to remove active logical volume vg0/lv02? [y/n]: y
Logical volume "lv02" successfully removed
Volume group "vg0" successfully removed
# pvremove로 sdb를 모두 지우고 새로 만들면 만들어진다.
[root@localhost ~]# pvremove /dev/sdb[1-4]
Labels on physical volume "/dev/sdb1" successfully wiped.
Labels on physical volume "/dev/sdb2" successfully wiped.
Labels on physical volume "/dev/sdb3" successfully wiped.
Labels on physical volume "/dev/sdb4" successfully wiped.
[root@localhost ~]# blkid
/dev/sda1: UUID="88f82736-89b0-49e6-88c5-165c88bcc5bf" TYPE="swap"
/dev/sda2: UUID="231c776b-3197-4e9f-a142-6b80be0ca930" TYPE="xfs"
[root@localhost ~]#
[root@localhost ~]# vgcreate vg0 /dev/sdb[1-4]
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
Physical volume "/dev/sdb3" successfully created.
Physical volume "/dev/sdb4" successfully created.
Volume group "vg0" successfully created
[root@localhost ~]# vgremove vg0
Volume group "vg0" successfully removed
[root@localhost ~]# pvremove /dev/sdb[1-4]
Labels on physical volume "/dev/sdb1" successfully wiped.
Labels on physical volume "/dev/sdb2" successfully wiped.
Labels on physical volume "/dev/sdb3" successfully wiped.
Labels on physical volume "/dev/sdb4" successfully wiped.
# 파티션을 먼저하는것이 아니라 디스크 자체를 볼륨 그룹으로 만들 수 있다.
[root@localhost ~]# 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.
Command (m for help): d
Partition number (1-4, default 4):
Partition 4 is deleted
Command (m for help): d
Partition number (1-3, default 3):
Partition 3 is deleted
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 is deleted
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help):
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
└─sda2 8:2 0 56G 0 part /
sdb 8:16 0 20G 0 disk
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# vgcreate vg0 /dev/sdb
WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y
Wiping dos signature on /dev/sdb.
Physical volume "/dev/sdb" successfully created.
Volume group "vg0" successfully created
# 하나의 디스크 안에서 파티션을 나누고 볼륨 그룹 하는 것과
# 하나의 디스크 자체를 볼륨 그룹하는 것 중에 후자가 낫다.
# 즉 전자는 디스크를 파티션하고 파티션을 pv해서 볼륨 그룹하는 것이고
# 후자는 디스크 하나를 pv하고 볼륨 그룹하는 것이다.
# 여러개의 디스크를 각각 pv하고 그 전체를 볼륨 그룹해서 사용하는 방식을 자주 사용한다.
728x90
'Linux' 카테고리의 다른 글
[Linux] GRUB의 이해 (0) | 2022.03.04 |
---|---|
[Linux] 부트 프로세스 (0) | 2022.03.04 |
[Linux] LVM - Logical Volume Management (0) | 2022.02.25 |
[Linux] Swap memory (0) | 2022.02.25 |
[Linux] 리눅스 명령어 - at, atd, cron, crontab (작업 스케줄링) (0) | 2022.02.24 |
@TTOII :: 뭉게뭉게 클라우드
영차영차 성장 블로그
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!