如何将交换文件链接到 LUKS 加密驱动器上的 RESUME 变量?| Ubuntu 21.10

如何将交换文件链接到 LUKS 加密驱动器上的 RESUME 变量?| Ubuntu 21.10

我想在 LUKS 加密文件系统上拥有 32GB 的 SWAP 并启用休眠。我的基本交换分区是 1GB,我已经创建了 31GB 的 ´/swapfile'。我首先尝试使用fallocate命令,如所述这里。我将我的/etc/initramfs-tools/conf.d/resume和编辑/etc/default/grub成如下内容:

> cat /etc/initramfs-tools/conf.d/resume 
RESUME=UUID=<uuid> resume_offset=<offset>

其中 和 是命令的结果:

> sudo findmnt -no UUID -T /swapfile
> sudo filefrag -v /swapfile | awk '{ if($1=="0:"){print substr($4, 1, length($4)-2)} }'

我打过电话,sudo update-grub但是sudo update-initramfs -u没用。

然后我尝试/swapfile用命令删除旧的并创建新的dd

> sudo dd if=/dev/zero of=/swapfile bs=1024 count=32768k
33554432+0 records in
33554432+0 records out
34359738368 bytes (34 GB, 32 GiB) copied, 69,0213 s, 498 MB/s
> sudo mkswap /swapfile 
mkswap: /swapfile: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 32 GiB (34359734272 bytes)
no label, UUID=b86d678c-9717-44a0-876d-6ee9e26f3685
> sudo chmod 0600 /swapfile 
> sudo swapon -a

然后我使用上面的 UUID 并再次编辑/etc/initramfs-tools/conf.d/resume/etc/default/grub,然后调用 sudo update-grubsudo update-initramfs -u。以下是一些输出:

> cat /etc/initramfs-tools/conf.d/resume 
RESUME=UUID=b86d678c-9717-44a0-876d-6ee9e26f3685
> sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-5.13.0-22-generic
cryptsetup: ERROR: Couldn't resolve device 
    UUID=b86d678c-9717-44a0-876d-6ee9e26f3685
W: initramfs-tools configuration sets RESUME=UUID=ea58698b-f7ec-425a-950f-f5e5bae157ce
W: but no matching swap device is available.
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.

我也尝试过从到 的随机/etc/fstab进入,但没有成功/swapfileUUID

更多系统信息:

> blkid
/dev/mapper/nvme0n1p3_crypt: UUID="5XbV4n-kt79-RvIe-xKsA-ZfX3-fqLJ-8FW9Zt" TYPE="LVM2_member"
/dev/mapper/vgubuntu-root: UUID="ea58698b-f7ec-425a-950f-f5e5bae157ce" BLOCK_SIZE="4096" TYPE="ext4"
/dev/nvme0n1p3: UUID="f7314e8e-de0d-4932-a081-5ebbaec6434b" TYPE="crypto_LUKS" PARTUUID="89c52d41-d933-4ea0-8741-0e52d04f82f7"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"
/dev/loop6: TYPE="squashfs"
/dev/loop7: TYPE="squashfs"
/dev/nvme1n1p1: UUID="5d52d5c1-aa21-4a99-8faa-7b397017ae5e" TYPE="crypto_LUKS" PARTUUID="6cc4e2cc-c761-47f4-9a17-522bfcb5db9e"
/dev/nvme0n1p1: UUID="E470-EC97" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="8852d515-0378-4677-ac67-544c672c1e2c"
/dev/nvme0n1p2: UUID="cf67ab1d-e312-40d5-85f2-5f8fd33e3aab" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="7f2c243e-c977-44ae-84b8-783994279798"
/dev/mapper/vgubuntu-swap_1: UUID="da63ab4f-fdeb-4f50-832c-85d31e9fe479" TYPE="swap"
/dev/loop8: TYPE="squashfs"
/dev/loop9: TYPE="squashfs"
/dev/loop10: TYPE="squashfs"
/dev/loop11: TYPE="squashfs"
/dev/loop12: TYPE="squashfs"
/dev/loop13: TYPE="squashfs"
/dev/loop14: TYPE="squashfs"
/dev/mapper/luks-5d52d5c1-aa21-4a99-8faa-7b397017ae5e: LABEL="/home" UUID="af98cf42-73d6-450a-a2fb-b6cd3a16a04b" BLOCK_SIZE="4096" TYPE="ext4"


> cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/vgubuntu-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/nvme0n1p2 during installation
UUID=cf67ab1d-e312-40d5-85f2-5f8fd33e3aab /boot           ext4    defaults        0       2
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=E470-EC97  /boot/efi       vfat    umask=0077      0       1
/dev/mapper/vgubuntu-swap_1 none            swap    sw              0       0
/swapfile   none    swap    sw  0   0
UUID=af98cf42-73d6-450a-a2fb-b6cd3a16a04b   /home    ext4    defaults   0  2

> ls /dev/mapper
control                                    nvme0n1p3_crypt  vgubuntu-swap_1
luks-5d52d5c1-aa21-4a99-8faa-7b397017ae5e  vgubuntu-root

> /etc/crypttab
nvme0n1p3_crypt UUID=f7314e8e-de0d-4932-a081-5ebbaec6434b none luks,discard
luks-5d52d5c1-aa21-4a99-8faa-7b397017ae5e UUID=5d52d5c1-aa21-4a99-8faa-7b397017ae5e none nofail

我在 grub 和 initramfs-tools 中尝试了文件偏移量和驱动器 UUID 的各种组合。我甚至尝试过简单的重启,希望它能起作用。我不知道下一步该怎么做。有人有解决方案吗?

相关内容