标签:sequence dir gdi xfs linux lvm 表示 100% 设备 5.0
这篇文章主要讲述lvm的基本术语,以及如何创建lvm。由于传统分区的乏方式带来的诸多问题:如我们碰到当分区大小不足的时候,只能通过增加新的硬盘,然后对新的硬盘进行分区、格式化后,将之前分区的所有数据都拷贝到新的分区里面,在生产环境,这是不能接受的,对于服务器我们要求7*24小时不间断运行,如果卸载分区,然后拷贝数据,服务势必受到影响,这种损失无法承担;另外,如果分区数据非常多,又会耗费相当长的时间;诸多限制,从而诞生了lvm
LVM: (Logical Volume Manager),逻辑卷管理,可以实现在线调整分区大小。
可以是一个分区或者一块硬盘,设备名不变,相当于贴标签
由一个或者多个pv组成的一个逻辑空间,设备名自定义,后期可动态添加pv来调整容量大小
逻辑卷建立在卷组之上,即在卷组上划分的一段空间,设备名自定义,可根据卷组的大小实现在线扩展或者缩减
PE就是我们逻辑卷管理的最基本单位,默认大小是4M大小,可以在创建卷组的时候自定义大小
等同于PE,不过是在逻辑卷中成为LE
pv:
查看pv信息:
pvs pvdisplay
创建pv:
pvcreate /dev/DEVICE
vg:
查看vg:
vgs vgdisplay
创建vg:
vgcreate [-s PE size] vgName pvName [pvName...]
管理vg:
vgextend vgName pvName
vgreduce vgName pvName
删除vg:
pvmove————> vgremove
lv:
真设备名:/dev/dm-#
软链接:/dev/mapper/vgName-lvName
/dev/vgName/lvName
查看lv:
lvs lvdisplay
创建lv:
lvcreate -L #[mMgGtT] -n lvName vgName ###直接指定lv大小
lvcreate -l 60%VG -n lvName vgName ###占vg百分比的方式指定lv大小
lvcreate -l 100%FREE -n lvName vgName ###使用vg全部剩余空间指定
删除lv:
lvremove /dev/vgName/lvName
重设文件系统大小:
ext系列:resize2fs [能扩展能缩减]
xfs系列: [只能扩展]
新增两块硬盘或者分区,重启识别;我这里已经提前准备了几块20G的硬盘。
[root@centos7 ~ ]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 30G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 3G 0 part [SWAP]
sdb 8:16 0 20G 0 disk
sdc 8:32 0 20G 0 disk
sdd 8:48 0 20G 0 disk
sde 8:64 0 20G 0 disk
sr0 11:0 1 8.8G 0 rom
注意:不建议对整个磁盘做PV初始化,建议使用分区(分区id调整为8e)
步骤1:分区并和设置分区类型
对/dev/sdb和/dev/sdc分别划分两个分区,大小为1G和2G
[root@centos7 ~ ]#fdisk -l /dev/sd{b,c}
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x5250ed1c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
/dev/sdb2 2099200 6293503 2097152 8e Linux LVM
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: 0xf15ae421
Device Boot Start End Blocks Id System
/dev/sdc1 2048 2099199 1048576 8e Linux LVM
/dev/sdc2 2099200 6293503 2097152 8e Linux LVM
步骤2:创建pv
[root@centos7 ~ ]#pvcreate /dev/sd{b,c}{1,2}
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
Physical volume "/dev/sdc1" successfully created.
Physical volume "/dev/sdc2" successfully created.
步骤3:查看pv信息
[root@centos7 ~ ]#pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 1.00g 1.00g
/dev/sdb2 lvm2 --- 2.00g 2.00g
/dev/sdc1 lvm2 --- 1.00g 1.00g
/dev/sdc2 lvm2 --- 2.00g 2.00g
[root@centos7 ~ ]#pvdisplay
"/dev/sdb2" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name ##显示为空,表示是孤立的设备,不属于任何卷组
PV Size 2.00 GiB
Allocatable NO
PE Size 0 ## PE大小未指定,在创建vg时才能指定
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Gc3f6r-gTjL-aG1w-Rn2P-zYGS-Iw0E-D7D8La ##注意:这里的UUID和文件系统的UUID不同,对比下面的blkid命令发现,已经显示为lvm成员,但是并没有显示文件系统;
[root@centos7 ~ ]#blkid
/dev/sda1: UUID="85313710-7117-4f9a-8b4b-a76fb36b7658" TYPE="xfs"
/dev/sda2: UUID="04d49ea8-1c42-4f88-9a0f-cfd5a7dae610" TYPE="xfs"
/dev/sda3: UUID="4e25d8dd-0f3d-40b3-8dc9-99fad70cfbf0" TYPE="xfs"
/dev/sda5: UUID="68f083ae-dcb4-4536-89b8-f5fda10ea7fc" TYPE="swap"
/dev/sdb1: UUID="e1wvwN-y6Sz-tDye-2hPt-3iIq-CShq-mAyxjc" TYPE="LVM2_member"
/dev/sdb2: UUID="Gc3f6r-gTjL-aG1w-Rn2P-zYGS-Iw0E-D7D8La" TYPE="LVM2_member"
/dev/sdc1: UUID="kwKous-XzVG-h9xY-b217-pwWd-yYS7-tycYae" TYPE="LVM2_member"
/dev/sdc2: UUID="kkVrLQ-pQSK-eTzs-aktd-tMWa-ChHk-4qkWES" TYPE="LVM2_member"
/dev/sr0: UUID="2018-05-07-12-53-47-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PT
......
步骤1:
[root@centos7 ~ ]#vgcreate vg0 -s 16M /dev/sd{b,c}{1,2} ##-s指定PE大小
Volume group "vg0" successfully created
步骤2:查看vg信息
[root@centos7 ~ ]#vgs
VG #PV #LV #SN Attr VSize VFree
vg0 4 0 0 wz--n- <5.94g <5.94g
[root@centos7 ~ ]#vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 4
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 4
Act PV 4
VG Size <5.94 GiB
PE Size 16.00 MiB ##PE大小
Total PE 380
Alloc PE / Size 0 / 0 ##已使用的PE
Free PE / Size 380 / <5.94 GiB ##空闲的PE
VG UUID 0PV32k-u0PM-0wh5-VyWR-A5qD-ERXa-2VPEiJ
[root@centos7 ~ ]#pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg0 lvm2 a-- 1008.00m 1008.00m
/dev/sdb2 vg0 lvm2 a-- 1.98g 1.98g
/dev/sdc1 vg0 lvm2 a-- 1008.00m 1008.00m
/dev/sdc2 vg0 lvm2 a-- 1.98g 1.98g
[root@centos7 ~ ]#pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name vg0 ##不再孤立,归属于vg0卷组
PV Size 1.00 GiB / not usable 16.00 MiB
Allocatable yes
PE Size 16.00 MiB ##PE的大小被定义
Total PE 63
Free PE 63
Allocated PE 0
PV UUID e1wvwN-y6Sz-tDye-2hPt-3iIq-CShq-mAyxjc
.......
步骤1:
[root@centos7 ~ ]#lvcreate -n lv0 -L 1500M vg0 ## -n指定逻辑卷名称,-L指定大小(K,M,G,T,P,E)
Rounding up size to full physical extent <1.47 GiB
Logical volume "lv0" created.
步骤2:查看lv信息
[root@centos7 ~ ]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv0 vg0 -wi-a----- <1.47g
[root@centos7 ~ ]#lvdisplay
--- Logical volume ---
LV Path /dev/vg0/lv0 ## 设备名
LV Name lv0
VG Name vg0
LV UUID HFNlrP-1da7-rdiJ-Jqew-0ym5-Lx0H-twQup5
LV Write Access read/write
LV Creation host, time centos7.localdomain, 2018-08-15 16:31:01 +0800
LV Status available
# open 0
LV Size <1.47 GiB
Current LE 94 ##当前已使用的LE数量(PE在lv中成为LE)
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@centos7 ~ ]#pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg0 lvm2 a-- 1008.00m 1008.00m
/dev/sdb2 vg0 lvm2 a-- 1.98g 528.00m ##即/dev/sdb2参与到lv的创建中
/dev/sdc1 vg0 lvm2 a-- 1008.00m 1008.00m
/dev/sdc2 vg0 lvm2 a-- 1.98g 1.98g
--- Physical volume ---
PV Name /dev/sdb2
VG Name vg0
PV Size 2.00 GiB / not usable 16.00 MiB
Allocatable yes
PE Size 16.00 MiB
Total PE 127
Free PE 33
Allocated PE 94 ##已使用的PE数量为94
PV UUID Gc3f6r-gTjL-aG1w-Rn2P-zYGS-Iw0E-D7D8La
步骤3:格式化
[root@centos7 ~ ]#mkfs.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
96384 inodes, 385024 blocks
19251 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=394264576
12 block groups
32768 blocks per group, 32768 fragments per group
8032 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
步骤4:挂载使用
[root@centos7 ~ ]#mkdir test1
[root@centos7 ~ ]#mount /dev/vg0/lv0 test1
[root@centos7 ~ ]#df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 52403200 3918996 48484204 8% /
devtmpfs 613144 0 613144 0% /dev
tmpfs 629036 0 629036 0% /dev/shm
tmpfs 629036 18032 611004 3% /run
tmpfs 629036 0 629036 0% /sys/fs/cgroup
/dev/sda3 31441920 1036092 30405828 4% /data
/dev/sda1 1038336 157932 880404 16% /boot
tmpfs 125808 12 125796 1% /run/user/42
tmpfs 125808 0 125808 0% /run/user/0
/dev/mapper/vg0-lv0 1483088 4512 1385188 1% /root/test1
标签:sequence dir gdi xfs linux lvm 表示 100% 设备 5.0
原文地址:http://blog.51cto.com/13668904/2160433