linux上文件系统扩容

发布时间:2022-06-20 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了linux上文件系统扩容脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

现在的云主机都可以给云盘扩容,然后我们就可以对分区进行无损扩容了。

例如:

/dev/sdb1       5.0G  1.2G  3.9G  24% /disk1
/dev/sdb2       5.0G  1.3G  3.8G  26% /disk2

给disk2扩容5G的空间

xfs 文件系统

先卸载分区,然后进行扩容分区:删除分区再重建,注意扇区起始位置要和删除前一致

[root@ ~]# umount  /disk2 
[root@ ~]# 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.


Command (m for help): p

Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 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: 0x00012087

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
/dev/sdb2        10487808    20973567     5242880   83  Linux                            ##sdb2的起始位置是10487808

Command (m for help): d 
Partition number (1,2, default 2): 2
Partition 2 is deleted

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): 2
First sector (10487808-62914559, default 10487808): 10487808                             ##这里sdb2的起始位置是10487808                     
Last sector, +sectors or +size{K,M,G} (10487808-62914559, default 62914559): 31459326    ##简单计算就可以得到要多少了
Partition 2 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 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: 0x00012087

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
/dev/sdb2        10487808    31459326    10485759+  83  Linux

partprobe 命令用于重读分区表

[root@ ~]# partprobe

xfs_growfs 命令扩容文件系统。xfs_growfs 需要先挂载分区,再操作。

[root@ ~]# mount /dev/sdb2 /disk2
[root@ ~]# xfs_growfs  /dev/sdb2 
meta-data=/dev/sdb2              isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1310720 to 2621439

就扩容好了,sdb2扩展了5G空间

ext4 文件系统

脚本宝典总结

以上是脚本宝典为你收集整理的linux上文件系统扩容全部内容,希望文章能够帮你解决linux上文件系统扩容所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: