前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Centos7创建LVM及扩容

Centos7创建LVM及扩容

作者头像
贰叁壹小窝
发布于 2020-07-21 17:57:40
发布于 2020-07-21 17:57:40
1.1K00
代码可运行
举报
文章被收录于专栏:贰叁壹运维贰叁壹运维
运行总次数:0
代码可运行

本文编写于 109 天前,最后修改于 109 天前,其中某些信息可能已经过时。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
                       **环境为VMware虚拟机上的Centos7系统**

1.列出当前系统磁盘信息,可看到/dev/sdb可用

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x00000a46

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/mapper/cl-root: 18.2 GB, 18249416704 bytes, 35643392 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
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Disk /dev/mapper/cl-swap: 2147 MB, 2147483648 bytes, 4194304 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
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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

2.使用fdisk进行分区

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# fdisk /dev/sdb

Command (m for help): p #打印分区,查看当前分区状态

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x62cab278

   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): 1 #分区号1
First sector (2048-20971519, default 2048):  #回车选择默认值
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):  #回车选择默认分区大小
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

3.修改分区类型,8e为LVM分区类型

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Command (m for help): p #打印分区,查看当前分区状态
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x62cab278

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   83  Linux

Command (m for help): Command (m for help): t #更改分区类型
Selected partition 1
Hex code (type L to list all codes): 8e #lvm分区类型
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p #打印分区,可看到类型修改为8e,linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x62cab278

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   8e  Linux LVM
Command (m for help): w #保存分区

4.开始创建pv

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

5.查看pv信息

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               cl
  PV Size               19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               yunbOn-2uCl-9Xtr-wWV0-3jkn-fUoz-xpw6Ap

  "/dev/sdb1" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               k8y4on-IAJP-URy6-l3eu-xmUH-D3Ov-OI3yfb

6.创建VG,xls_vg为vg的名称

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# vgcreate xls_vg /dev/sdb1
  Volume group "xls_vg" successfully created

7.查看VG信息

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# vgdisplay 
  --- Volume group ---
  VG Name               xls_vg
  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               10.00 GiB
  PE Size               4.00 MiB
  Total PE              2559
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2559 / 10.00 GiB
  VG UUID               NczNSi-vCaA-pe9L-Q857-GDig-ME0f-zzxRiB

8.创建lv,并分配空间,这里是将10个G全部分出去了,xls_lv为lv的名称

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# lvcreate -L 10000M -n xls_lv xls_vg
  Logical volume "xls_lv" created.

9.查看lv的信息

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/xls_vg/xls_lv
  LV Name                xls_lv
  VG Name                xls_vg
  LV UUID                fXQxBc-UYQi-4T6y-gkmE-e9FC-ACy3-YfATDN
  LV Write Access        read/write
  LV Creation host, time xls, 2020-04-01 22:55:12 -0400
  LV Status              available
  # open                 0
  LV Size                9.77 GiB
  Current LE             2500
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

10.格式化文件系统

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# mkfs.ext4 /dev/xls_vg/xls_lv 

11.挂载磁盘

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# mount /dev/xls_vg/xls_lv /data/
[root@xls ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/cl-root         17G 1020M   16G   6% /
devtmpfs                   478M     0  478M   0% /dev
tmpfs                      489M     0  489M   0% /dev/shm
tmpfs                      489M  6.7M  482M   2% /run
tmpfs                      489M     0  489M   0% /sys/fs/cgroup
/dev/sda1                 1014M  139M  876M  14% /boot
tmpfs                       98M     0   98M   0% /run/user/0
/dev/mapper/xls_vg-xls_lv  9.5G   37M  9.0G   1% /data

12.设置挂载重启后不失效

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# vi /etc/fstab 
/dev/mapper/xls_vg-xls_lv /data                 ext4    defaults        0 0

13.开始扩容lvm,在虚拟机中新增一块5G的硬盘,使用echo读取出新增的硬盘

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# echo "- - -" > /sys/class/scsi_host/host2/scan
[root@xls ~]# fdisk -l
Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 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

14.对新加的硬盘进行分区,分区操作同上

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# fdisk /dev/sdc
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 0x8dd3be7d.

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-10485759, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): 
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): p

Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 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: 0x8dd3be7d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    10485759     5241856   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): w

15.将新加的硬盘/dev/sdc1创建为pv

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# pvcreate /dev/sdc1 
 Physical volume "/dev/sdc1" successfully created.

