You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于将Linux系统中/dev/vda5分区扩展至/dev/vda全部200GB空间的操作咨询

如何将Linux系统中/dev/vda5分区扩展至/dev/vda全部200GB空间

Got it, let's walk through this step by step. First, a non-negotiable pre-step: back up all critical data from /dev/vda5 right away. Partition resizing can go wrong, and you don't want to lose your files. Also, since /dev/vda5 is your root partition, you can't modify it while the system is running from it—you'll need to boot into a Linux Live USB/CD (like Ubuntu Desktop's "Try Ubuntu" mode) to work on the disk offline.

关于/dev/vda2的说明

You mentioned /dev/sda2—I think that's a typo for /dev/vda2, your existing extended partition. Since MBR (dos) partition tables only allow logical partitions to live inside an extended partition, we need to delete the old, small /dev/vda2 first, then create a new extended partition that fills all remaining space on /dev/vda. The old /dev/vda2 is no longer useful once we replace it with a larger one.


具体操作步骤

1. 启动到Live环境

Boot your system from a Linux Live USB/CD, select "Try Ubuntu" (or the equivalent trial mode for your distro) so you're not using /dev/vda5 as your running system.

2. 确认当前分区状态

Open a terminal and run these commands to verify the partition layout matches what you shared:

sudo fdisk -l /dev/vda
df -h

Make sure /dev/vda5 doesn't show up in the df -h output (it shouldn't be mounted in the Live environment).

3. 删除旧的扩展分区和逻辑分区

We'll use fdisk to modify the partition table:

sudo fdisk /dev/vda

Inside fdisk:

  • Type d then press Enter to delete a partition. When prompted, enter 5 to delete /dev/vda5 (the logical partition).
  • Type d again, then enter 2 to delete /dev/vda2 (the old extended partition).
    Now /dev/vda only has /dev/vda1 (the 512MB EFI partition) and unallocated space filling the rest of the 200GB disk.

4. 创建新的扩展分区

Still in fdisk:

  • Type n to create a new partition. When asked for partition type, select e (Extended) and press Enter.
  • Partition number: Press Enter to use the default (2).
  • First sector: Press Enter to use the first available sector right after /dev/vda1.
  • Last sector: Press Enter to use the final sector of the disk (this makes the extended partition fill all remaining space).
  • Type t to change the partition type. Enter 2 to select the new extended partition, then type 5 and press Enter (this sets the type to "Extended", which is required for MBR).

5. 在新扩展分区内创建新的逻辑分区/dev/vda5

Continue in fdisk:

  • Type n to create another new partition. It will automatically default to a logical partition (since we're inside the extended partition), and the default partition number will be 5.
  • First sector: Press Enter to use the first available sector in the new extended partition.
  • Last sector: Press Enter to use the final sector of the extended partition (this makes /dev/vda5 fill the entire extended partition).
  • Type t to set the partition type. Enter 5 to select the new logical partition, then type 83 and press Enter (this sets it to "Linux Filesystem").
  • Type w and press Enter to save all changes to the partition table and exit fdisk.

6. 扩展文件系统以匹配新分区大小

The partition is now resized, but we need to stretch the actual filesystem to fill the new space:

  • First, run a filesystem check to ensure there are no errors (this is mandatory):
    sudo e2fsck -f /dev/vda5
    
  • Then, expand the filesystem:
    sudo resize2fs /dev/vda5
    
    Note: If your filesystem is XFS instead of ext4, you'll need to mount /dev/vda5 first (e.g., sudo mount /dev/vda5 /mnt) then run sudo xfs_growfs /mnt instead of resize2fs.

7. 验证结果

Run these commands to confirm everything worked:

sudo fdisk -l /dev/vda
df -h /dev/vda5

You should see /dev/vda5 now occupies nearly all the 200GB disk (minus the 512MB /dev/vda1).


备注:内容来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 09:29:37