• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >Linux > Linux磁盘管理之LVM的使用

Linux磁盘管理之LVM的使用

作者:qiuhom 字体:[增加 减小] 来源:互联网

本文主要包含Linux磁盘管理,Linux,LVM,Linux,磁盘等服务器相关知识,qiuhom 希望可以进行参考

一、LVM介绍

在我们管理Linux磁盘的时候,通常会遇到这么一种情况。在最初规划Linux的磁盘的时候,我们给某个分区划分了一定量的磁盘空间,使用一段时间后,发现我们规划的磁盘空间不足了,这个时候怎么办?我们肯定要想办法给扩容呀,找一块磁盘分区,格式化,然后挂载,然后把数据拷贝到新加的磁盘上,然后把原有的磁盘卸载掉,通常我们是这样做的。这样一来虽然达到了扩容的目的,但是费时费力;如果第二次扩容,空间还是不够,我们又要重复上面的步骤;如果分配的磁盘空间过大,使用了很久才发现它根本用不到那么多空间,这个时候是不是又要调整呀,听着就感觉很繁琐。这时候你肯定要想有没有那种可挂载上一块盘,我们利用某种管理手段,可以在线的调整磁盘的空间,这样有节约了时间,也可实现弹性管理磁盘。对,lvm就有这样的功能。

LVM(logical volume manager)逻辑卷管理,它可以弹性的管理文件系统的容量,LVM的工作原理是将一个或多个底层块设备组织成一个逻辑设备,这个逻辑设备可以在未来新增或移除其他的分区到这个逻辑设备中,从而实现了弹性管理磁盘。

PV:物理卷(physical volume);物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如raid),是LVM的基本储存逻辑块,但和基本的物理存储介质(如分区,磁盘等)比较,却包含有与LVM相关的管理参数

VG:卷组(volume group)LVM卷组类似于非LVM系统中的物理硬盘,尤其物理卷组成,可以在卷组上创建一个或多个LVM分区(逻辑卷),LVM卷组由一个或多个物理卷组成

LV:逻辑卷(logical volume)LVM的逻辑卷类似非LVM系统中的硬盘分区,在逻辑卷之上可以创建文件系统。

LVM就是将一些零碎的磁盘分区(PV)合并成一个较大的磁盘(VG),然后在根据需要对这个较大的磁盘(VG)进行划分成不同的大小分区(LV),这些小的分区(LV)是可以动态的扩展和缩小的,这就是LVM的逻辑卷管理过程。所谓LVM的大磁盘就是将许多PV整合成的VG,那么这个大磁盘最大可达到多少容量呢?我们知道在文件系统里面数据存储的最小单位是块(block),不过在LVM当中数据储存的最小单位是PE,PE的的作用同block的作用一样,需要注意到是LVM默认使用的PE大小是4M,而LVM的VG最多能包含65534个PE,也就是说默认LVM的VG会有4×65534M/1024M=256G,所以PE的大小决定了VG的最大容量,当然我们在创建VG的时候可指定PE大小,从而来决定VG的大小。

二、LVM实现

1)前期准备几块硬盘或者分区来模拟PV

[root@test-centos7-node1 ~]# lsblk
NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda   8:0  0  50G 0 disk 
├─sda1  8:1  0  2G 0 part /boot
├─sda2  8:2  0  2G 0 part [SWAP]
└─sda3  8:3  0  46G 0 part /
sdb   8:16  0  50G 0 disk 
sr0   11:0  1 792M 0 rom 
[root@test-centos7-node1 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6180123f.

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6180123f

  Device Boot   Start     End   Blocks  Id System

Command (m for help): n
Partition type:
  p  primary (0 primary, 0 extended, 4 free)
  e  extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-104857599, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +10G
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6180123f

  Device Boot   Start     End   Blocks  Id System
/dev/sdb1      2048  20973567  10485760  83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): n
Partition type:
  p  primary (1 primary, 0 extended, 3 free)
  e  extended
Select (default p): p
Partition number (2-4, default 2): 
First sector (20973568-104857599, default 20973568): 
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-104857599, default 104857599): +10G
Partition 2 of type Linux and of size 10 GiB is set

