Partition
在 virtualbox 內的 ubuntu 伺服器 18.04 上增長分區似乎不起作用
這些是我從這個答案嘗試的步驟:
我跑的步驟:
- 執行以下命令以獲取 PV (物理卷)名稱(例如
/dev/sda1
:)sudo pvs
tini-wini # pvs PV VG Fmt Attr PSize PFree /dev/sda3 ubuntu-vg lvm2 a-- <9,00g 0 tini-wini #
- 調整 PV 大小
sudo pvresize /dev/sda3
tini-wini # sudo pvresize /dev/sda3 Physical volume "/dev/sda3" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized tini-wini #
- 執行以下命令以獲取根邏輯卷名*(
/
行的文件系統值;例如/dev/mapper/ubuntu--vg-root
:)*df -h
tini-wini # df -h Filesystem Size Used Avail Use% Mounted on udev 948M 0 948M 0% /dev tmpfs 199M 1,1M 198M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 8,8G 8,2G 211M 98% / tmpfs 992M 0 992M 0% /dev/shm tmpfs 5,0M 0 5,0M 0% /run/lock tmpfs 992M 0 992M 0% /sys/fs/cgroup /dev/loop0 45M 45M 0 100% /snap/snapd/15314 /dev/loop1 62M 62M 0 100% /snap/core20/1405 /dev/loop2 62M 62M 0 100% /snap/core20/1376 /dev/loop3 68M 68M 0 100% /snap/lxd/22753 /dev/loop4 56M 56M 0 100% /snap/core18/2344 /dev/loop5 68M 68M 0 100% /snap/lxd/22526 /dev/loop6 44M 44M 0 100% /snap/snapd/15177 /dev/loop7 56M 56M 0 100% /snap/core18/2253 /dev/sda2 976M 207M 703M 23% /boot tmpfs 199M 0 199M 0% /run/user/1000 tini-wini #
- 展開邏輯卷:
sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-root
tini-wini # lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv Size of logical volume ubuntu-vg/ubuntu-lv unchanged from <9,00 GiB (2303 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized. resize2fs 1.45.5 (07-Jan-2020) The filesystem is already 2358272 (4k) blocks long. Nothing to do! tini-wini #
使用
lsblk
命令它告訴我磁碟中的空間在那裡。tini-wini # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 44,7M 1 loop /snap/snapd/15314 loop1 7:1 0 61,9M 1 loop /snap/core20/1405 loop2 7:2 0 61,9M 1 loop /snap/core20/1376 loop3 7:3 0 67,8M 1 loop /snap/lxd/22753 loop4 7:4 0 55,5M 1 loop /snap/core18/2344 loop5 7:5 0 67,9M 1 loop /snap/lxd/22526 loop6 7:6 0 43,6M 1 loop /snap/snapd/15177 loop7 7:7 0 55,5M 1 loop /snap/core18/2253 sda 8:0 0 21G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 1G 0 part /boot └─sda3 8:3 0 9G 0 part └─ubuntu--vg-ubuntu--lv 253:0 0 9G 0 lvm / sr0 11:0 1 1024M 0 rom tini-wini #
在這種情況下我需要做什麼?
更新
fdisk -l Disk /dev/loop0: 55,5 MiB, 58183680 bytes, 113640 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/loop1: 67,94 MiB, 71221248 bytes, 139104 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/loop2: 67,83 MiB, 71106560 bytes, 138880 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/loop3: 44,65 MiB, 46804992 bytes, 91416 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/loop4: 61,92 MiB, 64901120 bytes, 126760 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/loop5: 55,53 MiB, 58212352 bytes, 113696 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/loop6: 43,64 MiB, 45748224 bytes, 89352 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/loop7: 61,92 MiB, 64901120 bytes, 126760 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/sda: 21 GiB, 22548578304 bytes, 44040192 sectors Disk model: VBOX HARDDISK 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: gpt Disk identifier: 363D35B2-1971-493B-B67D-6C40297B89AB Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 2101247 2097152 1G Linux filesystem /dev/sda3 2101248 20969471 18868224 9G Linux filesystem Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 8,102 GiB, 9659482112 bytes, 18866176 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 tini-wini #
根據評論,該程序似乎不完整。這是在 VirtualBox VM 上調整 LV 大小時需要發生的一系列事件。
- 從 VirtualBox 級別開始。VirtualBox 將 VM 磁碟作為單獨的文件保存在主機系統上。將磁碟的大小更新為所需的值。
- 在來賓 VM 上,核心會辨識磁碟大小的增加,但它還不能使用。您需要使用諸如 、 或 (或其他 GUI 等效項)之類的工具
fdisk
從gdisk
額外gparted
空間創建分區。如果可用空間緊跟現有分區,您還可以擴展現有分區。- 接下來是最低的 LVM 級別 - 物理卷。如果創建了新分區,請執行
pvcreate
以從中創建新 PV。如果您擴展了分區,請執行pvresize
以獲取更改。- 到 LVM 的第二層 - 卷組。如果添加了 PV,您需要使用
vgextend
. 如果調整了 PV 的大小,則應自動獲取更改。此時,您應該會在目標卷組下看到一些可用空間。
- 接下來,LVM 的頂層——邏輯卷。擴展所需的 LV 使用
lvextend
以從您的捲組分配可用空間。使用諸如確定lsblk
要擴展哪個 LV 之類的命令。- 最後一步是告訴 LV 上的文件系統佔用新空間。
lvextend
可以使用該--resizefs
選項管理多個文件系統。否則,您可以使用特定於文件系統的工具來擴展它(resize2fs
對於 ext2/3/4,xfs_growfs
對於 XFS 等)。您現在應該擁有一個具有所需額外儲存空間量的文件系統。