16.查看pv

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# pvscan 
  PV /dev/sdb1   VG xls_vg          lvm2 [10.00 GiB / 236.00 MiB free]
  PV /dev/sda2   VG cl              lvm2 [19.00 GiB / 0    free]
  PV /dev/sdc1                      lvm2 [5.00 GiB]
  Total: 3 [33.99 GiB] / in use: 2 [28.99 GiB] / in no VG: 1 [5.00 GiB]

17.将/dec/sdc1加入到vg:xls_vg中

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# vgextend xls_vg /dev/sdc1
 Volume group "xls_vg" successfully extended
[root@xls ~]# vgdisplay  #可以看到vg空间从原10g增加到了15g
  --- Volume group ---
  VG Name               xls_vg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               14.99 GiB
  PE Size               4.00 MiB
  Total PE              3838
  Alloc PE / Size       2500 / 9.77 GiB
  Free  PE / Size       1338 / 5.23 GiB
  VG UUID               NczNSi-vCaA-pe9L-Q857-GDig-ME0f-zzxRiB

18.给lv扩容,这里将vg中所有空闲的空间全部扩入lv

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# lvextend -l +100%FREE /dev/xls_vg/xls_lv 
  Size of logical volume xls_vg/xls_lv changed from 9.77 GiB (2500 extents) to 14.99 GiB (3838 
extents).
  Logical volume xls_vg/xls_lv successfully resized.

19.查看lv信息,空间已扩大到15g

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/xls_vg/xls_lv
  LV Name                xls_lv
  VG Name                xls_vg
  LV UUID                fXQxBc-UYQi-4T6y-gkmE-e9FC-ACy3-YfATDN
  LV Write Access        read/write
  LV Creation host, time xls, 2020-04-01 22:55:12 -0400
  LV Status              available
  # open                 1
  LV Size                14.99 GiB
  Current LE             3838
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

20.使扩容的空间写入文件系统,如果文件系统格式是xfs则用xfs_growfs命令

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# resize2fs /dev/xls_vg/xls_lv 
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/xls_vg/xls_lv is mounted on /data; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/xls_vg/xls_lv is now 3930112 blocks long.

21.查看磁盘扩容后的信息

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@xls ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/cl-root         17G 1021M   16G   6% /
devtmpfs                   478M     0  478M   0% /dev
tmpfs                      489M     0  489M   0% /dev/shm
tmpfs                      489M  6.8M  482M   2% /run
tmpfs                      489M     0  489M   0% /sys/fs/cgroup
/dev/sda1                 1014M  139M  876M  14% /boot
tmpfs                       98M     0   98M   0% /run/user/0
/dev/mapper/xls_vg-xls_lv   15G   41M   14G   1% /data
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-04-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
React Hook实践指南
在React为什么需要Hook这篇文章中我们探讨了React开发团队为什么要为Function Component添加Hook的原因,在本篇文章中我将会为大家提供一份较为全面的React Hook实践指南,其中包括以下方面的内容:
进击的大葱
2022/08/22
2.6K0
React Hooks 分享
        hooks: 钩子, React Hooks 的意思是,组件尽量写成纯函数,如果需要外部功能和副作用,就用钩子把外部代码"钩"进来 。
