Partition

如何擴展 LUKS 分區以填充 LVM 上 2 個磁碟的整個邏輯卷?

  • July 26, 2021

我在我的 LVM 系統中添加了第二個磁碟。我在那裡創建了一個物理卷,將其添加到 ubuntu 的捲組“vgubuntu”,擴展邏輯卷以填充整個磁碟。如何擴展LUKS系統分區以填充整個邏輯卷?pvdisplay以下是,vgdisplay和提供的更多資訊lvdisplay

 --- Physical volume ---
 PV Name               /dev/mapper/nvme0n1p3_crypt
 VG Name               vgubuntu
 PV Size               <464.53 GiB / not usable 0   
 Allocatable           NO
 PE Size               4.00 MiB
 Total PE              118919
 Free PE               0
 Allocated PE          118919
 PV UUID               DwO3R1-DeRo-c83D-qx5F-xjC5-icXG-x3j28i

 --- Physical volume ---
 PV Name               /dev/nvme1n1p1
 VG Name               vgubuntu
 PV Size               <476.94 GiB / not usable 0   
 Allocatable           yes (but full)
 PE Size               4.00 MiB
 Total PE              122096
 Free PE               0
 Allocated PE          122096
 PV UUID               9UyJR4-m0G9-sYPG-BBkW-2WEg-TBdR-DAj0u3



root@omen15:~# vgdisplay
 --- Volume group ---
 VG Name               vgubuntu
 System ID             
 Format                lvm2
 Metadata Areas        2
 Metadata Sequence No  8
 VG Access             read/write
 VG Status             resizable
 MAX LV                0
 Cur LV                2
 Open LV               2
 Max PV                0
 Cur PV                2
 Act PV                2
 VG Size               941.46 GiB
 PE Size               4.00 MiB
 Total PE              241015
 Alloc PE / Size       241015 / 941.46 GiB
 Free  PE / Size       0 / 0   
 VG UUID               ANNTFf-p9hU-O4R3-jwDQ-bZhP-v8tm-hVL8Fn


root@omen15:~# lvdisplay
 --- Logical volume ---
 LV Path                /dev/vgubuntu/root
 LV Name                root
 VG Name                vgubuntu
 LV UUID                rxnIOU-yNg2-ythJ-Dz5V-N3Sr-X7DQ-WzbUUF
 LV Write Access        read/write
 LV Creation host, time ubuntu, 2021-07-24 17:25:39 +0300
 LV Status              available
 # open                 1
 LV Size                <940.51 GiB
 Current LE             240770
 Segments               2
 Allocation             inherit
 Read ahead sectors     auto
 - currently set to     256
 Block device           253:1

 --- Logical volume ---
 LV Path                /dev/vgubuntu/swap_1
 LV Name                swap_1
 VG Name                vgubuntu
 LV UUID                MOvhEP-64w3-wHHO-wmDh-YkSU-XARL-7hRQIf
 LV Write Access        read/write
 LV Creation host, time ubuntu, 2021-07-24 17:25:39 +0300
 LV Status              available
 # open                 2
 LV Size                980.00 MiB
 Current LE             245
 Segments               1
 Allocation             inherit
 Read ahead sectors     auto
 - currently set to     256
 Block device           253:2

這是df -h列印的內容:

root@omen15:~# df -h
Filesystem                 Size  Used Avail Use% Mounted on
tmpfs                      1.6G  2.1M  1.6G   1% /run
/dev/mapper/vgubuntu-root  925G  7.3G  871G   1% /
tmpfs                      7.6G   12M  7.6G   1% /dev/shm
tmpfs                      5.0M  4.0K  5.0M   1% /run/lock
tmpfs                      4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/nvme0n1p2             705M  251M  403M  39% /boot
/dev/nvme0n1p1             511M  5.3M  506M   2% /boot/efi
tmpfs                      1.6G  2.0M  1.6G   1% /run/user/1000

您已在 PV 級別配置了 LUKS,因此“在”您的 LVM 設置下,不幸的是您需要重新開始——您的 PV 必須加密,您不能將現有的 LUKS/dm-crypt 設備“擴展”到第二個磁碟。結構應該看起來像磁碟 -> 分區 -> LUKS -> PV -> VG -> LV(可以在 LV 級別配置加密,但您現有的配置在 PV 級別加密)。

所以你需要將你的rootLV 縮小回來,從中刪除你新創建的 PV vgubuntu,然後在nvme1n1p1( cryptsetup luksFormat /dev/nvme1n1p1) 上創建 LUKS,解鎖它 ( cryptsetup luksOpen /dev/nvme1n1p1 nvme1n1p1_crypt) 並/dev/mapper/nvme1n1p1_crypt用作第二個 PV。您還需要將新的 LUKS 設備添加到/etc/crypttab.

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