目录:
- 术语
- 转换
- 配置(+双启动)
术语
BIOS = 基本输入/输出系统
(U)EFI = (统一)可扩展固件接口
MBR = 主引导记录
GPT = GUID分区表
UEFI / EFI / BIOS = 固件接口
MBR / GPT = 计算机如何知道(每个硬盘)有哪些分区以及如何从中引导。
UEFI / BIOS
固件接口是固件(设备内部软件)和操作系统互动的方式。它初始化硬件,然后运行操作系统,并确保操作系统驱动程序可以操作硬件。
BIOS通常用作固件接口。UEFI是一种较新的界面,具有多个功能,例如更快速、带有GUI并且能够启动网络卡并获取IP地址。UEFI替换了EFI。 (开发EFI的人看到有其他人在做类似的事情,因此加入他们,并将EFI的想法带入其中。这就成为了UEFI)。
BIOS要求引导加载程序位于磁盘的开头,但UEFI使用一个分区来存储引导程序,并可以选择使用多个引导加载程序。
MBR / GPT + GRUB
MBR是磁盘起始处的一段代码,包含了引导加载程序(用于BIOS),分区映射和唯一的磁盘标识符。
要在具有MBR的磁盘上安装GRUB,GRUB会将一个小程序放入MBR中,从磁盘的其他部分加载GRUB的其余部分。(这样做是因为MBR太小,无法容纳所有的GRUB)。所选择的空间是MBR和第一个分区之间的空间,通常是存在的。
GPT是指定分区的标准。它确实有一个“保护性”MBR,但这仅用于允许基于BIOS的计算机引导,并阻止只知道MBR的工具试图破坏GPT。它可以有
(如何处理GPT取决于它是使用BIOS(或UEFI系统以BIOS仿真模式)还是UEFI进行引导。我将重点介绍与问题相关的UEFI)。
操作系统的引导加载程序存储在称为EFI系统分区的分区中,该分区通常使用FAT32格式化。这就是GRUB安装的位置。
转换
首先...
我们正在处理分区表,所以无法保证绝对安全。这是一个有风险的操作。然而,这种方法不应该丢失数据。
其他人遇到这个问题时:
不要在苹果电脑上使用。
现在...
您需要在一张光盘(或者另一个已经安装了Linux的磁盘)上进行此操作。
处理GPT磁盘时,我们需要使用一个支持GPT的程序。'GPT fdisk'是一个很好的工具,我将使用它。它可以被称为
gptfdisk
或者
gdisk
,具体取决于发行版(Ubuntu称其为
gdisk
)。Parted(和Gparted)也支持GPT,因此可以“安全地”用于GPT磁盘。
要进行转换,您需要:
- 调整分区大小以适应GPT数据和EFI系统分区。
- 转换磁盘并添加分区。
- 将GRUB安装到EFI系统分区。
1) 调整分区大小
使用
parted
(命令行)或
gparted
(图形界面)来调整第一个和最后一个分区的大小。第一个分区应该在前面有大约200MiB的空间,而最后一个分区应该在末尾减去1MiB到2MiB的空间(任何一个都可以)。
2) 转换磁盘
运行
gdisk /dev/sdx
更改您要转换的设备是
/dev/sdx
。
它应该告诉您它将转换分区表。
GPT fdisk (gdisk) version 0.6.14
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format.
THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if
you don't want to convert your MBR partitions to GPT format!
***************************************************************
Command (? for help):
现在添加一个新的分区,将其设置为“EFI系统”类型。它应该在开头找到空闲空间(我建议使用一些低扇区号,比如34),并自动使用所有的空闲空间。
示例中使用了一个4GB的USB闪存驱动器,已经有一个分区,并按照上述方式调整大小。
Command (? for help): n
Partition number (2-128, default 2): 2
First sector (34-7831518, default = 34) or {+-}size{KMGTP}:
Information: Moved requested sector from 34 to 2048 in
order to align on 2048-sector boundaries.
Use 'l' on the experts' menu to adjust alignment
Last sector (2048-421887, default = 421887) or {+-}size{KMGTP}:
Current type is 'Linux/Windows data'
Hex code or GUID (L to show codes, Enter = 0700): L
0700 Linux/Windows data 0c01 Microsoft reserved 2700 Windows RE
4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS
7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved
8200 Linux swap 8301 Linux reserved 8e00 Linux LVM
a500 FreeBSD disklabel a501 FreeBSD boot a502 FreeBSD swap
a503 FreeBSD UFS a504 FreeBSD ZFS a505 FreeBSD Vinum/RAID
a800 Apple UFS a901 NetBSD swap a902 NetBSD FFS
a903 NetBSD LFS a904 NetBSD concatenated a905 NetBSD encrypted
a906 NetBSD RAID ab00 Apple boot af00 Apple HFS/HFS+
af01 Apple RAID af02 Apple RAID offline af03 Apple label
af04 AppleTV recovery be00 Solaris boot bf00 Solaris root
bf01 Solaris /usr & Mac Z bf02 Solaris swap bf03 Solaris backup
bf04 Solaris /var bf05 Solaris /home bf06 Solaris alternate se
bf07 Solaris Reserved 1 bf08 Solaris Reserved 2 bf09 Solaris Reserved 3
bf0a Solaris Reserved 4 bf0b Solaris Reserved 5 c001 HP-UX data
c002 HP-UX service ef00 EFI System ef01 MBR partition scheme
ef02 BIOS boot partition fd00 Linux RAID
Hex code or GUID (L to show codes, Enter = 0700): ef00
Changed type of partition to 'EFI System'
你现在应该有了EFI分区。
Command (? for help): p
Disk /dev/sdd: 7831552 sectors, 3.7 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 669247F2-37F7-4797-98F9-9CE56F7EA8C8
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 7831518
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 421888 7829503 3.5 GiB 0700 Linux/Windows data
2 2048 421887 205.0 MiB EF00 EFI System
然后退出
gdisk
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed, possibly destroying your data? (Y/N): y
OK; writing new GUID partition table (GPT).
The operation has completed successfully.
现在使用Gparted(或命令行mkfs.vfat -F 32 /dev/partition
)将分区格式化为FAT32。
3)安装GRUB
这部分的保证比之前的少,因为我自己没有尝试过。
我不确定这一步,所以我会根据RAOF的说明猜测:
要切换到grub-efi,您需要:
- 找到您的EFI分区;将其挂载到/boot/efi中。将此添加到/etc/fstab¹
- 安装grub-efi软件包
- 将BIOS启动优先级从UEFI和Legacy切换为仅UEFI(或类似选项)
您应该确定要安装哪个版本的grub-efi
ioreg -l -p IODeviceTree | grep firmware-abi
如果显示为
EFI32
,则安装
grub-efi-ia32
软件包;如果显示为
EFI64
,则安装
grub-efi-amd64
软件包。您可以使用以下命令安装软件包:
sudo apt-get install <package name>
这可能只在EFI模式下起作用。
如果不起作用,你可以尝试一下
这些逐步说明(在“在(U)EFI系统中安装GRUB2”下),一旦安装了
grub-efi
。
配置(+双启动)
如果RAOK的说明有效,你应该能够将以下行添加到
/etc/grub.d/40_custom
文件中。
menuentry "Windows 7" {
set root='(hd0,gpt1)'
chainloader /EFI/microsoft/bootmgfw.efi
}
它假定Windows被GRUB识别为
hd0
。为了使其正常工作,可能需要更改为
hd1
。
现在运行。
update-grub
更新配置文件。
参考资料和进一步阅读
我使用了几个来源。