返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
个人数据保全计划

Why did I allocate 32G hard disk to the virtual machine, but Ubuntu only recognizes 16G?

I allocated a 32G disk in PVE, but it only shows as 15G in Ubuntu—where did this LVM stuff hide the space? The root directory alone took half? What kind of logic is this? It's utterly absurd. The three-step expansion process is straightforward, but who would actually use such a poorly designed setup?

曦远 (DealiAxy)约 7 分钟
目录4 个章节

Preface

Recently discovered my Ubuntu server freezing inexplicably

Logged in to check and found the hard drive was full

But using df -h revealed something strange—I had clearly allocated 32G of space in PVE, yet Ubuntu only showed 16G

$ df -h
/dev/mapper/ubuntu--vg-ubuntu--lv   15G   14G     0  100% /

Wait, what? I allocated 32G, so why is only 15G showing? Didn't half the space just vanish into thin air?

Initially thought it was a disk configuration error in PVE, but later realized—it really wasn't PVE's fault.

Very strange.

After some research, the reason turned out to be that the virtual disk allocated by PVE uses LVM.

The entire situation involves the layered relationship between virtualization disk, partition, LVM logical volume, and file system.

The Truth

Originally, Ubuntu enables LVM (Logical Volume Manager) by default during installation.

The logic of LVM is as follows: First, the entire disk is configured as a "Volume Group" (VG), and then several "Logical Volumes" (LVs) are created from it to be mounted and used.

The problem arises here—the installer, by default, allocates only about half of the space to the root directory.

Thus, although the virtual disk is 32GB, the root directory only received 16GB, while the remaining space quietly sits unused in the Volume Group.

It's somewhat like buying a 32GB USB drive but only creating a single 16GB partition to use, leaving the rest forgotten in a corner.

Expansion

Now that you know the cause, it's easy to fix. Just three simple steps:

Execute on the Ubuntu server:

# 1. Check the remaining space in the volume group
# Here it displays Free PE / Size, which is the unallocated space in the volume group (LVM).
vgdisplay
# 2. Expand the root logical volume to use all remaining space
# Here, +100%FREE means to allocate all remaining space in the volume group to this logical volume.
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
# 3. Extend the Filesystem to Actually Utilize the Space
resize2fs /dev/ubuntu-vg/ubuntu-lv

Here, the default filesystem is ext4, so we use the resize2fs command.

For xfs, use xfs_growfs /.

Then let's check with df -h... Perfect!

/dev/mapper/ubuntu--vg-ubuntu--lv   31G   14G   17G  45% /

Summary

This time, I got a lesson from LVM

I hadn't really used LVM before

Next time you see a situation like "allocated 32G but only showing 15G," you can try the solution described in this article.

_EOF_

Why did I allocate 32G hard disk to the virtual machine, but Ubuntu only recognizes 16G?

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…

Why did I allocate 32G hard disk to the virtual machine, but Ubuntu only recognizes 16G? · StarBlog