使用 LUKS 進行根加密:未找到根分割區

使用 LUKS 進行根加密:未找到根分割區

我唯一的磁碟的佈局如下: /dev/sda1 for the plaintext boot partition /dev/sda2 for the encrypted root partition

我的系統是ArchLinux,我遵循本指南設定根加密(無lvm,無raid)。這就是我所做的:繼續運行cryptsetup並將/dev/sda2其映射到/dev/mapper/cryptroot

我的/etc/fstab看起來像這樣: UUID=of /dev/mapper/cryptroot / ext4 rw,relatime,data=ordered,discard 0 1 UUID=of /dev/sda1 /boot ext4 rw,relatime,data=ordered,discard 0 2

在我的文件中/etc/default/grub,我將一行更改為: GRUB_CMDLINE_LINUX="cryptdevice=UUID of /dev/sda2:cryptroot:allow-discards"

/etc/mkinitcpio.conf鉤子中看起來像這樣: HOOKS="base udev autodetect modconf block encrypt filesystems keyboard fsck"

最後我沒有忘記分別跑mkinitcpio -p linuxgrub-mkconfig -o /boot/grub/grub.cfg

我以如此輕快的方式列舉了我的操作,因為我之前已經成功地為我的根檔案系統配置了加密。所以,最後我得到以下錯誤:

ERROR: device *UUID of /dev/mapper/cryptroot* not found. Skipping fsck. ERROR: unable to find root device *UUID of /dev/mapper/cryptroot* You are being dropped into recovery shell

奇怪的是,它嘗試尋找未加密的內容/dev/mapper/cryptroot,但它並沒有要求我提供密碼(這是我cryptsetup/dev/sda2開始時創建的)。因此,它自然無法找到未加密的區塊設備,因為它一開始就沒有詢問我其密碼。能告訴我我配置錯了什麼嗎?

答案1

我成功地使用了cryptdevice=/dev/disk/by-uuid/<UUID_OF_LOGICAL_DEVICE>:cryptroot root=/dev/mapper/cryptrootGRUB 中的附加核心選項。

值得注意的是,如果您在執行此操作時沒有精確複製和貼上 UUID(例如在控制台/tty 中),則可能會出現拼寫錯誤。這是一行字,從控制台輸入也很糟糕,但可能會更容易。

sed "s/\(GRUB_CMDLINE_LINUX=\"\)/\1cryptdevice=\/dev\/disk\/by-uuid\/$(blkid -o value -s UUID /dev/<LOGICAL_DEVICE>):cryptroot root=\/dev\/mapper\/cryptroot/" /etc/default/grub > ~/grub.defaults && mv ~/grub.defaults /etc/default/grub

答案2

您缺少 /etc/crypttab cpio 掛鉤指向作業系統無法辨識的分區

/etc/crypttab

%{/dev/mapper/cryptroot 的 UUID} / ext4 rw,relatime,data=ordered,discard,luks - 0 1

然後重新運行 grub 更新

相關內容