Linux 硬盘扩容

一、基础概念

centos7.0开始默认文件系统是xfs,centos6是ext4,centos5是ext3。

ext3介绍
ext3和ext4的最大区别在于,ext3在fsck时需要耗费大量时间(文件越多,时间越长),而ext4在fsck时用的时间会少非常多。

ext4介绍
ext4是第四代扩展文件系统(英语:Fourth EXtended filesystem,缩写为ext4)是linux系统下的日志文件系统,是ext3文件系统的后继版本
ext4的文件系统容量达到1EB,而文件容量则达到16TB,这是一个非常大的数字了。对一般的台式机和服务器而言,这可能并不重要,但对于大型磁盘阵列的用户而言,这就非常重要了。
ext3目前只支持32000个子目录,而ext4取消了这一限制,理论上支持无限数量的子目录。

xfs介绍
xfs是一种非常优秀的日志文件系统,它是SGI公司设计的。xfs被称为业界最先进的、最具可升级性的文件系统技术。
xfs是一个64位文件系统,最大支持8EB减1字节的单个文件系统,实际部署时取决于宿主操作系统的最大块限制。对于一个32位Linux系统,文件和文件系统的大小会被限制在16TB。

xfs在很多方面确实做的比ext4好,ext4受限制于磁盘结构和兼容问题,可扩展性和scalability确实不如xfs,另外xfs经过很多年发展,各种锁的细化做的也比较好!

二、扩容硬盘容量的场景

云服务器、虚拟机、物理服务器扩容硬盘

三、例子

虚拟机sda扩容20G硬盘

安装

[root@demo1 /]# yum install cloud-utils-growpart

[root@demo1 /]# yum install xfsprogs

虚拟机扩容前,显示sdb为124.6G

[root@demo1 /]# fdisk -l

Disk /dev/sda: 231.9 GB, 231928233984 bytes, 452984832 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: 0x000d2f4d

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

Disk /dev/sdb: 124.6 GB, 124554051584 bytes, 243269632 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

扩容后,需要重启,sdb显示为146G

[root@demo1 ~]# fdisk -l

Disk /dev/sda: 231.9 GB, 231928233984 bytes, 452984832 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: 0x000d2f4d

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

Disk /dev/sdb: 146.0 GB, 146028888064 bytes, 285212672 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/centos-root: 225.5 GB, 225485783040 bytes, 440401920 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

查看Free PE

[root@demo1 data]# vgdisplay -v
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <213.88 GiB
  PE Size               4.00 MiB
  Total PE              54753
  Alloc PE / Size       54752 / <213.88 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               s9f5SB-UljN-cSgv-fbD7-pHtU-KUQq-3URSlC
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                pLOnAV-Ti18-N4eF-o6xn-JONG-EZKL-1dftXT
  LV Write Access        read/write
  LV Creation host, time demo1.changhongit.com, 2021-12-15 14:07:01 +0800
  LV Status              available
  # open                 1
  LV Size                210.00 GiB
  Current LE             53760
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                ld0ZZB-kc0w-KiSP-0bvV-2zPs-Z4ea-luwfk1
  LV Write Access        read/write
  LV Creation host, time demo1.changhongit.com, 2021-12-15 14:07:03 +0800
  LV Status              available
  # open                 2
  LV Size                <3.88 GiB
  Current LE             992
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               PLJEQV-TqAF-VN1D-sv4r-TXHX-sdLE-Gygdam
  PV Status             allocatable
  Total PE / Free PE    54753 / 1

查看分区大小

[root@demo1 ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       210G  2.0G  208G   1% /
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G  9.0M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sdb                ext4      115G   61M  109G   1% /data

通过resize2fs /dev/sdb扩容

[root@demo1 ~]# resize2fs /dev/sdb
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/sdb is mounted on /data; on-line resizing required
old_desc_blocks = 15, new_desc_blocks = 17
The filesystem on /dev/sdb is now 35651584 blocks long.

[root@demo1 ~]# fdisk -l

Disk /dev/sda: 231.9 GB, 231928233984 bytes, 452984832 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: 0x000d2f4d

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

Disk /dev/sdb: 146.0 GB, 146028888064 bytes, 285212672 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/centos-root: 225.5 GB, 225485783040 bytes, 440401920 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/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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

[root@demo1 ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       210G  2.0G  208G   1% /
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G  9.0M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sdb                ext4      134G   60M  128G   1% /data

备注:

云盘使用使用growpart工具扩容分区+使用resize2fs工具扩容文件系统

详见

阿里云Linux热扩容云盘(growpart和resize2fs工具) - 简书

命令解释:

resize2fs 命令            针对的是ext2、ext3、ext4文件系统
xfs_growfs 命令         针对的是xfs文件系统

1)ext2/ext3/ext4文件系统的调整命令是resize2fs(增大和减小都支持)

1

2

3

4

5

lvextend -L 120G /dev/mapper/centos-home     #增大至120G

lvextend -L +20G /dev/mapper/centos-home     #增加20G

lvreduce -L 50G /dev/mapper/centos-home      #减小至50G

lvreduce -L -8G /dev/mapper/centos-home      #减小8G

resize2fs /dev/mapper/centos-home            #执行调整

2)xfs文件系统的调整命令是xfs_growfs(只支持增大)

1

2

3

4

5

6

lvextend -L 120G /dev/mapper/centos-home     #增大至120G

lvextend -L +20G /dev/mapper/centos-home     #增加20G

xfs_growfs /dev/mapper/centos-home           #执行调整

就是说:xfs文件系统只支持增大分区空间的情况,不支持减小的情况(切记!!)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值