linux 根分区扩容(非LVM)

11 篇文章 0 订阅
[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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值