linux上文件系统扩容
个人学习笔记,谢绝转载!!!
原文:https://www.cnblogs.com/wshenjin/p/16113785.html
现在的云主机都可以给云盘扩容,然后我们就可以对分区进行无损扩容了。
例如:
/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
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
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 文件系统
ext4文件系统前一步的分区扩容和上面的一样,主要新分区的起始位置就好。
然后就是:
partprobe /dev/sdb
e2fsck -f /dev/sdb1
resize2fs /dev/sdb1
mount /dev/sdb1 /disk1/