Partition

試圖在 Linux VM 中擴展卷時卡住了

  • March 28, 2018

我有一個在 Ubuntu 機器上執行(無頭)的 Debian Linux VM。我使用 vboxmanage 將虛擬磁碟的大小從原來的 20G 增加到了 30G。我已經嘗試了很多東西,但我仍然卡在顯示 20G 的 LVM 分區。

我從 ISO 啟動並進入修復模式。我通過刪除 sda2 和 sda5 分區並使用新的 End 扇區創建新分區來更改分區表。我無法從這裡擴展分區。

# df -h
Filesystem        Size  Used Avail Use% Mounted on
/dev/dm-0          19G   13G  5.5G  69% /
udev               10M     0   10M   0% /dev
tmpfs             1.6G  8.4M  1.6G   1% /run
tmpfs             4.0G     0  4.0G   0% /dev/shm
tmpfs             5.0M     0  5.0M   0% /run/lock
tmpfs             4.0G     0  4.0G   0% /sys/fs/cgroup
/dev/sda1         236M   33M  191M  15% /boot
192.168.10.177:/  8.2G  2.4G  5.4G  31% /mnt/nfs

# fdisk -l

Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0xf5edb169

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1  *      2048   499711   497664  243M 83 Linux
/dev/sda2       499712 62914559 62414848 29.8G  5 Extended
/dev/sda5       501760 62914559 62412800 29.8G 8e Linux LVM

Disk /dev/mapper/ArkSrvr--vg-root: 18.9 GiB, 20300431360 bytes, 39649280 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 /dev/mapper/ArkSrvr--vg-swap_1: 872 MiB, 914358272 bytes, 1785856 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


# pvdisplay
 --- Physical volume ---
 PV Name               /dev/sda5
 VG Name               ArkSrvr-vg
 PV Size               19.76 GiB / not usable 2.00 MiB
 Allocatable           yes (but full)
 PE Size               4.00 MiB
 Total PE              5058
 Free PE               0
 Allocated PE          5058
 PV UUID               yWin1N-w3A4-sIAR-O2q9-nqPp-ki4G-yPr7kr

# lvdisplay
 --- Logical volume ---
 LV Path                /dev/ArkSrvr-vg/root
 LV Name                root
 VG Name                ArkSrvr-vg
 LV UUID                6YHVao-5Pth-2gA7-w42j-wAW7-mc9W-sQcImK
 LV Write Access        read/write
 LV Creation host, time ArkSrvr, 2017-03-06 08:51:00 -0600
 LV Status              available
 # open                 1
 LV Size                18.91 GiB
 Current LE             4840
 Segments               1
 Allocation             inherit
 Read ahead sectors     auto
 - currently set to     256
 Block device           254:0

 --- Logical volume ---
 LV Path                /dev/ArkSrvr-vg/swap_1
 LV Name                swap_1
 VG Name                ArkSrvr-vg
 LV UUID                eElIsI-bGdy-Cuje-BacF-1zap-wzlS-ftD28h
 LV Write Access        read/write
 LV Creation host, time ArkSrvr, 2017-03-06 08:51:00 -0600
 LV Status              available
 # open                 2
 LV Size                872.00 MiB
 Current LE             218
 Segments               1
 Allocation             inherit
 Read ahead sectors     auto
 - currently set to     256
 Block device           254:1

# lvextend -L+10G /dev/ArkSrvr-vg/root
 Insufficient free space: 2560 extents needed, but only 0 available

# lvextend -l+100%FREE /dev/ArkSrvr-vg/root
 New size (4840 extents) matches existing size (4840 extents)
 Run `lvextend --help' for more information.

# resize2fs /dev/ArkSrvr-vg/root
resize2fs 1.42.12 (29-Aug-2014)
The filesystem is already 4956160 (4k) blocks long.  Nothing to do!

如何讓 /dev/ArkSrvr-vg/root 增加到 30G?

你錯過了一步。

您擁有的是分區內(一組1)物理卷內的邏輯卷內的文件系統。

您已經擴展了分區。下一步是擴展物理卷:

pvresize /dev/sda5

您不必在這裡指定大小:沒有大小參數,PV 將自動採用封閉容器允許的最大大小,在這種情況下是分區。

如果成功,該pvdisplay命令應顯示 Total PE 增加,並且 Free PE 不再為 0。因此您將擁有一些可以使用的空閒物理範圍。

下一步是擴展邏輯卷,然後是文件系統。看起來你已經知道該怎麼做了。

引用自:https://unix.stackexchange.com/questions/434179