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?
目录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 分钟
PVE折腾笔记 (2) 挂载之前在QNAP里使用的硬盘
QNAP硬盘数据迁移真够折腾的,RAID、DRBD、LVM层层嵌套,读出来比解方程还难。mdadm能识别但挂载失败,还得激活LVM才能看到文件,这坑比啥玩意儿。直接重做系统最省事,留原方案也行但风险不小,QTS的鸡贼设计简直让人想砸机器。
2025-06-15 · 个人数据保全计划 · 约 1 分钟
PVE折腾笔记 (3) 在原QNAP使用的硬盘上创建ZFS
QNAP硬盘换ZFS?自愈功能挺好用,但折腾Linux兼容性够闹心。LVM残留导致擦盘失败?内核对象得一个个干掉。Pool创建时参数选错?那可真是后患无穷。
2025-06-19 · 个人数据保全计划 · 约 1 分钟
个人数据保全计划:部署joplin server笔记同步服务
在这个数据爆炸的时代,个人数据的价值愈发凸显,成为我们生活与工作中无可替代的重要资产。上一篇文章里,我介绍了从印象笔记迁移至 Joplin 的过程,这是我寻求数据自主掌控的关键一步。在探索同步方案时,我尝试了 OneDrive,原以为它能提供稳定高效的同步服务,可实际使用时却发现它对小文件缺乏优化,同步速度极慢,极大影响了使用体验。虽说目前还不确定是否存在数据丢失问题,但这样的效率实在难以满足我的
2025-02-02 · 个人数据保全计划 · 约 1 分钟
讨论
共 0 条加载评论中…