曦远 (DealiAxy)一份私人的文字刊物

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 许可协议。转载请注明出处!

相关文章

个人数据保全计划:从印象笔记迁移到joplin

事实上我已经很多年没用印象笔记了,上次使用似乎还是很多年前大学时,当时还开了好几年会员,用来收藏网页、微信公众号文章,挺好用的。 可惜印象笔记(evernote)从某一年开始搞了中国特供版和国际版彻底切割,吃相越来越难看,而且导出格式也改成了专有格式,越来越封闭,这不是一个好兆头,我最怕被绑定在某个平台或者生态里。

2025-01-24 · 个人数据保全计划 · 约 1 分钟

个人数据保全计划:部署joplin server笔记同步服务

在这个数据爆炸的时代,个人数据的价值愈发凸显,成为我们生活与工作中无可替代的重要资产。上一篇文章里,我介绍了从印象笔记迁移至 Joplin 的过程,这是我寻求数据自主掌控的关键一步。在探索同步方案时,我尝试了 OneDrive,原以为它能提供稳定高效的同步服务,可实际使用时却发现它对小文件缺乏优化,同步速度极慢,极大影响了使用体验。虽说目前还不确定是否存在数据丢失问题,但这样的效率实在难以满足我的

2025-02-02 · 个人数据保全计划 · 约 1 分钟

讨论

共 0 条

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

加载评论中…