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 server笔记同步服务
在这个数据爆炸的时代,个人数据的价值愈发凸显,成为我们生活与工作中无可替代的重要资产。上一篇文章里,我介绍了从印象笔记迁移至 Joplin 的过程,这是我寻求数据自主掌控的关键一步。在探索同步方案时,我尝试了 OneDrive,原以为它能提供稳定高效的同步服务,可实际使用时却发现它对小文件缺乏优化,同步速度极慢,极大影响了使用体验。虽说目前还不确定是否存在数据丢失问题,但这样的效率实在难以满足我的
2025-02-02 · 个人数据保全计划 · 约 1 分钟
PVE折腾笔记 (2) 挂载之前在QNAP里使用的硬盘
QNAP硬盘数据迁移真够折腾的,RAID、DRBD、LVM层层嵌套,读出来比解方程还难。mdadm能识别但挂载失败,还得激活LVM才能看到文件,这坑比啥玩意儿。直接重做系统最省事,留原方案也行但风险不小,QTS的鸡贼设计简直让人想砸机器。
2025-06-15 · 个人数据保全计划 · 约 1 分钟
个人数据保全计划:搭建私有音乐库
下载音乐防灰,工具链折腾值不值?搭建私有流媒体,客户端体验一般般。数据自主权在手,平台下架算什么?
2023-09-29 · 个人数据保全计划 · 约 1 分钟
个人数据保全计划:安装本地DNS
SmartDNS SmartDNS 是一个运行在本地的 DNS 服务器,它接受来自本地客户端的 DNS 查询请求,然后从多个上游 DNS 服务器获取 DNS 查询结果,并将访问速度最快的结果返回给客户端,以此提高网络访问速度。 SmartDNS 同时支持指定特定域名 IP 地址,并高性匹配,可达到过滤广告的效果。 与 DNSmasq 的 all-servers 不同,SmartDNS 返回的是访问
2022-11-12 · 个人数据保全计划 · 约 1 分钟
讨论
共 0 条加载评论中…