如何增加精简配置虚拟机的硬盘空间?

如何增加精简配置虚拟机的硬盘空间?

创建了具有 100 GB 硬盘的精简配置 VM (Suse Linux)。现在由于空间要求,我需要将大小增加到 200GB。有人能告诉我如何增加“/”目录的空间吗?

Below is the output of the df -h command.

Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs            12G  8.0K   12G   1% /dev/shm
tmpfs           4.7G   18M  4.7G   1% /run
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/sda3        92G   53G   40G  57% /
/dev/sda1       511M  4.9M  507M   1% /boot/efi
tmpfs           2.4G   56K  2.4G   1% /run/user/467
tmpfs           2.4G   40K  2.4G   1% /run/user/465
tmpfs           2.4G   44K  2.4G   1% /run/user/1000
tmpfs           2.4G   40K  2.4G   1% /run/user/0
Below is the output of the fdisk -l command.

GPT PMBR size mismatch (209715199 != 419430399) will be corrected by write.
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Disk model: Virtual disk
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: 055ED88C-4E22-4F03-9C7F-4E4CCADBF54C

Device         Start       End   Sectors  Size Type
/dev/sda1       2048   1050623   1048576  512M EFI System
/dev/sda2  193429504 209715166  16285663  7.8G Linux swap
/dev/sda3    1050624 193429503 192378880 91.7G Linux filesystem

Partition table entries are not in disk order.

我尝试使用以下命令修复分区并更正 GPT PMBR 大小不匹配,然后重新启动。系统重新启动正常。

Enter into the disk partition place: 
fdisk /dev/sda

Command (m for help):   m  
Command action
  ...
   l   list known partition types
   m   print this menu
   p   print the partition table
   q   quit without saving changes
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help):   x

Expert command (m for help):   m
Command action
...
   f   fix partition order
   m   print this menu
   p   print the partition table
   q   quit without saving changes
   r   return to main menu
   v   verify the partition table
   w   write table to disk and exit

Expert command (m for help):   f
Done.

Expert command (m for help):   w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

我关闭了 SWAP 并删除了 SWAP 分区。然后我删除了“/”分区并重新创建了该分区,大小为 190G。

Commands used:

swapoff -a

fdisk  /dev/sda

由于“/”仍显示旧大小,我运行命令 xfs_growfs -d /。分区大小按预期增加。现在的问题是,我的系统无法以正常模式启动(只停留在 4 个点和蜥蜴标志上),而我可以启动到恢复模式。

我是否遗漏了什么?

答案1

问题已解决。“ / ”分区已扩展。但是,在完成所有活动后重新启动时,引导加载程序仍在尝试访问属于 SWAP 分区的旧 UUID。我更新了 UUID,它开始正常启动。

感谢大家的建议和支持。

答案2

首先进行备份以防万一。

我假设您发布的命令的输出来自 VM,而不是 HOST 服务器。

确认一下,您是否删除了分区 sda3,然后重新创建了大小为 190G 的分区?

如果我误读了您所发布的内容,并且您没有以正确的大小重新创建 sda3,那么请执行此操作。

由于 sda3 是 Linux 分区,我假设它是 ext4 分区,或 ext 系列之一。因此您需要运行 resizefs,而不是 xfs_growfs。xfs_growfs 仅适用于 xfs 文件系统。

resize2fs /dev/sda3 190G

相关内容