centos逻辑分区磁盘扩展

最近碰到服务器磁盘空间不足,需要扩展逻辑分区的需求,特地做下小笔记,方便后续自己回忆。下图是磁盘的相关概念示意图:

1、查看磁盘空间

[root@localhost ~]# df -h
#查看磁盘空间,根分区的大小是18G,已经用了43%。
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   18G  7.0G  9.5G  43% /
tmpfs                         2.0G   76K  2.0G   1% /dev/shm
/dev/sda1                     485M   40M  421M   9% /boot
/dev/sr0                      3.6G  3.6G     0 100% /media/cdrom

2、创建磁盘分区

#1、首先查询磁盘的相关信息,便于后续创建扩展时使用
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00083529

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.

#注意这里(Linux LVM类型的ID)后续扩展需要用到
/dev/sda2              64        2611    20458496   8e  Linux LVM

#/dev/sdb盘还有足够的空间
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


#2、创建磁盘分区
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xac7c929b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

#输入 p 回车
Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xac7c929b

   Device Boot      Start         End      Blocks   Id  System

#输入“n”
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
#输入“p”
p

#直接回车,使用默认值
Partition number (1-4): 1#分区号
First cylinder (1-2610, default 1):  #回车用默认的
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): #回车用默认的
Using default value 2610

Command (m for help): t #改变类型
Selected partition 1
#这里使用上述查询出来的具体ID值
Hex code (type L to list codes): 8e #LVM的分区代码
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xac7c929b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  8e  Linux LVM

#输入“w”完成磁盘分区的创建
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

#3、刷新磁盘分区的创建信息
[root@localhost ~]# partprobe
#将磁盘分区表变化信息通知内核,请求操作系统重新加载分区表,有些小报错不要紧。
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Error: Invalid partition table - recursive partition on /dev/sr0.

3、创建物理卷

#1、查询当前物理卷信息
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00083529

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xac7c929b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  8e  Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


#2、创建新的物理卷
[root@localhost ~]# pvcreate /dev/sdb1
#由fdisk -l查到LVM卷是/dev/sdb1,所以用/dev/sdb1来创建物理卷。
  Physical volume "/dev/sdb1" successfully created

4、扩展物理卷

