VMware 虚拟机给 Ubuntu 根分区扩容

共计 1935 个字符,预计需要花费 5 分钟才能阅读完成。

1. vmware 扩大磁盘

  • 关闭Ubuntu
  • 右键—>设置—>硬盘—->实用工具—>扩展
  • 填入扩展后的分区大小
  • 确定

2. 给虚拟机打快照

3. 查看根目录磁盘信息

 root@k3s-128  df -Th|grep sda2
/dev/sda2                                                                                                                                                                                                                                         ext4      79G   38G   38G  51% /

4. 使用 fdisk 进行操作

打印查看分区划分情况

 sudo fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: gpt
Disk identifier: BB1002CF-D749-4A1F-8DF7-EF0945D4DF0E

Device     Start      End  Sectors Size Type
/dev/sda1   2048     4095     2048   1M BIOS boot
/dev/sda2   4096 83886046 83881951  40G Linux filesystem

删除需要扩容的分区,这里是2,完成后不要执行 w 写入

Command (m for help): d
Partition number (1,2, default 2): 2


Command (m for help): p
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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: gpt
Disk identifier: 0976B291-839E-463D-BD05-936253587234

Device     Start   End Sectors Size Type
/dev/sda1   2048  4095    2048   1M BIOS boot

创建新分区

# 创建新分区 ,First和Last sector直接回车默认值,因为我是把剩下所有空闲的空间全部分配到扩容的新分区内
# 若是部分分配,请在Last sector输入对应的值
Command (m for help): n
Partition number (2-128, default 2):
First sector (4096-209715166, default 4096):
Last sector, +sectors or +size{K,M,G,T,P} (4096-209715166, default 209715166):

Created a new partition 2 of type 'Linux filesystem' and of size 100 GiB.
Partition '#2' contains a ext4 signature.

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

查看新分区

Command (m for help): p

Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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: gpt
Disk identifier: 0976B291-839E-463D-BD05-936253587234

Device     Start       End   Sectors  Size Type
/dev/sda1   2048      4095      2048    1M BIOS boot
/dev/sda2   4096 209715166 209711071  100G Linux filesystem

确认无误后 w 写入操作

Command (m for help): w

The partition table has been altered.
Syncing disks.

重启

sudo reboot

5. 执行扩容操作

sudo resize2fs /dev/sda2

6. 参考文档

https://kleinlsl.github.io/2020/11/13/VM%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%BB%99Ubuntu%E6%A0%B9%E5%88%86%E5%8C%BA%E6%89%A9%E5%AE%B9/

正文完
 0
评论(没有评论)