现在要将 /dev/sda3
分区删掉并扩容到 /dev/sda2
, 并且在不重启服务器的情况下扩容根文件系统(跟文件系统 /
挂载在 /dev/sda2
上, 并且 filesystem 是 ext4
)
磁盘初始分区和挂载情况
#
➜ ~ lsblk /dev/sda
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 98.5G 0 part /
└─sda3 8:3 0 976M 0 part
➜ ~ fdisk -l /dev/sda
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: BlockVolume
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: 40BED670-8B91-4520-9785-DB1F1035C039
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 207714303 206663680 98.5G Linux filesystem
/dev/sda3 207714304 209713151 1998848 976M Linux swap
➜ ~ df -hT /dev/sda2
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 97G 28G 64G 31% /
删除分区 /dev/sda3
#
➜ ~ fdisk /dev/sda
Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 has been deleted.
Command (m for help): p
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: BlockVolume
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: 40BED670-8B91-4520-9785-DB1F1035C039
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 207714303 206663680 98.5G Linux filesystem
Command (m for help): w # 保存退出
The partition table has been altered.
Syncing disks.
扩容分区 /dev/sda2
和 根文件系统
#
使用 fdisk
扩容 /dev/sda2
, 前提是 /dev/sda2
后面没有其他分区了,可以这样扩容(先删除不退出并重建分区, 分区 Start
不变, End
增大)
...