
我一直在嘗試遵循此論壇上的一些指南和文章以及其他有關如何擴展我當前的 Linux LVM 分區的指南和文章。
這是我目前的分區。我不明白 sda2 和 sda5 為何是相同的區塊是我的第一個問題。我的第二個問題是我不知道該選哪一個來擴充?
:/var$ sudo fdisk -l
Disk /dev/sda: 2199.0 GB, 2199023255552 bytes
255 heads, 63 sectors/track, 267349 cylinders, total 4294967296 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005011b
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 1782577151 891037697 5 Extended
/dev/sda5 501760 1782577151 891037696 8e Linux LVM
Disk /dev/mapper/webserver--vg-root: 908.1 GB, 908129730560 bytes
255 heads, 63 sectors/track, 110407 cylinders, total 1773690880 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/webserver--vg-root doesn't contain a valid partition table
Disk /dev/mapper/webserver--vg-swap_1: 4290 MB, 4290772992 bytes
255 heads, 63 sectors/track, 521 cylinders, total 8380416 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/webserver--vg-swap_1 doesn't contain a valid partition table
如何正確擴展它們而不冒丟失資料的風險?我擔心我會弄亂這個伺服器及其內容。
謝謝
新增 lvdisplay 的輸出:
--- Logical volume ---
LV Path /dev/webserver-vg/root
LV Name root
VG Name webserver-vg
LV UUID UfPECP-g3Ed-BYTv-GV1x-mkMk-Of1e-ujcM1t
LV Write Access read/write
LV Creation host, time webserver, 2015-02-10 10:09:20 -0500
LV Status available
open 1
LV Size 845.76 GiB
Current LE 216515
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Path /dev/webserver-vg/swap_1
LV Name swap_1
VG Name webserver-vg
LV UUID Hi6pMH-wrXI-H1MC-91Iu-V2ev-xven-Cna9Hc
LV Write Access read/write
LV Creation host, time webserver, 2015-02-10 10:09:20 -0500
LV Status available
open 2
LV Size 4.00 GiB
Current LE 1023
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
答案1
sda5
是一個邏輯分割區。它駐留在擴展分區 ( sda2
) 內。我假設這是一台較舊的機器/使用主引導記錄(MBR)安裝。即使在 MBR 下,擴展分區也不是真正必要的。擁有主/擴充/邏輯分割區是為了與早期版本的DOS/Windows 進行向後比較(Linux 在MBR 上支援4 個主分割區,而DOS/Win95 僅支援主/擴充分割區,而較新的GPT 分割區完全消除了這些限制)。
/dev/mapper/webserver--vg-root
是一個邏輯卷,駐留在sda5
.邏輯磁碟區用於抽象底層磁碟。您可以使用它vgdisplay
來顯示卷組(應該有一個)並lvdisplay
列出該組中的各個卷(您應該有兩個,一個用於交換,另一個用於根)。
您是否將分區複製到更大的硬碟?如果是這樣,您需要進行調整sda2
並sda5
具有相同的起始區塊,但有一個新的結束區塊(磁碟的末尾)。您可以fdisk
透過刪除並重新建立分割區來做到這一點。完成此操作後,vgextend
可以在整個磁碟區組上使用,將其擴展到分區的末尾。然後,您可以使用各種lv*
命令(lvdisplay
、lvextend
等)來擴展或移動各個磁碟區。
請務必在更改分割區或磁碟區組之前備份所有數據
以下命令集應該適合您的情況。您可能需要安裝parted
.或者,您可以安裝cloud-utils
並使用以下growpart
命令:
# via parted
parted /dev/sda resize 2 100%
parted /dev/sda resize 5 100%
# OR using cloud-utils / growpart
growpart /dev/sda 2
growpart /dev/sda 5
# Then have Linux re-read your partition talbe
partprobe /dev/sda
# Then expand your Physical Volume
pvresize /dev/sda5
# Extend the logical root volume
lvextend -l +100%FREE /dev/webserver-vg/root
# Extend the filesystem (assuming you're using ext2/3/4)
resize2fs /dev/webserver-vg/root