命令行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

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

相关推荐
时空无限1 小时前
EFK 中使用 ruby 和 javascript 脚本去掉日志中颜色字符详解
linux·javascript·elk·ruby
张火火isgudi8 小时前
fedora43 安装 nvidia 驱动以及开启视频编解码硬件加速
linux·运维·视频编解码·nvidia
IT19959 小时前
Qt笔记-使用SSH2进行远程连接linux服务器并上传文件
linux·服务器·笔记
XXYBMOOO9 小时前
内核驱动开发与用户级驱动开发:深度对比与应用场景解析
linux·c++·驱动开发·嵌入式硬件·fpga开发·硬件工程
whlqjn_12119 小时前
ubuntu启动失败报error: the initrd is too big错误
ubuntu
lengjingzju10 小时前
一网打尽Linux IPC(三):System V IPC
linux·服务器·c语言
大聪明-PLUS10 小时前
如何编写你的第一个 Linux 内核模块
linux·嵌入式·arm·smarc
知识分享小能手11 小时前
Ubuntu入门学习教程,从入门到精通,Ubuntu 22.04文件压缩与解压缩知识点详解(12)
linux·学习·ubuntu
用户61354114601611 小时前
Krb5-libs-1.18.2-5.ky10.x86_64.rpm 安装失败怎么办?附详细步骤
linux
zhougl99612 小时前
Vuex 模块命名冲突:问题解析与完整解决方案
linux·服务器·apache