命令简介:
physical volume (pv)物理卷管理命令:
pvcreate 创建,pvremove 移除pv上面的数据,pvscan 扫描
pvdisplay 详细查看(pvs查看简单信息), pvmove 移动某pv上数据到别的pv上
命令格式:
pvcreat /dev/sda{10,11}
pvs查看pv信息
volume group (vg)卷组管理命令:
vgcreate 创建,vgremove 删除vg,pvscan 扫描,vgextend 添加扩展
vgreduce 缩减,vgdiplay详细显示(vgs简单显示),vgscan 扫描
命令格式:
vgcreate VG_NAME /PATH/TO/PV
命令参数:
-s #:指定PE大小,默认为4MB #为数字
vgcreate myvg /dev/sda{10,11}
vgremove myvg
vgcreate -s 8M myvg /dev/sda{10,11}
vgs 查看vg信息
vgreduce myvg /dev/sda11 从myvg中缩减sda11
pvremove /dev/sda11 从pv中移除sda11
logical volume (lv)逻辑卷管理命令:
lvcreate 创建,lvremove 删除lv,lvextend 添加扩展,
lvreduce 缩减,lvdisplay显示(lvs)
命令格式:
lvcreate -n LV_NAME -L #G VG_NAME
命令参数:
-n:指定LV的名称
-L #:指定LV的大小,#表示数字
lvcreate -L 50M -n testlv myvg
lvdisplay /dev/myvg/testlv
mkfs -t ext4 /dev/myvg/testlv
mount /dev/myvg/testlv /mnt
lvremove /dev/mapper/myvg-testlv
命令实例:
1、创建一个pv,vg,lv 过程,并挂载使用该lv,以及移除lv(这里是使用2个物理硬盘做测试)
[[email protected] ~]# pvcreate /dev/sd{b,c} 把2个硬盘创建为一个physical volume(pv)物理卷
Physical volume "/dev/sdb" successfully created
Physical volume "/dev/sdc" successfully created
[[email protected] ~]# pvs 查看新建的pv信息
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 a-- 2.00g 2.00g
/dev/sdc lvm2 a-- 2.00g 2.00g
[[email protected] ~]# vgcreate myvg /dev/sd{b,c} 创建volume group(vg)卷组
Volume group "myvg" successfully created
[[email protected] ~]# vgs 查看卷组信息
VG #PV #LV #SN Attr VSize VFree
myvg 2 0 0 wz--n- 3.99g 3.99g
[[email protected] ~]# lvcreate -L 50M -n testlv myvg 创建一个大小为50MB的 logicalvolume(lv)逻辑卷,并命名为testlv
Rounding up size to full physical extent 52.00 MiB
Logical volume "testlv" created
[[email protected] ~]# lvs 显示逻辑卷信息
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
testlv myvg -wi-a----- 52.00m
[[email protected] ~]# vgs 显示卷组信息
VG #PV #LV #SN Attr VSize VFree
myvg 2 1 0 wz--n- 3.99g 3.94g
[[email protected] ~]# vgdisplay 显示卷组详细信息,PE大小为4MB
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 3.99 GiB
PE Size 4.00 MiB
Total PE 1022
Alloc PE / Size 13 / 52.00 MiB
Free PE / Size 1009 / 3.94 GiB
VG UUID t2xYgz-SPoN-DEDP-Z862-wx9v-7dAi-uGWz03
[[email protected] ~]# lvdisplay 显示逻辑卷的详细信息
--- Logical volume ---
LV Path /dev/myvg/testlv
LV Name testlv
VG Name myvg
LV UUID xl2L2D-kKH9-sdvs-PMzg-ok39-LcIU-39GgpD
LV Write Access read/write
LV Creation host, time xuelinux, 2016-11-05 16:26:33 +0800
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
[[email protected] ~]# mkfs -t ext4 /dev/myvg/testlv 把新建的lv格式化为ext4格式
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
13328 inodes, 53248 blocks
2662 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=54525952
7 block groups
8192 blocks per group, 8192 fragments per group
1904 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]# mount /dev/myvg/testlv /mnt 挂载该lv设备
[[email protected] ~]# ls /mnt
lost+found[[email protected] ~]# mount 查看已经挂载的设备
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda3 on /home type ext4 (rw)
/dev/sda7 on /tmp type ext4 (rw)
/dev/sda5 on /usr type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-testlv on /mnt type ext4 (rw) lv已经挂载成功
下面操作移除lv设备
[[email protected] ~]# umount /mnt 先把卸载已经挂载的lv设备
[[email protected] ~]# lvremove /dev/myvg/testlv 直接移除指定lv设备即可
Do you really want to remove active logical volume testlv? [y/n]: y 确定移除
Logical volume "testlv" successfully removed
[[email protected] ~]# lvdisplay 再次查看lv设备,已经没有lv设备,所以没显示。
[[email protected] ~]#
下面操作移除vg设备
[[email protected] ~]# vgreduce myvg /dev/sdb 把单个设备sdb从vg设备中缩减
Removed "/dev/sdb" from volume group "myvg"
[[email protected] ~]# vgs 查看vg信息
VG #PV #LV #SN Attr VSize VFree
myvg 1 0 0 wz--n- 2.00g 2.00g
[[email protected] ~]# vgremove myvg 直接移除整个vg
Volume group "myvg" successfully removed
[[email protected] ~]# vgs
No volume groups found 移除成功,vg设备没有
下面操作移除pv设备
[[email protected] ~]# pvs 查看pv信息
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 a-- 2.00g 2.00g
/dev/sdc lvm2 a-- 2.00g 2.00g
[[email protected]uelinux ~]# pvremove /dev/sdb 把sdb从pv中移除
Labels on physical volume "/dev/sdb" successfully wiped
[[email protected] ~]# pvremove /dev/sdc 把sdc从pv中移除
Labels on physical volume "/dev/sdc" successfully wiped
[[email protected] ~]# pvs 移除成功,pv设备没有信息
[[email protected] ~]#
2、创建一个pv,vg,lv 过程,并挂载使用该lv,以及移除lv(这里是使用2个分区做测试)
利用分区创建lv的过程,只是前面需要把分区类型修改为8e lvm类型即可,其他步骤一致。