当前位置: 首页 > news >正文

LINUX本地磁盘DISK空间扩容

vmware虚拟机本地磁盘空间不足,虚拟机层面扩容原有磁盘/dev/sda从50G到100G,系统层面fdisk划分磁盘分区,创建pv,添加到vg,扩展lv,xfs_growfs刷新文件系统空间。

1. 磁盘空间现状

df显示/总大小50G

[root@glodendb ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   45G   18G   27G  41% /
devtmpfs                24G     0   24G   0% /dev
tmpfs                   24G     0   24G   0% /dev/shm
tmpfs                   24G  8.9M   24G   1% /run
tmpfs                   24G     0   24G   0% /sys/fs/cgroup
/dev/sda1             1014M  133M  882M  14% /boot
/dev/loop0             4.2G  4.2G     0 100% /mnt/redhat_iso
tmpfs                  4.8G     0  4.8G   0% /run/user/0

lsblk显示sda已经扩容到100G

[root@glodendb ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0  100G  0 disk 
├─sda1          8:1    0    1G  0 part /boot
└─sda2          8:2    0   49G  0 part 
  ├─rhel-root 253:0    0 44.1G  0 lvm  /
  └─rhel-swap 253:1    0    5G  0 lvm  [SWAP]
sr0            11:0    1 1024M  0 rom  
loop0           7:0    0  4.2G  0 loop /mnt/redhat_iso

fdisk显示剩余50G空间未创建磁盘分区

[root@glodendb ~]# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000b5694

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

Disk /dev/mapper/rhel-root: 47.3 GB, 47303360512 bytes, 92389376 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 /dev/mapper/rhel-swap: 5301 MB, 5301600256 bytes, 10354688 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 /dev/loop0: 4497 MB, 4497342464 bytes, 8783872 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: 0x277a1f7d

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1   *           0     8783871     4391936    0  Empty
/dev/loop0p2          860440      877859        8710   ef  EFI (FAT-12/16/32)

2. fdisk划分新磁盘分区

[root@glodendb ~]# fdisk /dev/sda
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.


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

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

此时从lsblk不能看到新磁盘分区,需要partprobe刷新分区表

[root@glodendb ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0  100G  0 disk 
├─sda1          8:1    0    1G  0 part /boot
└─sda2          8:2    0   49G  0 part 
  ├─rhel-root 253:0    0 44.1G  0 lvm  /
  └─rhel-swap 253:1    0    5G  0 lvm  [SWAP]
sr0            11:0    1 1024M  0 rom  
loop0           7:0    0  4.2G  0 loop /mnt/redhat_iso

[root@glodendb ~]# partprobe /dev/sda
[root@glodendb ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0  100G  0 disk 
├─sda1          8:1    0    1G  0 part /boot
├─sda2          8:2    0   49G  0 part 
│ ├─rhel-root 253:0    0 44.1G  0 lvm  /
│ └─rhel-swap 253:1    0    5G  0 lvm  [SWAP]
└─sda3          8:3    0   50G  0 part 
sr0            11:0    1 1024M  0 rom  
loop0           7:0    0  4.2G  0 loop /mnt/redhat_iso

3. 新磁盘添加VG扩容LV

逻辑卷现状

[root@glodendb ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda2  rhel lvm2 a--  <49.00g 4.00m
[root@glodendb ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  rhel   1   2   0 wz--n- <49.00g 4.00m
[root@glodendb ~]# lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root rhel -wi-ao---- 44.05g                                                    
  swap rhel -wi-ao---- <4.94g  

创建PV

[root@glodendb ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
[root@glodendb ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree 
  /dev/sda2  rhel lvm2 a--  <49.00g  4.00m
  /dev/sda3       lvm2 ---   50.00g 50.00g

扩容VG

[root@glodendb ~]# vgextend rhel /dev/sda3
  Volume group "rhel" successfully extended
[root@glodendb ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree 
  rhel   2   2   0 wz--n- 98.99g 50.00g

扩容LV

[root@glodendb ~]# lvextend -L +50G /dev/rhel/root 
  Size of logical volume rhel/root changed from 44.05 GiB (11278 extents) to 94.05 GiB (24078 extents).
  Logical volume rhel/root successfully resized.
[root@glodendb ~]# lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root rhel -wi-ao---- 94.05g                                                    
  swap rhel -wi-ao---- <4.94g 

此时DF还不能看到容量增加

[root@glodendb ~]# df -Th
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs        45G   18G   27G  41% /
devtmpfs              devtmpfs   24G     0   24G   0% /dev
tmpfs                 tmpfs      24G     0   24G   0% /dev/shm
tmpfs                 tmpfs      24G  8.9M   24G   1% /run
tmpfs                 tmpfs      24G     0   24G   0% /sys/fs/cgroup
/dev/sda1             xfs      1014M  145M  869M  15% /boot
/dev/loop0            iso9660   4.2G  4.2G     0 100% /mnt/redhat_iso
tmpfs                 tmpfs     4.8G     0  4.8G   0% /run/user/0

xfs_growfs刷新文件系统空间

[root@glodendb ~]# xfs_growfs /dev/rhel/root 
meta-data=/dev/mapper/rhel-root  isize=512    agcount=4, agsize=2887168 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=11548672, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=5639, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 11548672 to 24655872
[root@glodendb ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   95G   18G   77G  19% /
devtmpfs                24G     0   24G   0% /dev
tmpfs                   24G     0   24G   0% /dev/shm
tmpfs                   24G  8.9M   24G   1% /run
tmpfs                   24G     0   24G   0% /sys/fs/cgroup
/dev/sda1             1014M  145M  869M  15% /boot
/dev/loop0             4.2G  4.2G     0 100% /mnt/redhat_iso
tmpfs                  4.8G     0  4.8G   0% /run/user/0
[root@glodendb ~]# 
http://www.dtcms.com/a/55080.html

相关文章:

  • SpringBoot 集成nacos,实现动态配置更新、docker安装nacos
  • 排序算法-冒泡排序
  • 计算机毕设-基于springboot的物业管理系统的设计与实现(附源码+lw+ppt+开题报告)
  • GPT-4 Turbo的重大升级与深远影响
  • Zabbix 安装部署
  • Ruby 安装 - Linux
  • 在 Ubuntu 上安装和切换多个 GCC 版本
  • 在Linux系统上集成OpenSlide与SpringBoot
  • HTTPS安全通信协议原理
  • Pytest安装和介绍
  • 【Go】Go zap 日志模块
  • STM32项目分享:STM32智能窗户
  • AI 实战 - pytorch框架基于retinaface实现face检测
  • Spring Boot面试问答
  • Docker 部署 vaultwarden
  • SyntaxError: Unexpected token ‘xxx‘
  • MySQL SELECT 查询性能优化指南
  • 批量将 Word 拆分成多个文件
  • [Vue warn]: Duplicate keys detected: ‘xxx‘. This may cause an update error.
  • RangeError: Maximum call stack size exceeded
  • P62 线程
  • React Native 0.76 升级后 APK 体积增大的原因及优化方案
  • Selenium 元素定位方法及最佳实践
  • 面试基础---分布式架构基础:CAP 理论与 BASE
  • DeepSeek大语言模型下几个常用术语
  • MySQL和Hive SQL 时间处理常用函数汇总
  • 字符串字典树-依依的瓶中信
  • 深度洞察!树莓集团南京产业园再布局的核心逻辑
  • 网络运维学习笔记(DeepSeek优化版) 013网工初级(HCIA-Datacom与CCNA-EI)ACL访问控制列表
  • 项目中同时使用Redis(lettuce)和Redisson的报错