[root@test_img ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 253:0 0 20G 0 disk
├─vda1 253:1 0 1G 0 part /boot
└─vda2 253:2 0 7G 0 part / 这个是我们要扩容的根分区
vdb 253:16 0 30G 0 disk
[root@test_img ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.32.1).
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/vda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x9cf27616
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 16777215 14678016 7G 83 Linux
Command (m for help): d 先删除根分区,但切忌不要退出, 记住start和end,下面创建新分区要用
Partition number (1,2, default 2):
Partition 2 has been deleted.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-41943039, default 2099200): 正好是之前vda2的start,所以可以直接用默认
Last sector, +sectors or +size{K,M,G,T,P} (2099200-41943039, default 41943039):
Created a new partition 2 of type 'Linux' and of size 19 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n 不要删除ext4 签名,已经有文件系统了
Command (m for help): p
Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x9cf27616
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 41943039 39843840 19G 83 Linux
Command (m for help): w 保存退出
The partition table has been altered.
Syncing disks.
[root@test_img ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 253:0 0 20G 0 disk
├─vda1 253:1 0 1G 0 part /boot
└─vda2 253:2 0 19G 0 part / 可以看到vda2已经扩容到19GB,但此时df -hT 看根分区仍然没有变化
vdb 253:16 0 30G 0 disk
[root@test_img ~]# partprobe /dev/vda 刷新分区
[root@test_img ~]# resize2fs /dev/vda2 使用resize2fs(ext4)或xfs_growfs 对挂载目录在线扩容
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/vda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 3
The filesystem on /dev/vda2 is now 4980480 (4k) blocks long.
[root@test_img ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.7G 0 3.7G 0% /dev
tmpfs tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs tmpfs 3.7G 8.6M 3.7G 1% /run
tmpfs tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
/dev/vda2 ext4 19G 6.4G 12G 36% / 可以看到已经扩容完成
/dev/vda1 ext4 976M 148M 762M 17% /boot
tmpfs tmpfs 745M 0 745M 0% /run/user/0
linux 根分区扩容(非LVM)
最新推荐文章于 2024-05-20 17:11:44 发布