Command (m for help): t
Partition number (1,2, default 2): 
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): n
Partition type:
  p  primary (2 primary, 0 extended, 2 free)
  e  extended
Select (default p): p
Partition number (3,4, default 3): 
First sector (41945088-104857599, default 41945088): 
Using default value 41945088
Last sector, +sectors or +size{K,M,G} (41945088-104857599, default 104857599): +10G
Partition 3 of type Linux and of size 10 GiB is set

Command (m for help): t
Partition number (1-3, default 3): 
Hex code (type L to list all codes): 8e 
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6180123f

  Device Boot   Start     End   Blocks  Id System
/dev/sdb1      2048  20973567  10485760  8e Linux LVM
/dev/sdb2    20973568  41945087  10485760  8e Linux LVM
/dev/sdb3    41945088  62916607  10485760  8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@test-centos7-node1 ~]# lsblk
NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda   8:0  0  50G 0 disk 
├─sda1  8:1  0  2G 0 part /boot
├─sda2  8:2  0  2G 0 part [SWAP]
└─sda3  8:3  0  46G 0 part /
sdb   8:16  0  50G 0 disk 
├─sdb1  8:17  0  10G 0 part 
├─sdb2  8:18  0  10G 0 part 
└─sdb3  8:19  0  10G 0 part 
sr0   11:0  1 792M 0 rom 
[root@test-centos7-node1 ~]#

说明:这里是用的分区来模拟硬盘当作PV,这里需要注意一点,就是我们分区完保存后,可能存在不同不到问题,就是我们分区完用lsblk看不到分区,可用 partprobe来同步分区信息。centos6 使用partx  -a /dev/sdb来增加分区同步到内存,如果是删除某个分区,就需要执行partx -d -nr # /dev/sdb  此命令表示从/dev/sdb的分区信息中删除sdb#分区信息,并同步到内存中。这里还需要注意一点的是我们分区的类型要选8e 表示Linux LVM

2)装lvm2这个包

[root@test-centos7-node1 ~]# lvs
-bash: lvs: command not found
[root@test-centos7-node1 ~]# yum info lvm2 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
Name    : lvm2
Arch    : x86_64
Epoch    : 7
Version   : 2.02.185
Release   : 2.el7_7.2
Size    : 1.3 M
Repo    : updates/7/x86_64
Summary   : Userland logical volume management tools
URL     : http://sources.redhat.com/lvm2
License   : GPLv2
Description : LVM2 includes all of the support for handling read/write operations on
      : physical volumes (hard disks, RAID-Systems, magneto optical, etc.,
      : multiple devices (MD), see mdadm(8) or even loop devices, see
      : losetup(8)), creating volume groups (kind of virtual disks) from one
      : or more physical volumes and creating one or more logical volumes
      : (kind of logical partitions) in volume groups.

[root@test-centos7-node1 ~]# yum install lvm2 -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running 
  


 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Linux磁盘管理之LVM的使用

相关文章

  • CentOS源码安装MySQL 5.6.16
  • centos6.8搭建dhcp服务器
  • rsync+inotify实现数据同步及常见问题
  • Asp.Net Core 发布和部署( MacOS + Linux + Nginx )
  • centos nginx 环境下 搭建 letsencrypt
  • Centos7.3部署Elasticsearch5.4.0集群
  • 在Ubuntu18.04上安装Docker CE的方法(社区版)
  • CentOS 6.4下编译安装MySQL 5.6.14
  • 使用vs2019进行Linux远程开发的方法步骤
  • CentOS 7.1下rpm安装 MySQL

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • CentOS下轻松修改mysql的root密码
    • Centos 6.8上安装Mysql 5.6.35
    • 详解Nginx轮询算法底层实现的方法
    • Linux下NFS搭建步骤
    • centos7部署LAMP+xcache
    • 指南:在Github和Git上如何Fork
    • centos6.5下部署elk
    • Centos下MySQL忘记密码修改方法
    • CentOS服务器系统下更改Apache默认网站目录
    • CentOS7上安装MySQL Workbench

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有