lvm是逻辑卷管理的简称,它将一个或多个物理硬盘分区(PV)组成一个逻辑硬盘(VG)来使用,  然后从这个VG中划分出逻辑分区(LV), 以上概念是我理解的东西,可能和书上的不一样。

以下所有命令都是在CENTOS6.5上进行操作的

1:对磁盘进行分区

使用fdisk对磁盘进行分区。注意分区的格式,LVM对应的是8e, 创建完成后记得重启电脑。

Command (m for help): p

Disk /dev/vda: 85.9 GB,  bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00035557 Device Boot Start End Blocks Id System
/dev/vda1 * Linux
Partition does not end on cylinder boundary.
/dev/vda2 8e Linux LVM
Partition does not end on cylinder boundary.
/dev/vda3 8e Linux LVM

2: 创建PV

pvcreate使用磁盘分区来创建PV

[root@centos-vm- ~]# pvcreate  /dev/vda3
Physical volume "/dev/vda3" successfully created
[root@centos-vm- ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name vg_centos6
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE
Free PE
Allocated PE
PV UUID YzeBUf-Pxvv-5fct-I5Mz-6NDg-fIsI-Zjv7RT "/dev/vda3" is a new physical volume of "60.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vda3
VG Name
PV Size 60.00 GiB
Allocatable NO
PE Size
Total PE
Free PE
Allocated PE
PV UUID 5B99Bs-waNc-QSnO-YWu5-XdMH-xRB6-epWFzJ

3:创建VG

如果已经有VG的话那么不需要创建新的VG,直接把PV添加到VG中就可以了。

[root@centos-vm- ~]# vgdisplay
--- Volume group ---
VG Name vg_centos6
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 19.51 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size / 19.51 GiB
Free PE / Size /
VG UUID wyjVpO-L0jl-ckoF-SU4K-JTNd-p3Nb-YwMgO9 [root@centos-vm- ~]# vgcreate vg_centos6_1 /dev/vda3

创建vg的使用后面可以跟多个PV(pv和磁盘分区同名)。

如果想把PV添加到已经存在的vg中使用下面的命令:

[root@centos-vm- ~]# vgextend vg_centos6 /dev/vda3
Volume group "vg_centos6" successfully extended

3:创建LV

显示当前的lv

[root@centos-vm- ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_centos6/lv_root
LV Name lv_root
VG Name vg_centos6
LV UUID 4QMRdu-2JYb-a7BM-OSw9-nRrz-nGmV-Z80yeO
LV Write Access read/write
LV Creation host, time centos6., -- :: +
LV Status available
# open
LV Size 17.54 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/vg_centos6/lv_swap
LV Name lv_swap
VG Name vg_centos6
LV UUID 8awkxq-UpsI-mPml-GTrx-tWDu-MkhI-tA3OhS
LV Write Access read/write
LV Creation host, time centos6., -- :: +
LV Status available
# open
LV Size 1.97 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device :

创建一个新的LV

 lvcreate -L  10G -n data  vg_centos6

-L指定分区的大小,-n指定分区名,vg_centos6是vg名字

扩展LV,有时不想添加新的分区,那么可以扩展该LV

[root@centos-vm- ~]# lvextend -L +18G   /dev/vg_centos6/lv_root
Extending logical volume lv_root to 77.00 GiB
Logical volume lv_root successfully resized
[root@centos-vm- ~]# resize2fs /dev/vg_centos6/lv_root
resize2fs 1.41. (-May-)
Filesystem at /dev/vg_centos6/lv_root is mounted on /; on-line resizing required
old desc_blocks = , new_desc_blocks =
Performing an on-line resize of /dev/vg_centos6/lv_root to (4k) blocks.
The filesystem on /dev/vg_centos6/lv_root is now blocks long. [root@centos-vm- ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos6-lv_root 76G .9G 71G % /
tmpfs 940M 72K 940M % /dev/shm
/dev/vda1 485M 40M 421M % /boot

注意-L的参数是 +18G,在扩展LV的容量后需要resize2fs是容量生效

4: 格式化文件系统

如果生成了新的LV,那么需要对分区进行文件系统格式化

mkfs.ext4   /dev/vg_centos6/lv_root

然后mout,最后修改/etc/fstab.

最新文章

  1. gulp启动一个小型web服务器配置&browserify(require)
  2. 现代软件工程 第十六章 【IT 行业的创新】练习与讨论
  3. [hihoCoder#1065]全图传送
  4. 如何把一个android工程作为另外一个android工程的lib库
  5. parseInt第二个参数详解
  6. loadView、viewDidLoad及viewDidUnload的关系
  7. phpexcel导入excel文件报the filename xxx is not recognised as an OLE file错误。
  8. Flask把变量注册到模板中
  9. Android自定义UI的实现和应用
  10. [POJ 2104]K-th Number【模板】(主席树)
  11. Python之路,进程、线程、协程篇
  12. Java垃圾回收(整理)
  13. LinkedList 的源码分析
  14. Linux内核读书笔记第三周 调试
  15. You are using safe update mode and you tried to update a table--mysql
  16. 擅于使用JS的eval方法
  17. C#流(stream)
  18. [Oracle]如何查看一个数据文件是否是自动扩展
  19. oracle相关链接
  20. flume采集启动报错,权限不够

热门文章

  1. GDB Core,gdb 调试大全,core文件调试
  2. 使用Python和OpenCV通过网址URL获取图片
  3. inux中,关于多路复用的使用,有三种不同的API,select、poll和epoll
  4. redis之 centos 6.7 下安装 redis-3.2.5
  5. poj 2262 Goldbach's Conjecture——筛质数(水!)
  6. Poj 2395 Out of Hay( 最小生成树 )
  7. Azure上每个VM多个IP地址
  8. 减小SSN影响
  9. Linux应用函数 -- 字符串
  10. Adobe Flash 无法正常使用