CentOS磁盘在根目录下扩容(无卷组情况下)

文章描述了一台Linux服务器通过关机扩容、使用fdisk删除并重建分区、xfs_growfs命令扩展文件系统大小的过程,最终成功将/dev/sda3的容量从51G增长到56G。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.关机扩容

 2.开机确认空间大小

[root@localhost ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs        51G  7.5G   44G  15% /
devtmpfs       devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs          tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs          tmpfs     1.9G   13M  1.9G   1% /run
tmpfs          tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1      xfs       297M  157M  140M  53% /boot
tmpfs          tmpfs     378M  4.0K  378M   1% /run/user/42
tmpfs          tmpfs     378M   20K  378M   1% /run/user/0
tmpfs          tmpfs      60M     0   60M   0% /var/log/rtlog
[root@localhost ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 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: 0x00097eb3

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     8744959     4064256   82  Linux swap / Solaris
/dev/sda3         8744960   115343359    53299200   83  Linux

3.删除sda3,再重建sda3(注意:删除后不要退出,紧接着重建,注意重建后的起始位置)

[root@localhost ~]# 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): p

Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 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: 0x00097eb3

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     8744959     4064256   82  Linux swap / Solaris
/dev/sda3         8744960   115343359    53299200   83  Linux

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

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): 3
First sector (8744960-125829119, default 8744960): 
Using default value 8744960
Last sector, +sectors or +size{K,M,G} (8744960-125829119, default 125829119): 
Using default value 125829119
Partition 3 of type Linux and of size 55.9 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.

这里可以看到sda3已扩容成功,查询并未增加空间

[root@localhost ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs        51G  7.5G   44G  15% /
devtmpfs       devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs          tmpfs     1.9G  4.0K  1.9G   1% /dev/shm
tmpfs          tmpfs     1.9G   13M  1.9G   1% /run
tmpfs          tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1      xfs       297M  157M  140M  53% /boot
tmpfs          tmpfs     378M  4.0K  378M   1% /run/user/42
tmpfs          tmpfs     378M   24K  378M   1% /run/user/0
tmpfs          tmpfs      60M     0   60M   0% /var/log/rtlog

4.重启刷新或者不重启用

partprobe /dev/sda
xfs_growfs /dev/sda3
[root@localhost ~]# xfs_growfs /dev/sda3
meta-data=/dev/sda3              isize=512    agcount=6, agsize=2348160 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13324800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4586, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13324800 to 14635520
[root@localhost ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs        56G  7.5G   49G  14% /
devtmpfs       devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs          tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs          tmpfs     1.9G   13M  1.9G   1% /run
tmpfs          tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1      xfs       297M  157M  140M  53% /boot
tmpfs          tmpfs     378M  8.0K  378M   1% /run/user/42
tmpfs          tmpfs     378M     0  378M   0% /run/user/0
tmpfs          tmpfs      60M     0   60M   0% /var/log/rtlog

可以看到已经从51G扩展到56G,到此扩展成功

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值