# 【 Linux】Ubuntu 擴充硬碟完整步驟

#  Proxmox / Ubuntu 擴充硬碟完整步驟

### 💡 目標：

將原本的 `/dev/sda` 從 78G 擴充到 200G（或更大），  
並讓 `/`（根目錄）可使用整個新容量。

【proxmox】先使用ui + disk

[![image-1759893318494.png](https://bookstack.treemanou.com/uploads/images/gallery/2025-10/scaled-1680-/8sUNIpNfeXM1xNvx-image-1759893318494.png)](https://bookstack.treemanou.com/uploads/images/gallery/2025-10/8sUNIpNfeXM1xNvx-image-1759893318494.png)

---

## 一、確認目前磁碟架構

```bash
lsblk

```

範例輸出：

```
sda
├─sda1  1M   BIOS boot
├─sda2  2G   /boot
└─sda3  78G  LVM → ubuntu--vg → ubuntu--lv → /

```

檢查磁碟實際大小：

```bash
sudo fdisk -l /dev/sda

```

確認 `sda3` 沒有覆蓋整顆磁碟（例如結束 sector 明顯在中段）。

---

## 二、調整分區（fdisk 擴大 /dev/sda3）

⚠️ **這步只修改分區表，不會刪資料。**  
關鍵是「Start sector 不變」，這樣 LVM 仍能識別。

```bash
sudo fdisk /dev/sda

```

依序輸入以下指令（每行結束按 Enter）：

```
Command (m for help): p
Command (m for help): d
Partition number (1-3, default 3): 3
Command (m for help): n
Partition number (3-128, default 3): 3
First sector (4198400-419430366, default 4198400): 4198400
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4198400-419430366, default 419430366): [直接 Enter 使用預設值]

```

當出現：

```
Partition #3 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o:

```

👉 **輸入 `N`（No）保留資料！**

繼續：

```
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code or alias (type L to list all): 8e
Command (m for help): w

```

---

## 三、重新讀取分區表

```bash
sudo partprobe

```

若出現 busy 警告，可忽略 `/dev/sr0`，只要 `/dev/sda3` 沒報錯即可。  
如有報錯，可重開機一次再繼續。

---

## 四、擴大 LVM 實體卷（PV）

```bash
sudo pvresize /dev/sda3

```

檢查是否成功：

```bash
sudo vgdisplay

```

你應該看到：

```
Free  PE / Size       >0 / 約120GiB

```

---

## 五、擴大邏輯卷（LV）

```bash
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

```

範例輸出：

```
Size of logical volume ubuntu-vg/ubuntu-lv changed from <78.00 GiB to <198.00 GiB

```

---

## 六、擴大檔案系統（線上擴充）

先確認檔案系統類型：

```bash
df -Th /

```

結果可能是：

```
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 ...

```

### ▸ 若是 ext4：

```bash
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

```

### ▸ 若是 xfs：

```bash
sudo xfs_growfs /

```

---

## 七、驗證結果

```bash
df -h

```

預期結果：

```
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv  196G   20G  170G  11% /

```

---

## ✅ 狀態總結

<table id="bkmrk-%E9%A0%85%E7%9B%AE-%E7%B5%90%E6%9E%9C-%E5%88%86%E5%8D%80-%2Fdev%2Fsda3-%E5%B7%B2"><thead><tr><th>項目</th><th>結果</th></tr></thead><tbody><tr><td>分區 `/dev/sda3`</td><td>已擴大到整顆磁碟</td></tr><tr><td>PV (`pvresize`)</td><td>已更新容量</td></tr><tr><td>VG / LV (`lvextend`)</td><td>成功放大</td></tr><tr><td>檔案系統 (`resize2fs`)</td><td>線上擴充完成</td></tr><tr><td>是否需重開機</td><td>❌ 不需要</td></tr></tbody></table>

---

## 💡 小提醒

- 如果修改的是 `/boot` 或 EFI 分區，才需要重開機。
- 若 `partprobe` 無法重新讀取分區表，可在安全狀態下 reboot。
- 這個流程對 Ubuntu / Debian / Proxmox VM 都適用。

---