子夜星辰
2022/11/15
2.4K0
React Hooks 分享
React系列-轻松学会Hooks
❗️❗️HOC、Render Props 等基于组件组合的方案,相当于先把要复用的逻辑包装成组件,再利用组件复用机制实现逻辑复用。自然就受限于组件复用,因而出现扩展能力受限、Ref 隔断、Wrapper Hell……等问题
落落落洛克
2021/01/08
4.4K0
React系列-轻松学会Hooks
手写ReactHook核心原理,再也不怕面试官问我ReactHook原理
调用useState会返回一个state变量,以及更新state变量的方法。useState的参数是state变量的初始值,初始值仅在初次渲染时有效。
JowayYoung
2021/02/03
4.5K1
手写ReactHook核心原理,再也不怕面试官问我ReactHook原理
react hook 那些事儿
首先,它是在react16.8版本中引入的概念,也就说如果你的react版本低于16.8,你是不能使用的,因此在使用它的时候,一定要注意react的版本。
程序那些事儿
2023/03/07
5420
react hook 那些事儿
React Hooks源码浅析
前段时间研究了一波React的渲染流程,内部机制的源码,阅读到一半的时候React终于推出了16.8.x的版本,主要带来的更新就是Hooks的新功能。相信已经有很多的使用教程或者源码阅读文章。那么我也来一个属于自己的阅读有感的文章,做一个记录吧。
LamHo
2022/09/26
1.9K0
React Hooks源码浅析
精读《React Hooks》
React Hooks 是 React 16.7.0-alpha 版本推出的新特性,想尝试的同学安装此版本即可。
ConardLi
2019/09/08
1.2K0
如何用 Hooks 来实现 React Class Component 写法?
温馨提示:因微信中外链都无法点击,请通过文末的 “阅读原文” 到技术博客中完整查阅版;
JSCON简时空
2020/03/02
2.1K0
React Hooks教程之基础篇
Hook 是 React 16.8 的新增特性。它可以让你在不编写 class 的情况下使用 state 以及其他的 React 特性。
乐圣
2022/11/19
3.1K0
React Hooks 解析(下):进阶
React Hooks 是从 v16.8 引入的又一开创性的新特性。第一次了解这项特性的时候,真的有一种豁然开朗,发现新大陆的感觉。我深深的为 React 团队天马行空的创造力和精益求精的钻研精神所折服。本文除了介绍具体的用法外,还会分析背后的逻辑和使用时候的注意事项,力求做到知其然也知其所以然。
Dickensl
2022/06/14
4520
超实用的 React Hooks 常用场景总结
React 在 v16.8 的版本中推出了 React Hooks 新特性。在我看来,使用 React Hooks 相比于从前的类组件有以下几点好处:
前端达人
2021/05/11
4.9K0
【react】203-十个案例学会 React Hooks
原文地址:https://github.com/happylindz/blog/issues/19
pingan8787
2019/07/23
3.2K0
浅谈 Hooks
如果你很熟悉 vue 与 react ,兴许你也觉得 vue3.0 抄袭了react,这项react 在不久前发布的新技术,在 vue3.0 中被重新搬上了舞台。也使它重新活跃在了人们的视野中,我技术不深,与大家分享我的见解和猜测。
我不是费圆
2020/10/13
2K0
useTypescript-React Hooks和TypeScript完全指南
React v16.8 引入了 Hooks,它可以让你在不编写 class 的情况下使用 state 以及其他的 React 特性。这些功能可以在应用程序中的各个组件之间使用,从而易于共享逻辑。Hook 令人兴奋并迅速被采用,React 团队甚至想象它们最终将替换类组件。
前端森林
2020/04/23
9.2K0
useTypescript-React Hooks和TypeScript完全指南
react进阶用法完全指南
React调用回调函数,正确设置this指向的三种方法 通过bind this.increment = this.increment.bind(this); 通过箭头函数 <button onClick={this.multi}>点我*10</button> multi = () => { this.setState({ count: this.state.count * 10 }) } 箭头函数包裹 <button onClick={() => {this.muti2(
xiaofeng123aa
2022/09/26
6.1K0
React 设计模式 0x3:Ract Hooks
React Hooks 是在函数式组件中使用的生命周期方法,React Hooks 在 React 16.8 中被引入。在类组件中的生命周期方法已被合并成 React Hooks,React Hooks 无法在类组件中使用。
Cellinlab
2023/05/17
1.7K0
再聊react hook
React Hook是React函数式组件,它不仅仅有函数组件的特性,还带有React框架的特性。所以,官网文档多次强调:
娜姐
2020/12/11
1K0
React Hooks-useTypescript!
在React v16.8新增了Hook,它提供了在函数组件中访问状态和React生命周期等能力,这些函数可以在程序的各个组件之间复用,达到共享逻辑的目的。
写代码的阿宗
2020/09/22
4.3K0
快速上手三大基础 React Hooks
20190313162354.png ? 快速上手三大基础 React Hooks Hooks 出了有段时间了,不知盆友们有在项目中开始使用了吗❓如果还没了解的童鞋,可以瞧瞧这篇文章,对比看下三大基础
JS菌
2019/04/10
1.6K0
React 进阶:Hooks 该怎么用
之前如果我们需要抽离一些重复的逻辑,就会选择 HOC 或者 render props 的方式。但是通过这样的方式去实现组件,你打开 React DevTools 就会发现组件被各种其他组件包裹在里面。这种方式首先提高了 debug 的难度,并且也很难实现共享状态。
小生方勤
2019/06/26
1.1K0
相关推荐
React Hook实践指南
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验