标签:lvm逻辑卷
逻辑卷管理器LVM :
LVM的优势:1、弹性存储 2、可以使用快照
LVM: 将几个物理分区通过软件组合在一起,看起来像是独立的大硬盘,而要用这块大硬盘,就要将它分成可以使用的分区,然后格式化,挂载等
PV物理卷:将物理磁盘或物理分区初始化成LVM能用的物理卷,分区中的类型是8e:Linux LVM
VG逻辑卷组:将一个或者多个PV组合成一个大的磁盘,将其称之为组
LV逻辑卷:从VG中分割出来的分区,称为LV,LV被用来格式化后,进行挂载,设备代为: /dev/vgname/lvname
相关命令整理
创建 | 删除 | 查看 | 详细查看 | 移动 | 扩展 | 减少 | |
PV | pvcreate | pvremove | pvs | pvdisplay | pvmove | ||
VG | vgcreate | vgremove | vgs | vgdisplay | vgmove | vgextend | vgreduce |
LV | lvcreate | lvremove | lvs | lvdisplay | lvmove | lvextend | lvreduce |
注:举例:如果一个PV下有两个物理分区sda6和sda7,现分区空间过大一个sda6已经够用想把sda7拆下,
以下为创建一个LV的具体操作:
首先创建分区,sda6 sda7 这里分区的文件系统选择 8e Linux LVM ,
[root@bird 桌面]# pvcreate /dev/sda6 /dev/sda7
WARNING: swap signature detected on /dev/sda6. Wipe it? [y/n]: y
Wiping swap signature on /dev/sda6.
Physical volume "/dev/sda6" successfully created
Physical volume "/dev/sda7" successfully created
[root@bird 桌面]# pvs 显示创建的pv
PV VG Fmt Attr PSize PFree
/dev/sda6 lvm2 --- 2.00g 2.00g
/dev/sda7 lvm2 --- 1.01g 1.01g
[root@bird 桌面]# pvdisplay 显示详细的pv信息
"/dev/sda6" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda6
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID itkIEM-poEM-FK3M-Ycoj-Fco1-S11Q-MXnlby
"/dev/sda7" is a new physical volume of "1.01 GiB"
--- NEW Physical volume ---
PV Name /dev/sda7
VG Name
PV Size 1.01 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID s9TdIp-v3hg-zYn3-BSJW-XDH2-wKXK-gXWJbW
[root@bird 桌面]# vgcreate zydata /dev/sda6 /dev/sda7 创建VG
Volume group "zydata" successfully created
[root@bird 桌面]# vgs 查看VG
VG #PV #LV #SN Attr VSize VFree
zydata 2 0 0 wz--n- 3.01g 3.01g
[root@bird 桌面]# vgdisplay 详细显示vg的信息
--- Volume group ---
VG Name zydata
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 3.01 GiB
PE Size 4.00 MiB
Total PE 770
Alloc PE / Size 0 / 0
Free PE / Size 770 / 3.01 GiB
VG UUID iEZS4P-4jLo-dS4V-WwSJ-1lLo-73yd-i88tlv
[root@bird 桌面]# vgremove zydata 直接移除vg zydata
Volume group "zydata" successfully removed
[root@bird 桌面]# vgs
[root@bird 桌面]# vgcreate -s 8M zydata /dev/sda6 创建PE大小为8M的 默认为4M 这里仅指定了sda6
Volume group "zydata" successfully created
[root@bird 桌面]# vgdisplay
--- Volume group ---
VG Name zydata
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 2.00 GiB
PE Size 8.00 MiB
Total PE 256
Alloc PE / Size 0 / 0
Free PE / Size 256 / 2.00 GiB
VG UUID mqn1Hj-pGoD-WyZS-8kgq-unEd-R3dj-7pFLa1
扩展逻辑卷:
[root@bird 桌面]# vgextend zydata /dev/sda7 扩展一个sda7进去
Volume group "zydata" successfully extended
[root@bird 桌面]# vgs
VG #PV #LV #SN Attr VSize VFree
zydata 2 0 0 wz--n- 3.01g 3.01g
[root@bird 桌面]# vgdisplay
--- Volume group ---
VG Name zydata
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 3.01 GiB 加sda7之后大小变为3G (sda6为2G 7为1G
PE Size 8.00 MiB 之前定义过,则自动将新扩展进来的sda7的PE设置为8M.
Total PE 385
Alloc PE / Size 0 / 0
Free PE / Size 385 / 3.01 GiB
VG UUID mqn1Hj-pGoD-WyZS-8kgq-unEd-R3dj-7pFLa1
# pvmove /dev/sda7 先用pvmove将sda7中的数据复制出来,即可以将7中数据移到其他的分区中去),
[root@bird 桌面]# vgreduce zydata /dev/sda7 用vgreduce从zydata中将sda7除去
Removed "/dev/sda7" from volume group "zydata"
[root@bird 桌面]# vgs
VG #PV #LV #SN Attr VSize VFree
zydata 1 0 0 wz--n- 2.00g 2.00g
[root@bird 桌面]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda6 zydata lvm2 a-- 2.00g 2.00g
/dev/sda7 lvm2 --- 1.01g 1.01g sda7不属于任何VG
[root@bird 桌面]# pvremove /dev/sda7 最后用pvremove 移除
Labels on physical volume "/dev/sda7" successfully wiped
[root@bird 桌面]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda6 zydata lvm2 a-- 2.00g 2.00g
必须先将sda7数据move出来再用vgreduce除去sda7,最后才能pvremove来移除sda7,vgremove是用来移除vg的,vgreduce和vgextend是用来减少和增加分区的如:
vgextend zydata /dev/sda7
vgreduce zydata /dev/sda7
[root@bird 桌面]# lvcreate -n testlv -L 1G zydata 创建大小为1G的lv
Logical volume "testlv" created.
[root@bird 桌面]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv zydata -wi-a----- 1.00g
[root@bird 桌面]# lvdisplay
--- Logical volume ---
LV Path /dev/zydata/testlv 路径
LV Name testlv
VG Name zydata
LV UUID MMkFjJ-qlMN-ebQ1-eoBm-nxfz-nPtF-By8WU3
LV Write Access read/write
LV Creation host, time bird, 2017-04-19 15:03:47 +0800
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 128
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@bird 桌面]# mke2fs -j /dev/zydata/testlv 格式化lv
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@bird 桌面]# mkdir /mnt/test3
[root@bird 桌面]# mount /dev/zydata/testlv /mnt/test3/ 挂载lv
[root@bird 桌面]# ls /mnt/test3/
lost+found 挂载成功
[root@bird 桌面]# cp /etc/fstab /mnt/test3/ 测试
[root@bird 桌面]# cd /mnt/test3/
[root@bird test3]# cat fstab
#
# /etc/fstab
# Created by anaconda on Mon Feb 13 23:50:17 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=43fa2114-8933-43bc-b4dc-d1d4811e7a64 / ext4 defaults 1 1
UUID=1ee52a34-d3a4-47f8-9863-f90aeeede43e /boot ext4 defaults 1 2
UUID=ea629952-0afa-45e9-bbb5-eb1dafa4cbc9 /home ext4 defaults 1 2
UUID=2aca97a2-9b18-41cb-9838-7a05b6fbf560 /usr ext4 defaults 1 2
UUID=7c374472-feea-47c6-a711-41a1d90b1bae 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/sda7 /mnt ext3 defaults 0 0
[root@bird ~]# lvextend -L +100M /dev/zydata/testlv 扩展lv,增加100M
Rounding size to boundary between physical extents: 104.00 MiB
Size of logical volume zydata/testlv changed from 1.00 GiB (128 extents) to 1.10 GiB (141 extents).
Logical volume testlv successfully resized
[root@bird ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv zydata -wi-ao---- 1.10g
[root@bird ~]# resize2fs -p /dev/zydata/testlv 这是逻辑边界的扩展必须进行,否则df -h查看的话lv的扩展没有变化
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/zydata/testlv is mounted on /mnt/test3; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/zydata/testlv to 288768 (4k) blocks.
The filesystem on /dev/zydata/testlv is now 288768 blocks long.
[root@bird ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 7.6G 411M 6.8G 6% /
tmpfs 504M 228K 503M 1% /dev/shm
/dev/sda1 1.9G 35M 1.8G 2% /boot
/dev/sda3 4.7G 336M 4.2G 8% /home
/dev/sda5 3.8G 3.2G 438M 89% /usr
/dev/sr0 3.6G 3.6G 0 100% /media/CentOS_6.7_Final
/dev/mapper/zydata-testlv
1.1G 34M 1021M 4% /mnt/test3 这里增加的100M就显示了
注意:扩展的话先lvextend 物理边界在resize2fs逻辑边界,可以在线扩展:
1、lvextend -L +100M /dev/zydata/testlv
2、/resize2fs -p /dev/zydata/testlv
缩减的话:1、不能在线缩减
2、必须先卸载,df -h确定已用的空间大于你要缩小的空间
3、e2fsck -f /dev/zydata/testlv 强行检查lv
4、resize2fs /dev/zydata/testlv —100M
5、lvreduce -L -100M /dev/zydata/testlv
(用法 resize2fs /dev/zydata/testlv —100M(不带加减号代表缩减至多少G)逻辑边界后,在用lvextend来缩减物理边界lvreduce -L -100M /dev/zydata/testlv
顺便补充一个快照卷的过程,
lvcreate -L 50M -s -p r -n kauizhao /dev/zydata/testlv
大小 -s指定创建快照 -p r指定只读 -n指定快照名 后面是lv的路径
至此一个完整的LVM的创建,扩展,缩减,以及要注意的地方都已经完成!OVER``````````
本文出自 “大鸟地带-点滴积累” 博客,谢绝转载!
标签:lvm逻辑卷
原文地址:http://09112012.blog.51cto.com/4813132/1917382