我有一台装有 Windows 7 的旧笔记本电脑,我在其上安装了 CentOS 8 双启动。
首次重新启动时,GRUB 仅显示 Linux 条目。因此我使用了 Boot-Repair-Disk,但不知何故无法安装 GRUB,因为现在笔记本电脑直接启动到 Windows。
磁盘分区如下(如Boot-Repair-Disk所见):
Partition Boot Start Sector End Sector # of Sectors Id System
/dev/sda1 2,048 3,074,047 3,072,000 27 Hidden NTFS (Recovery Environment)
/dev/sda2 * 3,074,048 629,905,407 626,831,360 7 NTFS / exFAT / HPFS
/dev/sda3 629,905,408 632,002,559 2,097,152 83 Linux
/dev/sda4 632,002,560 976,773,119 344,770,560 5 Extended
/dev/sda5 632,004,608 975,978,495 343,973,888 8e Linux LVM
这是它们的粗略尺寸以及它们的用途:
/dev/sda1 1.5 Gb Windows recovery partition
/dev/sda2 300 Gb Windows 7 partition
/dev/sda3 1 Gb Linux /boot partition
/dev/sda4 164 Gb Extended partition containing /dev/sda5
/dev/sda5 4 Gb /swap, 130 Gb /, 30 Gb /home, all LVM and LUKS-encrypted
值得注意的是,Windows 将/dev/sda4
其视为主(非扩展)分区。
这是 Boot-Repair-Disk 输出的一部分:
Is there RAID on this computer? no
File descriptor 8 (/proc/17432/mountinfo) leaked on lvs invocation. Parent PID 19248: /bin/sh
Error: /dev/mapper/cl-00: unrecognised disk label
Error: /dev/mapper/cl-01: unrecognised disk label
Error: /dev/mapper/cl-02: unrecognised disk label
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Error: Invalid partition table - recursive partition on /dev/sr0.
boot-repair is executed in live-session (Boot-Repair-Disk 64bit 1oct2017, zesty, Ubuntu, x86_64)
CPU op-mode(s): 32-bit, 64-bit
file=/cdrom/preseed/lubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash --
ls: cannot access '/home/usr/.config': No such file or directory
Set sda as corresponding disk of mapper/cl-00
Set sda as corresponding disk of mapper/cl-01
Set sda as corresponding disk of mapper/cl-02
mount: /mnt/boot-sav/mapper/cl-00: unknown filesystem type 'crypto_LUKS'.
mount /dev/mapper/cl-00 : Error code 32
mount -r /dev/mapper/cl-00 /mnt/boot-sav/mapper/cl-00
mount: /mnt/boot-sav/mapper/cl-00: unknown filesystem type 'crypto_LUKS'.
mount -r /dev/mapper/cl-00 : Error code 32
mount: /mnt/boot-sav/mapper/cl-01: unknown filesystem type 'crypto_LUKS'.
mount /dev/mapper/cl-01 : Error code 32
mount -r /dev/mapper/cl-01 /mnt/boot-sav/mapper/cl-01
mount: /mnt/boot-sav/mapper/cl-01: unknown filesystem type 'crypto_LUKS'.
mount -r /dev/mapper/cl-01 : Error code 32
mount: /mnt/boot-sav/mapper/cl-02: unknown filesystem type 'crypto_LUKS'.
mount /dev/mapper/cl-02 : Error code 32
mount -r /dev/mapper/cl-02 /mnt/boot-sav/mapper/cl-02
mount: /mnt/boot-sav/mapper/cl-02: unknown filesystem type 'crypto_LUKS'.
mount -r /dev/mapper/cl-02 : Error code 32
=================== os-prober:
/dev/sda1:Windows 7:Windows:chain
/dev/sda2:Windows 7:Windows1:chain
=================== blkid:
/dev/sda1: LABEL="System" UUID="FC30DADA30DA9B4A" TYPE="ntfs" PARTUUID="e7d2fa64-01"
/dev/sda2: LABEL="Main disk" UUID="E6C200E1C200B837" TYPE="ntfs" PARTUUID="e7d2fa64-02"
/dev/sda3: UUID="b43f57d3-c143-47b0-ad99-a5b12a0416be" TYPE="ext4" PARTUUID="e7d2fa64-03"
/dev/sr0: UUID="2017-10-29-00-56-18-00" LABEL="Boot-Repair-Disk 64bit" TYPE="iso9660" PTUUID="6b8b4567" PTTYPE="dos"
/dev/loop0: TYPE="squashfs"
/dev/sda5: UUID="sWZAY3-8hDE-wcdv-rEsu-pTcr-9lPV-QEfxlo" TYPE="LVM2_member" PARTUUID="e7d2fa64-05"
/dev/zram0: UUID="462ef96d-8ed3-405e-92c4-043654187abd" TYPE="swap"
/dev/zram1: UUID="df6b8b51-4029-4d37-86ec-d70532265f9b" TYPE="swap"
/dev/zram2: UUID="9d842b41-46c1-4ed3-aefb-447d99a6321f" TYPE="swap"
/dev/zram3: UUID="65d9a196-c801-4e87-9283-314b665108d6" TYPE="swap"
/dev/zram4: UUID="b2cb39b0-9fe1-4485-b044-7d408527117f" TYPE="swap"
/dev/zram5: UUID="f6b1cecd-603e-40a3-8eb3-2bc1ddaca8c1" TYPE="swap"
/dev/zram6: UUID="2fc865d0-0b3b-4d11-bb8d-c272a21e5c39" TYPE="swap"
/dev/zram7: UUID="5be79bcf-4b46-4d62-81b2-952b79e0ecda" TYPE="swap"
/dev/mapper/cl-00: UUID="6eac3a8f-7854-40c7-ae94-c1d288a60698" TYPE="crypto_LUKS"
/dev/mapper/cl-01: UUID="d0e378ae-9140-4335-94e6-2d73a3cb7bd1" TYPE="crypto_LUKS"
/dev/mapper/cl-02: UUID="00e698ad-ac0b-4e27-9bc7-bdcb524ce4ba" TYPE="crypto_LUKS"
1 disks with OS, 2 OS : 0 Linux, 0 MacOS, 2 Windows, 0 unknown type OS.
在尝试重新安装 GRUB 之前真的有必要解密 LUKS LVM 分区吗?
编辑:回答评论中的问题:
输出fdisk -l /dev/sda
:
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Disk model: Seagate ST950056
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: dos
Disk identifier: 0xe7d2fa64
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 3074047 3072000 1.5G 27 Hidden NTFS WinRE
/dev/sda2 * 3074048 629905407 626831360 298.9G 7 HPFS/NTFS/exFAT
/dev/sda3 629905408 632002559 2097152 1G 83 Linux
/dev/sda4 632002560 976773119 344770560 164.4G 5 Extended
/dev/sda5 632004608 975978495 343973888 164G 8e Linux LVM
它使用来自 CentOS 8 的默认 GRUB,即 GRUB2
LVM 分区是直接从 CentOS 安装程序创建的
笔记本电脑(将近 10 年的历史)使用 BIOS,而不是 UEFI
安装程序从不询问将 GRUB 放在哪里,它是自动完成的
我无法解释为什么 Boot-Repair-Disk 报告分区表错误,也无法解释为什么 Windows 认为这
/dev/sda4
是一个主分区。fdisk 的输出报告 MBR 分区表没有错误,并且还能够读取/dev/sda5
.所以,我们所要做的就是:
重新安装 grub2
Grub2 安装在 MBR 之后(和 2048 扇区之前)的扇区。磁盘中的那个 grub2 具有
/boot/grub
硬编码的目录地址。可悲的是, 的内容/boot/grub
都在 LVM 内部并用 LUKS 编码。Grub 需要:这两个模块也驻留在
/boot/grub
. 这就产生了一个catch-22的情况,即汽车的钥匙在车内。解决方案是将一些模块写入固定磁盘扇区并在启动时加载它们。然后询问 LUKS 密码,解密
/boot/grub
目录,加载更多模块,最后加载/boot/grub/grub.cfg
以知道需要加载哪些其他模块,并向用户呈现 OS 选择列表。但是,需要写入磁盘的模块在内部
/usr/lib/grub/i386-pc/lvm.mod
(例如)。是的,grub 可以在多种架构中使用。这也在您安装的系统上进行了加密。因此,唯一的解决方案是:
/usr/lib
)chroot
切换到磁盘上的“真实”系统。grub-install
将 grub 重新放置到磁盘。这是您应该遵循的拯救 CentOS 的指南。它被简化了,但遗憾的是,解密 LVM-LUKS 加密分区的部分增加了另一个扭曲。
完成之后,您的系统通过 grub 引导到 CentOS,您需要包括(如果 grub-install 没有自动检测到 windows)在 grub.cfg 文件中添加几个条目。使用此页面中的条目
有关的: