简介
LVM技术是为了解决能够对磁盘大小进行灵活变动而诞生的。
新增逻辑卷
一 创建逻辑卷
1 在虚拟机里添加2快5G硬盘
2 创建物理卷
查看一下当前磁盘 ls /dev/sd*
[root@linuxprobe ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdc
创建物理卷 pvcreate /dev/sd[b-c]
[root@linuxprobe ~]# pvcreate /dev/sd[b-c]
Physical volume "/dev/sdb" successfully created.
Physical volume "/dev/sdc" successfully created.
3 创建卷组
查看物理卷 pvdisplay
[root@linuxprobe ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size <49.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 12543
Free PE 0
Allocated PE 12543
PV UUID GsUSP1-tqbU-lvqR-M8S7-xm6j-vRQG-LDDicQ
"/dev/sdb" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID J4RBpE-byh2-mpK8-oh0I-KmWX-vEAo-DJIDQM
"/dev/sdc" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID EuEBqm-a6Hz-hNKh-vmfo-ZmG5-V7OF-rFRBp9
创建卷组,名称sonny,使用sdb和sdc vgcreate sonny /dev/sd[b-c]
[root@linuxprobe ~]# vgcreate sonny /dev/sd[b-c]
Volume group "sonny" successfully created
4 创建逻辑卷
查看卷组 vgdisplay
[root@linuxprobe ~]# vgdisplay
--- Volume group ---
VG Name sonny
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.99 GiB
PE Size 4.00 MiB
Total PE 2558
Alloc PE / Size 0 / 0
Free PE / Size 2558 / 9.99 GiB
VG UUID 3g6eZR-cjdw-x4yE-RGf2-wcGw-lSFV-YZDvS7
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12543 / <49.00 GiB
Free PE / Size 0 / 0
VG UUID 5YMEI8-CF12-9dBp-ZfJ5-sdif-PC94-rqwhM4
创建逻辑卷,使用卷组sonny 名称为xiaofeng,大小为100个PE(PE,基本单元,默认容量为4M) lvcreate -n xiaofeng -l 100 sonny
[root@linuxprobe ~]# lvcreate -n xiaofeng -l 100 sonny
Logical volume "xiaofeng" created.
二 格式化逻辑卷
查看逻辑卷 lvdisplay
[root@linuxprobe ~]# lvdisplay
--- Logical volume ---
LV Path /dev/sonny/xiaofeng
LV Name xiaofeng
VG Name sonny
LV UUID Z5JCJH-WgjQ-RG4Q-aAyw-MMt3-fDos-G7JCIU
LV Write Access read/write
LV Creation host, time linuxprobe.com, 2021-07-04 19:20:56 +0800
LV Status available
# open 0
LV Size 400.00 MiB
Current LE 100
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID XKgnDx-5cnL-SetS-GRFL-s14S-Dz1d-yASVag
LV Write Access read/write
LV Creation host, time linuxprobe.com, 2021-06-08 06:02:17 +0800
LV Status available
# open 2
LV Size 5.00 GiB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 3agf6T-s3v7-BMjq-Dxi7-Rvmw-GiKo-Umjt6l
LV Write Access read/write
LV Creation host, time linuxprobe.com, 2021-06-08 06:02:18 +0800
LV Status available
# open 1
LV Size <44.00 GiB
Current LE 11263
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
格式化逻辑卷 mkfs.ext4 /dev/sonny/xiaofeng
[root@linuxprobe ~]# mkfs.ext4 /dev/sonny/xiaofeng
mke2fs 1.44.3 (10-July-2018)
Creating filesystem with 409600 1k blocks and 102400 inodes
Filesystem UUID: ee9e3b76-e966-4625-82d9-af0b866c81c1
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
三 挂载逻辑卷
1 创建挂载目录 mkdir -p /root/new_disk/lv/xiaofeng
[root@linuxprobe ~]# mkdir -p /root/new_disk/lv/xiaofeng
2 配置挂载信息
编辑配置文件 vim /etc/fstab
[root@linuxprobe ~]# vim /etc/fstab
在最后一行添加 /dev/sonny/xiaofeng /root/new_disk/lv/xiaofeng ext4 defaults 0 0
#
# /etc/fstab
# Created by anaconda on Tue Jun 8 06:02:20 2021
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=2c1949d3-5cd8-4b71-b60d-8885bfc326e0 /boot xfs defaults 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/sonny/xiaofeng /root/new_disk/lv/xiaofeng ext4 defaults 0 0
~
3 挂载逻辑卷
挂载 mount -a
[root@linuxprobe ~]# mount -a
查看挂载信息 df -hT|grep xiaofeng
[root@linuxprobe ~]# df -hT|grep xiaofeng
/dev/mapper/sonny-xiaofeng ext4 380M 2.3M 354M 1% /root/new_disk/lv/xiaofeng
大功告成!