如何使用 LVM over LUKS 全碟加密在單獨的啟動分割區上手動設定 grub?

如何使用 LVM over LUKS 全碟加密在單獨的啟動分割區上手動設定 grub?

我安裝了 Linux Mint 17.2,硬碟分割如下:

sdc1 - 100MB ext2 for boot
sdc2 - rest of disk as LUKS -> Physical Volume -> LVM Volume

邏輯卷是:

/
/home
swap

安裝程序似乎工作正常,只是無法安裝引導程序,我被迫選擇“稍後手動安裝引導程序”選項。

我運行了 LiveCD,打開了 LUKS 卷,並將根邏輯卷安裝在 /mnt。

Q:如何安裝引導程式?

大多數說明都是這樣說的:

# grub-install --root-directory=/mnt/ /dev/sdc

但這會產生:

grub-probe: error: failed to get canonical path of `/cow'.
Installing for i386-pc platform.
grub-install.real: error: attempt to install to encrypted disk without cryptodisk enabled. Set `GRUB_ENABLE_CRYPTODISK=1' in file `/etc/default/grub'..

我已經編輯了/etc/default/grub/mnt/etc/default/grub並添加GRUB_ENABLE_CRYPTODISK=1到了兩者,但錯誤仍然發生。

正確的設定方法是什麼,以便 grub 安裝在未加密的 sdc1 上,提示輸入密碼,然後在解鎖後啟動系統?

更新

Grub 現在在啟動時加載,但它不會要求輸入密碼或正確解密。透過新增以下選項,/etc/default/grub我可以讓它提示輸入密碼,但輸入正確的密碼時它不會解密:

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
#GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`    
GRUB_CMDLINE_LINUX_DEFAULT="cryptopts=target=lvmbase,source=/dev/disk/by-uuid/f7ddbdb6-51c3-4c59-9d1e-7751b0438431,lvm=vg0_root"
GRUB_CMDLINE_LINUX=""

答案1

我通常會grub從內部恢復過來chroot。因此,從即時發行版啟動並...

打開 LUKS 磁碟區:

# cryprsetup open /dev/sdc2 luks-mint

激活 LVM 磁碟區:

# vgscan
# vgchange -a y vg_mint
# lvscan

登上 Mint 並做好準備chroot

# mount /dev/mapper/vg_mint-root /mnt
# mount /dev/sdc1 /mnt/boot
# mount --rbind /dev /mnt/dev
# mount --rbind /sys /mnt/sys
# mount -t proc none /mnt/proc

chroot進入薄荷:

# env -i HOME=/root TERM=$TERM chroot /mnt bash -l

配置並安裝grub,退出chroot

(chroot)# grub2-mkconfig > /boot/grub2/grub.cfg
(chroot)# grub2-install /dev/sdc
(chroot)# exit

重啟。

PS:相應地替換VG和LV名稱。

PPS:我假設 Linux Minut 使用,如果沒有,請從兩個命令grub2中刪除“2” 。grub

相關內容