准备磁盘分区
fdisk /dev/sdb
n 创建三个新分区,分别1G
t 改变分区类型为8e
准备物理卷
pvcreate /dev/sdb1
pvcreate /dev/sdb2
pvcreate /dev/sdb3
pvdisplay/pvs 列出当前的物理卷
pvremove /dev/sdb3 删除物理卷
准备卷组
vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
vgdisplay /vgs列出卷组
vgremove vg1 删除物理卷
创建逻辑卷
lvcreate -L 200M -n lv1 vg1
lvdisplay 列出逻辑卷
格式化mkfs.xfs /dev/vg1/lv1,再挂载
lvremove /dev/vg1/lv1 删除逻辑卷
扩容逻辑卷
lvresize -L 300M /dev/vg1/lv1 重新设置卷大小
e2fsck -f /dev/vg1/lv1 检查磁盘错误 (ext4执行)
resize2fs /dev/vg1/lv1 更新逻辑卷信息(ext4执行)
xfs_growfs /dev/vg1/lv1 xfs文件系统需要执行
缩减逻辑卷(xfs不支持 )
先umount
e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext)
resize2fs /dev/vg1/lv1 100M 更新逻辑卷信息(ext)
lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
扩展卷组
fdisk /dev/sdb 新增/dev/sdb5(逻辑分区8e) 2G
pvcreate /dev/sdb5
vgextend vg1 /dev/sdb5
lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
Lvm
1.创建物理分区;2.物理分区设置成物理卷;
3.物理卷设置成卷组;
4.卷组划分成逻辑卷,
5.然后再格式化,挂载
- 先创建3个分区,在分区的时候按创建分区,按t设置分区类型8e 为lvm
[root@localhost ~]# fdisk /dev/sdb
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+1G
分区 1 已设置为 Linux 类型,大小设为 1 GiB
命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xbc339889
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
/dev/sdb2 2099200 4196351 1048576 8e Linux LVM
/dev/sdb3 4196352 6293503 1048576 8e Linux LVM
1.创建物理卷
需要安装命令:pvcreate
注:如果只知道命令,不知道这个命令是那个包安装的,可以使用命令:yum provides /*/[命令] 来查找命令是那个包安装的。
[root@localhost ~]# yum provides /*/pvcreate
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 129 kB 00:00:00
(2/2): updates/7/x86_64/primary_db | 3.6 MB 00:00:02
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
extras/7/x86_64/filelists_db | 486 kB 00:00:00
updates/7/x86_64/filelists_db | 2.1 MB 00:00:01
1:bash-completion-2.1-6.el7.noarch : Programmable completion for Bash
源 :base
匹配来源:
文件名 :/usr/share/bash-completion/completions/pvcreate
7:lvm2-2.02.171-8.el7.x86_64 : Userland logical volume management tools
源 :base
匹配来源:
文件名 :/usr/sbin/pvcreate
1.1 安装完使用命令:pvcreate 创建物理卷
[root@localhost ~]# pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
[root@localhost ~]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created.
1.2 物理卷创建完后,使用命令:pvdisplay或者pvs来查看信息
[root@localhost ~]# pvdisplay
"/dev/sdb2" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID GqWi3Q-4XT9-1RyO-JE3C-Zber-oPw5-4zGyyp
"/dev/sdb1" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID zxaUnf-kxNt-Udki-sYSk-B3so-8hi1-qTM9gB
"/dev/sdb3" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb3
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 6TgcyT-DY1j-9PHt-upJH-nZql-V20D-Ttbm1w
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 1.00g 1.00g
/dev/sdb2 lvm2 --- 1.00g 1.00g
/dev/sdb3 lvm2 --- 1.00g 1.00g
- pvremove /dev/sdb3 删除物理卷
2.创建卷组
命令:vgcreate来创建卷组,可以1或者多个物理卷来创建1个卷组;
格式:vgcreate [卷组名] dev/sdb1 多个物理卷用空格隔开;
root@llocalhost ~]# vgcreate vg1 /dev/sdb1 dev/sdb2
Device dev/sdb2 not found (or ignored by filtering).
用命令:vgdisplay 或者vgs来查看信息:
[root@localhost ~]# vgdisplay
--- 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 1.99 GiB
PE Size 4.00 MiB
Total PE 510
Alloc PE / Size 0 / 0
Free PE / Size 510 / 1.99 GiB
VG UUID FbIw1F-dYh6-LL3L-Ah8O-NSTQ-v5gN-G2Lpsy
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 0 0 wz--n- 1.99g 1.99g
- vgremove vg1 删除物理卷
3.创建逻辑卷
命令:lvcreate
[root@localhost ~]# lvcreate -L 100M -n lv1 vg1
Logical volume "lv1" created.
命令:lvdisplay或者lvs来查看信息
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg1/lv1
LV Name lv1
VG Name vg1
LV UUID TOmOhK-Hf1Y-aKkQ-nfP4-9tu3-cmUD-lbGjMz
LV Write Access read/write
LV Creation host, time linux-128, 2017-11-06 22:54:39 +0800
LV Status available
# open 0
LV Size 100.00 MiB
Current LE 25
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@linux-128 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 100.00m
4.格式化成ext4
[root@localhost ~]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
5.挂载:mount
root@localhost ~]# mount /dev/vg1/lv1 /mnt
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 16G 1.3G 15G 8% /
devtmpfs 907M 0 907M 0% /dev
tmpfs 916M 0 916M 0% /dev/shm
tmpfs 916M 8.6M 908M 1% /run
tmpfs 916M 0 916M 0% /sys/fs/cgroup
/dev/sda1 197M 109M 88M 56% /boot
tmpfs 184M 0 184M 0% /run/user/0
/dev/mapper/vg1-lv1 93M 1.6M 85M 2% /mnt
[root@linux-128 ~]# mkdir /mnt/1122
[root@linux-128 ~]# touch /mnt/23.txt
[root@linux-128 ~]# echo "112233" > 23.txt
[root@linux-128 ~]# cat 23.txt
112233