本文已参与 ⌈新人创作礼⌋ 活动,一起开启掘金创作之路
CentOS 6.5 Lvm测试笔记 相关命令pvcreate、pvdisplay、vgcreate、vgextend、lvcreate、lvdisplay、lvchange、lvremove、vgchange、vgdisplay、pvremove、resize2fs等
[root@localhost ~]# cat /etc/issue ###查看系统版本
CentOS release 6.5 (Final)
Kernel \r on an \m
[root@localhost ~]# rpm -qa | grep lvm ###检查lvm相关包是否安装
lvm2-2.02.100-8.el6.x86_64
mesa-private-llvm-3.3-0.3.rc3.el6.x86_64
lvm2-libs-2.02.100-8.el6.x86_64
[root@localhost ~]#
[root@localhost /]# fdisk -l
###测试机磁盘列表
Disk /dev/sda: 236.2 GB, 236223201280 bytes
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
Disk /dev/sdc: 32.2 GB, 32212254720 bytes
Disk /dev/sdd: 42.9 GB, 42949672960 bytes
[root@localhost /]# pvcreate /dev/sdb/dev/sdc /dev/sdd ###创建物理卷
Physical volume "/dev/sdb" successfully created
Physical volume "/dev/sdc" successfully created
Physical volume "/dev/sdd" successfully created
[root@localhost /]#
[root@localhost /]# pvdisplay /dev/sdb ###查看物理卷sdb
"/dev/sdb" is a new physical volume of "20.00 GiB"
---NEW Physical volume ---
PVName /dev/sdb
VGName ###VGName为空,说明还没划入VG
PVSize 20.00 GiB
Allocatable NO ###(可分配)是No,也说明还没划入VG
PESize 0
Total PE 0
Free PE 0
Allocated PE 0
PVUUID OS9lOX-OPQi-crNu-U6F0-lwzp-xeMs-L1HQEc
[root@localhost /]# vgcreate vg_test/dev/sdb /dev/sdc ###使用两颗磁盘创建VG
Volume group "vg_test" successfully created
[root@localhost /]# vgextend vg_test/dev/sdd ###VG中添加磁盘
Volume group "vg_test" successfully extended
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# lvcreate -n lv_test1 -L60G vg_test ### 创建指定大小为60G的逻辑卷
Logical volume "lv_test1" created
[root@localhost /]# lvdisplay ###查看逻辑卷
---Logical volume ---
LVPath /dev/vg_test/lv_test1
LVName lv_test1
VGName vg_test
LVUUID BBDYaZ-adzL-qlm9-sR41-COlT-VUuv-6yBHdU
LVWrite Access read/write
LVCreation host, time localhost.localdomain, 2016-12-10 12:53:18 +0800
LVStatus available
#open 0
LVSize 60.00 GiB
Current LE 15360
Segments 2
Allocation inherit
Read ahead sectors auto
-currently set to 256
Block device 253:3
[root@localhost /]# mkfs -t ext4/dev/vg_test/lv_test1 ###格式化
[root@localhost /]# mkdir lvmtest
[root@localhost /]# mount/dev/vg_test/lv_test1 /lvmtest/ ###挂载
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 7.5G 40G 16% /
tmpfs 1.9G 76K 1.9G 1% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 164G 188M 155G 1% /home
/dev/mapper/vg_test-lv_test1 60G 180M 56G 1% /lvmtest
[root@localhost /]# vim /etc/fstab 编辑fstab,加入开机挂载
#
# /etc/fstab
# Created by anaconda on Thu Jul 2305:57:19 2015
#
# Accessible filesystems, by reference, aremaintained under '/dev/disk'
# See man pages fstab(5), findfs(8),mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
UUID=8fc44915-bd28-493a-8e4e-7823f5223f3c/boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_home /home ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/mapper/vg_test-lv_test1/lvmtest ext4 defaults 0 0
=====================创建完成===============================================
补充:
[root@localhost /]# lvcreate -n lv_test1 -L60G vg_test 创建指定容量大小
[root@localhost ~]# lvcreate -n lv_test2 -l+100%free vg_test 分配全部剩余空间
Logical volume "lv_test2" created
解除挂载
[root@localhost ~]# umount/dev/mapper/vg_test-lv_test1
[root@localhost ~]# lvchange -an/dev/vg_test/lv_test1 改变状态[-a|--activate[a|e|l]{y|n}]
[root@localhost ~]# lvdisplay/dev/vg_test/lv_test1
---Logical volume ---
LVPath /dev/vg_test/lv_test1
LVName lv_test1
VGName vg_test
LVUUID BBDYaZ-adzL-qlm9-sR41-COlT-VUuv-6yBHdU
LVWrite Access read/write
LVCreation host, time localhost.localdomain, 2016-12-10 12:53:18 +0800
LVStatus NOT available 状态变为不可用
LVSize 60.00 GiB
Current LE 15360
Segments 2
Allocation inherit
Read ahead sectors auto
[root@localhost ~]#
[root@localhost ~]# lvremove/dev/vg_test/lv_test1 移除逻辑卷
Logical volume "lv_test1" successfully removed
[root@localhost ~]#
[root@localhost ~]# lvdisplay/dev/vg_test/lv_test1 查看发现已经没有了
Oneor more specified logical volume(s) not found.
[root@localhost ~]#
[root@localhost ~]# vgdisplay vg_test 查看卷组
---Volume group ---
VGName vg_test
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 6
VGAccess read/write
VGStatus resizable
MAXLV 0
CurLV 0
Open LV 0
MaxPV 0
CurPV 3
ActPV 3
VGSize 89.99 GiB
PESize 4.00 MiB
Total PE 23037
Alloc PE / Size 0 / 0
Free PE / Size 23037 / 89.99 GiB
VGUUID BL2hpf-AstB-uYUD-LVpH-aexu-HvN2-bjf8jH
[root@localhost ~]#
[root@localhost ~]# vgchange -an vg_test
0logical volume(s) in volume group "vg_test" now active
[root@localhost ~]# vgremove vg_test
Volume group "vg_test" successfully removed
[root@localhost ~]# vgdisplay vg_test
Volume group "vg_test" not found
Skipping volume group vg_test
[root@localhost ~]#
[root@localhost ~]# pvremove /dev/sdc 移除物理卷
Labels on physical volume "/dev/sdc" successfully wiped
[root@localhost ~]# pvremove /dev/sdd
Labels on physical volume "/dev/sdd" successfully wiped
[root@localhost ~]# vgreduce vg_test/dev/sdd 从卷组中删除一个物理卷
Removed "/dev/sdd" from volume group "vg_test"
[root@localhost ~]#
实例:
给根分区添加空间
[root@localhost ~]# pvcreate /dev/sdd 创建物理卷
Physical volume "/dev/sdd" successfully created
[root@localhost ~]# vgextend VolGroup/dev/sdd 扩展卷组
Volume group "VolGroup" successfully extended
[root@localhost ~]# lvextend -L +20G /dev/mapper/VolGroup-lv_root增加20G空间给root
Extending logical volume lv_root to 70.00 GiB
Logical volume lv_root successfully resized
[root@localhost ~]# resize2fs -p/dev/mapper/VolGroup-lv_root 调整大小
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_rootis mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 5
Performing an on-line resize of/dev/mapper/VolGroup-lv_root to 18350080 (4k) blocks.
The filesystem on/dev/mapper/VolGroup-lv_root is now 18350080 blocks long.
[root@localhost ~]# df –h 结果验证
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 69G 7.5G 58G 12% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 164G 188M 155G 1% /home
[root@localhost ~]#