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

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

相关推荐
梦游钓鱼17 分钟前
pyshark安装使用,ubuntu:20.04
linux·运维·ubuntu
火龙谷20 分钟前
CentOS7将yum源更换为国内源教程
linux·centos
战族狼魂44 分钟前
CentOS 上安装各种应用的命令行总结
linux·运维·centos
学Linux的语莫1 小时前
ansible变量
linux·运维·服务器·ansible
北京迅为1 小时前
【北京迅为】iTOP-4412全能版使用手册-第十二章 Linux系统编程简介
linux·嵌入式硬件·4412开发板
清源妙木真菌1 小时前
Linux:进程控制
linux
爱吃喵的鲤鱼1 小时前
Linux——文件系统清尾、动静态库
linux·运维·服务器
最数据2 小时前
Linux或者Docker中时区查询和修改(差8小时问题)
linux·运维·服务器·docker·.net
mahuifa2 小时前
ubuntu设置程序开机自启动
服务器·ubuntu·开机自启动
皓月盈江2 小时前
Linux宝塔部署wordpress网站更换服务器IP后无法访问管理后台和打开网站页面显示错乱
linux·服务器·wordpress·无法访问wordpess后台·打开网站页面错乱·linux宝塔面板·wordpress更换服务器