Dual-Boot

在外部 USB 與 SSD 之間啟動時出現 Debian10 啟動問題

  • June 16, 2019

我已經在內部硬碟上安裝了 Debian 10,它與 UEFI 安全啟動配合得很好。

當我在外部 USB 上安裝第二個 Debian 時,它只能從那個 USB 啟動。

當我從筆記型電腦上拔下 USB 以啟動 SSD 時,出現錯誤

最小的類似 bash 的行編輯。

禁用安全啟動沒有幫助。

Disk /dev/sda: 238,5 GiB, 256060514304 bytes, 500118192 sectors
Disk model
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 

Device       Start       End   Sectors   Size Type
/dev/sda1     2048   1050623   1048576   512M EFI System
/dev/sda2  1050624   1550335    499712   244M Linux filesystem
/dev/sda3  1550336 500117503 498567168 237,8G Linux filesystem


Disk /dev/sdb: 57,3 GiB, 61505273856 bytes, 120127488 sectors
Disk model: Ultra USB 3.0   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 

Device       Start       End   Sectors  Size Type
/dev/sdb1     2048   1050623   1048576  512M EFI System
/dev/sdb2  1050624   1550335    499712  244M Linux filesystem
/dev/sdb3  1550336 120125439 118575104 56,6G Linux filesystem


Disk /dev/mapper/sdc3_crypt: 56,5 GiB, 60693676032 bytes, 118542336 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/usb--vg-root: 48,7 GiB, 52240056320 bytes, 102031360 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/usb--vg-swap_1: 7,9 GiB, 8451522560 bytes, 16506880 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

lvs 輸出

LV     VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
root   intern-vg -wi-a----- 229,80g                                                    
swap_1 intern-vg -wi-a-----  <7,87g                                                    
root   usb-vg    -wi-ao----  48,65g                                                    
swap_1 usb-vg    -wi-ao----   7,87g 

您應該注意,在撰寫本文時,Debian 10 仍處於testing狀態,因此這里和那裡可能存在粗糙的邊緣。

我的猜測是 Debian 安裝程序不知道第二次安裝將在可移動驅動器上,並覆蓋了 EFI 系統分區 (ESP) 上第一次安裝的 GRUB 副本,其中一個配置為從 USB 設備啟動。

要修復,您必須按任意順序做兩件事:

1.) 您應確保基於 USB 的安裝可自行啟動,即 USB 驅動器應包含一個 FAT32 分區,其中包含位於 的引導載入程序副本\EFI\boot\bootx64.efi。這就是使可移動 USB 在 UEFI 意義上可引導的原因。

2.) 要在內部硬碟上修復安裝的引導載入程序,您可以啟動到基於 USB 的安裝,然後掛載基於內部硬碟的安裝的分區並 chroot 進入該安裝。

您的fdisk -l輸出表明也可能正在使用 LVM。

根據您的fdisk -l輸出,這應該是所需命令的開頭。請注意,所有這些都應該以 root 身份執行,因此首先使用其中一個su -並輸入 root 密碼,或者sudo -i輸入您自己的密碼,成為 root。

# mkdir /mnt/hddsystem

# cryptsetup luksOpen /dev/sda3 sda3_crypt
<the above command will ask you the encryption passphrase of the HDD installation.
If successful, then /dev/mapper/sda3_crypt should now exist>

# vgscan
<this detects the LVM volume group within the encrypted container of the HDD installation>

# lvs
<this displays all the detected LVM logical volumes and their names>

# vgchange -ay intern-vg
# mount /dev/mapper/intern--vg-root /mnt/hddsystem

<if successful, directories like /mnt/hddsystem/dev, /mnt/hddsystem/proc, /mnt/hddsystem/sys 
should be visible and empty at this point. Other directories should be visible under /mnt/hddsystem too.>

# mount /dev/sda2 /mnt/hddsystem/boot
# mount /dev/sda1 /mnt/hddsystem/boot/efi

此時,修復 USB 系統的啟動也很容易,只需將尋找 USB 媒體以實際啟動的 GRUB 版本複製到 USB 上,然後再將其覆蓋到 HDD 上。

# mkdir /mnt/usb-esp
# mount /dev/sdb1 /mnt/usb-esp
# mkdir -p /mnt/usb-esp/EFI/boot
# cp -r /mnt/hddsystem/boot/efi/EFI/debian /mnt/usb-esp/EFI/
# cp /mnt/usb-esp/EFI/debian/grubx64.efi /mnt/usb-esp/EFI/boot/
# cp /mnt/hddsystem/boot/efi/EFI/debian/shimx64.efi /mnt/usb-esp/EFI/boot/bootx64.efi
# umount /mnt/usb-esp

回到修復硬碟安裝…

# mount -o bind /dev /mnt/hddsystem/dev
# mount -o bind /proc /mnt/hddsystem/proc
# mount -o bind /sys /mnt/hddsystem/sys
<these commands are preparations for the following chroot command, mounting all the necessary real and virtual filesystems so that the inactive HDD-based installation can be used like an active, running system.>

# chroot /mnt/hddsystem /bin/bash
<this command transitions us to the HDD-based environment; from this point onwards, for this shell session only, /mnt/hddsystem is /.>

# grub-install /dev/sda1
# update-grub 
<these two commands to fix the bootloader are what all the preparations above were for.>

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