标签:LVM逻辑卷
一、LVM(上)2、准备物理卷
使用 pvcreate命令创建物理卷:
[root@linux-01 ~]# pvcreate /dev/sdb1
如果没报错,请忽略。如果运行pvcreate /dev/sdb1报如图错误,则可以执行下: partprobe命令,这个命令可以自动生成/dev/sdb1文件
[root@linux-01 ~]# 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@linux-01 ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
[root@linux-01 ~]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created.
物理卷创建完成。
(扩展:使用 pvcreate命令需要yum install -y lvm2,如果不知道yum后面跟的包名称,可以使用命令: yum provides "/pvcreate"查找需要安装包的名称)
[root@linux-01 ~]# pvcreate /dev/sdb1
-bash: pvcreate: command not found
[root@linux-01 ~]# yum provides "/pvcreate"
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
7:lvm2-2.02.171-8.el7.x86_64 : Userland logical volume management tools
Repo : base
Matched from:
Filename : /usr/sbin/pvcreate
然后再使用yum install -y lvm2命令安装
二、LVM(中)
1、查看物理卷命令:
[root@linux-01 ~]# pvdisplay
或者 pvs命令可以更直观的查看
[root@linux-01 ~]# 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
2、创建巻组
vgcreate 巻组名字 对应的物理卷
[root@linux-01 ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2
Volume group "vg1" successfully created
查看巻组信息:
[root@linux-01 ~]# vgdisplay
或者 vgs查看巻组
[root@linux-01 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 0 0 wz--n- 1.99g 1.99g
删除巻组命令:vgremove
3、创建完巻组之后,创建逻辑卷
[root@linux-01 ~]# lvcreate -L 100M -n lv1 vg1
Logical volume "lv1" created.
4、格式化
[root@linux-01 ~]# mkfs.ext4 /dev/vg1/lv1
5、挂载
[root@linux-01 ~]# mount /dev/vg1/lv1 /mnt/
6、扩容逻辑卷:
作用:能够很方便的扩容和缩容
命令格式: lvresize -L 新的扩容大小 逻辑卷
lvresize -L 200M /dev/vg1/lv1 重新设置卷大小
[root@linux-01 ~]# umount /mnt
[root@linux-01 ~]# lvresize -L 200M /dev/vg1/lv1 //
New size (50 extents) matches existing size (50 extents).
e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext4执行)
[root@linux-01 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg1/lv1: 13/25688 files (7.7% non-contiguous), 8899/102400 blocks
resize2fs /dev/vg1/lv1 更新逻辑卷信息(ext4执行)
如果不更新,可能导致在挂载的时候识别新的大小
[root@linux-01 ~]# resize2fs /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 204800 blocks long.
7、缩减逻辑卷(xfs不支持)
先umount
[root@linux-01 ~]# umount /mnt/
e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext)
[root@linux-01 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg1/lv1: 13/49400 files (7.7% non-contiguous), 11887/204800 blocks
resize2fs /dev/vg1/lv1 100M 更新逻辑卷信息(ext)
[root@linux-01 ~]# resize2fs /dev/vg1/lv1 100M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 102400 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 102400 blocks long.
lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
[root@linux-01 ~]# lvresize -L 100M /dev/vg1/lv1
WARNING: Reducing active logical volume to 100.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: y
Size of logical volume vg1/lv1 changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents).
Logical volume vg1/lv1 successfully resized.
使用 lvdisplay 或 lvs 命令查看逻辑卷大小
[root@linux-01 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg1/lv1
LV Name lv1
VG Name vg1
LV UUID iHRmSs-fVEk-nr3D-0FwQ-M4FR-Emcm-Aqi3NT
LV Write Access read/write
LV Creation host, time linux-01, 2018-04-11 22:57:02 +0800
LV Status available
LV Size 100.00 MiB //大小显示100M
Current LE 25
Segments 1
Allocation inherit
Read ahead sectors auto
8、xfs扩容缩容(不需要卸载)
首先重新格式化:
[root@linux-01 ~]# mkfs.xfs -f /dev/vg1/lv1
meta-data=/dev/vg1/lv1 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
扩容到300M
[root@linux-01 ~]# lvresize -L 300M /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 300.00 MiB (75 extents).
Logical volume vg1/lv1 successfully resized.
扩容完lvs命令查看是否成功
[root@linux-01 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 300.00m
操作完之后xfs文件系统需要执行: xfs_growfs /dev/vg1/lv1
[root@linux-01 ~]# xfs_growfs /dev/vg1/lv1
meta-data=/dev/mapper/vg1-lv1 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 25600 to 76800
df -h查看
[root@linux-01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 28G 1.5G 27G 6% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.8M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 197M 97M 100M 50% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg1-lv1 297M 5.5M 292M 2% /mnt //xfs文件系统已经扩容成功
三、LVM(下)
扩展巻组
扩展巻组命令:vgextend vg1 /dev/sdb3
[root@linux-01 ~]# vgextend vg1 /dev/sdb3
Volume group "vg1" successfully extended
查看扩展巻组后的巻组大小: vgdisplay 或者 vgs 命令都可以查看
[root@linux-01 ~]# vgdisplay
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size <2.99 GiB
PE Size 4.00 MiB
Total PE 765
Alloc PE / Size 75 / 300.00 MiB
Free PE / Size 690 / <2.70 GiB
VG UUID I6GubU-Jycp-3x7k-bjLW-Rhm3-zpwf-yFU68Q
[root@linux-01 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 3 1 0 wz--n- <2.99g <2.70g
lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
四、磁盘故障小案例
如果挂载完磁盘重启服务器出现有报错情况,有可能是挂载有问题,需要 vi /etc/fstab 文件,把里面最后一行删掉,保存退出再重启就没有问题了
标签:LVM逻辑卷
原文地址:http://blog.51cto.com/13669226/2097205