目录
LVM 逻辑卷管理
LVM 逻辑卷简介
建立 LVM 的步骤
物理卷管理
硬盘分区
建立物理卷
查看物理卷
删除物理卷
卷组管理
建立卷组
查看卷组
增加卷组容量
减小卷组容量
删除卷组
逻辑卷管理
建立逻辑卷
查看逻辑卷
调整逻辑卷大小
删除逻辑卷
[root@localhost ~]# pvcreate [设备文件名]
[root@localhost ~]# pvcreate /dev/sdb
[root@localhost ~]# pvcreate /dev/sdb5
[root@localhost ~]# pvscan
PV /dev/sdb5 lvm2 [1.01 GiB]
PV /dev/sdb6 lvm2 [1.01 GiB]
PV /dev/sdb7 lvm2 [1.01 GiB]
Total: 3 [3.03 GiB] / in use: 0 [0 ] / in no VG: 3 [3.03 GiB]
[root@localhost ~]# pvremove /dev/sdb7
[root@localhost ~]# vgcreate [选项] 卷组名 物理卷名
[root@localhost ~]# vgcreate -s 8MB scvg /dev/sdb5 /dev/sdb6
Volume group "scvg" successfully created
[root@localhost ~]# vgscan
[root@localhost ~]# vgreduce scvg /dev/sdb7
Removed "/dev/sdb7" from volume group "scvg"
#在卷组中删除/dev/sdb7 物理卷
[root@localhost ~]# vgreduce -a
#删除所有的未使用物理卷
[root@localhost ~]# vgremove scvg
Volume group "scvg" successfully removed
[root@localhost ~]# lvcreate [选项] [-n 逻辑卷名] 卷组名
[root@localhost ~]# lvcreate -L 1.5G -n userlv scvg
Logical volume "userlv" created
#在 scvg 卷组中建立 1.5GB 的 userlv 逻辑卷
[root@localhost ~]# mkfs -t ext4 /dev/scvg/userlv
#格式化
[root@localhost ~]# mkdir /disklvm
[root@localhost ~]# mount /dev/scvg/userlv /disklvm/
#建立挂载点,并挂载
[root@localhost ~]# mount
…省略部分输出…
/dev/mapper/scvg-userlv on /disklvm type ext4 (rw)
#已经挂载了
[root@localhost ~]# lvscan
ACTIVE '/dev/scvg/userlv' [1.50 GiB] inherit
#能够看到激活的逻辑卷,大小为 1.5GB
[root@localhost ~]# lvresize [选项] 逻辑卷设备文件名
[root@localhost ~]# cd /disklvm/
[root@localhost disklvm]# touch testf
[root@localhost disklvm]# mkdir testd
[root@localhost disklvm]# ls
lost+found testd testf
[root@localhost disklvm]# lvresize -L 2.5G /dev/scvg/userlv
Extending logical volume userlv to 2.50 GiB
Logical volume userlv successfully resized
#增加 userlv 逻辑卷的大小到 2.5GB
#当然命令也可以这样写 [root@localhost disklvm]# lvresize -L +1G /dev/scvg/userlv
[root@localhost disklvm]# lvdisplay
--- Logical volume ---
LV Path /dev/scvg/userlv
LV Name userlv
VG Name scvg
LV UUID 2kyKmn-Nupd-CldB-8ngY-NsI3-b8hV-QeUuna
LV Write Access read/write
LV Creation host, time localhost, 2013-04-18 03:36:39 +0800
LV Status available
# open 1
LV Size 2.50 GiB #大小改变了
Current LE 320
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@localhost ~]# resize2fs [选项] [设备文件名] [调整的大小]
[root@localhost ~]# resize2fs /dev/scvg/userlv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/scvg/userlv is mounted on /disklvm; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/scvg/userlv to 655360 (4k) blocks.
The filesystem on /dev/scvg/userlv is now 655360 blocks long.
#已经调整了分区大小
[root@localhost ~]# lvremove 逻辑卷设备文件名
[root@localhost ~]# umount /dev/scvg/userlv
[root@localhost ~]# lvremove /dev/scvg/userlv
【注】:参考尚硅谷沈超老师教程