天天看点

菜鸟学Linux 第026篇笔记 LVM

菜鸟学Linux 第026篇笔记 LVM

lsmod — program to show the status of modules in the Linux Kernel

LVM

可以将物理硬盘组合成为一个逻辑上的一块硬盘,

传统硬盘如果扩容,有可能会影响其原数据,而用此种方式则不会,

还有一个优点可以用来做在线数据备份

DM: Device mapper

可以动态增减文件系统空间

Physical Volume PV

Physical Extend PE

Command: pvcreate, pvremove, pvscan, pvdisplay|pvs, pvremove

e.g. pvcreate /dev/sdb{5,6,7,8}

Volume Group VG

Command: vgcreate, vgremove, vgextend, vgreduce, vgs|vgdisplay, vgscan..

vgextend VGNAME /dev/sd#

Logical Volume LV

Logical Extend LE

Command: lvcreate lvremove, lvextend, lvreduce, lvresize, lvs|lvdisplay..

e.g. lvcreate -L 5G -n lvname vgname

 lvremove /dev/vg/lv

移除pv时,要先将pv数据移动到其它硬盘后再执行vgreduce

扩展逻辑卷(无损文件)

先扩充物理容量,后扩充逻辑容量

lvextend

-L [+]# /dev/vg/lv

resize2fs -p /dev/myvg/mylv 

df -lh

缩减逻辑卷(有可能会损失文件)

注意1.不能在线缩减,需先卸载;

2.确保缩减后的空间大小依然能存储原有的所有数据;

3.在缩减之前应该先强型检查文件,以确保文件系统处于一至性状态;

与扩展逻辑卷相反

先缩减逻辑容量,后缩减物理容量

umount /dev/myvg/mylv

e2fsck -f /dev/myvg/mylv

resize2fs /dev/myvg/mylv 3G 

lvreduce -L [-] 3G /dev/myvg/mylv

快照卷

1.生命周期为整个数据的时长;在这段时长内,数据的增长量不能超出快照卷大小;

2.快照卷应该是只读的;

3.跟原卷在同一卷组内;

快照卷可以用来做备份使用

lvcreate

-s, --snapshot

  Create a snapshot logical  volume  (or  snapshot)  for  an

  existing,  so  called original logical volume (or origin).

-p, --permission r|rw

  Set access permissions to read only or read and write.

  Default is read and write.

e.g. lvcreate -L 100M -n testsnap -s -p r /dev/myvg/mylv 

然后就可以将该卷挂载,将数据备份,备份后可以再进行删除该卷

本文转自Winthcloud博客51CTO不可靠,原文链接http://blog.51cto.com/winthcloud/1873110如需转载请自行联系原作者

Winthcloud

继续阅读