Linux磁盘管理之LVM
2016-11-03 13:51
176 查看
LVM:Logical Volume Manager 逻辑卷管理
传统分区使用固定大小分区,重新调整大小十分麻烦。但是,LVM可以创建和管理“逻辑”卷,而不是直接使用物理硬盘。可以让管理员弹性的管理逻辑卷的扩大缩小,操作简单,而不损坏已存储的数据。可以随意将新的硬盘添加到LVM,以直接扩展已经存在的逻辑卷。LVM并不需要重启就可以让内核知道分区的存在。
LVM使用原理结构,如下图所示。
命令总览:
准备磁盘分区
通过fdisk命令创建/dev/sdb5,/dev/sdb6,/dev/sdb7,/dev/sdb8四个分区。大小可以不同
Partition number (1-8, default 8): 5
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'[root@localhost ~]# pvcreate /dev/sdb{5,6,7}
Physical volume "/dev/sdb5" successfully created
Physical volume "/dev/sdb6" successfully created
Physical volume "/dev/sdb7" successfully created[root@localhost ~]# vgcreate testvg /dev/sdb{5,6,7}
Volume group "testvg" successfully created [root@localhost ~]# vgremove testvg [root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID b3OHcq-LnQy-lNfj-XDgM-s9tx-rAtq-levoi1
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-03-17 16:28:39 +0800
LV Status available
# open 0
LV Size 8.00 GiB
Current LE 2048
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0[root@localhost ~]# mke2fs -t ext4 /dev/testvg/testlv
[root@localhost ~]# mkdir /lvm-mount
[root@localhost ~]# mount /dev/testvg/testlv /lvm-mount/[root@localhost ~]# resize2fs /dev/testvg/testlv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/testvg/testlv is mounted on /lvm-mount; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/testvg/testlv is now 2621440 blocks long.[root@localhost ~]# umount /dev/testvg/testlv[root@localhost ~]# lvresize -L 5G /dev/testvg/testlv[root@localhost ~]# lvdisplay
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID b3OHcq-LnQy-lNfj-XDgM-s9tx-rAtq-levoi1
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-03-17 16:28:39 +0800
LV Status available
# open 0
LV Size 5.00 GiB
Current LE 1280
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0[root@localhost ~]# vgextend /dev/testvg /dev/sdb8
Physical volume "/dev/sdb8" successfully created
Volume group "testvg" successfully extended
传统分区使用固定大小分区,重新调整大小十分麻烦。但是,LVM可以创建和管理“逻辑”卷,而不是直接使用物理硬盘。可以让管理员弹性的管理逻辑卷的扩大缩小,操作简单,而不损坏已存储的数据。可以随意将新的硬盘添加到LVM,以直接扩展已经存在的逻辑卷。LVM并不需要重启就可以让内核知道分区的存在。
LVM使用原理结构,如下图所示。
命令总览:
功能 | 物理卷管理 | 卷组管理 | 逻辑卷管理 |
Scan扫描 | pvscan | vgscan | lvscan |
Create建立 | pvcreate | vgcreate | lvcreate |
Display显示 | pvdisplay | vgdisplay | lvdisplay |
Remove删除 | pvremove | vgremove | lvremove |
Extend扩展 | vgextend | lvextend |
准备磁盘分区
通过fdisk命令创建/dev/sdb5,/dev/sdb6,/dev/sdb7,/dev/sdb8四个分区。大小可以不同
# fdisk /dev/sdb[code]Command (m for help): t
Partition number (1-8, default 8): 5
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'[root@localhost ~]# pvcreate /dev/sdb{5,6,7}
Physical volume "/dev/sdb5" successfully created
Physical volume "/dev/sdb6" successfully created
Physical volume "/dev/sdb7" successfully created[root@localhost ~]# vgcreate testvg /dev/sdb{5,6,7}
Volume group "testvg" successfully created [root@localhost ~]# vgremove testvg [root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID b3OHcq-LnQy-lNfj-XDgM-s9tx-rAtq-levoi1
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-03-17 16:28:39 +0800
LV Status available
# open 0
LV Size 8.00 GiB
Current LE 2048
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0[root@localhost ~]# mke2fs -t ext4 /dev/testvg/testlv
[root@localhost ~]# mkdir /lvm-mount
[root@localhost ~]# mount /dev/testvg/testlv /lvm-mount/[root@localhost ~]# resize2fs /dev/testvg/testlv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/testvg/testlv is mounted on /lvm-mount; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/testvg/testlv is now 2621440 blocks long.[root@localhost ~]# umount /dev/testvg/testlv[root@localhost ~]# lvresize -L 5G /dev/testvg/testlv[root@localhost ~]# lvdisplay
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID b3OHcq-LnQy-lNfj-XDgM-s9tx-rAtq-levoi1
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-03-17 16:28:39 +0800
LV Status available
# open 0
LV Size 5.00 GiB
Current LE 1280
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0[root@localhost ~]# vgextend /dev/testvg /dev/sdb8
Physical volume "/dev/sdb8" successfully created
Volume group "testvg" successfully extended
相关文章推荐
- Linux学习之CentOS(二十六)--Linux磁盘管理:LVM逻辑卷的创建及使用
- Linux磁盘管理:LVM逻辑卷的创建及使用
- Linux学习之CentOS(二十五)--Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理
- Linux学习之CentOS(二十五)--Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理
- linux磁盘管理------LVM
- Linux磁盘管理之LVM与RAID(转载)
- Linux磁盘管理之LVM详解
- Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理
- Linux磁盘管理之LVM及RAID管理一之LVM管理
- Linux磁盘管理:LVM逻辑卷创建及使用
- Linux学习之CentOS(二十六)--Linux磁盘管理:LVM逻辑卷的创建及使用
- Linux学习之CentOS(二十五)--Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理
- Linux学习之CentOS(二十五)--Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理
- Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理(一)
- Linux磁盘管理之LVM及RAID管理二之RAID管理
- Linux学习之CentOS(二十七)--Linux磁盘管理:LVM逻辑卷的拉伸及缩减
- Linux学习之CentOS(二十六)--Linux磁盘管理:LVM逻辑卷的创建及使用
- Linux学习之CentOS(二十六)--Linux磁盘管理:LVM逻辑卷的创建及使用
- Linux磁盘管理:LVM逻辑卷的创建及使用(二)
- linux磁盘管理:LVM的基本概念与创建、扩展、缩减、删除