我需要将 LVM PE 移动到较小的磁盘,这可以吗?

我需要将 LVM PE 移动到较小的磁盘,这可以吗?

我需要将 Ubuntu 迁移到较小的磁盘。

我有一台虚拟机,其第一个磁盘为 50GiB:

$ sudo parted /dev/sda unit mib print free
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 51200MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start    End       Size      File system  Name                 Flags
        0.02MiB   1.00MiB   0.98MiB   Free Space
 1      1.00MiB   2.00MiB   1.00MiB                BIOS boot partition  bios_grub
        2.00MiB   2050MiB   2048MiB   Free Space
 2      2050MiB   51199MiB  49149MiB               LVM VG_SYSTEM        lvm
        51199MiB  51200MiB  0.98MiB   Free Space

它包含一个 48GiB-1MiB 的 VG,但仅占用了 25GiB-1MiB:

$ sudo pvs -o +pv_used --units m
  PV         VG        Fmt  Attr PSize     PFree     Used
  /dev/sda2  VG_SYSTEM lvm2 a--  49148.00m 23552.00m 25596.00m

如果我添加一个新的 25GiB 磁盘,其 BIOS 启动分区为 1MiB,另一个分区为 25GiB-1MiB,这样可以吗sudo pvmove /dev/sda2 /dev/sdb2

答案1

我添加了一个新的 25GiB 磁盘并重新扫描了 scsi 主机。然后我创建了一个 1MiB 的 BIOS 启动分区和另一个 25GiB-1MiB 的分区:

$ echo "- - -" | sudo tee /sys/class/scsi_host/host*/scan >/dev/null
$ sudo parted /dev/sdb unit gi print
Error: /dev/sdb: unrecognised disk label

Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 25.0GiB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 
$ sudo parted -s /dev/sdb mktable gpt
$ sudo parted -s /dev/sdb mkpart '"BIOS boot partition"' 1Mi 4095s
$ sudo parted -s /dev/sdb set 1 bios_grub on
$ sudo parted -s /dev/sdb -- mkpart '"LVM VG_SYSTEM"' 2Mi -1s
$ sudo parted -s /dev/sdb set 2 lvm on
$ sudo parted /dev/sdb unit mib print free
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 25600MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start    End       Size      File system  Name                 Flags
        0.02MiB  1.00MiB   0.98MiB   Free Space
 1      1.00MiB  2.00MiB   1.00MiB                BIOS boot partition  bios_grub
 2      2.00MiB  25600MiB  25598MiB               LVM VG_SYSTEM        lvm

然后我在 /dev/sda2 上创建了一个 LVM PV,将其添加到 VG_SYSTEM VG 并移动了 PE:

$ sudo pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created.
$ sudo vgextend VG_SYSTEM /dev/sdb2
  Volume group "VG_SYSTEM" successfully extended
$ time sudo pvmove /dev/sda2 /dev/sdb2
  /dev/sda2: Moved: 0.06%
  /dev/sda2: Moved: 7.97%
  /dev/sda2: Moved: 17.25%
  /dev/sda2: Moved: 22.61%
  /dev/sda2: Moved: 29.66%
  /dev/sda2: Moved: 39.96%
  /dev/sda2: Moved: 47.79%
  /dev/sda2: Moved: 55.81%
  /dev/sda2: Moved: 61.51%
  /dev/sda2: Moved: 63.99%
  /dev/sda2: Moved: 74.78%
  /dev/sda2: Moved: 80.00%
  /dev/sda2: Moved: 86.26%
  /dev/sda2: Moved: 94.22%
  /dev/sda2: Moved: 96.00%
  /dev/sda2: Moved: 100.00%

real    4m0.447s
user    0m0.003s
sys     0m0.009s

最后我从 VG_SYSTEM VG 中删除了 /dev/sdb2:

$ sudo vgreduce VG_SYSTEM /dev/sda2
  Removed "/dev/sda2" from volume group "VG_SYSTEM"
$ sudo pvremove /dev/sda2
  Labels on physical volume "/dev/sda2" successfully wiped.
$ sudo pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sdb2  VG_SYSTEM lvm2 a--  <25.00g    0
$ sudo grub-install /dev/sdb
Installing for i386-pc platform.
Installation finished. No error reported.
$ 

它非常有效 :-)

相关内容