惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tor Project blog
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
H
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
博客园 - 司徒正美
Jina AI
Jina AI
雷峰网
雷峰网
博客园_首页
博客园 - 三生石上(FineUI控件)
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Forbes - Security
Forbes - Security
T
Threatpost
V
Visual Studio Blog
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Spread Privacy
Spread Privacy
N
News and Events Feed by Topic
Vercel News
Vercel News
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
NISL@THU
NISL@THU
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
PCI Perspectives
PCI Perspectives
博客园 - 【当耐特】
IT之家
IT之家
S
Secure Thoughts
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
Cisco Talos Blog
Cisco Talos Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
月光博客
月光博客
Latest news
Latest news
小众软件
小众软件
Attack and Defense Labs
Attack and Defense Labs
I
Intezer
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
大猫的无限游戏
大猫的无限游戏

No Coding Life

读书笔记|《适时退出:以退为进的决策智慧》 庐山烟雨浙江潮 All You Need Is Still Attention 05/18-05/24 Timetable AI Agent 不是不够聪明,是没地方说话 别高估自己 当我把自己开源 人人都说自己在用 AI 工作。数据讲了一个不同的故事。 一句话变成一篇完整数据分析,AI 团队是怎么做到的 一套 90 万美元的房子,租和买到底差多少?我用数据算了 30 年 一句话需求,五个 AI,两篇文章:我的多智能体写作实验 我用 AI 算了一套西雅图的房子,结果算懵了 砂纸、天窗与帝王绿:投资里的赌石幻觉 我老了 世界的孩子,父母的宝贝 当Anthropic高管说“编程已死”,一个程序员的认知割裂 回国之见家长 回国之头等舱体验打卡 回国后,我看到了中国经济数据的“体感温差” 告别一月 愿新年的阳光打在你的脸上 《为成果管理》读书笔记|Part 1 我是如何用AI,一小时写出自媒体行业报告的?
Proxmox 虚拟机 LVM 磁盘无损缩容实战指南 (100G -> 70G)
Aaron · 2026-04-07 · via No Coding Life

# Proxmox 虚拟机 LVM 磁盘无损缩容实战指南 (100G -> 70G)

## 0. 背景与核心挑战

在 Proxmox (PVE) 环境下,缩小一个使用了 LVM 且带 GPT 分区表的虚拟机磁盘。

核心难点:数据碎片化。即使文件系统已缩小,如果逻辑卷(LV)的物理块(PE)分布在磁盘末尾,底层分区就无法收缩。

## 1. 核心操作流程图

## 2. 详细操作步骤

### 第一阶段:内部手术 (Live CD 环境)

1. 进入 GParted Live CD:确保根目录未挂载。

2. 缩小文件系统 (ext4)

e2fsck -f /dev/mapper/ubuntu--vg-ubuntu--lv (检查)

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv 60G (缩小到 60G)

3. 缩小逻辑卷 (LV)

lvreduce -L 60G /dev/mapper/ubuntu--vg-ubuntu--lv

### 第二阶段:数据搬运 (数据整理的关键)

这是我们遇到的最大障碍pvresize 报错,提示末尾有数据。

1. 分析物理分布

pvs -v --segments /dev/sda3

发现数据分布像“夹心饼干”,中间有洞,尾部有钉子户。

2. 强制搬运数据 (pvmove)

使用 --alloc anywhere 强制将尾部区块挪到前面的空洞。

sudo pvmove --alloc anywhere /dev/sda3:尾部起始-尾部结束

3. 收尾:确保 pvs 显示磁盘最后一段完全是 free

### 第三阶段:底层切割 (PVE Host 环境)

1. GParted UI:拖动分区条,将 /dev/sda3 缩小到 65G(留 5G 缓冲)。

2. PVE Shell 缩容

lvreduce -L 70G pve/vm-100-disk-0

3. 修改配置

编辑 /etc/pve/qemu-server/100.conf,将 size=100G 手动改为 size=70G

### 第四阶段:修复引导 (GPT 补丁)

由于切掉了磁盘末尾,GPT 备份表丢失。

1. 使用 gdisk 修复

sudo gdisk /dev/sda -> x (专家模式) -> e (重定位备份表到末尾) -> w (保存)。

Skills verson

# Skill: Proxmox LVM Disk Shrinking (Expert Mode)

## Definition

无损缩小 Proxmox 虚拟机磁盘(LVM over GPT),处理数据碎片化并修复引导。

## Requirements

- GParted Live ISO

- Target VM Backup (Mandatory)

## Execution Protocol

### Step 1: Internal Filesystem & LV Shrink

1. Boot GParted Live.

2. e2fsck -f /dev/mapper/VG-LV

3. resize2fs /dev/mapper/VG-LV {TargetSize}G

4. lvreduce -L {TargetSize}G /dev/mapper/VG-LV

### Step 2: Clear Disk Tail (The "Data Move" Skill)

1. Run pvs -v --segments /dev/sdaX to identify fragments.

2. If segments exist near the disk end:

pvmove --alloc anywhere /dev/sdaX:{Tail_Start}-{Tail_End}

3. Repeat until the last segment in pvs is "free".

### Step 3: Partition & Host Adjustment

1. GParted UI: Resize /dev/sdaX to {TargetSize + 5}G.

2. PVE Host Shell: lvreduce -L {FinalSize}G {Path_to_LV}

3. Edit /etc/pve/qemu-server/{VMID}.conf: Update size={FinalSize}G.

### Step 4: GPT Repair (Fix initramfs boot error)

1. gdisk /dev/sda

2. Key sequence: x -> e -> w -> Y.

## Error Handling

- "later ones are allocated": Execute Step 2 (pvmove).

- "initramfs prompt": Execute Step 4 (gdisk).

- "Storage not showing": Check Datacenter > Storage > Content (Enable "Disk image").