命令行fdisk扩展ubuntu 扩展分区sda2下的sda5 挂载根路径下的主分区

具体如下

bash 复制代码
root@ubuntu:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

#查询现有分区情况,40G需要扩展到50G
Command (m for help): p
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: VMware Virtual S
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: 0xa52b58b2

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048  1050623  1048576  512M  b W95 FAT32
/dev/sda2       1052670 83886079 82833410 39.5G  5 Extended
/dev/sda5       1052672 83886079 82833408 39.5G 83 Linux
#删除sda5分区
Command (m for help): d
Partition number (1,2,5, default 5): 5

Partition 5 has been deleted.
#删除sda2分区
Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.
# 创建新扩展分区sda2(不断的按默认回车)
Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e (选择扩展分区)
Partition number (2-4, default 2): 
First sector (1050624-104857599, default 1050624): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-104857599, default 104857599): +49.5G             
Value out of range.
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-104857599, default 104857599): 

Created a new partition 2 of type 'Extended' and of size 49.5 GiB.
#查询创建好的扩展分区
Command (m for help): p
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: VMware Virtual S
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: 0xa52b58b2

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048   1050623   1048576  512M  b W95 FAT32
/dev/sda2       1050624 104857599 103806976 49.5G  5 Extended
# 继续创建分区,默认主分区这个时候就是在扩展分区下面
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (1052672-104857599, default 1052672): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1052672-104857599, default 104857599): 

Created a new partition 5 of type 'Linux' and of size 49.5 GiB.
Partition #5 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: Y

The signature will be removed by a write command.
# 查询创建好的分区,这个时候所有的空间都已经用了
Command (m for help): p
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: VMware Virtual S
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: 0xa52b58b2

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048   1050623   1048576  512M  b W95 FAT32
/dev/sda2       1050624 104857599 103806976 49.5G  5 Extended
/dev/sda5       1052672 104857599 103804928 49.5G 83 Linux

Filesystem/RAID signature on partition 5 will be wiped.
# 保存退出,因为我们是根分区,所以会提示分区忙碌
Command (m for help): w
The partition table has been altered.
Failed to add partition 2 to system: Device or resource busy

The kernel still uses the old partitions. The new table will be used at the next reboot. 
Syncing disks.

重启服务器

bash 复制代码
init 6

重启后查看分区情况

发现还是没有生效,但是分区却已经扩展了

bash 复制代码
root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5        39G  7.4G   30G  20% /
/dev/sda1       511M  4.0K  511M   1% /boot/efi
root@ubuntu:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0    50G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0     1K  0 part 
└─sda5   8:5    0  49.5G  0 part /

刷新盘符

bash 复制代码
root@ubuntu:~# resize2fs /dev/sda5
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/sda5 is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 7
The filesystem on /dev/sda5 is now 12975616 (4k) blocks long.

root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
/dev/sda5        49G  7.4G   40G  16% /
/dev/sda1       511M  4.0K  511M   1% /boot/efi

最后重启一次服务器验证是否有问题

相关推荐
程序员 _孜然3 小时前
Ubuntu/Debian修改网卡名字enP3p49s0为eth0
linux·运维·驱动开发·嵌入式硬件·ubuntu·debian
可期不折腾3 小时前
NVIDIA Nsight Systems性能分析工具
ubuntu·nvidia·nsight systems·性能分析工具
IDIOT___IDIOT3 小时前
Linux mount 命令
linux·运维·服务器
CTRA王大大4 小时前
【golang】制作linux环境+golang的Dockerfile | 如何下载golang镜像源
linux·开发语言·docker·golang
小张程序人生4 小时前
《VMware 安装 CentOS 7.9 虚拟机详细教程(含图解步骤)》
linux·centos
泡沫冰@6 小时前
管理 SELinux 安全性
linux
展信佳_daydayup8 小时前
03 基础篇-润和开发板连接过程
linux·开源·嵌入式
两张不够花8 小时前
Shell脚本源码安装Redis、MySQL、Mongodb、PostgreSQL(无报错版)
linux·数据库·redis·mysql·mongodb·postgresql·云计算
tan77º8 小时前
【Linux网络编程】分布式Json-RPC框架 - 项目设计
linux·服务器·网络·分布式·网络协议·rpc·json
Ray Song9 小时前
【Linux】 wget、curl 用法区别
linux·运维·服务器·curl·wget