LVM은 독립적으로 구성된 디스크 파티션을 하나로 연결하여 한 파티션처럼 사용할 수 있도록 해줌
PV(physical volume, 물리 볼륨) : /dev/sdb1, /dev/sdb2 같은 실제 하드디스크의 파티션을 의미
VG(volume group, 볼륨 그룹) : 여러 개의 PV를 그룹으로 묶은 것을 뜻한다. 예를 들어 /dev/sdb1, /dev/sdb2가 GRP1이라는 그룹을 만들 때 GRP1을 VG라고 함
LV(logical volume, 논리 볼륨) : VG를 다시 적절한 크기의 파티션으로 나눌 때 각 파티션을 LV라고 함
PE(physical extent) : PV가 가진 일정한 블록을 의미
LE(logical extent) : LV가 가진 일정한 블록을 의미
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 9.5M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 247G 5.0G 242G 2% /
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 379M 32K 379M 1% /run/user/0
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 256G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 254.9G 0 part
├─centos-root 253:0 0 246.9G 0 lvm /
└─centos-swap 253:1 0 8G 0 lvm [SWAP]
sdb 8:16 0 21G 0 disk
증설 된 디스크는 sdb
[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): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-44040191, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-44040191, default 44040191):
Using default value 44040191
Partition 1 of type Linux and of size 21 GiB is set
Command (m for help): p
Disk /dev/sdb: 22.5 GB, 22548578304 bytes, 44040192 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: 0x05939b2c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 44040191 22019072 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 256G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 254.9G 0 part
├─centos-root 253:0 0 246.9G 0 lvm /
└─centos-swap 253:1 0 8G 0 lvm [SWAP]
sdb 8:16 0 21G 0 disk
└─sdb1 8:17 0 21G 0 part
디스크 모든 섹터를 파티션 포인트로 잡아주면 된다.
그리고 sdb디스크에서 sdb1로 파티션이 생성된걸 확인 할 수 있다.
[root@localhost ~]# pvscan
PV /dev/sda2 VG centos lvm2 [254.90 GiB / 4.00 MiB free]
Total: 1 [254.90 GiB] / in use: 1 [254.90 GiB] / in no VG: 0 [0 ]
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# pvscan
PV /dev/sda2 VG centos lvm2 [254.90 GiB / 4.00 MiB free]
PV /dev/sdb1 lvm2 [<21.00 GiB]
Total: 2 [275.90 GiB] / in use: 1 [254.90 GiB] / in no VG: 1 [<21.00 GiB]
[root@localhost ~]#
[root@localhost ~]# vgcreate vg0 /dev/sdb1
Volume group "vg0" successfully created
[root@localhost ~]# vgdisplay -v vg0
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size <21.00 GiB
PE Size 4.00 MiB
Total PE 5375
Alloc PE / Size 0 / 0
Free PE / Size 5375 / <21.00 GiB
VG UUID Iy6JwH-2oRa-zm7K-2Y7S-X0r6-9Ww4-Rhip8G
--- Physical volumes ---
PV Name /dev/sdb1
PV UUID DgGAd8-Zw2S-siiU-kpyw-fpnl-JQoY-vTLNXr
PV Status allocatable
Total PE / Free PE 5375 / 5375
[root@localhost ~]# lvcreate vg0 -l 100%FREE -n lv0
Logical volume "lv0" created.
[root@localhost ~]# lvscan
ACTIVE '/dev/centos/swap' [8.00 GiB] inherit
ACTIVE '/dev/centos/root' [<246.90 GiB] inherit
ACTIVE '/dev/vg0/lv0' [<21.00 GiB] inherit
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 256G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 254.9G 0 part
├─centos-root 253:0 0 246.9G 0 lvm /
└─centos-swap 253:1 0 8G 0 lvm [SWAP]
sdb 8:16 0 21G 0 disk
└─sdb1 8:17 0 21G 0 part
└─vg0-lv0 253:2 0 21G 0 lvm
LVM이 생성되어있는걸 볼 수 있다.
마운트 포인트가 안잡혀있으니 아직까진 사용할 수 없다.
lv에 파일시스템을 생성해줘야함
[root@localhost ~]# mkfs -t ext4 /dev/vg0/lv0
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
1376256 inodes, 5504000 blocks
275200 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
168 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]#
[root@localhost ~]# mkdir /mnt/disk1
[root@localhost ~]# mount /dev/vg0/lv0 /mnt/disk1
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 9.5M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 247G 5.0G 242G 2% /
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 379M 32K 379M 1% /run/user/0
/dev/mapper/vg0-lv0 21G 45M 20G 1% /mnt/disk1
[root@localhost ~]#
신규 디렉터리를 생성하고, 생성 된 디렉터리에 마운트를 잡아주면 된다
마지막으로 df -h로 확인해보면 신규디렉터리에 마운트포인트가 잡힌 걸 확인 할 수 있다.
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <254.91 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 65255
Free PE 1
Allocated PE 65254
PV UUID HRYCcd-RQ8W-psnk-qt2S-TSI4-OYjl-ulHGX3
"/dev/sdb1" is a new physical volume of "<21.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <21.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID DgGAd8-Zw2S-siiU-kpyw-fpnl-JQoY-vTLNXr
[root@localhost ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from <246.90 GiB (63206 extents) to <267.90 GiB (68582 extents).
Logical volume centos/root successfully resized.
[root@localhost ~]# resize2fs /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 9.5M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 247G 5.0G 242G 2% /
/dev/sda1 xfs 1014M 185M 830M 19% /boot
tmpfs tmpfs 379M 32K 379M 1% /run/user/0
에러가 발생했다, 파일시스템이 안맞는 것으로 추측된다.
파일시스템마다 명령어가 다르니 주의하도록!
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=16180736 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=64722944, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=31603, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 64722944 to 70227968
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 9.5M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 268G 5.0G 263G 2% /
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 379M 32K 379M 1% /run/user/0
[root@localhost ~]#
기존 디렉터리 /에 21G 증설된 걸 볼 수 있다.