#1、查询卷组信息
[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               qkBdcn-RQaR-ZliO-Ja2S-RhMC-stw8-CO213I
   
  "/dev/sdb1" is a new physical volume of "19.99 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               19.99 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               H7tDqG-6AZv-yBSA-U0ov-Ni0y-dlPA-kAA83i
   
#2、扩展物理卷组(注意这里的“VolGroup”,这是上面查询处理的【VG Name】需要保持一致,替换成自己的磁盘名称)
[root@localhost ~]# vgextend VolGroup /dev/sdb1
  Volume group "VolGroup" successfully extended
You have new mail in /var/spool/mail/root

#3、查询扩展后物理磁盘卷组信息
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               39.50 GiB
  PE Size               4.00 MiB
  Total PE              10112
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       5118 / 19.99 GiB
  VG UUID               dc0vI9-KzGu-4S59-A1xv-NM4Y-rYBF-3jDNRn

5、扩展逻辑卷

#1、扩展逻辑分区磁盘(注意这里的路径需要换成自己的,使用fdisk -l命令可查询得到)
[root@localhost ~]# lvextend -l +100%free /dev/mapper/VolGroup-lv_root
#free也可以大写FREE
  Extending logical volume lv_root to 37.50 GiB
  Logical volume lv_root successfully resized
[root@localhost ~]# blkid /dev/mapper/VolGroup-lv_root
#查看分区文件系统类型
/dev/mapper/VolGroup-lv_root: UUID="972fdddd-ddb8-469f-a342-e075eaeabeb2" TYPE="ext4" 

#2、检查分区
[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_root
#e2fsck -f检查分区
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/VolGroup-lv_root is mounted.
e2fsck: Cannot continue, aborting.

#3、根据具体的粪污文件系统类型执行不同的命令
[root@localhost ~]# resize2fs /dev/mapper/VolGroup-lv_root
#如果分区是xfs系统,则用xfs_growfs命令对文件系统进行扩展
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 9830400 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 9830400 blocks long.

[root@localhost ~]# df -h
#查看磁盘空间,根分区已扩展到37G。
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   37G  7.0G   29G  20% /
tmpfs                         2.0G  224K  2.0G   1% /dev/shm
/dev/sda1                     485M   40M  421M   9% /boot
/dev/sr0                      3.6G  3.6G     0 100% /media/cdrom

特别说明:不同的文件系统执行不同的命令,例如:

  • ext4类型,则使用命令:resize2fs /dev/mapper/VolGroup-lv_root
  • xfs类型,则使用命令:xfs_growfs /dev/mapper/VolGroup-lv_root

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/44600.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

RISCV -3 RV32I/RV64I基本整型指令集

RISCV -3 RV32I/RV64I基本整型指令集 1 RV32I Base Integer Instruction Set1.1 Programmers’ Model for Base Integer ISA1.2 Base Instruction Formats1.3 Immediate Encoding Variants1.4 Integer Computational Instructions1.4.1 Integer Register-Immediate Instruction…

深入浅出多种开发语言对接淘宝京东1688阿里巴巴等电商平台,获取实时商品详情数据API接口介绍

api接口详解大全?优秀的设计是产品变得卓越的原因设计API意味着提供有效的接口,可以帮助API使用者更好地了解、使用和集成,同时帮助人们有效地维护它每个产品都需要使用手册,API也不例外在API领域,可以将设计视为服务器和客户端之…

iPortal 注册登录模块扩展开发

作者:yx 文章目录 前言一、示例代码简介二、对接 iPortal REST API 接口2.1、登录模块扩展开发2.2、注册模块扩展开发 三、页面内容及样式实现四、配置启用定制页面 前言 针对注册登录模块,iPortal 允许用户通过 iFrame 方式接入自行开发的页面&#xf…

pytorch安装GPU版本 (Cuda12.1)教程: Windows、Mac和Linux系统快速安装指南

🌷🍁 博主 libin9iOak带您 Go to New World.✨🍁 🦄 个人主页——libin9iOak的博客🎐 🐳 《面试题大全》 文章图文并茂🦕生动形象🦖简单易学!欢迎大家来踩踩~&#x1f33…

语言尽头的奇幻旅程:如何求解最后一个单词的长度?

本篇博客会讲解力扣“58. 最后一个单词的长度”的解题思路,这是题目链接。 以示例2为例:s " fly me to the moon " 首先,找到字符串末尾的\0。s一开始指向首字符f,我们从这个位置开始,向后遍历&#xff0c…

基于高斯混合模型聚类的风电场短期功率预测方法(Pythonmatlab代码实现)

目录 💥1 概述 📚2 运行结果 2.1 Python 2.2 Matlab 🎉3 参考文献 🌈4 Matlab代码、数据、文章讲解 💥1 概述 文献来源: 摘要:对任意来流条件下的风电场发电功率进行准确预测,是提高电网对风电…

153、仿真-基于51单片机四相步进电机正反转控制系统设计(程序+Proteus仿真+参考论文+流程图+配套资料等)

毕设帮助、开题指导、技术解答(有偿)见文未 目录 一、设计功能 二、Proteus仿真图​ 三、程序源码 资料包括: 需要完整的资料可以点击下面的名片加下我,找我要资源压缩包的百度网盘下载地址及提取码。 方案选择 单片机的选择 方案一:ST…

vuejs源码之模版编译原理

之前我们说过虚拟dom,也就是虚拟dom拿到vnode后所做的事情,而模版编译是如何让虚拟dom拿到vnode。 模版编译的目标就是生成渲染函数,而渲染函数的作用是每次执行它,它就会使用当前最新的状态生成一份新的vnode,然后用…

ES6基础知识八:你是怎么理解ES6中Proxy的?使用场景?

一、介绍 定义: 用于定义基本操作的自定义行为 本质: 修改的是程序默认形为,就形同于在编程语言层面上做修改,属于元编程(meta programming) 元编程(Metaprogramming,又译超编程,是指某类计算…

.360勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复

引言: 近年来,随着互联网的普及和信息技术的快速发展,网络安全问题日益严峻。其中,勒索病毒成为网络安全领域的一大威胁。本文91数据恢复将重点介绍一种名为“.360勒索病毒”的恶意软件,并探讨被该病毒加密的数据文件…

quartus工具篇——PLL IP核的使用

quartus工具篇——PLL IP核的使用 1、PLL简介 PLL(Phase-Locked Loop,相位锁环)是FPGA中非常重要的时钟管理单元,其主要功能包括: 频率合成 - PLL可以生成比输入时钟频率高的时钟信号。频率分频 - PLL也可以输出分频后的较低频率时钟。减小时钟抖动 - PLL可以过滤输入时钟中…

踩坑 视觉SLAM 十四讲第二版 ch8 编译及运行问题

1.fmt相关 CMakeLists.txt中&#xff1a;在后面加上 fmt target_link_libraries(optical_flow ${OpenCV_LIBS} fmt ) target_link_libraries(direct_method ${OpenCV_LIBS} ${Pangolin_LIBRARIES} fmt )2.不存在用户定义的从 "std::_Bind<void (OpticalFlowTracker::…

架构重构实践心得

一、前言 大多数的技术研发都对重构有所了解&#xff0c;而每个研发又都有自己的理解。从代码重构到架构重构&#xff0c;我参与了携程大型全链路重构项目&#xff0c;积累了一点经验心得&#xff0c;在此抛砖引玉和大家分享。 二、重构的定义 重构是指在不改变外部行为的情…

改进的北方苍鹰算法优化VMD参数,最小包络熵、样本熵、信息熵、排列熵(适应度函数可自行选择,一键修改)包含MATLAB源代码...

今天给大家带来一期由改进的北方苍鹰算法(SCNGO)优化VMD的两个参数。 同样以西储大学数据集为例&#xff0c;选用105.mat中的X105_BA_time.mat数据中1000个数据点。没有数据的看这篇文章。西储大学轴承诊断数据处理&#xff0c;matlab免费代码获取 选取四种适应度函数进行优化&…

信息安全运维经验

1.备份系统 国外主流&#xff1a;veritas NetBackUp&#xff08;NBU&#xff09;、IBM&#xff08;TSM&#xff09; (191条消息) 【大数据-文摘笔记】Veritas NBU简介_weixin_30501857的博客-CSDN博客 虚拟机玩转 Veritas NetBackup&#xff08;NBU&#xff09;之服务端安装…

【云计算小知识】云环境是什么意思?有什么优点?

随着云计算的快速发展&#xff0c;了解云计算相关知识也是运维人员必备的。那你知道云环境是什么意思&#xff1f;有什么优点&#xff1f;云环境安全威胁有哪些&#xff1f;如何保证云环境的运维安全&#xff1f;这里我们就来简单聊聊。 云环境是什么意思&#xff1f; 云环境是…

水环境综合治理监测系统:筑牢城市水生态安全屏障

水是生命之源&#xff0c;是人类赖以生存的基础。然而&#xff0c;随着工业化、城市化的快速发展&#xff0c;水污染问题日益凸显&#xff0c;给居民的环境卫生以及用水安全带来了巨大的威胁。因此&#xff0c;加强水环境综合治理&#xff0c;保护水资源和维护生态平衡&#xf…

微信小程序导入微信地址

获取用户收货地址。调起用户编辑收货地址原生界面&#xff0c;并在编辑完成后返回用户选择的地址。 1&#xff1a;原生微信小程序接口使用API&#xff1a;wx.chooseAddress(OBJECT) wx.chooseAddress({success (res) {console.log(res.userName)console.log(res.postalCode)c…

一篇文章搞定《APP的启动流程》

一篇文章搞定《APP的启动流程》 前言冷启动、温启动、热启动启动中的重要成员简介zygote进程InstrumentationSystemServer进程ActivityManagerServiceBinderActivityThread 启动的步骤详解一、点击桌面图标二、创建进程三、初始化APP进程四、APP进程与System_server的绑定五、初…

【软件架构】企业架构4A定义

文章目录 前言战略、BA、DA、AA、TA五者的关系1、业务架构&#xff08;BA&#xff09;2、数据架构&#xff08;DA&#xff09;3、应用架构&#xff08;AA&#xff09;4、技术架构&#xff08;TA&#xff09;总结 前言 业务架构是跨系统的业务架构蓝图&#xff0c;应用架构、数…
最新文章