磁盘管逻辑卷(LVM)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了磁盘管逻辑卷(LVM)相关的知识,希望对你有一定的参考价值。
磁盘管理逻辑卷(LVM)
逻辑卷(Logical Volume)是由逻辑磁盘形成的虚拟盘,也可称为磁盘分区。
逻辑卷(lvm)允许对卷进行方便操作的抽象层,包括重新设定文件系统的大小 ,允许在多个物理设备间重新组织文件系统 ,将一个或多个底层设备组成一个逻辑设备的模块 。物理卷创建逻辑卷是由物理区域(PE)组成。通关过交换PE来进行资料的转换,将原来LV内的PE转移到其他的 设备中以降低LV的容量,或将其他设备中的PE加到LV中以加大容量,弹性的更改文件了系统容量。
设备名:/dev/dm-#
软链接:
/dev/mapper/VGname/LVname
/dev/mapper/vol0-root
/dev/VGname/LVname
/dev/vol0/root
查询设备名或链接命令
ll /dev/dm* #查看lv2801逻辑卷名字
brw-rw----. 1 root disk 253, 0 Feb 24 09:35 /dev/dm-0
ll /dev/mapper/vgmagedu-lv2801 #查看lv2801逻辑卷名字
lrwxrwxrwx. 1 root root 7 Feb 24 09:31 /dev/mapper/vgmagedu-lv2801 -> ../dm-0
ll /dev/testvg/* #查看lv2801逻辑卷名字
lrwxrwxrwx. 1 root root 7 Feb 24 09:31 /dev/vgmagedu/lv2801 -> ../dm-0
pv管理工具
显示物理卷信息
pvscan 简单查看创建pvcreate的信息
pvs 简单查看创建pvcreate的信息
pvdisplay 详细查看创建pvcreate的信息
[[email protected] ~]#pvs -------> 简单查看创建pvcreate的信息
PV VG Fmt Attr PSize PFree
/dev/sdp testvg lvm2 a--u 9.98g 9.98g
/dev/sdq testvg lvm2 a--u 10.98g 5.98g
[[email protected] ~]#pvscan ------->简单查看创建pvcreate的信息
PV /dev/sdq VG testvg lvm2 [10.98 GiB / 5.98 GiB free]
PV /dev/sdp VG testvg lvm2 [9.98 GiB / 9.98 GiB free]
Total: 2 [20.97 GiB] / in use: 2 [20.97 GiB] / in no VG: 0 [0 ]
[[email protected] ~]#pvdisplay ------>详细查看创建pvcreate的信息
--- Physical volume ---
PV Name /dev/sdq
VG Name testvg
PV Size 11.00 GiB / not usable 16.00 MiB
Allocatable yes
PE Size 16.00 MiB
Total PE 703
Free PE 383
Allocated PE 320
PV UUID ZtmVQG-U43k-nEg8-ndK3-AOAO-3Uti-AC3HXO
--- Physical volume ---
PV Name /dev/sdp
VG Name testvg
PV Size 10.00 GiB / not usable 16.00 MiB
Allocatable yes
PE Size 16.00 MiB
Total PE 639
Free PE 639
Allocated PE 0
PV UUID 2F7Jxh-4acs-2HX6-jGrh-S7f2-lnKo-Yfnc49
创建物理卷
pvcreate /dev/sda9 // 在 硬盘头部信息中添加成LVM格式
[[email protected] ~]#pvcreate /dev/sdr ----->创建物理卷(pv)
Physical volume "/dev/sdr" successfully created
[[email protected] ~]#pvs -------> 简单查看创建pvcreate的信息
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 ---- 2.00g 2.00g
/dev/sdp testvg lvm2 a--u 9.98g 9.98g
/dev/sdq testvg lvm2 a--u 10.98g 5.98g
/dev/sdr lvm2 ---- 512.00m 512.00m*
删除物理卷
pvmove 搬移PV中的资料(只限于同一VG中)
pvremove /dev/sda9 /dev/md1 //删除头部的LVM格式信息
[[email protected] ~]#pvremove /dev/sdr ---->删除物理卷
Labels on physical volume "/dev/sdr" successfully wiped
[[email protected] ~]#pvs -------> 简单查看创建pvcreate的信息
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 ---- 2.00g 2.00g
/dev/sdp testvg lvm2 a--u 9.98g 9.98g
/dev/sdq testvg lvm2 a--u 10.98g 5.98g
以二进制方式查看
hexdump -C -n 10240 /dev/sdq //以二进制方式查看硬盘前1024字节信息
[[email protected] ~]#hexdump -C -n 1024 /dev/sdb
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000200 4c 41 42 45 4c 4f 4e 45 01 00 00 00 00 00 00 00 |LABELONE........|
00000210 fe f1 4c 80 20 00 00 00 4c 56 4d 32 20 30 30 31 |..L. ...LVM2 001|
00000220 33 36 46 38 75 50 39 50 41 74 58 6c 67 6a 4d 65 |36F8uP9PAtXlgjMe|
00000230 74 52 44 71 33 35 32 43 6f 78 78 79 75 53 6a 43 |tRDq352CoxxyuSjC|
00000240 00 00 00 80 00 00 00 00 00 00 10 00 00 00 00 00 |................|
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000260 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 |................|
00000270 00 f0 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000280 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 |................|
00000290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000400
vg管理工具
显示卷组
vgs -------> 简单查看逻辑卷组(vg)的信息
vgscan -------> 简单查看逻辑卷组(vg)的信息
vgdisplay -------> 详细查看逻辑卷组(vg)的信息
[[email protected] ~]#vgs -------> 简单查看逻辑卷组(vg)的信息
VG #PV #LV #SN Attr VSize VFree
testvg 2 3 2 wz--n- 20.97g 15.97g
[[email protected] ~]#vgscan -------> 简单查看逻辑卷组(vg)的信息
Reading all physical volumes. This may take a while...
Found volume group "testvg" using metadata type lvm2
[[email protected] ~]#vgdisplay -------> 详细查看逻辑卷组(vg)的信息
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 11
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 20.97 GiB
PE Size 16.00 MiB
Total PE 1342
Alloc PE / Size 320 / 5.00 GiB
Free PE / Size 1022 / 15.97 GiB
VG UUID ZTCj4I-vEja-SKe2-3EcL-Prme-iqLe-Cmix8v
创建卷组
vgcreate vgmagedu /dev/sda9
vgcreate -s 16M 卷组名(vg) 磁盘 #指定PE大小为16MB
[[email protected] ~]#vgcreate vg1 /dev/sdr
Volume group "vg1" successfully created
[[email protected] ~]#vgs
VG #PV #LV #SN Attr VSize VFree
testvg 2 3 2 wz--n- 20.97g 15.97g
vg1 1 0 0 wz--n- 508.00m 508.00m
管理卷组()
**在vg里添加额外的pv
vgextend testvg /dev/sdq //增加卷组大小
[[email protected] ~]#vgextend vg1 /dev/sdq
Volume group "vg1" successfully extended
[[email protected] ~]#vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 0 0 wz--n- 11.49g 11.49g
**在vg内移除pv
vgreduce vg名 pv名
[[email protected] ~]#vgreduce vg1 /dev/sdq
Removed "/dev/sdq" from volume group "vg1"
[[email protected] ~]#vgs
VG #PV #LV #SN Attr VSize VFree
vg1 1 0 0 wz--n- 508.00m 508.00m
删除一个vg!卷组
vgremove: //删除卷组
先做pvmove,再做vgremove
[[email protected] ~]#vgremove vg1
Volume group "vg1" successfully removed
[[email protected] ~]#vgs
[[email protected] ~]#
修改卷组名
vgrename 源vg名 新vg名
[[email protected] ~]#vgrename vg1 vg2
Volume group "vg1" successfully renamed to "vg2"
[[email protected] ~]#vgs
VG #PV #LV #SN Attr VSize VFree
vg2 1 0 0 wz--n- 508.00m 508.00m
vgreduce 卷组 分区 ---删除卷组中的逻辑卷来缩小卷组大小,不可以删除全部
将某个pv从vg中删除,但该pv包含数据
1.pvmove /dev/sda9 [/dev/md1]
2.vgreduce vgmagedu /dev/sda9
3.pvremove /dev/sda9
跨主机迁移卷组
vgchange -an vgtest # -an 关掉不在激活
vgexport vgtest # 设置为被导出状态
vgimport vgtest #设置为导入状态
vgchange -ay #-ay 设置为激活状态
lv管理工具
显示逻辑卷
lvs -------> 简单查看逻辑卷(lv)的信息
lvscan -------> 简单查看逻辑卷(lv)的信息
Lvdisplay -------> 详细查看逻辑卷(lv)的信息
[[email protected] ~]#lvs -------> 简单查看逻辑卷(lv)的信息
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg2 -wi-a----- 52.00m
[[email protected] ~]#lvscan -------> 简单查看逻辑卷(lv)的信息
ACTIVE ‘/dev/vg2/lv1‘ [52.00 MiB] inherit
[[email protected] ~]#lvdisplay -------> 详细查看逻辑卷(lv)的信息
--- Logical volume ---
LV Path /dev/vg2/lv1
LV Name lv1
VG Name vg2
LV UUID sKWovu-PhYU-2QeD-RZz5-UI5B-XsJY-iVI0cd
LV Write Access read/write
LV Creation host, time centos6.magedu.com, 2018-02-28 18:05:59 -0500
LV Status available
\# open 0
LV Size 52.00 MiB
Current LE 13
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
创建逻辑卷
lvcreate -L 55M -n lv2801 vgmagedu #-L 指定大小
lvcreate -l 10 -n lv2802 vgmagedu #指定PE 个数
lvcreate -l +100%FREE -n lv2803 vgmagedu #剩余全部分配
[[email protected] ~]#lvcreate -L 50M -n lv1 vg2
Rounding up size to full physical extent 52.00 MiB
Logical volume "lv1" created.
[[email protected] ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg2 -wi-a----- 52.00m
增加逻辑卷lv容量
lvextend -L 200M /dev/vgmagedu/lv2801 -r
减小逻辑卷lv容量
lvreduce -L 100M /dev/vgmage01/lv2801
删除一个逻辑卷lv
lvremove: lvremove /dev/VG_NAME/LV_NAME
对逻辑卷lv进行容量大小的调整(增加|减小)
lvresize -L [-|+]100M /dev/vgmage01/lv2801
查询指定逻辑卷名字
ll /dev/dm* #查看lv2801逻辑卷名字
brw-rw----. 1 root disk 253, 0 Feb 24 09:35 /dev/dm-0
ll /dev/mapper/vgmagedu-lv2801 #查看lv2801逻辑卷名字
lrwxrwxrwx. 1 root root 7 Feb 24 09:31 /dev/mapper/vgmagedu-lv2801 -> ../dm-0
ll /dev/testvg/* #查看lv2801逻辑卷名字
lrwxrwxrwx. 1 root root 7 Feb 24 09:31 /dev/vgmagedu/lv2801 -> ../dm-0
格式化逻辑卷,创建文件系统
mkfs.ext4 /dev/vgmagedu/lv2801
挂载逻辑卷
mount /dev/vgmagedu/lv2801 /users/
扩展和缩减逻辑卷
扩展逻辑卷
ext4文件系统
1,如果卷组空间不够扩展需求,应先扩展卷组
vgextend vgmagedu /dev/md1 (如没有可用pv,应该先创建pv)
lvextend /dev/vgmagedu/lv2801 -L 100M #扩展逻辑卷-L 100M 指定逻辑捐卷最终大小
lvextend /dev/vgmagedu/lv2801 -L +100M ##扩展逻辑卷-L +100M 指定逻辑捐卷大小再加100M
resize2fs /dev/vgmagedu/lv2801 #重制文件系统大小(可以不指定大小默认全部分配)
[[email protected] ~]#vgs -->查看空间够lv扩展
VG #PV #LV #SN Attr VSize VFree
vg2 2 1 0 wz--n- 11.49g 10.42g
[[email protected] ~]#lvs -->扩展前
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg2 -wi-ao---- 900.00m
[[email protected] ~]#lvextend /dev/vg2/lv1 -L +200M --->扩展200M
Size of logical volume vg2/lv1 changed from 900.00 MiB (225 extents) to 1.07 GiB (275 extents).
Logical volume lv1 successfully resized.
[[email protected] ~]#lvs -->扩展后
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg2 -wi-ao---- 1.07g
[[email protected] ~]#resize2fs /dev/vg2 --->重制文件系统大小(可以不指定大小默认全部分配)
resize2fs 1.41.12 (17-May-2010)
open: Is a directory while opening /dev/vg2
[[email protected] ~]#resize2fs /dev/vg2/lv1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg2/lv1 is mounted on /media; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 5
Performing an on-line resize of /dev/vg2/lv1 to 1126400 (1k) blocks.
The filesystem on /dev/vg2/lv1 is now 1126400 blocks long.
[[email protected] ~]#df -h -->查看文件系统,扩展出来了
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 4.6G 15G 25% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda3 20G 196M 19G 2% /app
/dev/sda1 190M 35M 146M 20% /boot
/dev/md127 991M 1.3M 939M 1% /backup
/dev/md5 2.0G 3.0M 1.9G 1% /mydata
/dev/md3 5.8G 12M 5.5G 1% /magedata
/dev/mapper/vg2-lv1 1.1G 2.2M 1007M 1% /media
2,如果卷组空间足够,直接扩展
lvextend -L 200M /dev/vgmagedu/lv2801 -r
(加上-r一步到位,即扩展逻辑卷,同时扩展文件系统大小)
[[email protected] ~]#df ----->扩展前
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 20511356 4745176 14717604 25% /
tmpfs 502056 72 501984 1% /dev/shm
/dev/sda3 20511356 200504 19262276 2% /app
/dev/sda1 194241 35157 148844 20% /boot
/dev/md127 1014680 1284 961020 1% /backup
/dev/md5 2029392 3072 1921568 1% /mydata
/dev/md3 6049536 12280 5723300 1% /magedata
/dev/mapper/vg2-lv1 47463 842 43959 2% /media
[[email protected] ~]#lvextend /dev/vg2/lv1 -L 800M -r --->扩展 直接同步到文件系统中
Size of logical volume vg2/lv1 changed from 52.00 MiB (13 extents) to 800.00 MiB (200 extents).
Logical volume lv1 successfully resized.
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg2-lv1 is mounted on /media; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/vg2-lv1 to 819200 (1k) blocks.
The filesystem on /dev/mapper/vg2-lv1 is now 819200 blocks long.
[[email protected] ~]#df --->扩展后
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 20511356 4745184 14717596 25% /
tmpfs 502056 72 501984 1% /dev/shm
/dev/sda3 20511356 200504 19262276 2% /app
/dev/sda1 194241 35157 148844 20% /boot
/dev/md127 1014680 1284 961020 1% /backup
/dev/md5 2029392 3072 1921568 1% /mydata
/dev/md3 6049536 12280 5723300 1% /magedata
/dev/mapper/vg2-lv1 791053 2054 748300 1% /media
xfs文件系统
对于xfs文件系统,也可直接在lvextend中直接用-r,一步到位,如果要分开操作,先扩展逻辑卷,再拉伸文件系统,则应该使用xfs_growfs如下
xfs_growfs /dev/vgmagedu/lv2801
减小逻辑卷
1.umount 卸载挂载
2.e2fsck -f /dev/vgmage01/lv2801 进行扫描
3.resize2fs /dev/vgmage01/lv2801 100M 先减文件系统
4.lvreduce -L 100M /dev/vgmage01/lv2801 再减逻辑卷
5.mount 最后挂载
[[email protected] ~]#df -h -->缩小前查看文件系统
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 4.6G 15G 25% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda3 20G 196M 19G 2% /app
/dev/sda1 190M 35M 146M 20% /boot
/dev/md127 991M 1.3M 939M 1% /backup
/dev/md5 2.0G 3.0M 1.9G 1% /mydata
/dev/md3 5.8G 12M 5.5G 1% /magedata
/dev/mapper/vg2-lv1 1.1G 2.2M 1007M 1% /media
[[email protected] ~]#lvs --->缩小前超看lv
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg2 -wi-ao---- 1.07g
[[email protected] ~]#umount /media ----->>卸载挂载
[[email protected] ~]#e2fsck -f /dev/vg2/lv1 ---->进行扫描
e2fsck 1.41.12 (17-May-2010)
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/vg2/lv1: 11/262752 files (9.1% non-contiguous), 39530/1126400 blocks
[[email protected] ~]#resize2fs /dev/vg2/lv1 500M ---->先减文件系统500M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg2/lv1 to 512000 (1k) blocks.
The filesystem on /dev/vg2/lv1 is now 512000 blocks long.
[[email protected] ~]#lvreduce /dev/vg2/lv1 -L 500M -----> 再减逻辑卷500M
WARNING: Reducing active logical volume to 500.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg2/lv1? [y/n]: y
Size of logical volume vg2/lv1 changed from 1.07 GiB (275 extents) to 500.00 MiB (125 extents).
Logical volume lv1 successfully resized.
[[email protected] ~]#lvs ------>查看逻辑卷lv
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg2 -wi-a----- 500.00m
[[email protected] ~]#mount /dev/vg2/lv1 /media/ --->挂载逻辑卷
[[email protected] ~]#df -h ------>查看文件系统
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 4.6G 15G 25% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda3 20G 196M 19G 2% /app
/dev/sda1 190M 35M 146M 20% /boot
/dev/md127 991M 1.3M 939M 1% /backup
/dev/md5 2.0G 3.0M 1.9G 1% /mydata
/dev/md3 5.8G 12M 5.5G 1% /magedata
/dev/mapper/vg2-lv1 482M 1.9M 455M 1% /media
减小逻辑卷(错误示例CentOS5)
centos6和7中拒绝此错误操作
centos5 拓展分区为用户家目录挂载目录
格式化完成后进入/etc/fstab文件中编辑一条dev/vgmage01/lvhome的开机检测自动挂载信息
lvreduce -L 100M /dev/vgmage01/lvhome #直接减小逻辑卷
resize2fs /dev/vgmage01/lvhome 100M #报错
e2fsck -f /dev/vgmage01/lvhome #报错
reboot
-----修复过程
登录用户名密码
当前启动挂载磁盘以只读方式挂载,需要挂载磁盘变为可读写方式
mount -o remount.rw /
在编辑/etc/fstab文件
vim /etc/fstab
将故障硬盘对用最后的 1 2 改成 1 0
reboot
系统可以正常启动了
-----用正常顺序减小逻辑卷
lvs查看逻辑卷大小
lvextend -L 200M -r /dev/vgmage01/lvhome #恢复减少逻辑卷大小
1.umount 卸载挂载
2.e2fsck -f /dev/vgmage01/lvhome 进行扫描
3.resize2fs /dev/vgmage01/lvhome 100M 先减文件系统
4.lvreduce -L 100M /dev/vgmage01/lvhome 再减逻辑卷
5.mount 最后挂载
迁移卷组到新系统试验
将包含lvm的磁盘迁移到其他主机
要先添加一个硬盘后创建为逻辑卷,
mount /dev/vgtest/lvtest/ /mnt/datatest/
1.umount /mnt/datatest/ #卸载
2.vgchange -an vgtest # -an 关掉不在激活
3.vgexport vgtest # 设置为被导出状态
4.迁移硬盘
5.在新的主机 pvscan 或 vgs
6.vgimport vgtest #设置为导入状态
7.vgchange -ay #-ay 设置为激活状态
创建迁移前状态
[[email protected] ~]#mount /dev/vg2/lv1 /mnt/test/ ----->挂载逻辑卷
[[email protected] ~]#cp /etc/passwd /mnt/test/ --->复制文件到挂载点
[[email protected] ~]#ll /mnt/test --->查看挂载点文件
total 16
drwx------. 2 root root 12288 Feb 28 18:10 lost+found
-rw-r--r--. 1 root root 2195 Feb 28 19:21 passwd
[[email protected] ~]#lvdisplay /dev/vg2/lv1 ------>查看逻辑卷来自那个逻辑卷组
--- Logical volume ---
LV Path /dev/vg2/lv1
LV Name lv1
VG Name vg2
LV UUID sKWovu-PhYU-2QeD-RZz5-UI5B-XsJY-iVI0cd
LV Write Access read/write
LV Creation host, time centos6.magedu.com, 2018-02-28 18:05:59 -0500
LV Status available
\# open 0
LV Size 500.00 MiB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[[email protected] ~]#pvdisplay ----->查看pv被那个vg使用
--- Physical volume ---
PV Name /dev/sdb
VG Name vg5
PV Size 2.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 511
Free PE 386
Allocated PE 125
PV UUID KQeIVz-Hp1X-e3jK-ivO1-VpTZ-vM86-K2an9a
--- Physical volume ---
PV Name /dev/sdr
VG Name vg2
PV Size 512.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 127
Free PE 2
Allocated PE 125
PV UUID Bcm38a-IvoA-RsIy-Kfhs-1Gqn-sRVZ-PPS8nk
--- Physical volume ---
PV Name /dev/sdq
VG Name vg2
PV Size 11.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2815
Free PE 2815
Allocated PE 0
PV UUID ZtmVQG-U43k-nEg8-ndK3-AOAO-3Uti-AC3HXO
"/dev/sdp" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdp
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 2F7Jxh-4acs-2HX6-jGrh-S7f2-lnKo-Yfnc49
把/dev/sdq上的数据迁移至/dev/sdb上
[[email protected] ~]#pvmove /dev/sdq /dev/sdb
Physical Volume "/dev/sdb" not found in Volume Group "vg2".
[[email protected] ~]#vgreduce vg2 /dev/sdq
Removed "/dev/sdq" from volume group "vg2"
[[email protected] ~]#pvremove /dev/sdq ----> 删除pv /dev/sdq
Labels on physical volume "/dev/sdq" successfully wiped
[[email protected] ~]#pvdisplay --->查看pv被那个vg使用
--- Physical volume ---
PV Name /dev/sdr
VG Name vg2
PV Size 512.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 127
Free PE 2
Allocated PE 125
PV UUID Bcm38a-IvoA-RsIy-Kfhs-1Gqn-sRVZ-PPS8nk
--- Physical volume ---
PV Name /dev/sdb
VG Name vg5
PV Size 2.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 511
Free PE 386
Allocated PE 125
PV UUID KQeIVz-Hp1X-e3jK-ivO1-VpTZ-vM86-K2an9a
"/dev/sdp" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdp
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 2F7Jxh-4acs-2HX6-jGrh-S7f2-lnKo-Yfnc49
卸载
[[email protected] ~]#umount /media/
[[email protected] ~]#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 4.6G 15G 25% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda3 20G 196M 19G 2% /app
/dev/sda1 190M 35M 146M 20% /boot
/dev/md127 991M 1.3M 939M 1% /backup
/dev/md5 2.0G 3.0M 1.9G 1% /mydata
/dev/md3 5.8G 12M 5.5G 1% /magedata
2.vgchange -an vgtest # -an 关掉不在激活
3.vgexport vgtest # 设置为被导出状态
[[email protected] ~]#vgchange -an vg2 ------> -an 关掉不在激活
0 logical volume(s) in volume group "vg2" now active
[[email protected] ~]#vgex ----># 设置为被导出状态
vgexport vgextend
[[email protected] ~]#vgexport vg2
Volume group "vg2" successfully exported
4.迁移硬盘
5.虚拟机可以通过这个命令系统从新读取硬盘
echo ‘- - -‘ > /sys/class/scsi_host/host0/scan
echo ‘- - -‘ > /sys/class/scsi_host/host1/scan
echo ‘- - -‘ > /sys/class/scsi_host/host2/scan
5.在新的主机 pvscan 或 vgs
6.vgimport vgtest #设置为导入状态
7.vgchange -ay #-ay 设置为激活状态
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg5 1 1 0 wz--n- <2.00g <1.51g
[[email protected] ~]# pvscan
PV /dev/sdb VG vg5 lvm2 [<2.00 GiB / <1.51 GiB free]
Total: 1 [<2.00 GiB] / in use: 1 [<2.00 GiB] / in no VG: 0 [0 ]
[[email protected] ~]# vgimport vg5
Volume group "vg5" is not exported
[[email protected] ~]# vgchange -ay
1 logical volume(s) in volume group "vg5" now active
[[email protected] ~]# mount /dev/vg5/lv5 /media/
创建逻辑卷示例
[[email protected] ~]#pvcreate /dev/sdb ----->创建pv
Physical volume "/dev/sdb" successfully created
[[email protected] ~]#pvs ---->查看pv
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 ---- 2.00g 2.00g
[[email protected] ~]#vgcreate vg5 /dev/sdb --->创建vg
Volume group "vg5" successfully created --->查看vg
[[email protected] ~]#vgs
VG #PV #LV #SN Attr VSize VFree
vg5 1 0 0 wz--n- 2.00g 2.00g
[[email protected] ~]#lvcreate -L 500M -n lv5 vg5 --->创建lv
Logical volume "lv5" created.
[[email protected] ~]#lvs --->查看lv
Volume group vg2 is exported
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv5 vg5 -wi-a----- 500.00m
查询指定逻辑卷名字
ll /dev/dm* #查看lv2801逻辑卷名字
brw-rw----. 1 root disk 253, 0 Feb 24 09:35 /dev/dm-0
ll /dev/mapper/vgmagedu-lv2801 #查看lv2801逻辑卷名字
lrwxrwxrwx. 1 root root 7 Feb 24 09:31 /dev/mapper/vgmagedu-lv2801 -> ../dm-0
ll /dev/testvg/* #查看lv2801逻辑卷名字
lrwxrwxrwx. 1 root root 7 Feb 24 09:31 /dev/vgmagedu/lv2801 -> ../dm-0
[[email protected] ~]#mkfs.ext4 /dev/vg5/lv5 -->格式化 创建文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]#mount /dev/vg5/lv5 /media/ --->挂载
[[email protected] ~]#df -h ----->查看文件xit
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 4.6G 15G 25% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda3 20G 196M 19G 2% /app
/dev/sda1 190M 35M 146M 20% /boot
/dev/md127 991M 1.3M 939M 1% /backup
/dev/md5 2.0G 3.0M 1.9G 1% /mydata
/dev/md3 5.8G 12M 5.5G 1% /magedata
/dev/mapper/vg5-lv5 477M 2.3M 449M 1% /media
实验两个硬盘做lvm跨主机迁移
创建pv两个
[[email protected] media]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created.
[[email protected] media]# pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created.
[[email protected] media]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb vg5 lvm2 a-- <2.00g <1.51g
/dev/sdc lvm2 --- 3.00g 3.00g
/dev/sdd lvm2 --- 3.00g 3.00g
创建vg
[[email protected] media]# vgcreate vg3 /dev/sdc
Volume group "vg3" successfully created
[[email protected] media]# vgs
VG #PV #LV #SN Attr VSize VFree
vg3 1 0 0 wz--n- <3.00g <3.00g
vg5 1 1 0 wz--n- <2.00g <1.51g
加一个pv扩大vg
[[email protected] media]# vgextend vg3 /dev/sdd
Volume group "vg3" successfully extended
[[email protected] media]# vgs
VG #PV #LV #SN Attr VSize VFree
vg3 2 0 0 wz--n- 5.99g 5.99g
vg5 1 1 0 wz--n- <2.00g <1.51g
创建lv
[[email protected] media]# lvcreate -L 4G -n lv3 vg3
Logical volume "lv3" created.
[[email protected] media]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv3 vg3 -wi-a----- 4.00g
lv5 vg5 -wi-ao---- 500.00m
格式化
[[email protected] media]# mkfs.ext4 /dev/vg3/lv3
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
262144 inodes, 1048576 blocks
52428 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
挂载
[[email protected] media]# mkdir /media/3333
[[email protected] media]# mount /dev/vg3/lv3 /media/3333/
[[email protected] media]#
[[email protected] media]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 3.5G 17G 18% /
devtmpfs 978M 0 978M 0% /dev
tmpfs 993M 0 993M 0% /dev/shm
tmpfs 993M 9.0M 984M 1% /run
tmpfs 993M 0 993M 0% /sys/fs/cgroup
/dev/sda5 20G 12G 8.9G 56% /app
/dev/sda1 197M 136M 61M 70% /boot
tmpfs 199M 12K 199M 1% /run/user/42
/dev/mapper/vg3-lv3 3.9G 16M 3.6G 1% /media/3333
挂载点文件
[[email protected] 3333333]# ll -h
total 3.8G
drwx------. 2 root root 16K Mar 3 21:23 lost+found
-rw-r--r--. 1 root root 3.8G Mar 3 21:40 passwd
-rw-r--r--. 1 root root 35K Mar 3 21:36 passwd1
[[email protected] ~]# umount /media/3333333/ ------>卸载
[[email protected] ~]# vgchange -an vg3 ----------->-an 关掉设备不在激活
0 logical volume(s) in volume group "vg3" now active
[[email protected] ~]# vgexport vg3 ----------->设置为导出状态
Volume group "vg3" successfully exported
[[email protected] ~]# pvs ----------->查看pv状态
PV VG Fmt Attr PSize PFree
/dev/sdc vg3 lvm2 ax- <3.00g 0 ---> 导出状态
/dev/sdd vg3 lvm2 ax- <3.00g 504.00m --->导出状态
迁移硬盘
[[email protected] ~]#pvscan ------->从新读取
PV /dev/sds is in exported VG vg3 [3.00 GiB / 0 free]
PV /dev/sdr is in exported VG vg3 [3.00 GiB / 504.00 MiB free]
PV /dev/sdq is in exported VG vg2 [508.00 MiB / 8.00 MiB free]
PV /dev/sdo lvm2 [10.00 GiB]
Total: 4 [16.49 GiB] / in use: 3 [6.49 GiB] / in no VG: 1 [10.00 GiB]
[[email protected] ~]#vgs ----------->从新读取
VG #PV #LV #SN Attr VSize VFree
vg2 1 1 0 wzx-n- 508.00m 8.00m
vg3 2 1 0 wzx-n- 5.99g 504.00m
[[email protected] ~]#vgimport vg3 vg -----------> 设置为导入状态
Volume group "vg3" successfully imported
Volume group "vg" not found
Cannot process volume group vg
[[email protected] ~]#pvs ----------->查看pv
PV VG Fmt Attr PSize PFree
/dev/sdo lvm2 ---- 10.00g 10.00g
/dev/sdq vg2 lvm2 ax-u 508.00m 8.00m
/dev/sdr vg3 lvm2 a--u 3.00g 504.00m
/dev/sds vg3 lvm2 a--u 3.00g 0
[[email protected] ~]#vgs ----------->查看vg
VG #PV #LV #SN Attr VSize VFree
vg2 1 1 0 wzx-n- 508.00m 8.00m
vg3 2 1 0 wz--n- 5.99g 504.00m
[[email protected] ~]#vgchange -ay ----------->设置为激活状态
1 logical volume(s) in volume group "vg3" now active
Volume group "vg2" is exported
[[email protected] ~]#mount /dev/vg3/lv3 /mnt/ ----------->挂载
[[email protected] ~]#df ----------->检查挂载
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 20511356 4745636 14717144 25% /
tmpfs 502056 72 501984 1% /dev/shm
/dev/sda3 20511356 200504 19262276 2% /app
/dev/sda1 194241 35157 148844 20% /boot
/dev/md127 1014680 1284 961020 1% /backup
/dev/md5 2029392 3072 1921568 1% /mydata
/dev/md3 6049536 12280 5723300 1% /magedata
/dev/mapper/vg3-lv3 5545568 16412 5256536 1% /mnt
[[email protected] ~]#cd /mnt
[[email protected] mnt]#ls
lost+found passwd1
[[email protected] mnt]#cat passwd1 ----------->查看源文件
ppsssroot:x:0:0:root:/root:/bin/bash
rd:x:997:996:User for colord:/var/lib/colord:/sbin/nologin
saslauth:x:996:76:Saslauthd user:/run/saslauthd:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
chrony:x:995:993::/var/lib/chrony:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
--------省略部分-------
逻辑卷管理器快照
逻辑卷管理器快照
快照就是将当时的系统信息记录下来,就好像照相一般, 若将来有任何数据改动了,则原始数据会被移动到快照区 ,没有改动的区域则由快照区和文件系统共享
由于快照区与原本的LV共用很多PE的区块,因此快照去与被 快照的LV必须在同一个VG.系统恢复的时候的文件数量不能高 于快照区的实际容量
创建可读写快照
lvcreate -L 1G -s -n kuaizhaoname /dev/vgname/lvname
\# -L 1G //指定大小 -s //快照选项 -n name //快照名字 /dev/..//快照源文件2
lvdisply #查看lv
mkdir /mnt/snapname #创建快照目录
挂载快照:mount /dev/vgname/kuaizhaoname /mnt/snapname
快照创建成功,当对原文将修改数据空间超过快照空间达到100%,快照会被撑死,快照已不能使用了.
(为快照永远不死,快照与源文件空间相同,一般大小为原文件20%-30%)
快照可以用于冷备份,创建一个只读快照给定一个空间证备份期间原文件不被更改,备份快照就可以了
虚拟机快照:先安装完成一个系统,创建n+1个快照,对源系统进行关机处理以保证源文件不被修改,使用快照系统,如果快照系统出问题,直接删除,从新在做一个快照使用.
为现有逻辑卷创建只读快照
#lvcreate -l 64 -s -n snap-data -p r /dev/vg0/data
挂载快照
#mkdir -p /mnt/snap
#mount -o ro /dev/vg0/snap-data /mnt/snap
恢复快照
#umount /dev/vg0/snap-data
#umount /dev/vg0/data
#lvconvert --merge /dev/vg0/snap-data
删除快照
#umount /mnt/databackup
#lvremove /dev/vg0/databackup
示例
1.创建一个至少有两个PV组成的大小为20G的名为testvg的VG;
2.要求PE大小为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
\# 先 lsblk 或 blkid 查看硬盘
[[email protected] ~]#mkfs.ext4 /dev/sdr #格式化,创建文件系统 /dev/sdq
mke2fs 1.41.12 (17-May-2010)
/dev/sdr is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
720896 inodes, 2883584 blocks
144179 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2952790016
88 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
Writing inode tables: done
Creating journal (32768 blocks):
done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]#mkfs.ext4 /dev/sdq #格式化,创建文件系统 /dev/sdq
mke2fs 1.41.12 (17-May-2010)
/dev/sdq is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]#blkid
1/dev/sdr: UUID="7b516c4d-832d-4ad8-8282-4688513fee68" TYPE="ext4"
/dev/sdq: UUID="285addd4-7dee-4fad-8c47-2fa9f4067ab4" TYPE="ext4"
[[email protected] ~]#vgcreate -s 16M testvg /dev/sdr #创建卷组 testvg 并设置PE大小为16MB
Volume group "testvg" successfully created
[[email protected] ~]#vgdisplay #查看卷组 testvg详细信息
--- Volume group ---
VG Name testvg
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 10.98 GiB
PE Size 16.00 MiB
Total PE 703
Alloc PE / Size 0 / 0
Free PE / Size 703 / 10.98 GiB
VG UUID ZTCj4I-vEja-SKe2-3EcL-Prme-iqLe-Cmix8v
[[email protected] ~]#vgextend testvg /dev/sdq #管理卷组 增加卷组 testvg的大小
Volume group "testvg" successfully extended
[[email protected] ~]#vgdisplay #查看testvg卷组详细信息
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
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 20.97 GiB
PE Size 16.00 MiB
Total PE 1342
Alloc PE / Size 0 / 0
Free PE / Size 1342 / 20.97 GiB
VG UUID ZTCj4I-vEja-SKe2-3EcL-Prme-iqLe-Cmix8v
[[email protected] ~]#lvcreate -L 5G -n testlv testvg #创建逻辑卷 testlv
Logical volume "testlv" created.
[[email protected] ~]#lvs #查看逻辑卷 testlv
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-a----- 5.00g
-----三种查看逻辑卷testlv磁盘目录
[[email protected] ~]#ll /dev/dm* #查看testlv逻辑卷名字
brw-rw----. 1 root disk 253, 0 Feb 24 09:35 /dev/dm-0
[[email protected] ~]#ll /dev/mapper/testvg-testlv #查看testlv逻辑卷名字
lrwxrwxrwx. 1 root root 7 Feb 24 09:31 /dev/mapper/testvg-testlv -> ../dm-0
[[email protected] ~]#ll /dev/testvg/* #查看testlv逻辑卷名字
lrwxrwxrwx. 1 root root 7 Feb 24 09:31 /dev/testvg/testlv -> ../dm-0
[[email protected] ~]#mkfs.ext4 /dev/testvg/testlv #格式化,创建文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]#mkdir /mnt/qwe #创建挂载目录
[[email protected] ~]#mv /qwe /users
[[email protected] ~]#mount /dev/testvg/testlv /users/ #挂载
[[email protected] ~]#df -l #查看挂载
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 20511356 4712940 14749840 25% /
tmpfs 502056 72 501984 1% /dev/shm
/dev/sda3 20511356 200464 19262316 2% /app
/dev/sda1 194241 35157 148844 20% /boot
/dev/md127 1014680 1284 961020 1% /backup
/dev/md5 2029392 3072 1921568 1% /mydata
/dev/md3 6049536 12280 5723300 1% /magedata
/dev/mapper/testvg-testlv
5029504 10232 4757128 1% /users
2、 新建用户archlinux,要求其家目录为/users/archlinux,而后su切换至archlinux用户,复制/etc/pam.d目录至自己的家目录
[[email protected] /]#useradd -d /users/archlinux archlinux #/users/archlinux为未创建目录
3、扩展testlv至7G,要求archlinux用户的文件不能丢失
[[email protected] /]#lvextend -L 7G /dev/testvg/testlv -r
Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents).
Logical volume testlv successfully resized.
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/testvg-testlv is mounted on /users; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/testvg-testlv to 1835008 (4k) blocks.
The filesystem on /dev/mapper/testvg-testlv is now 1835008 blocks long.
[[email protected] /]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 7.00g
4、收缩testlv至3G,要求archlinux用户的文件不能丢失
[[email protected] /]#umount /dev/testvg/testlv
umount: /dev/testvg/testlv: not mounted
[[email protected] /]#e2fsck -f /dev/testvg/testlv
e2fsck 1.41.12 (17-May-2010)
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/testvg/testlv: 78/458752 files (0.0% non-contiguous), 64509/1835008 blocks
[[email protected] /]#e2fsck -f /dev/testvg/testlv
e2fsck 1.41.12 (17-May-2010)
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/testvg/testlv: 78/458752 files (0.0% non-contiguous), 64509/1835008 blocks
[[email protected] /]#resize2
-bash: resize2: command not found
[[email protected] /]#resize2fs /dev/testvg/testlv 3G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/testvg/testlv to 786432 (4k) blocks.
The filesystem on /dev/testvg/testlv is now 786432 blocks long.
[[email protected] /]#lvreduce -L 3G /dev/testvg/testlv
WARNING: Reducing active logical volume to 3.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testvg/testlv? [y/n]: y
Size of logical volume testvg/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents).
Logical volume testlv successfully resized.
[[email protected] /]#df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 20511356 4713184 14749596 25% /
tmpfs 502056 72 501984 1% /dev/shm
/dev/sda3 20511356 200464 19262316 2% /app
/dev/sda1 194241 35157 148844 20% /boot
/dev/md127 1014680 1284 961020 1% /backup
/dev/md5 2029392 3072 1921568 1% /mydata
/dev/md3 6049536 12280 5723300 1% /magedata
[[email protected] /]#mount /dev/testvg/testlv /users/
[[email protected] /]#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 4.5G 15G 25% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda3 20G 196M 19G 2% /app
/dev/sda1 190M 35M 146M 20% /boot
/dev/md127 991M 1.3M 939M 1% /backup
/dev/md5 2.0G 3.0M 1.9G 1% /mydata
/dev/md3 5.8G 12M 5.5G 1% /magedata
/dev/mapper/testvg-testlv
2.9G 7.8M 2.7G 1% /users
5、对testlv创建快照,并尝试基于快照备份数据,验正快照 的功能
[[email protected] diska]#lvcreate -L 1G -s -n testlvsnap /dev/testvg/testlv
Logical volume "testlvsnap1" created.
[[email protected] diska]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg owi-a-s--- 3.00g
testlvsnap testvg swi-aos--- 1.00g testlv 0.00
[[email protected] diska]#mount /dev/testvg/testlvsnap /mnt/diska/
[[email protected] diska]#df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 20511356 4713600 14749180 25% /
tmpfs 502056 72 501984 1% /dev/shm
/dev/sda3 20511356 200464 19262316 2% /app
/dev/sda1 194241 35157 148844 20% /boot
/dev/md127 1014680 1284 961020 1% /backup
/dev/md5 2029392 3072 1921568 1% /mydata
/dev/md3 6049536 12280 5723300 1% /magedata
/dev/mapper/testvg-testlvsnap
2965264 7928 2800064 1% /mnt/qwe/qwe
/dev/mapper/testvg-testlvsnap
2965264 7928 2800064 1% /mnt/diska
以上是关于磁盘管逻辑卷(LVM)的主要内容,如果未能解决你的问题,请参考以下文章