Growpart 不适用于 Debian 上的 LVM 分区

Growpart 不适用于 Debian 上的 LVM 分区

我正在尝试使用“growpart”在使用 LVM 的虚拟机上扩展分区。该命令报告成功,并且似乎输出了正确的更改。但是,运行后什么也没发生,即使重新启动后分区也没有改变。

我正在尝试将 /dev/sda 上的分区 5(lvm)从当前的 32g 扩展到 42g

$ lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                     8:0    0   42G  0 disk
├─sda1                  8:1    0  487M  0 part /boot
├─sda2                  8:2    0    1K  0 part
└─sda5                  8:5    0 31.5G  0 part
  ├─debian--vg-root   254:0    0 30.5G  0 lvm  /
  └─debian--vg-swap_1 254:1    0  976M  0 lvm  [SWAP]
sr0                    11:0    1 1024M  0 rom

$ fdisk -l
Disk /dev/sda: 42 GiB, 45097156608 bytes, 88080384 sectors
Disk model: QEMU 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: dos
Disk identifier: 0x3991920e

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048   999423   997376  487M 83 Linux
/dev/sda2       1001470 67106815 66105346 31.5G  5 Extended
/dev/sda5       1001472 67106815 66105344 31.5G 8e Linux LVM


Disk /dev/mapper/debian--vg-root: 30.5 GiB, 32774291456 bytes, 64012288 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/debian--vg-swap_1: 976 MiB, 1023410176 bytes, 1998848 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

现在,使用 growpart 试运行并扩大分区,您可以看到分区 5 上的结束块66105344从变为87078879

$ sudo growpart -N /dev/sda 5
CHANGE: partition=5 start=1001472 old: size=66105344 end=67106816 new: size=87078879,end=88080351
# === old sfdisk -d ===
label: dos
label-id: 0x3991920e
device: /dev/sda
unit: sectors

/dev/sda1 : start=        2048, size=      997376, type=83, bootable
/dev/sda2 : start=     1001470, size=    66105346, type=5
/dev/sda5 : start=     1001472, size=    66105344, type=8e
# === new sfdisk -d ===
label: dos
label-id: 0x3991920e
device: /dev/sda
unit: sectors

/dev/sda1 : start=        2048, size=      997376, type=83, bootable
/dev/sda2 : start=     1001470, size=    66105346, type=5
/dev/sda5 : start=     1001472, size=    87078879, type=8e

$ sudo growpart /dev/sda 5
CHANGED: partition=5 start=1001472 old: size=66105344 end=67106816 new: size=87078879,end=88080351

现在我希望 lsblk 能够显示扩展大小,但什么都没有改变。说实话,我不确定发生了什么,重启后也是一样

$ lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                     8:0    0   42G  0 disk
├─sda1                  8:1    0  487M  0 part /boot
├─sda2                  8:2    0    1K  0 part
└─sda5                  8:5    0 31.5G  0 part
  ├─debian--vg-root   254:0    0 30.5G  0 lvm  /
  └─debian--vg-swap_1 254:1    0  976M  0 lvm  [SWAP]
sr0

答案1

这个过程与上面提到的完全一样。先扩大扩展分区,然后再扩大子分区。之后,您就可以照常进行操作了。

扩展两个部分 -> 扩展 -> 子部分:

# grow the extended part
$ sudo growpart /dev/sda 2
CHANGED: partition=2 start=1001470 old: size=66105346 end=67106816 new: size=87078881,end=88080351

# now grow the child part
$ sudo growpart /dev/sda 5
CHANGED: partition=5 start=1001472 old: size=66105344 end=67106816 new: size=87078879,end=88080351

然后扩展物理卷:

$ sudo pvresize /dev/sda5

现在逻辑卷:

$ sudo lvextend -l +100%FREE /dev/debian-vg/root

最后部分是文件系统:

$ sudo resize2fs /dev/debian-vg/root

# now you will finally see it under `df` and is usable by the filesystem without restart
$ df -h
Filesystem                   Size  Used Avail Use% Mounted on
udev                         9.8G     0  9.8G   0% /dev
tmpfs                        2.0G   17M  2.0G   1% /run
/dev/mapper/debian--vg-root   40G   17G   21G  45% /
tmpfs                        9.9G     0  9.9G   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                        9.9G     0  9.9G   0% /sys/fs/cgroup
/dev/sda1                    470M   83M  363M  19% /boot
tmpfs                        2.0G     0  2.0G   0% /run/user/0
tmpfs                        2.0G     0  2.0G   0% /run/user/1002
tmpfs                        2.0G     0  2.0G   0% /run/user/1000

相关内容