![如何調整/擴大/成長非 LVM ext4 分區](https://rvso.com/image/1108690/%E5%A6%82%E4%BD%95%E8%AA%BF%E6%95%B4%2F%E6%93%B4%E5%A4%A7%2F%E6%88%90%E9%95%B7%E9%9D%9E%20LVM%20ext4%20%E5%88%86%E5%8D%80.png)
我已經搜索過論壇,但找不到合適的答案:
我有一個 Ubuntu Server 10.04 作為 KVM 主機和一個也運行 10.04 的來賓系統。主機系統使用 LVM,並且存在三個邏輯卷,它們作為虛擬區塊設備提供給來賓 - 一個用於 /,一個用於 /home,一個用於交換。來賓系統已在沒有 LVM 的情況下進行分割。
我已經擴大了主機系統中的邏輯磁碟區 - 來賓成功地看到了更大的虛擬磁碟。然而,該虛擬磁碟包含一個「良好的舊」分割區,該分割區仍然具有舊的小尺寸。
fdisk -l 的輸出是
me@produktion:/$ LC_ALL=en_US sudo fdisk -l
Disk /dev/vda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8ce7
Device Boot Start End Blocks Id System
/dev/vda1 * 1 3917 31455232 83 Linux
Disk /dev/vdb: 2147 MB, 2147483648 bytes
244 heads, 47 sectors/track, 365 cylinders
Units = cylinders of 11468 * 512 = 5871616 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f2bf7
Device Boot Start End Blocks Id System
/dev/vdb1 1 366 2095104 82 Linux swap / Solaris
Partition 1 has different physical/logical beginnings (non-Linux?):
phys=(0, 32, 33) logical=(0, 43, 28)
Partition 1 has different physical/logical endings:
phys=(260, 243, 47) logical=(365, 136, 44)
Disk /dev/vdc: 225.5 GB, 225485783040 bytes
255 heads, 63 sectors/track, 27413 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00027f25
Device Boot Start End Blocks Id System
/dev/vdc1 1 9138 73398272 83 Linux
parted print all 的輸出是
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 32.2GB 32.2GB primary ext4 boot
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 2146MB 2145MB primary linux-swap(v1)
Model: Virtio Block Device (virtblk)
Disk /dev/vdc: 225GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 75.2GB 75.2GB primary ext4
我想要實現的是簡單地增長或調整分區 /dev/vdc1 的大小,以便它使用虛擬區塊裝置 /dev/vdc 提供的整個空間。問題是,當我嘗試用分離來做到這一點時,它會抱怨:
(parted) select /dev/vdc
Using /dev/vdc
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vdc: 225GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 75.2GB 75.2GB primary ext4
(parted) resize 1
WARNING: you are attempting to use parted to operate on (resize) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Start? [1049kB]?
End? [75.2GB]? 224GB
Error: File system has an incompatible feature enabled. Compatible features are has_journal, dir_index, filetype, sparse_super and large_file. Use tune2fs
or debugfs to remove features.
那我能做什麼呢?這是一個無頭生產系統。增加此分割區的安全方法是什麼?不過,我可以卸載它 - 所以這不是問題。
編輯:Cfdisk 顯示了一個小的可用空間未分割空間,然後是分割區(標記為“boot”和 Linux/ext3),然後是其餘的未分割空間。刪除分割區並使用 cfdisk 再次建立分割區後 - cfdisk 顯示一個大分割區區域(這對我來說沒問題)並且檔案系統類型僅“Linux”
Resize2fs 傳回此錯誤
resize2fs 1.41.11 (14-Mar-2010) resize2fs: Bad magic number in super-block while trying to open /dev/vdc1 Couldn't find valid filesystem superblock
答案1
答案2
一個例子:
/dev/sdb2 是 /boot 分割區。它有 100 MB,相當小。要在正在運行的系統上增加此 ext4 分割區(以 root 或 sudo 身分):
卸載/啟動
分開/dev/sdb
(分開)列印
型號:ATA Patriot Torqx 2 (scsi)
磁碟 /dev/sdb:32.0GB
磁區大小(邏輯/實體):512B/512B
分割區表:msdos編號 開始結束 大小 類型 檔案系統 標誌
1 1049kB 12.9GB 12.9GB 主類型=83
2 12.9GB 13.0GB 107MB 主 ext4 類型=83(分手)rm 2
(已分手)mkpart
分區類型?主要/擴展?主要
檔案系統類型? [擴展2]?
開始? 12.9GB
結束了嗎? 13.4GB(分手)退出
調整大小2fs /dev/sdb2
resize2fs 1.42.6 (21-Sep-2012)
/dev/sdb2 處的檔案系統安裝在 /boot 上;需要線上調整大小
old_desc_blocks = 1, new_desc_blocks = 2
/dev/sdb2 上的檔案系統現在的長度為 498688 區塊。
完畢!
所有數據均保持不變。 /boot 已準備好使用,大小為 472MB(parted 的大小並不安全,請閱讀手冊以了解原因)
所有資料之前都已備份,但只是作為預防措施。我建議也這樣做。
如果失敗,請使用下列命令尋找正在停止卸載 /boot 的進程:
lsof /啟動
祝你好運!
答案3
如果您嘗試刪除並重新建立分割區,當您的分割區開始時間低於 2048 時,您可能會遇到像我一樣的麻煩resize2fs
。
Couldn't find valid filesystem superblock.
從fdisk 版本 2.17.2,fdisk IIUC 強制您從 2048 開始,以確保您的硬碟「正確對齊」。因此,如果您的原始分區在 2048 年之前開始,那麼您在嘗試重新建立分割區時將經歷一段坎坷的旅程。
最好的方法是克隆磁碟時的 rsync。