https://wiki.archlinux.org/api.php?action=feedcontributions&user=Geekbaby&feedformat=atomArchWiki - User contributions [en]2024-03-29T07:31:21ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=REFInd_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=304017REFInd (简体中文)2014-03-11T13:05:01Z<p>Geekbaby: Created page with "Category:Boot loaders (简体中文) en:REFInd {{Lowercase title}} rEFInd是rEFIt启动管理器(用于Intel Macs)的一个分支,由gdisk的作者Rod Smith维..."</p>
<hr />
<div>[[Category:Boot loaders (简体中文)]]<br />
[[en:REFInd]]<br />
{{Lowercase title}}<br />
rEFInd是rEFIt启动管理器(用于Intel Macs)的一个分支,由gdisk的作者Rod Smith维护。rEFInd修复了rEFIt在非Mac电脑上UEFI启动的很多问题,同时支持[[EFISTUB]]方式启动内核,也包含了一些专属的特性。<br />
<br />
== 分区准备及内核的储存位置 ==<br />
<br />
rEFInd is a UEFI boot manager that was written to handle EFI boot, and make booting Windows, Linux and Mac OS a relatively pain free process, particularly as the linux kernel is now built with its own EFI stub boot loader.<br />
<br />
It is convenient to set up the arch linux system so that the kernel and initial ramdisk files are in a journalled filesystem, so that repairs are possible in the event of errors in the<br />
filesystem, and keep only a minimal set of necessary files on the EFI, which is required to be formatted as VFAT. <br />
<br />
It is also desirable to have the system rebootable immediately after a kernel update, without further preparation or moving the kernel files from the location that they are created by pacman.<br />
<br />
The assumption here is that the EFI will be mounted after the install as /boot/efi<br />
<br />
If the root partition is mounted as / and a directory called /boot is created, then a convenient way to mount the EFI partition is to mount it as /boot/efi. Then the normal install location for the kernel and initial ramdisk is in /boot/ and the (VFAT) EFI is mounted at /boot/efi/. Then the rEFInd binary and associated directories and files can be placed in a newly created directory at /boot/efi/EFI/refind/<br />
<br />
== Boot EFISTUB using rEFInd ==<br />
{{Tip|If you're new to [[EFISTUB]] and/or rEFInd, you need to read [http://www.rodsbooks.com/refind/linux.html The rEFInd Boot Manager: Methods of Booting Linux] before going any further. This section illustrates only one possible use-case for a pure Arch linux system which is not suitable for all configurations, and includes a section with one use-case for dual booting Archlinux with Windows 8.1.}}<br />
<br />
{{Note|{{pkg|refind-efi}} includes a install script from upstream at {{ic|/usr/bin/refind-install}} which does the job of setting-up of rEFInd similar to the steps below.}}<br />
<br />
{{Note|For 32-bit aka IA32 EFI, replace '''x64''' with '''ia32''' (case-sensitive) in the commands below.}}<br />
<br />
* Mount efivarfs<br />
<br />
# mount -t efivarfs efivarfs /sys/firmware/efi/efivars # ignore if already mounted<br />
<br />
* Install the {{Pkg|refind-efi}} package.<br />
<br />
* Copy the following files from their source directory to their destination<br />
<br />
# cp /usr/share/refind/refind_x64.efi /boot/efi/EFI/refind/refind_x64.efi<br />
# cp /usr/share/refind/refind.conf-sample /boot/efi/EFI/refind/refind.conf<br />
# cp -r /usr/share/refind/icons /boot/efi/EFI/refind/<br />
# cp -r /usr/share/refind/fonts /boot/efi/EFI/refind/<br />
# cp -r /usr/share/refind/drivers_x64 /boot/efi/EFI/refind/<br />
<br />
* Edit rEFInd's config file at {{ic|/boot/efi/EFI/refind/refind.conf}}. The file is well commented and self explanatory. rEFInd should automatically find kernel files in /boot, but it is also possible to add a menu entry for Arch Linux. Set the default boot item to the Archlinux kernel by adding the line:<br />
<br />
default_selection vmlinuz<br />
<br />
A menu entry can be added to refind.conf such as<br />
<br />
{{hc|refind.conf|<nowiki><br />
menuentry "Arch Linux" {<br />
icon EFI/refind/icons/os_linux.icns<br />
volume "/"<br />
loader /boot/vmlinuz-linux<br />
initrd /boot/initramfs-linux.img<br />
options "root=PARTUUID=3518bb68-d01e-45c9-b973-0b5d918aae96 rw rootfstype=ext4"<br />
}<br />
</nowiki>}}<br />
<br />
but this may not be necessary unless standard options need to be changed. Note that the "volume" line contains the label of the volume where the root partition is. For alphameric characters only it is not necessary to put the name in quotes, but if you use special characters then the kernel will not boot unless the name is in quotes. Also the partition can be referenced using the PARTUUID or the UUID provided the appropriate string is used as verified from the output of the blkid command. If the root partition is not ext4 then the rootfstype will be as needed for the partition type, but should be detected automatically without this parameter.<br />
<br />
Note that if you choose to mount your ESP as a different name to /boot/efi then replace these paths as appropriate as in the lines above.<br />
<br />
{{Note|Modify the loader and initrd paths if you did not place them in your ESP's root. Replace the string after PARTUUID with your root's PARTUUID. Please note in the example above that PARTUUID/PARTLABEL identifies a GPT partition, and differs from the UUID/LABEL, which identifies a filesystem. Using the PARTUUID/PARTLABEL is advantageous because it is invariant if you reformat the partition with another filesystem. It's also useful if you don't have a filesystem on the partition (or use LUKS, which doesn't support LABELs).}}<br />
<br />
To find the PARTUUID (or UUID) for the root partition use:<br />
<br />
# blkid<br />
<br />
and<br />
<br />
# lsblk -f<br />
<br />
to get the partition information matched to the correct root partition.<br />
<br />
* If the kernel and initramfs are located at /boot as default, you can create a {{ic|refind_linux.conf}} file inside the directory where the kernel and initramfs files are located. Or you can copy the sample file to the same directory that the kernel and initramfs are located using:<br />
<br />
# cp /usr/share/refind/refind_linux.conf-sample /boot/refind_linux.conf<br />
<br />
{{hc|refind_linux.conf|<nowiki><br />
"Boot with defaults" "root=PARTUUID=XXXXXXXX rootfstype=XXXX ro"<br />
"Boot to terminal" "root=PARTUUID=XXXXXXXX rootfstype=XXXX ro systemd.unit=multi-user.target"</nowiki>}}<br />
<br />
where the PARTUUID from the blkid command is used, and the rootfstype is commonly ext4.<br />
<br />
This file tells rEFInd where the root partition is located for the system boot, so the PARTUUID is that for the root partition.<br />
<br />
The drivers that were copied to the refind directory in the ESP include an ext4 driver, and allow the rEFInd binary to read the kernel and initramfs file in the ext4 /boot directory.<br />
<br />
{{Tip|Each line of {{ic|refind_linux.conf}} is displayed as a submenu by rEFInd. Access the submenu with "+" or "insert" or "F2" keys.}}<br />
<br />
* Create a boot entry in the UEFI NVRAM in the motherboard using efibootmgr<br />
<br />
# efibootmgr -c -d /dev/sdX -p Y -l /EFI/refind/refind_x64.efi -L "rEFInd"<br />
<br />
where sdX is drive containing the EFI partition, and Y is the partition number for the EFI on that drive.<br />
<br />
The entries can be checked by just using the command <br />
<br />
# efibootmgr<br />
<br />
on its own to verify that there is now a refind entry, and the boot order should show that this is the first entry in the list.<br />
<br />
For a few system types if the efibootmgr command does not create NVRAM entries correctly, then an alternative is to use bcfg from within a UEFI shell version 2, to write and manage NVRAM entries. Information about this is available elsewhere in the wiki.<br />
<br />
{{Note|As of {{Pkg|refind-efi}} 0.2.7, refind can auto-detect kernels in {{ic|/boot}}, if there are UEFI drivers for the filesystem used by /boot partition (or / partition if no separate /boot is used) in the ESP, and are loaded by rEFInd. This is enabled in the default configuration in {{ic|refind.conf}} (you may need to include the PATH to the drivers folders in the ESP). See [http://www.rodsbooks.com/refind/drivers.html] for more info.}}<br />
<br />
Once the system is rebooted when the install is complete the system should then boot to the graphical rEFInd screen after the POST is complete, and by default a 20 second timeout<br />
will run after which the system should boot by default to Archlinux (The timeout period can be changed by editing refind.conf). Once the system has booted then the root user can login and continue to configure the newly installed system.<br />
<br />
During the 20 second timeout period the rEFInd boot manager can be interrupted to select different icons that can be booted, and it is also possible to change the boot kernel parameters<br />
in a similar way to what many users have been familiar with in the past using grub.<br />
<br />
It is also possible to get a screenshot of the graphical rEFInd screen by hitting F10 and a bmp image file will be written to the top level directory of the EFI.<br />
<br />
When the Archlinux kernel is updated via pacman then no further action is needed other than to reboot if the setup described above is used. For customised setups where the kernel is not placed in the /boot directory then the kernel and initramfs files may need to be moved to the directory where they will be booted before the new kernel will be active after reboot.<br />
<br />
== A dual boot setup for Archlinux and Windows 8.1 using rEFInd ==<br />
<br />
A second use-case is where an arch install is to be added to a pre-existing Windows 8.1 setup as a dual boot system, where booting to both operating systems is desired as well as any factory Recovery partitions.<br />
<br />
Here only the differences between the pure Archlinux setup above and the dual boot system are highlighted.<br />
<br />
Normally Windows 8 or 8.1 boots under Secure Boot. Although in principle Secure Boot could be setup for Archlinux it is not straighforward, and it is recommended to switch off Secure Boot in the BIOS if the machine is to be dual booted with Archlinux. Check that the machine still boots correctly with Secure Boot turned off.<br />
<br />
It is also necessary to switch off Fastboot from within Windows 8.1 before attempting to install Archlinux in a dual boot system. Fastboot is a type of hybrid suspend with part of the<br />
system stored during shutdown. If Fastboot is not turned off then corruption is likely if Windows is booted again after the system has booted Archlinux.<br />
<br />
The changes that are therefore recommended for a pre-existing Windows 8 or 8.1 system on which Archlinux is going to be installed are as follows:<br />
<br />
1) Within Windows 8.1 switch off Fastboot and check that Windows restarts without any problem.<br />
2) Switch off Secure Boot from the BIOS settings, and check that Windows restarts correctly.<br />
<br />
In order to create space on the disk for linux partitions it is recommended that, with Windows 8.1 running, go to the Windows Disk Management facility and shrink the C: drive to make<br />
space for new partitions in which Archlinux will be installed.<br />
<br />
Note here that if you change the partitions using an externally booted partition editor such as gparted it is possible that Windows, or any Recovery boot partitions may not boot once the partitions, or particularly the partition numbers, have been changed. <br />
<br />
It is straightforward to create new partitions using the Archlinux install iso during the install process using the gdisk command.<br />
<br />
It is recommended not to create additional EFI partitions, and to utilise the existing EFI partition that the pre-existing Windows system uses. Hence it is only necessary to create a root partition ( / ), and possibly an additional partition for /home or /opt ( often as ext4, but any suitable linux partition type can be used by preference). A linux swap partition may also be desirable and in this use case it is no different to a standard Archlinux install. For an existing UEFI system the main hard drive will have a GPT partition table, and from the Archlinux install iso, once booted, the gdisk facility is simple to use to create the additional linux partitions.<br />
<br />
Once the partitions have been created then a filesystem must be created in each new partition except swap.<br />
<br />
This can be done using for example mkfs -t ext4 /dev/sdXY as necessary for each new linux partition.<br />
<br />
The only difference between a dual boot system and the pure linux install described in the first section of this page, is that the rEFInd files are placed in a new directory that is <br />
created in the pre-existing EFI, leaving the existing directories and files for Windows and recovery binary files untouched.<br />
<br />
Hence create a new directory within the EFI:<br />
<br />
/boot/efi/EFI/refind<br />
<br />
Then install rEFInd as in the pure linux case above, and copy the same set of files and directories as above into this directory.<br />
<br />
The remainder of the install is the same as for a pure Archlinux install.<br />
<br />
Once the remainder of the Archlinux install is complete, then booting the new system should result in the rEFInd screen with Archlinux as the default entry visible, but with additional icons visible for booting Windows 8.1 as well as Recovery to Factory Settings if this was provided by the original manufacturer. Note that if the Recovery boot is initiated it will overwrite the linux partitions, and so would normally only be used in the event that the Windows 8.1 system was unrecoverable, in which case Archlinux would then need to be installed again from scratch.<br />
<br />
== Upgrading rEFInd ==<br />
<br />
When a new version of the refind package is installed as an update via pacman, then all that is necessary is to copy the refind directories and files, except the refind.conf and refind_linux.conf as in the pure Archlinux install section above.<br />
<br />
To automatically update rEFInd to the latest version, you could run refind-install (in cronjob) as alternative to the systemd script below.<br />
The command will be executed as follow:<br />
{{hc|/usr/bin/refind-install|<nowiki><br />
Installing rEFInd on Linux....<br />
ESP was found at /boot/efi using vfat<br />
Found rEFInd installation in /boot/efi/EFI/refind; upgrading it.<br />
Installing driver for ext4 (ext4_x64.efi)<br />
Copied rEFInd binary files<br />
<br />
Notice: Backed up existing icons directory as icons-backup.<br />
Existing refind.conf file found; copying sample file as refind.conf-sample<br />
to avoid overwriting your customizations.<br />
<br />
rEFInd has been set as the default boot manager.<br />
Existing //boot/refind_linux.conf found; not overwriting.<br />
<br />
Installation has completed successfully.<br />
</nowiki>}}<br />
<br />
== Systemd Automation (Upgrading) ==<br />
<br />
To automate the process of copying refind files and updating the nvram (if needed) use the following script.<br />
<br />
{{Note|If you want to change the directory that refind is installed in the UEFISYS partition, just change the value of $refind_dir in the script}}<br />
{{hc|/usr/lib/systemd/scripts/refind_name_patchv2|<nowiki><br />
#!/usr/bin/env bash<br />
## COPYRIGHT 2013 : MARK E. LEE (BLUERIDER) : mlee24@binghamton.edu; mark@markelee.com<br />
<br />
## LOG<br />
## 1/17/2013 : Version 2 of refind_name_patch is released<br />
## : Supports long subdirectory location for refind<br />
## : Updates nvram when needed<br />
## : 10% speed boost<br />
## 7/15/2013 : Changed arch to match 32-bit (ia32) and 64-bit (x64) naming scheme<br />
## : Changed directory copying in update-efi-dir to copy tools and drivers directories explicitly<br />
## : Changed efibootmgr writing code to be more concise and added (-w) to write the entry as per dusktreader's excellent guide : https://docs.google.com/document/d/1pvgm3BprpXoadsQi38FxqMOCUZhcSqFhZ26FZBkmn9I/edit<br />
## : Function to check if NVRAM boot entry was already listed was fixed to use awk and an if then clause<br />
## : ref_bin_escape was modified from : ref_bin_escape=${ref_bin//\//\\\\} to remove extra backslashes (error does not show up when using cmdline)<br />
## 7/29/2013 : Changed location of tools,drivers, and binary directory to match capricious upstream move to /usr/share/refind<br />
<br />
function main () { ## main insertion function<br />
declare -r refind_dir="/boot/efi/EFI/refind"; ## set the refind directory<br />
arch=$(uname -m | awk -F'_' '{if ($1 == "x86") {print "x"$2} else if ($1 == "i686") {print "ia32"}}') && ## get bit architecture<br />
update-efi-dir; ## updates or creates the refind directory<br />
update-efi-nvram; ## updates nvram if needed<br />
}<br />
<br />
function update-efi-dir () { ## setup the refind directory<br />
if [ ! -d $refind_dir ]; then ## check if refind directory exists<br />
echo "Couldn't find $refind_dir";<br />
mkdir $refind_dir && ## make the refind directory if needed<br />
echo "Made $refind_dir";<br />
fi;<br />
if [ "$arch" ]; then ## check if anything was stored in $arch<br />
cp -r /usr/share/refind/{refind_$arch.efi,keys,images,icons,fonts,docs,{tools,drivers}_$arch} $refind_dir/ && ## update the bins and dirs<br />
echo "Updated binaries and directory files for refind at $refind_dir";<br />
else<br />
echo "Failed to detect an x86 architecture";<br />
exit;<br />
fi;<br />
}<br />
<br />
function update-efi-nvram () { ## update the nvram with efibootmgr<br />
declare -r ref_bin=${refind_dir/\/boot\/efi}/refind_$arch.efi; ## get path of refind binary (without /boot/efi)<br />
declare -r ref_bin_escape=${ref_bin//\//\\}; ## insert escape characters into $ref_bin<br />
[ "$(efibootmgr -v | awk "/${ref_bin_escape//\\/\\\\}/")" ] && ( ## check if boot entry is in nvram \<br />
echo "Found boot entry, no need to update nvram";<br />
) || ( ## if boot entry is not in nvram; add it<br />
declare -r esp=$(mount -l | awk '/ESP/ {print $1}') && ## get ESP partition<br />
efibootmgr -cgw -d ${esp:0:8} -p ${esp:8} -L "rEFInd" -l $ref_bin_escape && ## update nvram<br />
echo "<br />
Updated nvram with entry rEFInd to boot $ref_bin<br />
Did not copy configuration files, please move refind.conf to $refind_dir/";<br />
)<br />
}<br />
main; ## run the main insertion function<br />
</nowiki>}}<br />
<br />
{{hc|/usr/lib/systemd/system/refind_update.path|<nowiki><br />
[Unit]<br />
Description=Update rEFInd bootloader files<br />
<br />
[Path]<br />
PathChanged=/usr/share/refind/refind_<arch>.efi<br />
Unit=refind_update.service<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki>}}<br />
<br />
{{hc|/usr/lib/systemd/system/refind_update.service|<nowiki><br />
[Unit]<br />
Description=Update rEFInd directories, binaries, and nvram<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/bin/bash /usr/lib/systemd/scripts/refind_name_patchv2<br />
RemainAfterExit=no<br />
</nowiki>}}<br />
<br />
Enable the systemd path unit by running:<br />
# systemctl enable refind_update.path<br />
<br />
== Apple Macs ==<br />
<br />
In case of Apple Macs, try {{AUR|mactel-boot}} for an experimental "bless" utility for Linux. If that does not work, use "bless" from within OSX to set rEFInd as default bootloader. Assuming UEFISYS partition is mounted at {{ic|/mnt/efi}} within OSX, do<br />
<br />
$ sudo bless --setBoot --folder /mnt/efi/EFI/refind --file /mnt/efi/EFI/refind/refind_x64.efi<br />
<br />
== VirtualBox ==<br />
<br />
In case of VirtualBox, see [[VirtualBox#Using_Arch_under_Virtualbox_EFI_mode]].</div>Geekbabyhttps://wiki.archlinux.org/index.php?title=REFInd&diff=304016REFInd2014-03-11T12:49:17Z<p>Geekbaby: </p>
<hr />
<div>[[Category:Boot loaders]]<br />
[[zh-CN:REFInd]]<br />
{{Lowercase title}}<br />
rEFInd is a fork of rEFIt Boot Manager (used in Intel Macs) by Rod Smith (author of gdisk). rEFInd fixes many issues in rEFIt with respect to non-Mac UEFI booting and also has support for booting [[EFISTUB]] kernels and contains some features specific to them.<br />
<br />
== Planning the partitions and kernel location ==<br />
<br />
rEFInd is a UEFI boot manager that was written to handle EFI boot, and make booting Windows, Linux and Mac OS a relatively pain free process, particularly as the linux kernel is now built with its own EFI stub boot loader.<br />
<br />
It is convenient to set up the arch linux system so that the kernel and initial ramdisk files are in a journalled filesystem, so that repairs are possible in the event of errors in the<br />
filesystem, and keep only a minimal set of necessary files on the EFI, which is required to be formatted as VFAT. <br />
<br />
It is also desirable to have the system rebootable immediately after a kernel update, without further preparation or moving the kernel files from the location that they are created by pacman.<br />
<br />
The assumption here is that the EFI will be mounted after the install as /boot/efi<br />
<br />
If the root partition is mounted as / and a directory called /boot is created, then a convenient way to mount the EFI partition is to mount it as /boot/efi. Then the normal install location for the kernel and initial ramdisk is in /boot/ and the (VFAT) EFI is mounted at /boot/efi/. Then the rEFInd binary and associated directories and files can be placed in a newly created directory at /boot/efi/EFI/refind/<br />
<br />
== Boot EFISTUB using rEFInd ==<br />
{{Tip|If you're new to [[EFISTUB]] and/or rEFInd, you need to read [http://www.rodsbooks.com/refind/linux.html The rEFInd Boot Manager: Methods of Booting Linux] before going any further. This section illustrates only one possible use-case for a pure Arch linux system which is not suitable for all configurations, and includes a section with one use-case for dual booting Archlinux with Windows 8.1.}}<br />
<br />
{{Note|{{pkg|refind-efi}} includes a install script from upstream at {{ic|/usr/bin/refind-install}} which does the job of setting-up of rEFInd similar to the steps below.}}<br />
<br />
{{Note|For 32-bit aka IA32 EFI, replace '''x64''' with '''ia32''' (case-sensitive) in the commands below.}}<br />
<br />
* Mount efivarfs<br />
<br />
# mount -t efivarfs efivarfs /sys/firmware/efi/efivars # ignore if already mounted<br />
<br />
* Install the {{Pkg|refind-efi}} package.<br />
<br />
* Copy the following files from their source directory to their destination<br />
<br />
# cp /usr/share/refind/refind_x64.efi /boot/efi/EFI/refind/refind_x64.efi<br />
# cp /usr/share/refind/refind.conf-sample /boot/efi/EFI/refind/refind.conf<br />
# cp -r /usr/share/refind/icons /boot/efi/EFI/refind/<br />
# cp -r /usr/share/refind/fonts /boot/efi/EFI/refind/<br />
# cp -r /usr/share/refind/drivers_x64 /boot/efi/EFI/refind/<br />
<br />
* Edit rEFInd's config file at {{ic|/boot/efi/EFI/refind/refind.conf}}. The file is well commented and self explanatory. rEFInd should automatically find kernel files in /boot, but it is also possible to add a menu entry for Arch Linux. Set the default boot item to the Archlinux kernel by adding the line:<br />
<br />
default_selection vmlinuz<br />
<br />
A menu entry can be added to refind.conf such as<br />
<br />
{{hc|refind.conf|<nowiki><br />
menuentry "Arch Linux" {<br />
icon EFI/refind/icons/os_linux.icns<br />
volume "/"<br />
loader /boot/vmlinuz-linux<br />
initrd /boot/initramfs-linux.img<br />
options "root=PARTUUID=3518bb68-d01e-45c9-b973-0b5d918aae96 rw rootfstype=ext4"<br />
}<br />
</nowiki>}}<br />
<br />
but this may not be necessary unless standard options need to be changed. Note that the "volume" line contains the label of the volume where the root partition is. For alphameric characters only it is not necessary to put the name in quotes, but if you use special characters then the kernel will not boot unless the name is in quotes. Also the partition can be referenced using the PARTUUID or the UUID provided the appropriate string is used as verified from the output of the blkid command. If the root partition is not ext4 then the rootfstype will be as needed for the partition type, but should be detected automatically without this parameter.<br />
<br />
Note that if you choose to mount your ESP as a different name to /boot/efi then replace these paths as appropriate as in the lines above.<br />
<br />
{{Note|Modify the loader and initrd paths if you did not place them in your ESP's root. Replace the string after PARTUUID with your root's PARTUUID. Please note in the example above that PARTUUID/PARTLABEL identifies a GPT partition, and differs from the UUID/LABEL, which identifies a filesystem. Using the PARTUUID/PARTLABEL is advantageous because it is invariant if you reformat the partition with another filesystem. It's also useful if you don't have a filesystem on the partition (or use LUKS, which doesn't support LABELs).}}<br />
<br />
To find the PARTUUID (or UUID) for the root partition use:<br />
<br />
# blkid<br />
<br />
and<br />
<br />
# lsblk -f<br />
<br />
to get the partition information matched to the correct root partition.<br />
<br />
* If the kernel and initramfs are located at /boot as default, you can create a {{ic|refind_linux.conf}} file inside the directory where the kernel and initramfs files are located. Or you can copy the sample file to the same directory that the kernel and initramfs are located using:<br />
<br />
# cp /usr/share/refind/refind_linux.conf-sample /boot/refind_linux.conf<br />
<br />
{{hc|refind_linux.conf|<nowiki><br />
"Boot with defaults" "root=PARTUUID=XXXXXXXX rootfstype=XXXX ro"<br />
"Boot to terminal" "root=PARTUUID=XXXXXXXX rootfstype=XXXX ro systemd.unit=multi-user.target"</nowiki>}}<br />
<br />
where the PARTUUID from the blkid command is used, and the rootfstype is commonly ext4.<br />
<br />
This file tells rEFInd where the root partition is located for the system boot, so the PARTUUID is that for the root partition.<br />
<br />
The drivers that were copied to the refind directory in the ESP include an ext4 driver, and allow the rEFInd binary to read the kernel and initramfs file in the ext4 /boot directory.<br />
<br />
{{Tip|Each line of {{ic|refind_linux.conf}} is displayed as a submenu by rEFInd. Access the submenu with "+" or "insert" or "F2" keys.}}<br />
<br />
* Create a boot entry in the UEFI NVRAM in the motherboard using efibootmgr<br />
<br />
# efibootmgr -c -d /dev/sdX -p Y -l /EFI/refind/refind_x64.efi -L "rEFInd"<br />
<br />
where sdX is drive containing the EFI partition, and Y is the partition number for the EFI on that drive.<br />
<br />
The entries can be checked by just using the command <br />
<br />
# efibootmgr<br />
<br />
on its own to verify that there is now a refind entry, and the boot order should show that this is the first entry in the list.<br />
<br />
For a few system types if the efibootmgr command does not create NVRAM entries correctly, then an alternative is to use bcfg from within a UEFI shell version 2, to write and manage NVRAM entries. Information about this is available elsewhere in the wiki.<br />
<br />
{{Note|As of {{Pkg|refind-efi}} 0.2.7, refind can auto-detect kernels in {{ic|/boot}}, if there are UEFI drivers for the filesystem used by /boot partition (or / partition if no separate /boot is used) in the ESP, and are loaded by rEFInd. This is enabled in the default configuration in {{ic|refind.conf}} (you may need to include the PATH to the drivers folders in the ESP). See [http://www.rodsbooks.com/refind/drivers.html] for more info.}}<br />
<br />
Once the system is rebooted when the install is complete the system should then boot to the graphical rEFInd screen after the POST is complete, and by default a 20 second timeout<br />
will run after which the system should boot by default to Archlinux (The timeout period can be changed by editing refind.conf). Once the system has booted then the root user can login and continue to configure the newly installed system.<br />
<br />
During the 20 second timeout period the rEFInd boot manager can be interrupted to select different icons that can be booted, and it is also possible to change the boot kernel parameters<br />
in a similar way to what many users have been familiar with in the past using grub.<br />
<br />
It is also possible to get a screenshot of the graphical rEFInd screen by hitting F10 and a bmp image file will be written to the top level directory of the EFI.<br />
<br />
When the Archlinux kernel is updated via pacman then no further action is needed other than to reboot if the setup described above is used. For customised setups where the kernel is not placed in the /boot directory then the kernel and initramfs files may need to be moved to the directory where they will be booted before the new kernel will be active after reboot.<br />
<br />
== A dual boot setup for Archlinux and Windows 8.1 using rEFInd ==<br />
<br />
A second use-case is where an arch install is to be added to a pre-existing Windows 8.1 setup as a dual boot system, where booting to both operating systems is desired as well as any factory Recovery partitions.<br />
<br />
Here only the differences between the pure Archlinux setup above and the dual boot system are highlighted.<br />
<br />
Normally Windows 8 or 8.1 boots under Secure Boot. Although in principle Secure Boot could be setup for Archlinux it is not straighforward, and it is recommended to switch off Secure Boot in the BIOS if the machine is to be dual booted with Archlinux. Check that the machine still boots correctly with Secure Boot turned off.<br />
<br />
It is also necessary to switch off Fastboot from within Windows 8.1 before attempting to install Archlinux in a dual boot system. Fastboot is a type of hybrid suspend with part of the<br />
system stored during shutdown. If Fastboot is not turned off then corruption is likely if Windows is booted again after the system has booted Archlinux.<br />
<br />
The changes that are therefore recommended for a pre-existing Windows 8 or 8.1 system on which Archlinux is going to be installed are as follows:<br />
<br />
1) Within Windows 8.1 switch off Fastboot and check that Windows restarts without any problem.<br />
2) Switch off Secure Boot from the BIOS settings, and check that Windows restarts correctly.<br />
<br />
In order to create space on the disk for linux partitions it is recommended that, with Windows 8.1 running, go to the Windows Disk Management facility and shrink the C: drive to make<br />
space for new partitions in which Archlinux will be installed.<br />
<br />
Note here that if you change the partitions using an externally booted partition editor such as gparted it is possible that Windows, or any Recovery boot partitions may not boot once the partitions, or particularly the partition numbers, have been changed. <br />
<br />
It is straightforward to create new partitions using the Archlinux install iso during the install process using the gdisk command.<br />
<br />
It is recommended not to create additional EFI partitions, and to utilise the existing EFI partition that the pre-existing Windows system uses. Hence it is only necessary to create a root partition ( / ), and possibly an additional partition for /home or /opt ( often as ext4, but any suitable linux partition type can be used by preference). A linux swap partition may also be desirable and in this use case it is no different to a standard Archlinux install. For an existing UEFI system the main hard drive will have a GPT partition table, and from the Archlinux install iso, once booted, the gdisk facility is simple to use to create the additional linux partitions.<br />
<br />
Once the partitions have been created then a filesystem must be created in each new partition except swap.<br />
<br />
This can be done using for example mkfs -t ext4 /dev/sdXY as necessary for each new linux partition.<br />
<br />
The only difference between a dual boot system and the pure linux install described in the first section of this page, is that the rEFInd files are placed in a new directory that is <br />
created in the pre-existing EFI, leaving the existing directories and files for Windows and recovery binary files untouched.<br />
<br />
Hence create a new directory within the EFI:<br />
<br />
/boot/efi/EFI/refind<br />
<br />
Then install rEFInd as in the pure linux case above, and copy the same set of files and directories as above into this directory.<br />
<br />
The remainder of the install is the same as for a pure Archlinux install.<br />
<br />
Once the remainder of the Archlinux install is complete, then booting the new system should result in the rEFInd screen with Archlinux as the default entry visible, but with additional icons visible for booting Windows 8.1 as well as Recovery to Factory Settings if this was provided by the original manufacturer. Note that if the Recovery boot is initiated it will overwrite the linux partitions, and so would normally only be used in the event that the Windows 8.1 system was unrecoverable, in which case Archlinux would then need to be installed again from scratch.<br />
<br />
== Upgrading rEFInd ==<br />
<br />
When a new version of the refind package is installed as an update via pacman, then all that is necessary is to copy the refind directories and files, except the refind.conf and refind_linux.conf as in the pure Archlinux install section above.<br />
<br />
To automatically update rEFInd to the latest version, you could run refind-install (in cronjob) as alternative to the systemd script below.<br />
The command will be executed as follow:<br />
{{hc|/usr/bin/refind-install|<nowiki><br />
Installing rEFInd on Linux....<br />
ESP was found at /boot/efi using vfat<br />
Found rEFInd installation in /boot/efi/EFI/refind; upgrading it.<br />
Installing driver for ext4 (ext4_x64.efi)<br />
Copied rEFInd binary files<br />
<br />
Notice: Backed up existing icons directory as icons-backup.<br />
Existing refind.conf file found; copying sample file as refind.conf-sample<br />
to avoid overwriting your customizations.<br />
<br />
rEFInd has been set as the default boot manager.<br />
Existing //boot/refind_linux.conf found; not overwriting.<br />
<br />
Installation has completed successfully.<br />
</nowiki>}}<br />
<br />
== Systemd Automation (Upgrading) ==<br />
<br />
To automate the process of copying refind files and updating the nvram (if needed) use the following script.<br />
<br />
{{Note|If you want to change the directory that refind is installed in the UEFISYS partition, just change the value of $refind_dir in the script}}<br />
{{hc|/usr/lib/systemd/scripts/refind_name_patchv2|<nowiki><br />
#!/usr/bin/env bash<br />
## COPYRIGHT 2013 : MARK E. LEE (BLUERIDER) : mlee24@binghamton.edu; mark@markelee.com<br />
<br />
## LOG<br />
## 1/17/2013 : Version 2 of refind_name_patch is released<br />
## : Supports long subdirectory location for refind<br />
## : Updates nvram when needed<br />
## : 10% speed boost<br />
## 7/15/2013 : Changed arch to match 32-bit (ia32) and 64-bit (x64) naming scheme<br />
## : Changed directory copying in update-efi-dir to copy tools and drivers directories explicitly<br />
## : Changed efibootmgr writing code to be more concise and added (-w) to write the entry as per dusktreader's excellent guide : https://docs.google.com/document/d/1pvgm3BprpXoadsQi38FxqMOCUZhcSqFhZ26FZBkmn9I/edit<br />
## : Function to check if NVRAM boot entry was already listed was fixed to use awk and an if then clause<br />
## : ref_bin_escape was modified from : ref_bin_escape=${ref_bin//\//\\\\} to remove extra backslashes (error does not show up when using cmdline)<br />
## 7/29/2013 : Changed location of tools,drivers, and binary directory to match capricious upstream move to /usr/share/refind<br />
<br />
function main () { ## main insertion function<br />
declare -r refind_dir="/boot/efi/EFI/refind"; ## set the refind directory<br />
arch=$(uname -m | awk -F'_' '{if ($1 == "x86") {print "x"$2} else if ($1 == "i686") {print "ia32"}}') && ## get bit architecture<br />
update-efi-dir; ## updates or creates the refind directory<br />
update-efi-nvram; ## updates nvram if needed<br />
}<br />
<br />
function update-efi-dir () { ## setup the refind directory<br />
if [ ! -d $refind_dir ]; then ## check if refind directory exists<br />
echo "Couldn't find $refind_dir";<br />
mkdir $refind_dir && ## make the refind directory if needed<br />
echo "Made $refind_dir";<br />
fi;<br />
if [ "$arch" ]; then ## check if anything was stored in $arch<br />
cp -r /usr/share/refind/{refind_$arch.efi,keys,images,icons,fonts,docs,{tools,drivers}_$arch} $refind_dir/ && ## update the bins and dirs<br />
echo "Updated binaries and directory files for refind at $refind_dir";<br />
else<br />
echo "Failed to detect an x86 architecture";<br />
exit;<br />
fi;<br />
}<br />
<br />
function update-efi-nvram () { ## update the nvram with efibootmgr<br />
declare -r ref_bin=${refind_dir/\/boot\/efi}/refind_$arch.efi; ## get path of refind binary (without /boot/efi)<br />
declare -r ref_bin_escape=${ref_bin//\//\\}; ## insert escape characters into $ref_bin<br />
[ "$(efibootmgr -v | awk "/${ref_bin_escape//\\/\\\\}/")" ] && ( ## check if boot entry is in nvram \<br />
echo "Found boot entry, no need to update nvram";<br />
) || ( ## if boot entry is not in nvram; add it<br />
declare -r esp=$(mount -l | awk '/ESP/ {print $1}') && ## get ESP partition<br />
efibootmgr -cgw -d ${esp:0:8} -p ${esp:8} -L "rEFInd" -l $ref_bin_escape && ## update nvram<br />
echo "<br />
Updated nvram with entry rEFInd to boot $ref_bin<br />
Did not copy configuration files, please move refind.conf to $refind_dir/";<br />
)<br />
}<br />
main; ## run the main insertion function<br />
</nowiki>}}<br />
<br />
{{hc|/usr/lib/systemd/system/refind_update.path|<nowiki><br />
[Unit]<br />
Description=Update rEFInd bootloader files<br />
<br />
[Path]<br />
PathChanged=/usr/share/refind/refind_<arch>.efi<br />
Unit=refind_update.service<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki>}}<br />
<br />
{{hc|/usr/lib/systemd/system/refind_update.service|<nowiki><br />
[Unit]<br />
Description=Update rEFInd directories, binaries, and nvram<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/bin/bash /usr/lib/systemd/scripts/refind_name_patchv2<br />
RemainAfterExit=no<br />
</nowiki>}}<br />
<br />
Enable the systemd path unit by running:<br />
# systemctl enable refind_update.path<br />
<br />
== Apple Macs ==<br />
<br />
In case of Apple Macs, try {{AUR|mactel-boot}} for an experimental "bless" utility for Linux. If that does not work, use "bless" from within OSX to set rEFInd as default bootloader. Assuming UEFISYS partition is mounted at {{ic|/mnt/efi}} within OSX, do<br />
<br />
$ sudo bless --setBoot --folder /mnt/efi/EFI/refind --file /mnt/efi/EFI/refind/refind_x64.efi<br />
<br />
== VirtualBox ==<br />
<br />
In case of VirtualBox, see [[VirtualBox#Using_Arch_under_Virtualbox_EFI_mode]].</div>Geekbabyhttps://wiki.archlinux.org/index.php?title=UEFI_Bootloaders_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=222455UEFI Bootloaders (简体中文)2012-09-10T13:55:18Z<p>Geekbaby: </p>
<hr />
<div>[[Category:Boot loaders]]<br />
[[en:UEFI Bootloaders]]<br />
[[zh-CN:UEFI Bootloaders]]<br />
该页包含了关于[[UEFI]] 启动管理器启动Linux内核的信息。在阅读该页之前,建议先阅读[[UEFI]]以及[[GPT]]页面。 [[Boot Loader|启动管理器]] (稳定性由好到差排序) 如下:<br />
<br />
# Linux Kernel EFISTUB<br />
# GRUB(2)<br />
# Fedora's GRUB-Legacy fork<br />
# ELILO<br />
# EFILINUX<br />
<br />
== Linux Kernel EFISTUB ==<br />
<br />
Linux Kernel >= 3.3 contains a stub which is capable of acting as the kernel's UEFI bootloader (which in a way means the kernel is its own bootloader), thus removing the need for a separate bootloader to launch the kernel (a boot manager might be required though, explained in detail later). This support is called {{ic|EFI BOOT STUB}} by upstream or {{ic|EFISTUB}} in short. EFISTUB should enabled by setting {{ic|1=CONFIG_EFI_STUB=y}} in Kernel config. The upstream documentation about EFISTUB booting is at https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/efi-stub.txt;hb=HEAD . More (unofficial) info is at http://www.rodsbooks.com/efi-bootloaders/efistub.html .<br />
<br />
Since the kernel is responsible for booting only itself, a single EFISTUB enabled kernel is not capable of launching other kernels. And each EFISTUB Kernel+Initramfs pair requires a separate boot menu entry. Thus when multiple kernels and/or initramfs files are involved, a UEFI Boot Manager is recommended to manage them.<br />
<br />
=== Setting up EFISTUB ===<br />
<br />
# Create an FAT32 UEFI System Partition - [[Unified_Extensible_Firmware_Interface#Create_an_UEFI_System_Partition_in_Linux]]<br />
# Mount the UEFI System Partition at {{ic|/boot/efi}}.<br />
# Create {{ic|/boot/efi/EFI/arch/}} directory.<br />
# Copy {{ic|/boot/vmlinuz-linux}} to {{ic|/boot/efi/EFI/arch/vmlinuz-linux.efi}} . The {{ic|.efi}} file extension is very important as some UEFI firmwares refuse to launch a file without the {{ic|.efi}} file extension.<br />
# Copy {{ic|/boot/initramfs-linux.img}} to {{ic|/boot/efi/EFI/arch/initramfs-linux.img}}.<br />
# Create {{ic|/boot/efi/EFI/arch/linux.conf}} with the kernel parameters to be passed to the kernel (example file shown below). This file should consist of only one line and simply contains all the kernel parameters to be used by the EFISTUB loader to the kernel. <br />
<br />
{{hc|/boot/efi/EFI/arch/linux.conf|<nowiki><br />
root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap initrd=\EFI\arch\initramfs-linux.img</nowiki>}} <br />
<br />
{{Note|1=This config file is not supported by any currently shipping kernel version and is expected to be supported only in kernels >=3.6 .}}<br />
<br />
{{Note|The kernel and initramfs files at {{ic|/boot/efi/EFI/arch/}} should be updated everytime those files in {{ic|/boot}} are updated.}}<br />
<br />
{{Warning|In Linux Kernel EFISTUB booting, {{ic|1=initrd=}} path should use UEFI-style backslashes (\) and should be relative to the UEFI System Partition's root, not relative to the current directory in the UEFI Shell. An improper {{ic|1=initrd=}} option leads to a system hang without any error message from the firmware or the kernel.}}<br />
<br />
==== Sync EFISTUB Kernel in UEFISYS partition using Systemd ====<br />
<br />
[[Systemd]] init system supports defining tasks that should be performed when certain files/paths are changed. This feature of systemd is used to copy updated EFISTUB kernel and initramfs files when they are update in {{ic|/boot}}, like during package updates or during manual run of mkinitcpio etc.<br />
<br />
For this create the files as defined below:<br />
<br />
{{hc|/etc/systemd/system/efistub_copy.path|<nowiki><br />
[Unit]<br />
Description=Copy EFISTUB Kernel and Initramfs to UEFISYS Partition<br />
<br />
[Path]<br />
PathChanged=/boot/initramfs-linux-fallback.img<br />
Unit=efistub_copy.service<br />
<br />
[Install]<br />
WantedBy=multi-user.target</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/efistub_copy.service|<nowiki><br />
[Unit]<br />
Description=Copy EFISTUB Kernel and Initramfs to UEFISYS Partition<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/bin/cp -f /boot/vmlinuz-linux /boot/efi/EFI/arch/vmlinuz-linux.efi<br />
ExecStart=/bin/cp -f /boot/initramfs-linux.img /boot/efi/EFI/arch/initramfs-linux.img<br />
ExecStart=/bin/cp -f /boot/initramfs-linux-fallback.img /boot/efi/EFI/arch/initramfs-linux-fallback.img<br />
</nowiki>}}<br />
<br />
After creating the files run:<br />
<br />
# systemctl enable efistub_copy.path<br />
# systemctl start efistub_copy.path<br />
<br />
==== Sync EFISTUB Kernel in UEFISYS partition using Incron ====<br />
<br />
Incron can also be used to automatically sync the EFISTUB kernel after updates.<br />
<br />
First, [[pacman|install]] the {{Pkg|incron}} package from the [[Official Repositories]].<br />
<br />
Next you will need to set up a script to do the actual copying. You can call this script whatever you want, but make sure you use absolute paths in the commands.<br />
{{hc|File: /root/copykernel.sh|<nowiki><br />
/bin/cp -f /boot/vmlinuz-linux /boot/efi/EFI/arch/vmlinuz-linux.efi<br />
/bin/cp -f /boot/initramfs-linux.img /boot/efi/EFI/arch/initramfs-linux.img<br />
/bin/cp -f /boot/initramfs-linux-fallback.img /boot/efi/EFI/arch/initramfs-linux-fallback.img<br />
</nowiki>}}<br />
<br />
Specify which file to watch for changes in {{ic|/etc/incron.d/kernel.conf}}. The first parameter is the file to watch: {{ic|/boot/initramfs-linux-fallback.img}}. The second parameter {{ic|IN_CLOSE_WRITE}} is the action to watch for. The third parameter {{ic|/root/copykernel.sh}} is the script to execute.<br />
{{hc|File: /etc/incron.d/kernel.conf|<nowiki><br />
/boot/initramfs-linux-fallback.img IN_CLOSE_WRITE /root/copykernel.sh<br />
</nowiki>}}<br />
<br />
Now just add incrond to the daemon list in {{ic|/etc/rc.conf}} and it will automatically start up and copy the new files to the proper place every time the kernel is updated.<br />
==== Sync EFISTUB Kernel in UEFISYS partition using Mkinitcpio hook ====<br />
<br />
This uses a hook that spawns a background process, which waits for the generation process to finish, then copies the finished kernel and initrd.<br />
<br />
This approach doesn't need a system level daemon to function.<br />
<br />
{{hc|File: /usr/lib/initcpio/install/uefi|<nowiki><br />
<br />
#!/bin/bash<br />
<br />
function get_kernel() {<br />
<br />
next="0"<br />
for a in ${BASH_ARGV[*]} ; do<br />
if [[ $next == "1" ]] ; then<br />
eval "$1='$a'"<br />
return<br />
fi<br />
<br />
if [[ $a == "-c" ]] ; then<br />
next="1"<br />
fi <br />
done<br />
<br />
}<br />
<br />
build() {<br />
<br />
kernel_name=''<br />
get_kernel kernel_name<br />
bash /root/watch.sh $GENIMG $kernel_name &<br />
}<br />
<br />
<br />
help() {<br />
cat <<HELPEOF<br />
This hook simply waits for mkinitcpio to finish and copies the finished ramdisk and kernel to UEFI<br />
HELPEOF<br />
}<br />
<br />
# vim: set ft=sh ts=4 sw=4 et:<br />
<br />
<br />
</nowiki>}}<br />
<br />
<br />
<br />
{{hc|File: /root/watch.sh|<nowiki><br />
<br />
#!/bin/bash<br />
<br />
EFI_DIR="/boot/efi/EFI/arch"<br />
<br />
<br />
INITRD="$1"<br />
IMAGE="$2"<br />
IMAGE_BASENAME=$(basename $2)<br />
EFI_IMAGE="$EFI_DIR/$IMAGE_BASENAME.efi"<br />
<br />
function do_copy(){<br />
cp $INITRD $EFI_DIR<br />
cp $IMAGE $EFI_IMAGE<br />
echo "Synced $INITRD to $EFI_DIR"<br />
}<br />
<br />
while [ : ]; do<br />
<br />
if [[ ! -d "/proc/$PPID" ]]; then<br />
do_copy<br />
exit 1<br />
fi<br />
sleep 1<br />
<br />
done<br />
<br />
</nowiki>}}<br />
<br />
<br />
Then simply add {{ic|uefi}} to the list of hooks in {{ic|/etc/mkinitcpio.conf}}<br />
<br />
=== Booting EFISTUB ===<br />
<br />
There are various ways of booting EFISTUB kernels. Those described here are:<br />
<br />
# Using rEFInd UEFI Boot Manager<br />
# Using UEFI Shell<br />
# Using efibootmgr entry<br />
<br />
==== Using rEFInd ====<br />
<br />
rEFInd is a fork of rEFIt Boot Manager (used in Intel Macs) by Rod Smith (author is GPT-fdisk). rEFInd fixes many issues in rEFIt with respect to non-Mac UEFI booting and also has support for booting EFISTUB kernels and contains some features specific to them. More info about rEFInd support for EFISTUB is at http://www.rodsbooks.com/refind/linux.html .<br />
<br />
There are two ways of installing rEFInd. One is using the {{Pkg|refind-efi-x86_64}} from [extra] repo or {{AUR|refind-efi-x86_64-git}} AUR package (only for x86_64 UEFI) (recommended). The other is to use the precompiled binaries provided by upstream at http://sourceforge.net/projects/refind/ . If you downloaded the precompiled binaries provided by upstream, then setup rEFInd as follows ({{ic|/boot/efi}} is UEFISYS partition mountpoint):<br />
<br />
# Extract the refind-bin-*.zip file.<br />
# Copy {{ic|refind}} directory to {{ic|/boot/efi/EFI/arch/refind}}<br />
# Rename {{ic|/boot/efi/EFI/arch/refind/refind.conf-sample}} to {{ic|/boot/efi/EFI/arch/refind/refind.conf}} and edit it according to your needs. It is possible define boot entries within {{ic|refind.conf}} itself. Follow the example menuentries defined in {{ic|/boot/efi/EFI/arch/refind/refind.conf}} to create your own.<br />
# Rename {{ic|/boot/efi/EFI/arch/refind/refind_x64.efi}} to {{ic|/boot/efi/EFI/arch/refind/refindx64.efi}}. (Or refind_ia32.efi to refindia32.efi in case of 32-bit UEFI).<br />
<br />
The above steps are automatically done by the AUR package. After setting up, create {{ic|/boot/efi/EFI/arch/refind_linux.conf}} with the kernel parameters to be used to EFISTUB kernel by rEFInd. An example file is shown below.<br />
<br />
{{hc|/boot/efi/EFI/arch/refind_linux.conf|<nowiki><br />
"Boot with defaults" "root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap"<br />
"Boot to Terminal" "root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap 3"</nowiki>}}<br />
<br />
These options are displayed as a submenu by rEFInd. The sub-menu can be accessed by using "+" or "insert" keys.<br />
<br />
In non-Mac systems create an entry for rEFInd using efibootmgr. <br />
<br />
# efibootmgr -c -l \\EFI\\arch\\refind\\refindx64.efi -L rEFInd -p X<br />
<br />
"X" is the partition number containing the bootloader.<br />
<br />
In case of Apple Macs, try {{AUR|mactel-boot}} for an experimental "bless" utility for Linux. If that does not work, use "bless" form within OSX to set rEFInd as default bootloader. Assuming UEFISYS partition is mounted at {{ic|/mnt/efi}} within OSX, do<br />
<br />
$ sudo bless --setBoot --folder /mnt/efi/EFI/refind --file /mnt/efi/EFI/refind/refindx64.efi<br />
<br />
==== Using UEFI Shell ====<br />
<br />
It is possible to launch EFISTUB kernel form UEFI Shell as if its a normal UEFI application. In this case the kernel parameters are passed as normal parameters to the launched EFISTUB kernel file.<br />
<br />
> fs0:<br />
> cd \EFI\arch<br />
> vmlinuz-linux.efi root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap initrd=\EFI\arch\initramfs-linux.img<br />
<br />
==== Using efibootmgr entry ====<br />
<br />
It is possible to directly embed the kernel parameters within the boot entry created by efibootmgr. Do (as root)<br />
<br />
# echo "root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap initrd=\\EFI\\arch\\initramfs-linux.img" | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1 --label "Archlinux (EFISTUB)" --loader "\\EFI\\arch\\vmlinuz-linux.efi" --append-binary-args -<br />
<br />
{{Note|The trailing hyphen after {{ic|--append-binary-args}} is required to instruct efibootmgr to read the parameters from STDIN (standard input). The code should be {{ic|--append-binary-args -}} .}}<br />
<br />
More info about efibootmgr at [[UEFI#efibootmgr]]. Forum post https://bbs.archlinux.org/viewtopic.php?pid=1090040#p1090040 .<br />
<br />
== GRUB(2) ==<br />
<br />
GRUB(2) contains its own filesystem drivers and does not rely on the firmware to access the files. It can directly read files from {{ic|/boot}} and does not require the kernel and initramfs files to be in the UEFISYS partition. Detailed information at [[GRUB#UEFI_systems_2]]. For bzr development version try AUR package - {{AUR|grub-efi-x86_64-bzr}}.<br />
<br />
== GRUB Legacy Fedora ==<br />
<br />
[[GRUB Legacy]] upstream sources (and the package Archlinux ships) do not support UEFI. However Fedora/Redhat's fork contains UEFI patches provided by Intel. The patched sources are at https://github.com/vathpela/grub-fedora . GRUB-Legacy-Fedora contains its own filesystem drivers (including ext4) and does not rely on the firmware to access the files. Thus it can directly read files form /boot and does not require the kernel and initramfs files to be in the UEFISYS partition. AUR package - {{AUR|grub-legacy-fedora-efi-x86_64-git}} (only for x86_64 UEFI).<br />
<br />
{{Note|Fedora developers have mentioned that after the release of Fedora 17, grub-legacy-fedora development will stop and Fedora will be switching to GRUB(2) as the default UEFI bootloader from F18 onwards. Fedora already uses GRUB(2) as its default BIOS bootloader since F16. Users are recommended to switch to EFISTUB or GRUB(2) instead.}}<br />
<br />
== ELILO ==<br />
<br />
ELILO is the UEFI version of LILO Boot Loader. It was originally created for Intel Itanium systems which supported only EFI (precursor to UEFI). It is the oldest UEFI bootloader for Linux. It is still in development but happens at a very slow pace. Upstream provided compiled binaries are available at http://sourceforge.net/projects/elilo/ . Elilo config file {{ic|elilo.conf}} is similar to [[LILO]]'s config file. AUR package - {{AUR|elilo-x86_64}} (only for x86_64 UEFI).<br />
<br />
== EFILINUX ==<br />
<br />
EFILINUX is a reference implementation of a UEFI Linux bootloader and precursor to Kenrel EFISTUB support. It is considered to be a alpha quality software (as on 16-MAY-2012). Upstream sources are at https://github.com/mfleming/efilinux . and the usage instructions are at http://thread.gmane.org/gmane.linux.kernel/1172645 and http://article.gmane.org/gmane.linux.kernel/1175060 . AUR packages - {{AUR|efilinux-x86_64}} and {{AUR|efilinux-x86_64-git}} (only for x86_64 UEFI).<br />
<br />
==See also==<br />
<br />
* [http://www.rodsbooks.com/efi-bootloaders/ Rod Smith - Managing EFI Boot Loaders for Linux]<br />
* [http://www.rodsbooks.com/refind/ Rod Smith - rEFInd, a fork or rEFIt]<br />
* [https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/efi-stub.txt;hb=HEAD Linux Kernel Documentation on EFISTUB]<br />
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=291f36325f9f252bd76ef5f603995f37e453fc60;hp=55839d515495e766605d7aaabd9c2758370a8d27 Linux Kernel EFISTUB Git Commit]<br />
* [http://www.rodsbooks.com/efi-bootloaders/efistub.html Rod Smith's page on EFISTUB]<br />
* [http://www.rodsbooks.com/refind/linux.html rEFInd Documentation for booting EFISTUB Kernels]</div>Geekbabyhttps://wiki.archlinux.org/index.php?title=UEFI_Bootloaders_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=222454UEFI Bootloaders (简体中文)2012-09-10T13:54:13Z<p>Geekbaby: Created page with "Category:Boot loaders zh-CN:UEFI Bootloaders 该页包含了关于UEFI 启动管理器启动Linux内核的信息。在阅读该页之前,建议先阅读UEFI..."</p>
<hr />
<div>[[Category:Boot loaders]]<br />
[[zh-CN:UEFI Bootloaders]]<br />
该页包含了关于[[UEFI]] 启动管理器启动Linux内核的信息。在阅读该页之前,建议先阅读[[UEFI]]以及[[GPT]]页面。 [[Boot Loader|启动管理器]] (稳定性由好到差排序) 如下:<br />
<br />
# Linux Kernel EFISTUB<br />
# GRUB(2)<br />
# Fedora's GRUB-Legacy fork<br />
# ELILO<br />
# EFILINUX<br />
<br />
== Linux Kernel EFISTUB ==<br />
<br />
Linux Kernel >= 3.3 contains a stub which is capable of acting as the kernel's UEFI bootloader (which in a way means the kernel is its own bootloader), thus removing the need for a separate bootloader to launch the kernel (a boot manager might be required though, explained in detail later). This support is called {{ic|EFI BOOT STUB}} by upstream or {{ic|EFISTUB}} in short. EFISTUB should enabled by setting {{ic|1=CONFIG_EFI_STUB=y}} in Kernel config. The upstream documentation about EFISTUB booting is at https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/efi-stub.txt;hb=HEAD . More (unofficial) info is at http://www.rodsbooks.com/efi-bootloaders/efistub.html .<br />
<br />
Since the kernel is responsible for booting only itself, a single EFISTUB enabled kernel is not capable of launching other kernels. And each EFISTUB Kernel+Initramfs pair requires a separate boot menu entry. Thus when multiple kernels and/or initramfs files are involved, a UEFI Boot Manager is recommended to manage them.<br />
<br />
=== Setting up EFISTUB ===<br />
<br />
# Create an FAT32 UEFI System Partition - [[Unified_Extensible_Firmware_Interface#Create_an_UEFI_System_Partition_in_Linux]]<br />
# Mount the UEFI System Partition at {{ic|/boot/efi}}.<br />
# Create {{ic|/boot/efi/EFI/arch/}} directory.<br />
# Copy {{ic|/boot/vmlinuz-linux}} to {{ic|/boot/efi/EFI/arch/vmlinuz-linux.efi}} . The {{ic|.efi}} file extension is very important as some UEFI firmwares refuse to launch a file without the {{ic|.efi}} file extension.<br />
# Copy {{ic|/boot/initramfs-linux.img}} to {{ic|/boot/efi/EFI/arch/initramfs-linux.img}}.<br />
# Create {{ic|/boot/efi/EFI/arch/linux.conf}} with the kernel parameters to be passed to the kernel (example file shown below). This file should consist of only one line and simply contains all the kernel parameters to be used by the EFISTUB loader to the kernel. <br />
<br />
{{hc|/boot/efi/EFI/arch/linux.conf|<nowiki><br />
root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap initrd=\EFI\arch\initramfs-linux.img</nowiki>}} <br />
<br />
{{Note|1=This config file is not supported by any currently shipping kernel version and is expected to be supported only in kernels >=3.6 .}}<br />
<br />
{{Note|The kernel and initramfs files at {{ic|/boot/efi/EFI/arch/}} should be updated everytime those files in {{ic|/boot}} are updated.}}<br />
<br />
{{Warning|In Linux Kernel EFISTUB booting, {{ic|1=initrd=}} path should use UEFI-style backslashes (\) and should be relative to the UEFI System Partition's root, not relative to the current directory in the UEFI Shell. An improper {{ic|1=initrd=}} option leads to a system hang without any error message from the firmware or the kernel.}}<br />
<br />
==== Sync EFISTUB Kernel in UEFISYS partition using Systemd ====<br />
<br />
[[Systemd]] init system supports defining tasks that should be performed when certain files/paths are changed. This feature of systemd is used to copy updated EFISTUB kernel and initramfs files when they are update in {{ic|/boot}}, like during package updates or during manual run of mkinitcpio etc.<br />
<br />
For this create the files as defined below:<br />
<br />
{{hc|/etc/systemd/system/efistub_copy.path|<nowiki><br />
[Unit]<br />
Description=Copy EFISTUB Kernel and Initramfs to UEFISYS Partition<br />
<br />
[Path]<br />
PathChanged=/boot/initramfs-linux-fallback.img<br />
Unit=efistub_copy.service<br />
<br />
[Install]<br />
WantedBy=multi-user.target</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/efistub_copy.service|<nowiki><br />
[Unit]<br />
Description=Copy EFISTUB Kernel and Initramfs to UEFISYS Partition<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/bin/cp -f /boot/vmlinuz-linux /boot/efi/EFI/arch/vmlinuz-linux.efi<br />
ExecStart=/bin/cp -f /boot/initramfs-linux.img /boot/efi/EFI/arch/initramfs-linux.img<br />
ExecStart=/bin/cp -f /boot/initramfs-linux-fallback.img /boot/efi/EFI/arch/initramfs-linux-fallback.img<br />
</nowiki>}}<br />
<br />
After creating the files run:<br />
<br />
# systemctl enable efistub_copy.path<br />
# systemctl start efistub_copy.path<br />
<br />
==== Sync EFISTUB Kernel in UEFISYS partition using Incron ====<br />
<br />
Incron can also be used to automatically sync the EFISTUB kernel after updates.<br />
<br />
First, [[pacman|install]] the {{Pkg|incron}} package from the [[Official Repositories]].<br />
<br />
Next you will need to set up a script to do the actual copying. You can call this script whatever you want, but make sure you use absolute paths in the commands.<br />
{{hc|File: /root/copykernel.sh|<nowiki><br />
/bin/cp -f /boot/vmlinuz-linux /boot/efi/EFI/arch/vmlinuz-linux.efi<br />
/bin/cp -f /boot/initramfs-linux.img /boot/efi/EFI/arch/initramfs-linux.img<br />
/bin/cp -f /boot/initramfs-linux-fallback.img /boot/efi/EFI/arch/initramfs-linux-fallback.img<br />
</nowiki>}}<br />
<br />
Specify which file to watch for changes in {{ic|/etc/incron.d/kernel.conf}}. The first parameter is the file to watch: {{ic|/boot/initramfs-linux-fallback.img}}. The second parameter {{ic|IN_CLOSE_WRITE}} is the action to watch for. The third parameter {{ic|/root/copykernel.sh}} is the script to execute.<br />
{{hc|File: /etc/incron.d/kernel.conf|<nowiki><br />
/boot/initramfs-linux-fallback.img IN_CLOSE_WRITE /root/copykernel.sh<br />
</nowiki>}}<br />
<br />
Now just add incrond to the daemon list in {{ic|/etc/rc.conf}} and it will automatically start up and copy the new files to the proper place every time the kernel is updated.<br />
==== Sync EFISTUB Kernel in UEFISYS partition using Mkinitcpio hook ====<br />
<br />
This uses a hook that spawns a background process, which waits for the generation process to finish, then copies the finished kernel and initrd.<br />
<br />
This approach doesn't need a system level daemon to function.<br />
<br />
{{hc|File: /usr/lib/initcpio/install/uefi|<nowiki><br />
<br />
#!/bin/bash<br />
<br />
function get_kernel() {<br />
<br />
next="0"<br />
for a in ${BASH_ARGV[*]} ; do<br />
if [[ $next == "1" ]] ; then<br />
eval "$1='$a'"<br />
return<br />
fi<br />
<br />
if [[ $a == "-c" ]] ; then<br />
next="1"<br />
fi <br />
done<br />
<br />
}<br />
<br />
build() {<br />
<br />
kernel_name=''<br />
get_kernel kernel_name<br />
bash /root/watch.sh $GENIMG $kernel_name &<br />
}<br />
<br />
<br />
help() {<br />
cat <<HELPEOF<br />
This hook simply waits for mkinitcpio to finish and copies the finished ramdisk and kernel to UEFI<br />
HELPEOF<br />
}<br />
<br />
# vim: set ft=sh ts=4 sw=4 et:<br />
<br />
<br />
</nowiki>}}<br />
<br />
<br />
<br />
{{hc|File: /root/watch.sh|<nowiki><br />
<br />
#!/bin/bash<br />
<br />
EFI_DIR="/boot/efi/EFI/arch"<br />
<br />
<br />
INITRD="$1"<br />
IMAGE="$2"<br />
IMAGE_BASENAME=$(basename $2)<br />
EFI_IMAGE="$EFI_DIR/$IMAGE_BASENAME.efi"<br />
<br />
function do_copy(){<br />
cp $INITRD $EFI_DIR<br />
cp $IMAGE $EFI_IMAGE<br />
echo "Synced $INITRD to $EFI_DIR"<br />
}<br />
<br />
while [ : ]; do<br />
<br />
if [[ ! -d "/proc/$PPID" ]]; then<br />
do_copy<br />
exit 1<br />
fi<br />
sleep 1<br />
<br />
done<br />
<br />
</nowiki>}}<br />
<br />
<br />
Then simply add {{ic|uefi}} to the list of hooks in {{ic|/etc/mkinitcpio.conf}}<br />
<br />
=== Booting EFISTUB ===<br />
<br />
There are various ways of booting EFISTUB kernels. Those described here are:<br />
<br />
# Using rEFInd UEFI Boot Manager<br />
# Using UEFI Shell<br />
# Using efibootmgr entry<br />
<br />
==== Using rEFInd ====<br />
<br />
rEFInd is a fork of rEFIt Boot Manager (used in Intel Macs) by Rod Smith (author is GPT-fdisk). rEFInd fixes many issues in rEFIt with respect to non-Mac UEFI booting and also has support for booting EFISTUB kernels and contains some features specific to them. More info about rEFInd support for EFISTUB is at http://www.rodsbooks.com/refind/linux.html .<br />
<br />
There are two ways of installing rEFInd. One is using the {{Pkg|refind-efi-x86_64}} from [extra] repo or {{AUR|refind-efi-x86_64-git}} AUR package (only for x86_64 UEFI) (recommended). The other is to use the precompiled binaries provided by upstream at http://sourceforge.net/projects/refind/ . If you downloaded the precompiled binaries provided by upstream, then setup rEFInd as follows ({{ic|/boot/efi}} is UEFISYS partition mountpoint):<br />
<br />
# Extract the refind-bin-*.zip file.<br />
# Copy {{ic|refind}} directory to {{ic|/boot/efi/EFI/arch/refind}}<br />
# Rename {{ic|/boot/efi/EFI/arch/refind/refind.conf-sample}} to {{ic|/boot/efi/EFI/arch/refind/refind.conf}} and edit it according to your needs. It is possible define boot entries within {{ic|refind.conf}} itself. Follow the example menuentries defined in {{ic|/boot/efi/EFI/arch/refind/refind.conf}} to create your own.<br />
# Rename {{ic|/boot/efi/EFI/arch/refind/refind_x64.efi}} to {{ic|/boot/efi/EFI/arch/refind/refindx64.efi}}. (Or refind_ia32.efi to refindia32.efi in case of 32-bit UEFI).<br />
<br />
The above steps are automatically done by the AUR package. After setting up, create {{ic|/boot/efi/EFI/arch/refind_linux.conf}} with the kernel parameters to be used to EFISTUB kernel by rEFInd. An example file is shown below.<br />
<br />
{{hc|/boot/efi/EFI/arch/refind_linux.conf|<nowiki><br />
"Boot with defaults" "root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap"<br />
"Boot to Terminal" "root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap 3"</nowiki>}}<br />
<br />
These options are displayed as a submenu by rEFInd. The sub-menu can be accessed by using "+" or "insert" keys.<br />
<br />
In non-Mac systems create an entry for rEFInd using efibootmgr. <br />
<br />
# efibootmgr -c -l \\EFI\\arch\\refind\\refindx64.efi -L rEFInd -p X<br />
<br />
"X" is the partition number containing the bootloader.<br />
<br />
In case of Apple Macs, try {{AUR|mactel-boot}} for an experimental "bless" utility for Linux. If that does not work, use "bless" form within OSX to set rEFInd as default bootloader. Assuming UEFISYS partition is mounted at {{ic|/mnt/efi}} within OSX, do<br />
<br />
$ sudo bless --setBoot --folder /mnt/efi/EFI/refind --file /mnt/efi/EFI/refind/refindx64.efi<br />
<br />
==== Using UEFI Shell ====<br />
<br />
It is possible to launch EFISTUB kernel form UEFI Shell as if its a normal UEFI application. In this case the kernel parameters are passed as normal parameters to the launched EFISTUB kernel file.<br />
<br />
> fs0:<br />
> cd \EFI\arch<br />
> vmlinuz-linux.efi root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap initrd=\EFI\arch\initramfs-linux.img<br />
<br />
==== Using efibootmgr entry ====<br />
<br />
It is possible to directly embed the kernel parameters within the boot entry created by efibootmgr. Do (as root)<br />
<br />
# echo "root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap initrd=\\EFI\\arch\\initramfs-linux.img" | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1 --label "Archlinux (EFISTUB)" --loader "\\EFI\\arch\\vmlinuz-linux.efi" --append-binary-args -<br />
<br />
{{Note|The trailing hyphen after {{ic|--append-binary-args}} is required to instruct efibootmgr to read the parameters from STDIN (standard input). The code should be {{ic|--append-binary-args -}} .}}<br />
<br />
More info about efibootmgr at [[UEFI#efibootmgr]]. Forum post https://bbs.archlinux.org/viewtopic.php?pid=1090040#p1090040 .<br />
<br />
== GRUB(2) ==<br />
<br />
GRUB(2) contains its own filesystem drivers and does not rely on the firmware to access the files. It can directly read files from {{ic|/boot}} and does not require the kernel and initramfs files to be in the UEFISYS partition. Detailed information at [[GRUB#UEFI_systems_2]]. For bzr development version try AUR package - {{AUR|grub-efi-x86_64-bzr}}.<br />
<br />
== GRUB Legacy Fedora ==<br />
<br />
[[GRUB Legacy]] upstream sources (and the package Archlinux ships) do not support UEFI. However Fedora/Redhat's fork contains UEFI patches provided by Intel. The patched sources are at https://github.com/vathpela/grub-fedora . GRUB-Legacy-Fedora contains its own filesystem drivers (including ext4) and does not rely on the firmware to access the files. Thus it can directly read files form /boot and does not require the kernel and initramfs files to be in the UEFISYS partition. AUR package - {{AUR|grub-legacy-fedora-efi-x86_64-git}} (only for x86_64 UEFI).<br />
<br />
{{Note|Fedora developers have mentioned that after the release of Fedora 17, grub-legacy-fedora development will stop and Fedora will be switching to GRUB(2) as the default UEFI bootloader from F18 onwards. Fedora already uses GRUB(2) as its default BIOS bootloader since F16. Users are recommended to switch to EFISTUB or GRUB(2) instead.}}<br />
<br />
== ELILO ==<br />
<br />
ELILO is the UEFI version of LILO Boot Loader. It was originally created for Intel Itanium systems which supported only EFI (precursor to UEFI). It is the oldest UEFI bootloader for Linux. It is still in development but happens at a very slow pace. Upstream provided compiled binaries are available at http://sourceforge.net/projects/elilo/ . Elilo config file {{ic|elilo.conf}} is similar to [[LILO]]'s config file. AUR package - {{AUR|elilo-x86_64}} (only for x86_64 UEFI).<br />
<br />
== EFILINUX ==<br />
<br />
EFILINUX is a reference implementation of a UEFI Linux bootloader and precursor to Kenrel EFISTUB support. It is considered to be a alpha quality software (as on 16-MAY-2012). Upstream sources are at https://github.com/mfleming/efilinux . and the usage instructions are at http://thread.gmane.org/gmane.linux.kernel/1172645 and http://article.gmane.org/gmane.linux.kernel/1175060 . AUR packages - {{AUR|efilinux-x86_64}} and {{AUR|efilinux-x86_64-git}} (only for x86_64 UEFI).<br />
<br />
==See also==<br />
<br />
* [http://www.rodsbooks.com/efi-bootloaders/ Rod Smith - Managing EFI Boot Loaders for Linux]<br />
* [http://www.rodsbooks.com/refind/ Rod Smith - rEFInd, a fork or rEFIt]<br />
* [https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/efi-stub.txt;hb=HEAD Linux Kernel Documentation on EFISTUB]<br />
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=291f36325f9f252bd76ef5f603995f37e453fc60;hp=55839d515495e766605d7aaabd9c2758370a8d27 Linux Kernel EFISTUB Git Commit]<br />
* [http://www.rodsbooks.com/efi-bootloaders/efistub.html Rod Smith's page on EFISTUB]<br />
* [http://www.rodsbooks.com/refind/linux.html rEFInd Documentation for booting EFISTUB Kernels]</div>Geekbabyhttps://wiki.archlinux.org/index.php?title=UEFI_Bootloaders&diff=222448UEFI Bootloaders2012-09-10T13:44:32Z<p>Geekbaby: </p>
<hr />
<div>[[Category:Boot loaders]]<br />
[[zh-CN:UEFI Bootloaders]]<br />
This page contains info about various [[UEFI]] Bootloaders capable of booting Linux kernel. It is recommended to read the [[UEFI]] and [[GPT]] pages before reading this page. The following [[Boot Loader|bootloaders]] (listed in decreasing order of stability) are explained here:<br />
<br />
# Linux Kernel EFISTUB<br />
# GRUB(2)<br />
# Fedora's GRUB-Legacy fork<br />
# ELILO<br />
# EFILINUX<br />
<br />
== Linux Kernel EFISTUB ==<br />
<br />
Linux Kernel >= 3.3 contains a stub which is capable of acting as the kernel's UEFI bootloader (which in a way means the kernel is its own bootloader), thus removing the need for a separate bootloader to launch the kernel (a boot manager might be required though, explained in detail later). This support is called {{ic|EFI BOOT STUB}} by upstream or {{ic|EFISTUB}} in short. EFISTUB should enabled by setting {{ic|1=CONFIG_EFI_STUB=y}} in Kernel config. The upstream documentation about EFISTUB booting is at https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/efi-stub.txt;hb=HEAD . More (unofficial) info is at http://www.rodsbooks.com/efi-bootloaders/efistub.html .<br />
<br />
Since the kernel is responsible for booting only itself, a single EFISTUB enabled kernel is not capable of launching other kernels. And each EFISTUB Kernel+Initramfs pair requires a separate boot menu entry. Thus when multiple kernels and/or initramfs files are involved, a UEFI Boot Manager is recommended to manage them.<br />
<br />
=== Setting up EFISTUB ===<br />
<br />
# Create an FAT32 UEFI System Partition - [[Unified_Extensible_Firmware_Interface#Create_an_UEFI_System_Partition_in_Linux]]<br />
# Mount the UEFI System Partition at {{ic|/boot/efi}}.<br />
# Create {{ic|/boot/efi/EFI/arch/}} directory.<br />
# Copy {{ic|/boot/vmlinuz-linux}} to {{ic|/boot/efi/EFI/arch/vmlinuz-linux.efi}} . The {{ic|.efi}} file extension is very important as some UEFI firmwares refuse to launch a file without the {{ic|.efi}} file extension.<br />
# Copy {{ic|/boot/initramfs-linux.img}} to {{ic|/boot/efi/EFI/arch/initramfs-linux.img}}.<br />
# Create {{ic|/boot/efi/EFI/arch/linux.conf}} with the kernel parameters to be passed to the kernel (example file shown below). This file should consist of only one line and simply contains all the kernel parameters to be used by the EFISTUB loader to the kernel. <br />
<br />
{{hc|/boot/efi/EFI/arch/linux.conf|<nowiki><br />
root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap initrd=\EFI\arch\initramfs-linux.img</nowiki>}} <br />
<br />
{{Note|1=This config file is not supported by any currently shipping kernel version and is expected to be supported only in kernels >=3.6 .}}<br />
<br />
{{Note|The kernel and initramfs files at {{ic|/boot/efi/EFI/arch/}} should be updated everytime those files in {{ic|/boot}} are updated.}}<br />
<br />
{{Warning|In Linux Kernel EFISTUB booting, {{ic|1=initrd=}} path should use UEFI-style backslashes (\) and should be relative to the UEFI System Partition's root, not relative to the current directory in the UEFI Shell. An improper {{ic|1=initrd=}} option leads to a system hang without any error message from the firmware or the kernel.}}<br />
<br />
==== Sync EFISTUB Kernel in UEFISYS partition using Systemd ====<br />
<br />
[[Systemd]] init system supports defining tasks that should be performed when certain files/paths are changed. This feature of systemd is used to copy updated EFISTUB kernel and initramfs files when they are update in {{ic|/boot}}, like during package updates or during manual run of mkinitcpio etc.<br />
<br />
For this create the files as defined below:<br />
<br />
{{hc|/etc/systemd/system/efistub_copy.path|<nowiki><br />
[Unit]<br />
Description=Copy EFISTUB Kernel and Initramfs to UEFISYS Partition<br />
<br />
[Path]<br />
PathChanged=/boot/initramfs-linux-fallback.img<br />
Unit=efistub_copy.service<br />
<br />
[Install]<br />
WantedBy=multi-user.target</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/efistub_copy.service|<nowiki><br />
[Unit]<br />
Description=Copy EFISTUB Kernel and Initramfs to UEFISYS Partition<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/bin/cp -f /boot/vmlinuz-linux /boot/efi/EFI/arch/vmlinuz-linux.efi<br />
ExecStart=/bin/cp -f /boot/initramfs-linux.img /boot/efi/EFI/arch/initramfs-linux.img<br />
ExecStart=/bin/cp -f /boot/initramfs-linux-fallback.img /boot/efi/EFI/arch/initramfs-linux-fallback.img<br />
</nowiki>}}<br />
<br />
After creating the files run:<br />
<br />
# systemctl enable efistub_copy.path<br />
# systemctl start efistub_copy.path<br />
<br />
==== Sync EFISTUB Kernel in UEFISYS partition using Incron ====<br />
<br />
Incron can also be used to automatically sync the EFISTUB kernel after updates.<br />
<br />
First, [[pacman|install]] the {{Pkg|incron}} package from the [[Official Repositories]].<br />
<br />
Next you will need to set up a script to do the actual copying. You can call this script whatever you want, but make sure you use absolute paths in the commands.<br />
{{hc|File: /root/copykernel.sh|<nowiki><br />
/bin/cp -f /boot/vmlinuz-linux /boot/efi/EFI/arch/vmlinuz-linux.efi<br />
/bin/cp -f /boot/initramfs-linux.img /boot/efi/EFI/arch/initramfs-linux.img<br />
/bin/cp -f /boot/initramfs-linux-fallback.img /boot/efi/EFI/arch/initramfs-linux-fallback.img<br />
</nowiki>}}<br />
<br />
Specify which file to watch for changes in {{ic|/etc/incron.d/kernel.conf}}. The first parameter is the file to watch: {{ic|/boot/initramfs-linux-fallback.img}}. The second parameter {{ic|IN_CLOSE_WRITE}} is the action to watch for. The third parameter {{ic|/root/copykernel.sh}} is the script to execute.<br />
{{hc|File: /etc/incron.d/kernel.conf|<nowiki><br />
/boot/initramfs-linux-fallback.img IN_CLOSE_WRITE /root/copykernel.sh<br />
</nowiki>}}<br />
<br />
Now just add incrond to the daemon list in {{ic|/etc/rc.conf}} and it will automatically start up and copy the new files to the proper place every time the kernel is updated.<br />
==== Sync EFISTUB Kernel in UEFISYS partition using Mkinitcpio hook ====<br />
<br />
This uses a hook that spawns a background process, which waits for the generation process to finish, then copies the finished kernel and initrd.<br />
<br />
This approach doesn't need a system level daemon to function.<br />
<br />
{{hc|File: /usr/lib/initcpio/install/uefi|<nowiki><br />
<br />
#!/bin/bash<br />
<br />
function get_kernel() {<br />
<br />
next="0"<br />
for a in ${BASH_ARGV[*]} ; do<br />
if [[ $next == "1" ]] ; then<br />
eval "$1='$a'"<br />
return<br />
fi<br />
<br />
if [[ $a == "-c" ]] ; then<br />
next="1"<br />
fi <br />
done<br />
<br />
}<br />
<br />
build() {<br />
<br />
kernel_name=''<br />
get_kernel kernel_name<br />
bash /root/watch.sh $GENIMG $kernel_name &<br />
}<br />
<br />
<br />
help() {<br />
cat <<HELPEOF<br />
This hook simply waits for mkinitcpio to finish and copies the finished ramdisk and kernel to UEFI<br />
HELPEOF<br />
}<br />
<br />
# vim: set ft=sh ts=4 sw=4 et:<br />
<br />
<br />
</nowiki>}}<br />
<br />
<br />
<br />
{{hc|File: /root/watch.sh|<nowiki><br />
<br />
#!/bin/bash<br />
<br />
EFI_DIR="/boot/efi/EFI/arch"<br />
<br />
<br />
INITRD="$1"<br />
IMAGE="$2"<br />
IMAGE_BASENAME=$(basename $2)<br />
EFI_IMAGE="$EFI_DIR/$IMAGE_BASENAME.efi"<br />
<br />
function do_copy(){<br />
cp $INITRD $EFI_DIR<br />
cp $IMAGE $EFI_IMAGE<br />
echo "Synced $INITRD to $EFI_DIR"<br />
}<br />
<br />
while [ : ]; do<br />
<br />
if [[ ! -d "/proc/$PPID" ]]; then<br />
do_copy<br />
exit 1<br />
fi<br />
sleep 1<br />
<br />
done<br />
<br />
</nowiki>}}<br />
<br />
<br />
Then simply add {{ic|uefi}} to the list of hooks in {{ic|/etc/mkinitcpio.conf}}<br />
<br />
=== Booting EFISTUB ===<br />
<br />
There are various ways of booting EFISTUB kernels. Those described here are:<br />
<br />
# Using rEFInd UEFI Boot Manager<br />
# Using UEFI Shell<br />
# Using efibootmgr entry<br />
<br />
==== Using rEFInd ====<br />
<br />
rEFInd is a fork of rEFIt Boot Manager (used in Intel Macs) by Rod Smith (author is GPT-fdisk). rEFInd fixes many issues in rEFIt with respect to non-Mac UEFI booting and also has support for booting EFISTUB kernels and contains some features specific to them. More info about rEFInd support for EFISTUB is at http://www.rodsbooks.com/refind/linux.html .<br />
<br />
There are two ways of installing rEFInd. One is using the {{Pkg|refind-efi-x86_64}} from [extra] repo or {{AUR|refind-efi-x86_64-git}} AUR package (only for x86_64 UEFI) (recommended). The other is to use the precompiled binaries provided by upstream at http://sourceforge.net/projects/refind/ . If you downloaded the precompiled binaries provided by upstream, then setup rEFInd as follows ({{ic|/boot/efi}} is UEFISYS partition mountpoint):<br />
<br />
# Extract the refind-bin-*.zip file.<br />
# Copy {{ic|refind}} directory to {{ic|/boot/efi/EFI/arch/refind}}<br />
# Rename {{ic|/boot/efi/EFI/arch/refind/refind.conf-sample}} to {{ic|/boot/efi/EFI/arch/refind/refind.conf}} and edit it according to your needs. It is possible define boot entries within {{ic|refind.conf}} itself. Follow the example menuentries defined in {{ic|/boot/efi/EFI/arch/refind/refind.conf}} to create your own.<br />
# Rename {{ic|/boot/efi/EFI/arch/refind/refind_x64.efi}} to {{ic|/boot/efi/EFI/arch/refind/refindx64.efi}}. (Or refind_ia32.efi to refindia32.efi in case of 32-bit UEFI).<br />
<br />
The above steps are automatically done by the AUR package. After setting up, create {{ic|/boot/efi/EFI/arch/refind_linux.conf}} with the kernel parameters to be used to EFISTUB kernel by rEFInd. An example file is shown below.<br />
<br />
{{hc|/boot/efi/EFI/arch/refind_linux.conf|<nowiki><br />
"Boot with defaults" "root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap"<br />
"Boot to Terminal" "root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap 3"</nowiki>}}<br />
<br />
These options are displayed as a submenu by rEFInd. The sub-menu can be accessed by using "+" or "insert" keys.<br />
<br />
In non-Mac systems create an entry for rEFInd using efibootmgr. <br />
<br />
# efibootmgr -c -l \\EFI\\arch\\refind\\refindx64.efi -L rEFInd -p X<br />
<br />
"X" is the partition number containing the bootloader.<br />
<br />
In case of Apple Macs, try {{AUR|mactel-boot}} for an experimental "bless" utility for Linux. If that does not work, use "bless" form within OSX to set rEFInd as default bootloader. Assuming UEFISYS partition is mounted at {{ic|/mnt/efi}} within OSX, do<br />
<br />
$ sudo bless --setBoot --folder /mnt/efi/EFI/refind --file /mnt/efi/EFI/refind/refindx64.efi<br />
<br />
==== Using UEFI Shell ====<br />
<br />
It is possible to launch EFISTUB kernel form UEFI Shell as if its a normal UEFI application. In this case the kernel parameters are passed as normal parameters to the launched EFISTUB kernel file.<br />
<br />
> fs0:<br />
> cd \EFI\arch<br />
> vmlinuz-linux.efi root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap initrd=\EFI\arch\initramfs-linux.img<br />
<br />
==== Using efibootmgr entry ====<br />
<br />
It is possible to directly embed the kernel parameters within the boot entry created by efibootmgr. Do (as root)<br />
<br />
# echo "root=/dev/sdaX ro rootfstype=ext4 add_efi_memmap initrd=\\EFI\\arch\\initramfs-linux.img" | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1 --label "Archlinux (EFISTUB)" --loader "\\EFI\\arch\\vmlinuz-linux.efi" --append-binary-args -<br />
<br />
{{Note|The trailing hyphen after {{ic|--append-binary-args}} is required to instruct efibootmgr to read the parameters from STDIN (standard input). The code should be {{ic|--append-binary-args -}} .}}<br />
<br />
More info about efibootmgr at [[UEFI#efibootmgr]]. Forum post https://bbs.archlinux.org/viewtopic.php?pid=1090040#p1090040 .<br />
<br />
== GRUB(2) ==<br />
<br />
GRUB(2) contains its own filesystem drivers and does not rely on the firmware to access the files. It can directly read files from {{ic|/boot}} and does not require the kernel and initramfs files to be in the UEFISYS partition. Detailed information at [[GRUB#UEFI_systems_2]]. For bzr development version try AUR package - {{AUR|grub-efi-x86_64-bzr}}.<br />
<br />
== GRUB Legacy Fedora ==<br />
<br />
[[GRUB Legacy]] upstream sources (and the package Archlinux ships) do not support UEFI. However Fedora/Redhat's fork contains UEFI patches provided by Intel. The patched sources are at https://github.com/vathpela/grub-fedora . GRUB-Legacy-Fedora contains its own filesystem drivers (including ext4) and does not rely on the firmware to access the files. Thus it can directly read files form /boot and does not require the kernel and initramfs files to be in the UEFISYS partition. AUR package - {{AUR|grub-legacy-fedora-efi-x86_64-git}} (only for x86_64 UEFI).<br />
<br />
{{Note|Fedora developers have mentioned that after the release of Fedora 17, grub-legacy-fedora development will stop and Fedora will be switching to GRUB(2) as the default UEFI bootloader from F18 onwards. Fedora already uses GRUB(2) as its default BIOS bootloader since F16. Users are recommended to switch to EFISTUB or GRUB(2) instead.}}<br />
<br />
== ELILO ==<br />
<br />
ELILO is the UEFI version of LILO Boot Loader. It was originally created for Intel Itanium systems which supported only EFI (precursor to UEFI). It is the oldest UEFI bootloader for Linux. It is still in development but happens at a very slow pace. Upstream provided compiled binaries are available at http://sourceforge.net/projects/elilo/ . Elilo config file {{ic|elilo.conf}} is similar to [[LILO]]'s config file. AUR package - {{AUR|elilo-x86_64}} (only for x86_64 UEFI).<br />
<br />
== EFILINUX ==<br />
<br />
EFILINUX is a reference implementation of a UEFI Linux bootloader and precursor to Kenrel EFISTUB support. It is considered to be a alpha quality software (as on 16-MAY-2012). Upstream sources are at https://github.com/mfleming/efilinux . and the usage instructions are at http://thread.gmane.org/gmane.linux.kernel/1172645 and http://article.gmane.org/gmane.linux.kernel/1175060 . AUR packages - {{AUR|efilinux-x86_64}} and {{AUR|efilinux-x86_64-git}} (only for x86_64 UEFI).<br />
<br />
==See also==<br />
<br />
* [http://www.rodsbooks.com/efi-bootloaders/ Rod Smith - Managing EFI Boot Loaders for Linux]<br />
* [http://www.rodsbooks.com/refind/ Rod Smith - rEFInd, a fork or rEFIt]<br />
* [https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/efi-stub.txt;hb=HEAD Linux Kernel Documentation on EFISTUB]<br />
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=291f36325f9f252bd76ef5f603995f37e453fc60;hp=55839d515495e766605d7aaabd9c2758370a8d27 Linux Kernel EFISTUB Git Commit]<br />
* [http://www.rodsbooks.com/efi-bootloaders/efistub.html Rod Smith's page on EFISTUB]<br />
* [http://www.rodsbooks.com/refind/linux.html rEFInd Documentation for booting EFISTUB Kernels]</div>Geekbabyhttps://wiki.archlinux.org/index.php?title=Unified_Extensible_Firmware_Interface_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=222445Unified Extensible Firmware Interface (简体中文)2012-09-10T13:42:33Z<p>Geekbaby: </p>
<hr />
<div>[[Category:Boot process]]<br />
[[ru:Unified Extensible Firmware Interface]]<br />
[[zh-CN:Unified Extensible Firmware Interface]]<br />
{{Article summary start}}<br />
{{Article summary text|An overview of the Unified Extensible Firmware Interface.}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|GUID Partition Table}}<br />
{{Article summary wiki|Master Boot Record}}<br />
{{Article summary wiki|Arch Boot Process}}<br />
{{Article summary end}}<br />
<br />
'''统一可扩展固件界面(Unified Extensible Firmware Interface)''' (或者简称为UEFI) 最初是由Intel为基于安腾系统设计的一种新型固件。 它介绍了一种新的启动系统的方式,该方式有别于传统BIOS系统所使用的“MBR启动代码”。它起始于Intel EFI的1.x版本,之后被称作UEFI论坛的一群公司接管了它的开发工作。从此,它被称为统一的EFI,其版本始于2.0。自2012年5月23号起,UEFI规格2.3.1是最新的一个版本。<br />
<br />
{{note|除非特别指定为EFI 1.x,否者EFI以及UEFI这两者是可以互换使用的,均是指UEFI 2.x固件。同样,除非明确指出, these instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and therefore it is not a standard UEFI firmware.}}<br />
<br />
== Booting an OS using BIOS ==<br />
<br />
A BIOS or Basic Input-Output System is the very first program that is executed once the system is switched on. After all the hardware has been initialized and the POST operation has completed, the BIOS executes the first boot code in the first device in the device booting list. <br />
<br />
If the list starts with a CD/DVD drive, then the El-Torito entry in the CD/DVD is executed. This is how bootable CD/DVD works. If the list starts with a HDD, then BIOS executes the very first 440 bytes MBR boot code. The boot code then chainloads or bootstraps a much larger and complex bootloader which then loads the OS.<br />
<br />
Basically, the BIOS does not know how to read a partition table or filesystem. All it does is initialize the hardware, then load and run the 440-byte boot code.<br />
<br />
=== Multiboot on BIOS ===<br />
<br />
Since very little can be achieved by a program that fits into the 440-byte boot code area, multi-booting using BIOS requires a multi-boot capable bootloader (multi-boot refers to booting multiple operating systems, not to booting a kernel in the Multiboot format specified by the GRUB developers). So usually a common bootloader like [[GRUB]] or [[GRUB2]] or [[Syslinux]] or [[LILO]] would be loaded by the BIOS, and it would load an operating system by either chain-loading or directly loading the kernel.<br />
<br />
== Booting an OS using UEFI ==<br />
<br />
UEFI firmware does not support booting through the above mentioned method which is the only way supported by BIOS. UEFI has support for reading both the partition table as well as understanding filesystems. <br />
<br />
The commonly used UEFI firmwares support both MBR and GPT partition table. EFI in Apple-Intel Macs are known to support Apple Partition Map also apart from MBR and GPT. Most of the UEFI firmwares have support for accessing FAT12 (floppy disks) , FAT16 and FAT32 filesystems in HDD and ISO9660 (and UDF) in CD/DVDs. EFI in Apple-Intel Macs can access HFS/HFS+ filesystems also apart from the mentioned ones.<br />
<br />
UEFI does not launch any boot code in the MBR whether it exists or not. Instead it uses a special partition in the partition table called "EFI SYSTEM PARTITION" in which files required to be launched by the firmware is stored. Each vendor can store its files under <EFI SYSTEM PARTITION>/EFI/<VENDOR NAME>/ folder and can use the firmware or its shell (UEFI shell) to launch the boot program. An EFI System Partition is usually formatted as FAT32.<br />
<br />
Under UEFI, every program whether they are OS loaders or some utilities (like memory testing apps) or recovery tools outside the OS, should be a UEFI Application corresponding to the EFI firmware architecture. Most of the UEFI firmware in the market, including recent Apple Macs use x86_64 EFI firmware. Only some older macs use i386 EFI firmware while no non-Apple UEFI system is known to use i386 EFI firmware.<br />
<br />
A x86_64 EFI firmware does not include support for launching 32-bit EFI apps unlike the 64-bit Linux and Windows which include such support. Therefore the bootloader must be compiled for that architecture correctly.<br />
<br />
=== Multibooting on UEFI ===<br />
<br />
Since each OS or vendor can maintain its own files within the EFI SYSTEM PARTITION without affecting the other, multi-booting using UEFI is just a matter of launching a different UEFI application corresponding to the particular OS's bootloader. This removes the need for relying on chainloading mechanisms of one bootloader to load another to switch OSes.<br />
<br />
==== Linux Windows x86_64 UEFI-GPT Multiboot ====<br />
<br />
Windows Vista (SP1+) and 7 pr 8 x86_64 versions support booting natively using UEFI firmware. But for this they need [[GPT]] partitioning of the disk used for UEFI booting. Windows x86_64 versions support either UEFI-GPT booting or BIOS-MBR booting. Windows 32-bit versions support only BIOS-MBR booting. Follow the instructions provided in the forum link given in the references sections as to how to do this. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;2581408 for more info.<br />
<br />
This limitation does not exist in Linux Kernel but rather depends on the bootloader used. For the sake of Windows UEFI booting, the Linux bootloader used should also be installed in UEFI-GPT mode if booting from the same disk.<br />
<br />
== Boot Process under UEFI ==<br />
<br />
# System switched on - Power On Self Test, or POST process.<br />
# UEFI firmware is loaded.<br />
# Firmware reads its Boot Manager to determine which UEFI application to be launched and from where (ie. from which disk and partition).<br />
# Firmware launches the UEFI application from the FAT32 formatted UEFISYS partition as defined in the boot entry in the firmware's boot manager.<br />
# UEFI application may launch another application (in case of UEFI Shell or a boot manager like rEFInd) or the kernel and initramfs (in case of a bootloader like GRUB2) depending on how the UEFI application was configured.<br />
<br />
== Detecting UEFI Firmware Arch ==<br />
<br />
If you have a non-mac UEFI system, then you have a x86_64 (aka 64-bit) UEFI 2.x firmware.<br />
<br />
Some of the known x86_64 UEFI 2.x firmwares are Phoenix SecureCore Tiano, AMI Aptio, Insyde H2O.<br />
<br />
Some of the known systems using these firmwares are Asus EZ Mode BIOS (in Sandy Bridge P67 and H67 motherboards), MSI ClickBIOS, HP EliteBooks, Sony Vaio Z series, many Intel Server and Desktop motherboards<br />
<br />
<br />
Pre-2008 Macs mostly have i386-efi firmware while >=2008 Macs have mostly x86_64-efi. All macs capable of running Mac OS X Snow Leopard 64-bit Kernel have x86_64 EFI 1.x firmware.<br />
<br />
To find out the arch of the efi firmware in a Mac, boot into Mac OS X and type the following command<br />
<br />
<pre><br />
ioreg -l -p IODeviceTree | grep firmware-abi<br />
</pre><br />
<br />
If the command returns EFI32 then it is i386 EFI 1.x firmware. If it returns EFI64 then it is x86_64 EFI 1.x firmware. Macs do not have UEFI 2.x firmware as Apple's EFI implementation is not fully compliant with UEFI Specification.<br />
<br />
== UEFI Support in Linux Kernel ==<br />
<br />
=== Linux Kernel config options for UEFI ===<br />
<br />
The required Linux Kernel configuration options for UEFI systems are :<br />
<br />
CONFIG_EFI=y<br />
CONFIG_EFI_STUB=y<br />
CONFIG_RELOCATABLE=y<br />
CONFIG_FB_EFI=y<br />
CONFIG_FRAMEBUFFER_CONSOLE=y<br />
<br />
UEFI Runtime Variables/Services Support - 'efivars' kernel module . This option is important as this is required to manipulate UEFI Runtime Variables using tools like '''efibootmgr'''.<br />
<br />
CONFIG_EFI_VARS=m<br />
<br />
{{Note| This option is compiled as module in Arch core/testing kernel.}}<br />
<br />
{{Note|For Linux to access UEFI Runtime Services, the UEFI Firmware processor architecture and the Linux kernel processor architecture must match. This is independent of the bootloader used.}}<br />
<br />
{{Note|If the UEFI Firmware arch and Linux Kernel arch are different, then the "'''noefi'''" kernel parameter must be used to avoid the kernel panic and boot successfully. The "noefi" option instructs the kernel not to access the UEFI Runtime Services.}}<br />
<br />
GUID Partition Table [[GPT]] config option - mandatory for UEFI support<br />
<br />
CONFIG_EFI_PARTITION=y<br />
<br />
{{Note|All of the above options are required to boot Linux via UEFI, and are enabled in Archlinux kernels in official repos.}}<br />
<br />
Retrieved from http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/x86_64/uefi.txt;hb=HEAD .<br />
<br />
== UEFI Variables Support ==<br />
<br />
UEFI defines variables through which an operating system can interact with the firmware. UEFI Boot Variables are used by the boot-loader and used by the OS only for early system start-up. UEFI Runtime Variables allow an OS to manage certain settings of the firmware like the UEFI Boot Manager or managing the keys for UEFI Secure Boot Protocol etc.<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + x86 32-bit Kernel and vice-versa config will not work. This is true only for efivars kernel module and efibootmgr step. The other steps (ie. upto setting up <UEFISYS>/efi/arch/grub.{efi,cfg} ) can be done even in BIOS/Legacy boot mode.}}<br />
<br />
Access to UEFI Runtime services is provided by "efivars" kernel module which is enabled through the {{ic|<nowiki>CONFIG_EFI_VAR=m</nowiki>}} kernel config option. This module once loaded exposes the variables under the directory {{ic|/sys/firnware/efi/vars}}. One way to check whether the system has booted in UEFI boot mode is to load the "efivars" kernel module and check for the existence of {{ic|/sys/firnware/efi/vars}} directory with contents similar to :<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel):<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
The UEFI Runtime Variables will not be exposed to the OS if you have used "noefi" kernel parameter in the boot-loader menu. This parameter instructs the kernel to completely ignore UEFI Runtime Services.<br />
<br />
=== Userspace Tools ===<br />
<br />
There are few tools that can access/modify the UEFI variables, namely<br />
<br />
# efibootmgr - Used to create/modify boot entries in the UEFI Boot Manager - {{Pkg|efibootmgr}} or {{AUR|efibootmgr-git}}<br />
# uefivars - simply dumps the variables - {{AUR|uefivars-git}} - uses efibootmgr library<br />
# Ubuntu's Firmware Test Suite - fwts - {{AUR|fwts-git}} - uefidump command - {{ic|fwts uefidump}} <br />
<br />
=== Non-Mac UEFI systems ===<br />
<br />
==== efibootmgr ====<br />
<br />
{{Warning|Using {{ic|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs. Experimental "bless" utility for Linux by Fedora developers - {{AUR|mactel-boot}}.}}<br />
<br />
{{Note|{{ic|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Otherwise the message {{ic|Fatal: Couldn't open either sysfs or procfs directories for accessing EFI variables}} is shown.}}<br />
<br />
Initially the user may be required to manually launch the boot-loader from the firmware itself (using maybe the UEFI Shell) if the UEFI boot-loader was installed when the system is booted in BIOS mode. Then {{ic|efibootmgr}} should be run to make the UEFI boot-loader entry as the default entry in the UEFI Boot Manager.<br />
<br />
To use efibootmgr, first load the 'efivars' kernel module:<br />
<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables (noefi?).<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode, without the "noefi" kernel parameter.<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{ic|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB.<br />
<br />
{{Note| The below commands use grub-efi-x86_64 boot-loader as example.}}<br />
<br />
Assume the boot-loader file to be launched is {{ic|/boot/efi/efi/arch_grub/grubx64.efi}}. {{ic|/boot/efi/efi/arch_grub/grubx64.efi}} can be split up as {{ic|/boot/efi}} and {{ic|/efi/arch_grub/grubx64.efi}}, wherein {{ic|/boot/efi}} is the mountpoint of the UEFI System Partition, which is assumed to be /dev/sdXY (here X and Y are just placeholders for the actual values - eg:- in /dev/sda1 , X=a Y=1).<br />
<br />
To determine the actual device path for the UEFI System Partition, try :<br />
<br />
# cat /proc/self/mounts | grep /boot/efi | awk '{print $1}'<br />
/dev/sdXY<br />
<br />
Then create the boot entry using efibootmgr as follows :<br />
<br />
# efibootmgr --create --gpt --disk /dev/sdX --part Y --write-signature --label "Arch Linux (GRUB2)" --loader '\EFI\arch_grub\grubx64.efi'<br />
<br />
In the above command {{ic|/boot/efi/efi/arch_grub/grubx64.efi}} translates to {{ic|/boot/efi}} and {{ic|/efi/arch_grub/grubx64.efi}} which in turn translate to drive {{ic|/dev/sdX}} -> partition Y -> file {{ic|/EFI/arch_grub/grubx64.efi}}.<br />
<br />
UEFI uses backward slash as path separator (similar to Windows paths).<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README] .<br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{ic|\EFI\arch_grub\grubx64.efi}} or {{ic|\efi\arch_grub\grubx64.efi}} does not matter (this will change if the filesystem encoding is UTF-8).<br />
<br />
== Linux Bootloaders for UEFI ==<br />
<br />
See [[UEFI Bootloaders]].<br />
<br />
== Create an UEFI System Partition in Linux ==<br />
<br />
{{Note|The UEFISYS partition can be of any size supported by FAT32 filesystem. According to Microsoft Documentation, the minimum partition/volume size for FAT32 is 512 MiB. Therefore it is recommended for UEFISYS partition to be atleast 512 MiB. Higher partition sizes are fine, especially if you use multiple UEFI bootloaders, or multiple OSes booting via UEFI, so that there is enough space to hold all the related files. If you are using Linux EFISTUB booting, then you need to make sure there is adequate space available for keeping the Kernel and Initramfs files in the UEFISYS partition.}}<br />
<br />
=== For GPT partitioned disks ===<br />
Two choices:<br />
* Using GNU Parted/GParted: Create a FAT32 partition. Set "boot" flag on for that partition.<br />
* Using GPT fdisk (aka gdisk): Create a partition with gdisk type code "EF00". Then format that partition as FAT32 using {{ic|mkfs.vfat -F32 /dev/<THAT_PARTITION>}}<br />
<br />
{{Note|Setting "boot" flag in parted in a MBR partition marks that partition as active, while the same "boot" flag in a GPT partition marks that partition as "UEFI System Partition".}}<br />
<br />
{{Warning|Do not use util-linux fdisk, cfdisk or sfdisk to change the type codes in a GPT disk. Similarly do not use gptfdisk gdisk, cgdisk or sgdisk on a MBR disk, it will be automatically converted to GPT (no data loss will occur, but the system will fail to boot).}}<br />
<br />
=== For MBR partitioned disks ===<br />
Two choices:<br />
* Using GNU Parted/GParted: Create FAT32 partition. Change the type code of that partition to 0xEF using fdisk, cfdisk or sfdisk.<br />
* Using fdisk: Create a partition with partition type 0xEF and format it as FAT32 using {{ic|mkfs.vfat -F32 /dev/<THAT_PARTITION>}}<br />
<br />
{{Note|It is recommended to use always GPT for UEFI boot as some UEFI firmwares do not allow UEFI-MBR boot.}}<br />
<br />
== UEFI Shell ==<br />
<br />
The UEFI Shell is a shell/terminal for the firmware which allows launching uefi applications which include uefi bootloaders. Apart from that, the shell can also be used to obtain various other information about the system or the firmware like memory map (memmap), modifying boot manager variables (bcfg), running partitioning programs (diskpart), loading uefi drivers, editing text files (edit), hexedit etc. <br />
<br />
=== UEFI Shell download links === <br />
<br />
You can download a BSD licensed UEFI Shell from Intel's Tianocore UDK/EDK2 Sourceforge.net project.<br />
<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ShellBinPkg/UefiShell/X64/Shell.efi x86_64 UEFI Shell 2.0 (Beta)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/X64/Shell_Full.efi x86_64 UEFI Shell 1.0 (Old)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ShellBinPkg/UefiShell/Ia32/Shell.efi i386 UEFI Shell 2.0 (Beta)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/Ia32/Shell_Full.efi i386 UEFI Shell 1.0 (Old)]<br />
<br />
Shell 2.0 works only in UEFI 2.3+ systems and is recommended over Shell 1.0 in those systems. Shell 1.0 should work in all UEFI systems irrespective of the spec. version the firmware follows. More info at [http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=ShellPkg ShellPkg] and [http://sourceforge.net/mailarchive/message.php?msg_id=28690732 this mail]<br />
<br />
=== Launching UEFI Shell ===<br />
<br />
Few Asus and other AMI Aptio x86_64 UEFI firmware based motherboards (from Sandy Bridge onwards) provide an option called {{ic|"Launch EFI Shell from filesystem device"}} . For those motherboards, download the x86_64 UEFI Shell and copy it to your UEFI SYSTEM PARTITION as {{ic|<UEFI_SYSTEM_PARTITION>/shellx64.efi}} (mostly {{ic|/boot/efi/shellx64.efi}}) .<br />
<br />
Systems with Phoenix SecureCore Tiano UEFI firmware are known to have embedded UEFI Shell which can be launched using either F6, F11 or F12 key.<br />
<br />
{{Note|If you are unable to launch UEFI Shell from the firmware directly using any of the above mentioned methods, create a FAT32 USB pen drive with Shell.efi copied as (USB)/efi/boot/bootx64.efi . This USB should come up in the firmware boot menu. Launching this option will launch the UEFI Shell for you.}}<br />
<br />
=== Important UEFI Shell Commands === <br />
<br />
More info at http://software.intel.com/en-us/articles/efi-shells-and-scripting/<br />
<br />
==== bcfg ====<br />
<br />
BCFG command is used to modify the UEFI NVRAM entries, which allow the user to change the boot entries or driver options. This command is described in detail in page 83 (Section 5.3) of "UEFI Shell Specification 2.0" pdf document.<br />
<br />
{{Note| Users are recommended to try {{ic|bcfg}} only if {{ic|efibootmgr}} fails to create working boot entries in their system.}}<br />
<br />
{{Note| UEFI Shell 1.0 does not support {{ic|bcfg}} command.}}<br />
<br />
To dump a list of current boot entries -<br />
<br />
Shell> bcfg boot dump -v<br />
<br />
To add a boot menu entry for grub2's grubx64.efi (for example) as 4th (numbeering starts from zero) option in the boot menu<br />
<br />
Shell> bcfg boot add 3 fs0:\EFI\arch\grubx64.efi "Arch Linux (GRUB2)"<br />
<br />
where fs0: is the mapping corresponding to the UEFI System Partition and \EFI\arch\grubx64.efi is the file to be launched.<br />
<br />
To remove the 4th boot option<br />
<br />
Shell> bcfg boot rm 3<br />
<br />
To move the boot option #3 to #0 (i.e. 1st or the default entry in the UEFI Boot menu)<br />
<br />
Shell> bcfg boot mv 3 0<br />
<br />
For bcfg help text<br />
<br />
Shell> help bcfg -v -b<br />
<br />
or<br />
<br />
Shell> bcfg -? -v -b<br />
<br />
==== edit ====<br />
<br />
EDIT command provides a basic text editor with an interface similar to nano text editor, but slightly less functional. It handles UTF-8 encoding and takes care or LF vs CRLF line endings.<br />
<br />
To edit, for example grub2's grub.cfg in the UEFI System Partition (fs0: in the firmware)<br />
<br />
Shell> fs0:<br />
FS0:\> cd \efi\grub<br />
FS0:\efi\grub\> edit grub.cfg<br />
<br />
== Hardware Compatibility ==<br />
<br />
Main page [[HCL/Firmwares/UEFI]]<br />
<br />
<br />
== Create UEFI bootable USB from ISO ==<br />
<br />
{{Note|dd'ing the ISO (isohybrid method) to the USB drive will not work for UEFI boot.}}<br />
<br />
=== Archiso ===<br />
<br />
1. Create a directory {{ic|/tmp/archiso}} and extract the archiso file contents to it (use file-roller or something similiar).<br />
<br />
2. Create a directory {{ic|/tmp/archiso_efiboot}} and extract {{ic|/tmp/archiso/EFI/archiso/efiboot.img}} to it using {{ic|7z}} command from {{Pkg|p7zip}} package (use file-roller, or 7z)<br />
<br />
Example for 7z:<br />
$ 7z e -opath efiboot.img # without space between -o and path<br />
<br />
3. Run the below commands:<br />
<br />
$ mkdir -p /tmp/archiso/EFI/{archiso,boot}<br />
$ cp /tmp/archiso/arch/boot/x86_64/vmlinuz /tmp/archiso/EFI/archiso/vmlinuz.efi<br />
$ cp /tmp/archiso/arch/boot/x86_64/archiso.img /tmp/archiso/EFI/archiso/archiso.img<br />
$ cp /tmp/archiso_efiboot/bootx64.efi /tmp/archiso/EFI/boot/bootx64.efi<br />
$ cp /tmp/archiso_efiboot/startup.nsh /tmp/archiso/EFI/boot/startup.nsh<br />
<br />
4. Find out the filesystem label to be used for the USB by reading "{{ic|1=archisolabel=}}" part in {{ic|/tmp/archiso/EFI/boot/startup.nsh}}. For example if {{ic|/tmp/archiso/EFI/boot/startup.nsh}} has {{ic|1=archisolabel=ARCH_201208}} then the filesystem label to be used is {{ic|ARCH_201208}} . <br />
<br />
5. Create a directory {{ic|/tmp/archisousb}} . Format the USB drive as FAT32 (or FAT16) (no other filesystem is supported) and set the filesystem label same as the one obtained in step 4, and mount it to {{ic|/tmp/archisousb}} .<br />
<br />
6. Copy the contents of {{ic|/tmp/archiso}} to {{ic|/tmp/archisousb}} and then umount {{ic|/tmp/archisousb}} .<br />
<br />
=== [[Archboot]] ===<br />
<br />
1. Create a directory {{ic|/tmp/archboot}} and extract the archiso file contents to it.<br />
<br />
{{Note|Follow steps 2 and 3 only if {{ic|/tmp/archboot/EFI/boot/bootx64.efi}} does not exist, even after extracting archboot iso to {{ic|/tmp/archboot}} .}}<br />
<br />
2. Create a directory {{ic|/tmp/archboot_efiboot}} and extract {{ic|/tmp/archboot/boot/grub/grub_uefi_x86_64.bin}} to it using {{ic|7z}} command from {{Pkg|p7zip}} package.<br />
<br />
3. Run the below commands:<br />
<br />
# mkdir -p /tmp/archboot/EFI/boot<br />
# cp /tmp/archboot_efiboot/EFI/boot/bootx64.efi /tmp/archboot/EFI/boot/bootx64.efi<br />
<br />
4. Create a directory {{ic|/tmp/archbootusb}} . Format the USB drive as FAT32 (or FAT16) (no other filesystem is supported) and mount it to {{ic|/tmp/archbootusb}} .<br />
<br />
5. Copy the contents of {{ic|/tmp/archboot}} to {{ic|/tmp/archbootusb}} and then umount {{ic|/tmp/archbootusb}} .<br />
<br />
== Remove UEFI boot support from ISO ==<br />
<br />
Most of the 32-bit EFI Macs and some 64-bit EFI Macs refuse to boot from a UEFI(X64)+BIOS bootable CD/DVD. In these cases the iso should be rebuilt without UEFI boot support, retaining only BIOS boot.<br />
<br />
=== Archiso ===<br />
<br />
1. Obtain the ISO label from the output of {{ic|file <path_to_iso>}}. Let it be {{ic|ARCH_201208}} for example.<br />
<br />
2. Create a directory {{ic|/tmp/archiso}} and extract the archiso file contents to it.<br />
<br />
3. Run {{ic|xorriso}} (part of {{Pkg|libisoburn}} package) as shown below:<br />
<br />
$ xorriso -as mkisofs -iso-level 3 \<br />
-full-iso9660-filenames \<br />
-volid "ARCH_201208" \<br />
-appid "Arch Linux Live/Rescue CD" \<br />
-publisher "Arch Linux <https://www.archlinux.org>" \<br />
-preparer "prepared by user" \<br />
-eltorito-boot isolinux/isolinux.bin \<br />
-eltorito-catalog isolinux/boot.cat \<br />
-no-emul-boot -boot-load-size 4 -boot-info-table \<br />
-isohybrid-mbr "/tmp/archiso/isolinux/isohdpfx.bin" \<br />
-output "/tmp/archiso.iso" "/tmp/archiso/"<br />
<br />
4. Burn {{ic|/tmp/archiso.iso}} to a CD and boot into your Mac using that CD.<br />
<br />
=== [[Archboot]] ===<br />
<br />
1. Create a directory {{ic|/tmp/archboot}} and extract the archboot iso file contents to it.<br />
<br />
2. Run {{ic|xorriso}} (part of {{Pkg|libisoburn}} package) as shown below:<br />
<br />
$ xorriso -as mkisofs -iso-level 3 -rock -joliet \<br />
-max-iso9660-filenames -omit-period \<br />
-omit-version-number -allow-leading-dots \<br />
-relaxed-filenames -allow-lowercase -allow-multidot \<br />
-volid "ARCHBOOT" -preparer "prepared by user" \<br />
-eltorito-boot boot/syslinux/isolinux.bin \<br />
-eltorito-catalog boot/syslinux/boot.cat \<br />
-no-emul-boot -boot-load-size 4 -boot-info-table \<br />
-isohybrid-mbr /tmp/archboot/boot/syslinux/isohdpfx.bin \<br />
-output "/tmp/archboot.iso" "/tmp/archboot/"<br />
<br />
3. Burn {{ic|/tmp/archboot.iso}} to a CD and boot into your Mac using that CD.<br />
<br />
== See also ==<br />
<br />
* Wikipedia's page on [http://en.wikipedia.org/wiki/UEFI UEFI]<br />
* Wikipedia's page on [http://en.wikipedia.org/wiki/EFI_System_partition UEFI SYSTEM Partition]<br />
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/x86_64/uefi.txt;hb=HEAD Linux Kernel UEFI Documentation]<br />
* [http://www.uefi.org/home/ UEFI Forum] - contains the official [http://www.uefi.org/specs/ UEFI Specifications] - GUID Partition Table is part of UEFI Specification<br />
* [http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Welcome_to_TianoCore Intel's Tianocore Project] for Open-Source UEFI firmware which includes DuetPkg for direct BIOS based booting and OvmfPkg used in QEMU and Oracle VirtualBox<br />
* [http://www.intel.com/technology/efi/ Intel's page on EFI]<br />
* [http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/efi-boot-process.html FGA: The EFI boot process]<br />
* [http://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx Microsoft's Windows and GPT FAQ] - Contains info on Windows UEFI booting also<br />
* [https://gitorious.org/tianocore_uefi_duet_builds/pages/Windows_x64_BIOS_to_UEFI Convert Windows Vista SP1+ or 7 x86_64 boot from BIOS-MBR mode to UEFI-GPT mode without Reinstall]<br />
* [https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB Create a Linux BIOS+UEFI and Windows x64 BIOS+UEFI bootable USB drive]<br />
* [http://rodsbooks.com/bios2uefi/ Rod Smith - A BIOS to UEFI Transformation]<br />
* [https://lkml.org/lkml/2011/6/8/322 UEFI Boot problems on some newer machines (LKML)]<br />
* [http://software.intel.com/en-us/articles/efi-shells-and-scripting/ EFI Shells and Scripting - Intel Documentation]<br />
* [http://software.intel.com/en-us/articles/uefi-shell/ UEFI Shell - Intel Documentation]<br />
* [http://www.hpuxtips.es/?q=node/293 UEFI Shell - bcfg command info]<br />
* [http://hackthejoggler.freeforums.org/download/file.php?id=28 Some useful 32-bit UEFI Shell utilities]</div>Geekbabyhttps://wiki.archlinux.org/index.php?title=Unified_Extensible_Firmware_Interface_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=222444Unified Extensible Firmware Interface (简体中文)2012-09-10T13:41:56Z<p>Geekbaby: </p>
<hr />
<div>[[Category:Boot process]]<br />
[[ru:Unified Extensible Firmware Interface]]<br />
[[zh-CN:Unified Extensible Firmware Interface]]<br />
{{Article summary start}}<br />
{{Article summary text|An overview of the Unified Extensible Firmware Interface.}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|GUID Partition Table}}<br />
{{Article summary wiki|Master Boot Record}}<br />
{{Article summary wiki|Arch Boot Process}}<br />
{{Article summary end}}<br />
<br />
'''统一可扩展固件界面(Unified Extensible Firmware Interface)''' (或者简称为UEFI) 最初是由Intel为基于安腾系统设计的一种新型固件。 它介绍了一种新的启动系统的方式,该方式有别于传统BIOS系统所使用的“MBR启动代码”。它起始于Intel EFI的1.x版本,之后被称作UEFI论坛的一群公司接管了它的开发工作。从此,它被称为统一的EFI,其版本始于2.0。自2012年5月23号起,UEFI规格2.3.1是最新的一个版本。<br />
<br />
{{注|除非特别指定为EFI 1.x,否者EFI以及UEFI这两者是可以互换使用的,均是指UEFI 2.x固件。同样,除非明确指出, these instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and therefore it is not a standard UEFI firmware.}}<br />
<br />
== Booting an OS using BIOS ==<br />
<br />
A BIOS or Basic Input-Output System is the very first program that is executed once the system is switched on. After all the hardware has been initialized and the POST operation has completed, the BIOS executes the first boot code in the first device in the device booting list. <br />
<br />
If the list starts with a CD/DVD drive, then the El-Torito entry in the CD/DVD is executed. This is how bootable CD/DVD works. If the list starts with a HDD, then BIOS executes the very first 440 bytes MBR boot code. The boot code then chainloads or bootstraps a much larger and complex bootloader which then loads the OS.<br />
<br />
Basically, the BIOS does not know how to read a partition table or filesystem. All it does is initialize the hardware, then load and run the 440-byte boot code.<br />
<br />
=== Multiboot on BIOS ===<br />
<br />
Since very little can be achieved by a program that fits into the 440-byte boot code area, multi-booting using BIOS requires a multi-boot capable bootloader (multi-boot refers to booting multiple operating systems, not to booting a kernel in the Multiboot format specified by the GRUB developers). So usually a common bootloader like [[GRUB]] or [[GRUB2]] or [[Syslinux]] or [[LILO]] would be loaded by the BIOS, and it would load an operating system by either chain-loading or directly loading the kernel.<br />
<br />
== Booting an OS using UEFI ==<br />
<br />
UEFI firmware does not support booting through the above mentioned method which is the only way supported by BIOS. UEFI has support for reading both the partition table as well as understanding filesystems. <br />
<br />
The commonly used UEFI firmwares support both MBR and GPT partition table. EFI in Apple-Intel Macs are known to support Apple Partition Map also apart from MBR and GPT. Most of the UEFI firmwares have support for accessing FAT12 (floppy disks) , FAT16 and FAT32 filesystems in HDD and ISO9660 (and UDF) in CD/DVDs. EFI in Apple-Intel Macs can access HFS/HFS+ filesystems also apart from the mentioned ones.<br />
<br />
UEFI does not launch any boot code in the MBR whether it exists or not. Instead it uses a special partition in the partition table called "EFI SYSTEM PARTITION" in which files required to be launched by the firmware is stored. Each vendor can store its files under <EFI SYSTEM PARTITION>/EFI/<VENDOR NAME>/ folder and can use the firmware or its shell (UEFI shell) to launch the boot program. An EFI System Partition is usually formatted as FAT32.<br />
<br />
Under UEFI, every program whether they are OS loaders or some utilities (like memory testing apps) or recovery tools outside the OS, should be a UEFI Application corresponding to the EFI firmware architecture. Most of the UEFI firmware in the market, including recent Apple Macs use x86_64 EFI firmware. Only some older macs use i386 EFI firmware while no non-Apple UEFI system is known to use i386 EFI firmware.<br />
<br />
A x86_64 EFI firmware does not include support for launching 32-bit EFI apps unlike the 64-bit Linux and Windows which include such support. Therefore the bootloader must be compiled for that architecture correctly.<br />
<br />
=== Multibooting on UEFI ===<br />
<br />
Since each OS or vendor can maintain its own files within the EFI SYSTEM PARTITION without affecting the other, multi-booting using UEFI is just a matter of launching a different UEFI application corresponding to the particular OS's bootloader. This removes the need for relying on chainloading mechanisms of one bootloader to load another to switch OSes.<br />
<br />
==== Linux Windows x86_64 UEFI-GPT Multiboot ====<br />
<br />
Windows Vista (SP1+) and 7 pr 8 x86_64 versions support booting natively using UEFI firmware. But for this they need [[GPT]] partitioning of the disk used for UEFI booting. Windows x86_64 versions support either UEFI-GPT booting or BIOS-MBR booting. Windows 32-bit versions support only BIOS-MBR booting. Follow the instructions provided in the forum link given in the references sections as to how to do this. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;2581408 for more info.<br />
<br />
This limitation does not exist in Linux Kernel but rather depends on the bootloader used. For the sake of Windows UEFI booting, the Linux bootloader used should also be installed in UEFI-GPT mode if booting from the same disk.<br />
<br />
== Boot Process under UEFI ==<br />
<br />
# System switched on - Power On Self Test, or POST process.<br />
# UEFI firmware is loaded.<br />
# Firmware reads its Boot Manager to determine which UEFI application to be launched and from where (ie. from which disk and partition).<br />
# Firmware launches the UEFI application from the FAT32 formatted UEFISYS partition as defined in the boot entry in the firmware's boot manager.<br />
# UEFI application may launch another application (in case of UEFI Shell or a boot manager like rEFInd) or the kernel and initramfs (in case of a bootloader like GRUB2) depending on how the UEFI application was configured.<br />
<br />
== Detecting UEFI Firmware Arch ==<br />
<br />
If you have a non-mac UEFI system, then you have a x86_64 (aka 64-bit) UEFI 2.x firmware.<br />
<br />
Some of the known x86_64 UEFI 2.x firmwares are Phoenix SecureCore Tiano, AMI Aptio, Insyde H2O.<br />
<br />
Some of the known systems using these firmwares are Asus EZ Mode BIOS (in Sandy Bridge P67 and H67 motherboards), MSI ClickBIOS, HP EliteBooks, Sony Vaio Z series, many Intel Server and Desktop motherboards<br />
<br />
<br />
Pre-2008 Macs mostly have i386-efi firmware while >=2008 Macs have mostly x86_64-efi. All macs capable of running Mac OS X Snow Leopard 64-bit Kernel have x86_64 EFI 1.x firmware.<br />
<br />
To find out the arch of the efi firmware in a Mac, boot into Mac OS X and type the following command<br />
<br />
<pre><br />
ioreg -l -p IODeviceTree | grep firmware-abi<br />
</pre><br />
<br />
If the command returns EFI32 then it is i386 EFI 1.x firmware. If it returns EFI64 then it is x86_64 EFI 1.x firmware. Macs do not have UEFI 2.x firmware as Apple's EFI implementation is not fully compliant with UEFI Specification.<br />
<br />
== UEFI Support in Linux Kernel ==<br />
<br />
=== Linux Kernel config options for UEFI ===<br />
<br />
The required Linux Kernel configuration options for UEFI systems are :<br />
<br />
CONFIG_EFI=y<br />
CONFIG_EFI_STUB=y<br />
CONFIG_RELOCATABLE=y<br />
CONFIG_FB_EFI=y<br />
CONFIG_FRAMEBUFFER_CONSOLE=y<br />
<br />
UEFI Runtime Variables/Services Support - 'efivars' kernel module . This option is important as this is required to manipulate UEFI Runtime Variables using tools like '''efibootmgr'''.<br />
<br />
CONFIG_EFI_VARS=m<br />
<br />
{{Note| This option is compiled as module in Arch core/testing kernel.}}<br />
<br />
{{Note|For Linux to access UEFI Runtime Services, the UEFI Firmware processor architecture and the Linux kernel processor architecture must match. This is independent of the bootloader used.}}<br />
<br />
{{Note|If the UEFI Firmware arch and Linux Kernel arch are different, then the "'''noefi'''" kernel parameter must be used to avoid the kernel panic and boot successfully. The "noefi" option instructs the kernel not to access the UEFI Runtime Services.}}<br />
<br />
GUID Partition Table [[GPT]] config option - mandatory for UEFI support<br />
<br />
CONFIG_EFI_PARTITION=y<br />
<br />
{{Note|All of the above options are required to boot Linux via UEFI, and are enabled in Archlinux kernels in official repos.}}<br />
<br />
Retrieved from http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/x86_64/uefi.txt;hb=HEAD .<br />
<br />
== UEFI Variables Support ==<br />
<br />
UEFI defines variables through which an operating system can interact with the firmware. UEFI Boot Variables are used by the boot-loader and used by the OS only for early system start-up. UEFI Runtime Variables allow an OS to manage certain settings of the firmware like the UEFI Boot Manager or managing the keys for UEFI Secure Boot Protocol etc.<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + x86 32-bit Kernel and vice-versa config will not work. This is true only for efivars kernel module and efibootmgr step. The other steps (ie. upto setting up <UEFISYS>/efi/arch/grub.{efi,cfg} ) can be done even in BIOS/Legacy boot mode.}}<br />
<br />
Access to UEFI Runtime services is provided by "efivars" kernel module which is enabled through the {{ic|<nowiki>CONFIG_EFI_VAR=m</nowiki>}} kernel config option. This module once loaded exposes the variables under the directory {{ic|/sys/firnware/efi/vars}}. One way to check whether the system has booted in UEFI boot mode is to load the "efivars" kernel module and check for the existence of {{ic|/sys/firnware/efi/vars}} directory with contents similar to :<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel):<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
The UEFI Runtime Variables will not be exposed to the OS if you have used "noefi" kernel parameter in the boot-loader menu. This parameter instructs the kernel to completely ignore UEFI Runtime Services.<br />
<br />
=== Userspace Tools ===<br />
<br />
There are few tools that can access/modify the UEFI variables, namely<br />
<br />
# efibootmgr - Used to create/modify boot entries in the UEFI Boot Manager - {{Pkg|efibootmgr}} or {{AUR|efibootmgr-git}}<br />
# uefivars - simply dumps the variables - {{AUR|uefivars-git}} - uses efibootmgr library<br />
# Ubuntu's Firmware Test Suite - fwts - {{AUR|fwts-git}} - uefidump command - {{ic|fwts uefidump}} <br />
<br />
=== Non-Mac UEFI systems ===<br />
<br />
==== efibootmgr ====<br />
<br />
{{Warning|Using {{ic|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs. Experimental "bless" utility for Linux by Fedora developers - {{AUR|mactel-boot}}.}}<br />
<br />
{{Note|{{ic|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Otherwise the message {{ic|Fatal: Couldn't open either sysfs or procfs directories for accessing EFI variables}} is shown.}}<br />
<br />
Initially the user may be required to manually launch the boot-loader from the firmware itself (using maybe the UEFI Shell) if the UEFI boot-loader was installed when the system is booted in BIOS mode. Then {{ic|efibootmgr}} should be run to make the UEFI boot-loader entry as the default entry in the UEFI Boot Manager.<br />
<br />
To use efibootmgr, first load the 'efivars' kernel module:<br />
<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables (noefi?).<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode, without the "noefi" kernel parameter.<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{ic|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB.<br />
<br />
{{Note| The below commands use grub-efi-x86_64 boot-loader as example.}}<br />
<br />
Assume the boot-loader file to be launched is {{ic|/boot/efi/efi/arch_grub/grubx64.efi}}. {{ic|/boot/efi/efi/arch_grub/grubx64.efi}} can be split up as {{ic|/boot/efi}} and {{ic|/efi/arch_grub/grubx64.efi}}, wherein {{ic|/boot/efi}} is the mountpoint of the UEFI System Partition, which is assumed to be /dev/sdXY (here X and Y are just placeholders for the actual values - eg:- in /dev/sda1 , X=a Y=1).<br />
<br />
To determine the actual device path for the UEFI System Partition, try :<br />
<br />
# cat /proc/self/mounts | grep /boot/efi | awk '{print $1}'<br />
/dev/sdXY<br />
<br />
Then create the boot entry using efibootmgr as follows :<br />
<br />
# efibootmgr --create --gpt --disk /dev/sdX --part Y --write-signature --label "Arch Linux (GRUB2)" --loader '\EFI\arch_grub\grubx64.efi'<br />
<br />
In the above command {{ic|/boot/efi/efi/arch_grub/grubx64.efi}} translates to {{ic|/boot/efi}} and {{ic|/efi/arch_grub/grubx64.efi}} which in turn translate to drive {{ic|/dev/sdX}} -> partition Y -> file {{ic|/EFI/arch_grub/grubx64.efi}}.<br />
<br />
UEFI uses backward slash as path separator (similar to Windows paths).<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README] .<br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{ic|\EFI\arch_grub\grubx64.efi}} or {{ic|\efi\arch_grub\grubx64.efi}} does not matter (this will change if the filesystem encoding is UTF-8).<br />
<br />
== Linux Bootloaders for UEFI ==<br />
<br />
See [[UEFI Bootloaders]].<br />
<br />
== Create an UEFI System Partition in Linux ==<br />
<br />
{{Note|The UEFISYS partition can be of any size supported by FAT32 filesystem. According to Microsoft Documentation, the minimum partition/volume size for FAT32 is 512 MiB. Therefore it is recommended for UEFISYS partition to be atleast 512 MiB. Higher partition sizes are fine, especially if you use multiple UEFI bootloaders, or multiple OSes booting via UEFI, so that there is enough space to hold all the related files. If you are using Linux EFISTUB booting, then you need to make sure there is adequate space available for keeping the Kernel and Initramfs files in the UEFISYS partition.}}<br />
<br />
=== For GPT partitioned disks ===<br />
Two choices:<br />
* Using GNU Parted/GParted: Create a FAT32 partition. Set "boot" flag on for that partition.<br />
* Using GPT fdisk (aka gdisk): Create a partition with gdisk type code "EF00". Then format that partition as FAT32 using {{ic|mkfs.vfat -F32 /dev/<THAT_PARTITION>}}<br />
<br />
{{Note|Setting "boot" flag in parted in a MBR partition marks that partition as active, while the same "boot" flag in a GPT partition marks that partition as "UEFI System Partition".}}<br />
<br />
{{Warning|Do not use util-linux fdisk, cfdisk or sfdisk to change the type codes in a GPT disk. Similarly do not use gptfdisk gdisk, cgdisk or sgdisk on a MBR disk, it will be automatically converted to GPT (no data loss will occur, but the system will fail to boot).}}<br />
<br />
=== For MBR partitioned disks ===<br />
Two choices:<br />
* Using GNU Parted/GParted: Create FAT32 partition. Change the type code of that partition to 0xEF using fdisk, cfdisk or sfdisk.<br />
* Using fdisk: Create a partition with partition type 0xEF and format it as FAT32 using {{ic|mkfs.vfat -F32 /dev/<THAT_PARTITION>}}<br />
<br />
{{Note|It is recommended to use always GPT for UEFI boot as some UEFI firmwares do not allow UEFI-MBR boot.}}<br />
<br />
== UEFI Shell ==<br />
<br />
The UEFI Shell is a shell/terminal for the firmware which allows launching uefi applications which include uefi bootloaders. Apart from that, the shell can also be used to obtain various other information about the system or the firmware like memory map (memmap), modifying boot manager variables (bcfg), running partitioning programs (diskpart), loading uefi drivers, editing text files (edit), hexedit etc. <br />
<br />
=== UEFI Shell download links === <br />
<br />
You can download a BSD licensed UEFI Shell from Intel's Tianocore UDK/EDK2 Sourceforge.net project.<br />
<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ShellBinPkg/UefiShell/X64/Shell.efi x86_64 UEFI Shell 2.0 (Beta)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/X64/Shell_Full.efi x86_64 UEFI Shell 1.0 (Old)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ShellBinPkg/UefiShell/Ia32/Shell.efi i386 UEFI Shell 2.0 (Beta)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/Ia32/Shell_Full.efi i386 UEFI Shell 1.0 (Old)]<br />
<br />
Shell 2.0 works only in UEFI 2.3+ systems and is recommended over Shell 1.0 in those systems. Shell 1.0 should work in all UEFI systems irrespective of the spec. version the firmware follows. More info at [http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=ShellPkg ShellPkg] and [http://sourceforge.net/mailarchive/message.php?msg_id=28690732 this mail]<br />
<br />
=== Launching UEFI Shell ===<br />
<br />
Few Asus and other AMI Aptio x86_64 UEFI firmware based motherboards (from Sandy Bridge onwards) provide an option called {{ic|"Launch EFI Shell from filesystem device"}} . For those motherboards, download the x86_64 UEFI Shell and copy it to your UEFI SYSTEM PARTITION as {{ic|<UEFI_SYSTEM_PARTITION>/shellx64.efi}} (mostly {{ic|/boot/efi/shellx64.efi}}) .<br />
<br />
Systems with Phoenix SecureCore Tiano UEFI firmware are known to have embedded UEFI Shell which can be launched using either F6, F11 or F12 key.<br />
<br />
{{Note|If you are unable to launch UEFI Shell from the firmware directly using any of the above mentioned methods, create a FAT32 USB pen drive with Shell.efi copied as (USB)/efi/boot/bootx64.efi . This USB should come up in the firmware boot menu. Launching this option will launch the UEFI Shell for you.}}<br />
<br />
=== Important UEFI Shell Commands === <br />
<br />
More info at http://software.intel.com/en-us/articles/efi-shells-and-scripting/<br />
<br />
==== bcfg ====<br />
<br />
BCFG command is used to modify the UEFI NVRAM entries, which allow the user to change the boot entries or driver options. This command is described in detail in page 83 (Section 5.3) of "UEFI Shell Specification 2.0" pdf document.<br />
<br />
{{Note| Users are recommended to try {{ic|bcfg}} only if {{ic|efibootmgr}} fails to create working boot entries in their system.}}<br />
<br />
{{Note| UEFI Shell 1.0 does not support {{ic|bcfg}} command.}}<br />
<br />
To dump a list of current boot entries -<br />
<br />
Shell> bcfg boot dump -v<br />
<br />
To add a boot menu entry for grub2's grubx64.efi (for example) as 4th (numbeering starts from zero) option in the boot menu<br />
<br />
Shell> bcfg boot add 3 fs0:\EFI\arch\grubx64.efi "Arch Linux (GRUB2)"<br />
<br />
where fs0: is the mapping corresponding to the UEFI System Partition and \EFI\arch\grubx64.efi is the file to be launched.<br />
<br />
To remove the 4th boot option<br />
<br />
Shell> bcfg boot rm 3<br />
<br />
To move the boot option #3 to #0 (i.e. 1st or the default entry in the UEFI Boot menu)<br />
<br />
Shell> bcfg boot mv 3 0<br />
<br />
For bcfg help text<br />
<br />
Shell> help bcfg -v -b<br />
<br />
or<br />
<br />
Shell> bcfg -? -v -b<br />
<br />
==== edit ====<br />
<br />
EDIT command provides a basic text editor with an interface similar to nano text editor, but slightly less functional. It handles UTF-8 encoding and takes care or LF vs CRLF line endings.<br />
<br />
To edit, for example grub2's grub.cfg in the UEFI System Partition (fs0: in the firmware)<br />
<br />
Shell> fs0:<br />
FS0:\> cd \efi\grub<br />
FS0:\efi\grub\> edit grub.cfg<br />
<br />
== Hardware Compatibility ==<br />
<br />
Main page [[HCL/Firmwares/UEFI]]<br />
<br />
<br />
== Create UEFI bootable USB from ISO ==<br />
<br />
{{Note|dd'ing the ISO (isohybrid method) to the USB drive will not work for UEFI boot.}}<br />
<br />
=== Archiso ===<br />
<br />
1. Create a directory {{ic|/tmp/archiso}} and extract the archiso file contents to it (use file-roller or something similiar).<br />
<br />
2. Create a directory {{ic|/tmp/archiso_efiboot}} and extract {{ic|/tmp/archiso/EFI/archiso/efiboot.img}} to it using {{ic|7z}} command from {{Pkg|p7zip}} package (use file-roller, or 7z)<br />
<br />
Example for 7z:<br />
$ 7z e -opath efiboot.img # without space between -o and path<br />
<br />
3. Run the below commands:<br />
<br />
$ mkdir -p /tmp/archiso/EFI/{archiso,boot}<br />
$ cp /tmp/archiso/arch/boot/x86_64/vmlinuz /tmp/archiso/EFI/archiso/vmlinuz.efi<br />
$ cp /tmp/archiso/arch/boot/x86_64/archiso.img /tmp/archiso/EFI/archiso/archiso.img<br />
$ cp /tmp/archiso_efiboot/bootx64.efi /tmp/archiso/EFI/boot/bootx64.efi<br />
$ cp /tmp/archiso_efiboot/startup.nsh /tmp/archiso/EFI/boot/startup.nsh<br />
<br />
4. Find out the filesystem label to be used for the USB by reading "{{ic|1=archisolabel=}}" part in {{ic|/tmp/archiso/EFI/boot/startup.nsh}}. For example if {{ic|/tmp/archiso/EFI/boot/startup.nsh}} has {{ic|1=archisolabel=ARCH_201208}} then the filesystem label to be used is {{ic|ARCH_201208}} . <br />
<br />
5. Create a directory {{ic|/tmp/archisousb}} . Format the USB drive as FAT32 (or FAT16) (no other filesystem is supported) and set the filesystem label same as the one obtained in step 4, and mount it to {{ic|/tmp/archisousb}} .<br />
<br />
6. Copy the contents of {{ic|/tmp/archiso}} to {{ic|/tmp/archisousb}} and then umount {{ic|/tmp/archisousb}} .<br />
<br />
=== [[Archboot]] ===<br />
<br />
1. Create a directory {{ic|/tmp/archboot}} and extract the archiso file contents to it.<br />
<br />
{{Note|Follow steps 2 and 3 only if {{ic|/tmp/archboot/EFI/boot/bootx64.efi}} does not exist, even after extracting archboot iso to {{ic|/tmp/archboot}} .}}<br />
<br />
2. Create a directory {{ic|/tmp/archboot_efiboot}} and extract {{ic|/tmp/archboot/boot/grub/grub_uefi_x86_64.bin}} to it using {{ic|7z}} command from {{Pkg|p7zip}} package.<br />
<br />
3. Run the below commands:<br />
<br />
# mkdir -p /tmp/archboot/EFI/boot<br />
# cp /tmp/archboot_efiboot/EFI/boot/bootx64.efi /tmp/archboot/EFI/boot/bootx64.efi<br />
<br />
4. Create a directory {{ic|/tmp/archbootusb}} . Format the USB drive as FAT32 (or FAT16) (no other filesystem is supported) and mount it to {{ic|/tmp/archbootusb}} .<br />
<br />
5. Copy the contents of {{ic|/tmp/archboot}} to {{ic|/tmp/archbootusb}} and then umount {{ic|/tmp/archbootusb}} .<br />
<br />
== Remove UEFI boot support from ISO ==<br />
<br />
Most of the 32-bit EFI Macs and some 64-bit EFI Macs refuse to boot from a UEFI(X64)+BIOS bootable CD/DVD. In these cases the iso should be rebuilt without UEFI boot support, retaining only BIOS boot.<br />
<br />
=== Archiso ===<br />
<br />
1. Obtain the ISO label from the output of {{ic|file <path_to_iso>}}. Let it be {{ic|ARCH_201208}} for example.<br />
<br />
2. Create a directory {{ic|/tmp/archiso}} and extract the archiso file contents to it.<br />
<br />
3. Run {{ic|xorriso}} (part of {{Pkg|libisoburn}} package) as shown below:<br />
<br />
$ xorriso -as mkisofs -iso-level 3 \<br />
-full-iso9660-filenames \<br />
-volid "ARCH_201208" \<br />
-appid "Arch Linux Live/Rescue CD" \<br />
-publisher "Arch Linux <https://www.archlinux.org>" \<br />
-preparer "prepared by user" \<br />
-eltorito-boot isolinux/isolinux.bin \<br />
-eltorito-catalog isolinux/boot.cat \<br />
-no-emul-boot -boot-load-size 4 -boot-info-table \<br />
-isohybrid-mbr "/tmp/archiso/isolinux/isohdpfx.bin" \<br />
-output "/tmp/archiso.iso" "/tmp/archiso/"<br />
<br />
4. Burn {{ic|/tmp/archiso.iso}} to a CD and boot into your Mac using that CD.<br />
<br />
=== [[Archboot]] ===<br />
<br />
1. Create a directory {{ic|/tmp/archboot}} and extract the archboot iso file contents to it.<br />
<br />
2. Run {{ic|xorriso}} (part of {{Pkg|libisoburn}} package) as shown below:<br />
<br />
$ xorriso -as mkisofs -iso-level 3 -rock -joliet \<br />
-max-iso9660-filenames -omit-period \<br />
-omit-version-number -allow-leading-dots \<br />
-relaxed-filenames -allow-lowercase -allow-multidot \<br />
-volid "ARCHBOOT" -preparer "prepared by user" \<br />
-eltorito-boot boot/syslinux/isolinux.bin \<br />
-eltorito-catalog boot/syslinux/boot.cat \<br />
-no-emul-boot -boot-load-size 4 -boot-info-table \<br />
-isohybrid-mbr /tmp/archboot/boot/syslinux/isohdpfx.bin \<br />
-output "/tmp/archboot.iso" "/tmp/archboot/"<br />
<br />
3. Burn {{ic|/tmp/archboot.iso}} to a CD and boot into your Mac using that CD.<br />
<br />
== See also ==<br />
<br />
* Wikipedia's page on [http://en.wikipedia.org/wiki/UEFI UEFI]<br />
* Wikipedia's page on [http://en.wikipedia.org/wiki/EFI_System_partition UEFI SYSTEM Partition]<br />
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/x86_64/uefi.txt;hb=HEAD Linux Kernel UEFI Documentation]<br />
* [http://www.uefi.org/home/ UEFI Forum] - contains the official [http://www.uefi.org/specs/ UEFI Specifications] - GUID Partition Table is part of UEFI Specification<br />
* [http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Welcome_to_TianoCore Intel's Tianocore Project] for Open-Source UEFI firmware which includes DuetPkg for direct BIOS based booting and OvmfPkg used in QEMU and Oracle VirtualBox<br />
* [http://www.intel.com/technology/efi/ Intel's page on EFI]<br />
* [http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/efi-boot-process.html FGA: The EFI boot process]<br />
* [http://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx Microsoft's Windows and GPT FAQ] - Contains info on Windows UEFI booting also<br />
* [https://gitorious.org/tianocore_uefi_duet_builds/pages/Windows_x64_BIOS_to_UEFI Convert Windows Vista SP1+ or 7 x86_64 boot from BIOS-MBR mode to UEFI-GPT mode without Reinstall]<br />
* [https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB Create a Linux BIOS+UEFI and Windows x64 BIOS+UEFI bootable USB drive]<br />
* [http://rodsbooks.com/bios2uefi/ Rod Smith - A BIOS to UEFI Transformation]<br />
* [https://lkml.org/lkml/2011/6/8/322 UEFI Boot problems on some newer machines (LKML)]<br />
* [http://software.intel.com/en-us/articles/efi-shells-and-scripting/ EFI Shells and Scripting - Intel Documentation]<br />
* [http://software.intel.com/en-us/articles/uefi-shell/ UEFI Shell - Intel Documentation]<br />
* [http://www.hpuxtips.es/?q=node/293 UEFI Shell - bcfg command info]<br />
* [http://hackthejoggler.freeforums.org/download/file.php?id=28 Some useful 32-bit UEFI Shell utilities]</div>Geekbabyhttps://wiki.archlinux.org/index.php?title=Unified_Extensible_Firmware_Interface_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=222440Unified Extensible Firmware Interface (简体中文)2012-09-10T13:35:41Z<p>Geekbaby: Created page with "Category:Boot process ru:Unified Extensible Firmware Interface zh-CN:Unified Extensible Firmware Interface {{Article summary start}} {{Article summary text|An over..."</p>
<hr />
<div>[[Category:Boot process]]<br />
[[ru:Unified Extensible Firmware Interface]]<br />
[[zh-CN:Unified Extensible Firmware Interface]]<br />
{{Article summary start}}<br />
{{Article summary text|An overview of the Unified Extensible Firmware Interface.}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|GUID Partition Table}}<br />
{{Article summary wiki|Master Boot Record}}<br />
{{Article summary wiki|Arch Boot Process}}<br />
{{Article summary end}}<br />
<br />
'''统一可扩展固件界面(Unified Extensible Firmware Interface)''' (或者简称为UEFI) 最初是由Intel为基于安腾系统设计的一种新型固件。 它介绍了一种新的启动系统方式,该方式有别于传统BIOS系统所使用的“MBR启动代码”。它起始于Intel EFI的1.x版本,之后被称作UEFI论坛的一群公司接管了它的开发工作 。从此,它被称为统一的EFI,其版本开始于2.0。从2012年5月23号起,UEFI规格2.3.1是最近的一个版本。<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, these instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and therefore it is not a standard UEFI firmware.}}<br />
<br />
== Booting an OS using BIOS ==<br />
<br />
A BIOS or Basic Input-Output System is the very first program that is executed once the system is switched on. After all the hardware has been initialized and the POST operation has completed, the BIOS executes the first boot code in the first device in the device booting list. <br />
<br />
If the list starts with a CD/DVD drive, then the El-Torito entry in the CD/DVD is executed. This is how bootable CD/DVD works. If the list starts with a HDD, then BIOS executes the very first 440 bytes MBR boot code. The boot code then chainloads or bootstraps a much larger and complex bootloader which then loads the OS.<br />
<br />
Basically, the BIOS does not know how to read a partition table or filesystem. All it does is initialize the hardware, then load and run the 440-byte boot code.<br />
<br />
=== Multiboot on BIOS ===<br />
<br />
Since very little can be achieved by a program that fits into the 440-byte boot code area, multi-booting using BIOS requires a multi-boot capable bootloader (multi-boot refers to booting multiple operating systems, not to booting a kernel in the Multiboot format specified by the GRUB developers). So usually a common bootloader like [[GRUB]] or [[GRUB2]] or [[Syslinux]] or [[LILO]] would be loaded by the BIOS, and it would load an operating system by either chain-loading or directly loading the kernel.<br />
<br />
== Booting an OS using UEFI ==<br />
<br />
UEFI firmware does not support booting through the above mentioned method which is the only way supported by BIOS. UEFI has support for reading both the partition table as well as understanding filesystems. <br />
<br />
The commonly used UEFI firmwares support both MBR and GPT partition table. EFI in Apple-Intel Macs are known to support Apple Partition Map also apart from MBR and GPT. Most of the UEFI firmwares have support for accessing FAT12 (floppy disks) , FAT16 and FAT32 filesystems in HDD and ISO9660 (and UDF) in CD/DVDs. EFI in Apple-Intel Macs can access HFS/HFS+ filesystems also apart from the mentioned ones.<br />
<br />
UEFI does not launch any boot code in the MBR whether it exists or not. Instead it uses a special partition in the partition table called "EFI SYSTEM PARTITION" in which files required to be launched by the firmware is stored. Each vendor can store its files under <EFI SYSTEM PARTITION>/EFI/<VENDOR NAME>/ folder and can use the firmware or its shell (UEFI shell) to launch the boot program. An EFI System Partition is usually formatted as FAT32.<br />
<br />
Under UEFI, every program whether they are OS loaders or some utilities (like memory testing apps) or recovery tools outside the OS, should be a UEFI Application corresponding to the EFI firmware architecture. Most of the UEFI firmware in the market, including recent Apple Macs use x86_64 EFI firmware. Only some older macs use i386 EFI firmware while no non-Apple UEFI system is known to use i386 EFI firmware.<br />
<br />
A x86_64 EFI firmware does not include support for launching 32-bit EFI apps unlike the 64-bit Linux and Windows which include such support. Therefore the bootloader must be compiled for that architecture correctly.<br />
<br />
=== Multibooting on UEFI ===<br />
<br />
Since each OS or vendor can maintain its own files within the EFI SYSTEM PARTITION without affecting the other, multi-booting using UEFI is just a matter of launching a different UEFI application corresponding to the particular OS's bootloader. This removes the need for relying on chainloading mechanisms of one bootloader to load another to switch OSes.<br />
<br />
==== Linux Windows x86_64 UEFI-GPT Multiboot ====<br />
<br />
Windows Vista (SP1+) and 7 pr 8 x86_64 versions support booting natively using UEFI firmware. But for this they need [[GPT]] partitioning of the disk used for UEFI booting. Windows x86_64 versions support either UEFI-GPT booting or BIOS-MBR booting. Windows 32-bit versions support only BIOS-MBR booting. Follow the instructions provided in the forum link given in the references sections as to how to do this. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;2581408 for more info.<br />
<br />
This limitation does not exist in Linux Kernel but rather depends on the bootloader used. For the sake of Windows UEFI booting, the Linux bootloader used should also be installed in UEFI-GPT mode if booting from the same disk.<br />
<br />
== Boot Process under UEFI ==<br />
<br />
# System switched on - Power On Self Test, or POST process.<br />
# UEFI firmware is loaded.<br />
# Firmware reads its Boot Manager to determine which UEFI application to be launched and from where (ie. from which disk and partition).<br />
# Firmware launches the UEFI application from the FAT32 formatted UEFISYS partition as defined in the boot entry in the firmware's boot manager.<br />
# UEFI application may launch another application (in case of UEFI Shell or a boot manager like rEFInd) or the kernel and initramfs (in case of a bootloader like GRUB2) depending on how the UEFI application was configured.<br />
<br />
== Detecting UEFI Firmware Arch ==<br />
<br />
If you have a non-mac UEFI system, then you have a x86_64 (aka 64-bit) UEFI 2.x firmware.<br />
<br />
Some of the known x86_64 UEFI 2.x firmwares are Phoenix SecureCore Tiano, AMI Aptio, Insyde H2O.<br />
<br />
Some of the known systems using these firmwares are Asus EZ Mode BIOS (in Sandy Bridge P67 and H67 motherboards), MSI ClickBIOS, HP EliteBooks, Sony Vaio Z series, many Intel Server and Desktop motherboards<br />
<br />
<br />
Pre-2008 Macs mostly have i386-efi firmware while >=2008 Macs have mostly x86_64-efi. All macs capable of running Mac OS X Snow Leopard 64-bit Kernel have x86_64 EFI 1.x firmware.<br />
<br />
To find out the arch of the efi firmware in a Mac, boot into Mac OS X and type the following command<br />
<br />
<pre><br />
ioreg -l -p IODeviceTree | grep firmware-abi<br />
</pre><br />
<br />
If the command returns EFI32 then it is i386 EFI 1.x firmware. If it returns EFI64 then it is x86_64 EFI 1.x firmware. Macs do not have UEFI 2.x firmware as Apple's EFI implementation is not fully compliant with UEFI Specification.<br />
<br />
== UEFI Support in Linux Kernel ==<br />
<br />
=== Linux Kernel config options for UEFI ===<br />
<br />
The required Linux Kernel configuration options for UEFI systems are :<br />
<br />
CONFIG_EFI=y<br />
CONFIG_EFI_STUB=y<br />
CONFIG_RELOCATABLE=y<br />
CONFIG_FB_EFI=y<br />
CONFIG_FRAMEBUFFER_CONSOLE=y<br />
<br />
UEFI Runtime Variables/Services Support - 'efivars' kernel module . This option is important as this is required to manipulate UEFI Runtime Variables using tools like '''efibootmgr'''.<br />
<br />
CONFIG_EFI_VARS=m<br />
<br />
{{Note| This option is compiled as module in Arch core/testing kernel.}}<br />
<br />
{{Note|For Linux to access UEFI Runtime Services, the UEFI Firmware processor architecture and the Linux kernel processor architecture must match. This is independent of the bootloader used.}}<br />
<br />
{{Note|If the UEFI Firmware arch and Linux Kernel arch are different, then the "'''noefi'''" kernel parameter must be used to avoid the kernel panic and boot successfully. The "noefi" option instructs the kernel not to access the UEFI Runtime Services.}}<br />
<br />
GUID Partition Table [[GPT]] config option - mandatory for UEFI support<br />
<br />
CONFIG_EFI_PARTITION=y<br />
<br />
{{Note|All of the above options are required to boot Linux via UEFI, and are enabled in Archlinux kernels in official repos.}}<br />
<br />
Retrieved from http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/x86_64/uefi.txt;hb=HEAD .<br />
<br />
== UEFI Variables Support ==<br />
<br />
UEFI defines variables through which an operating system can interact with the firmware. UEFI Boot Variables are used by the boot-loader and used by the OS only for early system start-up. UEFI Runtime Variables allow an OS to manage certain settings of the firmware like the UEFI Boot Manager or managing the keys for UEFI Secure Boot Protocol etc.<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + x86 32-bit Kernel and vice-versa config will not work. This is true only for efivars kernel module and efibootmgr step. The other steps (ie. upto setting up <UEFISYS>/efi/arch/grub.{efi,cfg} ) can be done even in BIOS/Legacy boot mode.}}<br />
<br />
Access to UEFI Runtime services is provided by "efivars" kernel module which is enabled through the {{ic|<nowiki>CONFIG_EFI_VAR=m</nowiki>}} kernel config option. This module once loaded exposes the variables under the directory {{ic|/sys/firnware/efi/vars}}. One way to check whether the system has booted in UEFI boot mode is to load the "efivars" kernel module and check for the existence of {{ic|/sys/firnware/efi/vars}} directory with contents similar to :<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel):<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
The UEFI Runtime Variables will not be exposed to the OS if you have used "noefi" kernel parameter in the boot-loader menu. This parameter instructs the kernel to completely ignore UEFI Runtime Services.<br />
<br />
=== Userspace Tools ===<br />
<br />
There are few tools that can access/modify the UEFI variables, namely<br />
<br />
# efibootmgr - Used to create/modify boot entries in the UEFI Boot Manager - {{Pkg|efibootmgr}} or {{AUR|efibootmgr-git}}<br />
# uefivars - simply dumps the variables - {{AUR|uefivars-git}} - uses efibootmgr library<br />
# Ubuntu's Firmware Test Suite - fwts - {{AUR|fwts-git}} - uefidump command - {{ic|fwts uefidump}} <br />
<br />
=== Non-Mac UEFI systems ===<br />
<br />
==== efibootmgr ====<br />
<br />
{{Warning|Using {{ic|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs. Experimental "bless" utility for Linux by Fedora developers - {{AUR|mactel-boot}}.}}<br />
<br />
{{Note|{{ic|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Otherwise the message {{ic|Fatal: Couldn't open either sysfs or procfs directories for accessing EFI variables}} is shown.}}<br />
<br />
Initially the user may be required to manually launch the boot-loader from the firmware itself (using maybe the UEFI Shell) if the UEFI boot-loader was installed when the system is booted in BIOS mode. Then {{ic|efibootmgr}} should be run to make the UEFI boot-loader entry as the default entry in the UEFI Boot Manager.<br />
<br />
To use efibootmgr, first load the 'efivars' kernel module:<br />
<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables (noefi?).<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode, without the "noefi" kernel parameter.<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{ic|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB.<br />
<br />
{{Note| The below commands use grub-efi-x86_64 boot-loader as example.}}<br />
<br />
Assume the boot-loader file to be launched is {{ic|/boot/efi/efi/arch_grub/grubx64.efi}}. {{ic|/boot/efi/efi/arch_grub/grubx64.efi}} can be split up as {{ic|/boot/efi}} and {{ic|/efi/arch_grub/grubx64.efi}}, wherein {{ic|/boot/efi}} is the mountpoint of the UEFI System Partition, which is assumed to be /dev/sdXY (here X and Y are just placeholders for the actual values - eg:- in /dev/sda1 , X=a Y=1).<br />
<br />
To determine the actual device path for the UEFI System Partition, try :<br />
<br />
# cat /proc/self/mounts | grep /boot/efi | awk '{print $1}'<br />
/dev/sdXY<br />
<br />
Then create the boot entry using efibootmgr as follows :<br />
<br />
# efibootmgr --create --gpt --disk /dev/sdX --part Y --write-signature --label "Arch Linux (GRUB2)" --loader '\EFI\arch_grub\grubx64.efi'<br />
<br />
In the above command {{ic|/boot/efi/efi/arch_grub/grubx64.efi}} translates to {{ic|/boot/efi}} and {{ic|/efi/arch_grub/grubx64.efi}} which in turn translate to drive {{ic|/dev/sdX}} -> partition Y -> file {{ic|/EFI/arch_grub/grubx64.efi}}.<br />
<br />
UEFI uses backward slash as path separator (similar to Windows paths).<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README] .<br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{ic|\EFI\arch_grub\grubx64.efi}} or {{ic|\efi\arch_grub\grubx64.efi}} does not matter (this will change if the filesystem encoding is UTF-8).<br />
<br />
== Linux Bootloaders for UEFI ==<br />
<br />
See [[UEFI Bootloaders]].<br />
<br />
== Create an UEFI System Partition in Linux ==<br />
<br />
{{Note|The UEFISYS partition can be of any size supported by FAT32 filesystem. According to Microsoft Documentation, the minimum partition/volume size for FAT32 is 512 MiB. Therefore it is recommended for UEFISYS partition to be atleast 512 MiB. Higher partition sizes are fine, especially if you use multiple UEFI bootloaders, or multiple OSes booting via UEFI, so that there is enough space to hold all the related files. If you are using Linux EFISTUB booting, then you need to make sure there is adequate space available for keeping the Kernel and Initramfs files in the UEFISYS partition.}}<br />
<br />
=== For GPT partitioned disks ===<br />
Two choices:<br />
* Using GNU Parted/GParted: Create a FAT32 partition. Set "boot" flag on for that partition.<br />
* Using GPT fdisk (aka gdisk): Create a partition with gdisk type code "EF00". Then format that partition as FAT32 using {{ic|mkfs.vfat -F32 /dev/<THAT_PARTITION>}}<br />
<br />
{{Note|Setting "boot" flag in parted in a MBR partition marks that partition as active, while the same "boot" flag in a GPT partition marks that partition as "UEFI System Partition".}}<br />
<br />
{{Warning|Do not use util-linux fdisk, cfdisk or sfdisk to change the type codes in a GPT disk. Similarly do not use gptfdisk gdisk, cgdisk or sgdisk on a MBR disk, it will be automatically converted to GPT (no data loss will occur, but the system will fail to boot).}}<br />
<br />
=== For MBR partitioned disks ===<br />
Two choices:<br />
* Using GNU Parted/GParted: Create FAT32 partition. Change the type code of that partition to 0xEF using fdisk, cfdisk or sfdisk.<br />
* Using fdisk: Create a partition with partition type 0xEF and format it as FAT32 using {{ic|mkfs.vfat -F32 /dev/<THAT_PARTITION>}}<br />
<br />
{{Note|It is recommended to use always GPT for UEFI boot as some UEFI firmwares do not allow UEFI-MBR boot.}}<br />
<br />
== UEFI Shell ==<br />
<br />
The UEFI Shell is a shell/terminal for the firmware which allows launching uefi applications which include uefi bootloaders. Apart from that, the shell can also be used to obtain various other information about the system or the firmware like memory map (memmap), modifying boot manager variables (bcfg), running partitioning programs (diskpart), loading uefi drivers, editing text files (edit), hexedit etc. <br />
<br />
=== UEFI Shell download links === <br />
<br />
You can download a BSD licensed UEFI Shell from Intel's Tianocore UDK/EDK2 Sourceforge.net project.<br />
<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ShellBinPkg/UefiShell/X64/Shell.efi x86_64 UEFI Shell 2.0 (Beta)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/X64/Shell_Full.efi x86_64 UEFI Shell 1.0 (Old)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ShellBinPkg/UefiShell/Ia32/Shell.efi i386 UEFI Shell 2.0 (Beta)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/Ia32/Shell_Full.efi i386 UEFI Shell 1.0 (Old)]<br />
<br />
Shell 2.0 works only in UEFI 2.3+ systems and is recommended over Shell 1.0 in those systems. Shell 1.0 should work in all UEFI systems irrespective of the spec. version the firmware follows. More info at [http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=ShellPkg ShellPkg] and [http://sourceforge.net/mailarchive/message.php?msg_id=28690732 this mail]<br />
<br />
=== Launching UEFI Shell ===<br />
<br />
Few Asus and other AMI Aptio x86_64 UEFI firmware based motherboards (from Sandy Bridge onwards) provide an option called {{ic|"Launch EFI Shell from filesystem device"}} . For those motherboards, download the x86_64 UEFI Shell and copy it to your UEFI SYSTEM PARTITION as {{ic|<UEFI_SYSTEM_PARTITION>/shellx64.efi}} (mostly {{ic|/boot/efi/shellx64.efi}}) .<br />
<br />
Systems with Phoenix SecureCore Tiano UEFI firmware are known to have embedded UEFI Shell which can be launched using either F6, F11 or F12 key.<br />
<br />
{{Note|If you are unable to launch UEFI Shell from the firmware directly using any of the above mentioned methods, create a FAT32 USB pen drive with Shell.efi copied as (USB)/efi/boot/bootx64.efi . This USB should come up in the firmware boot menu. Launching this option will launch the UEFI Shell for you.}}<br />
<br />
=== Important UEFI Shell Commands === <br />
<br />
More info at http://software.intel.com/en-us/articles/efi-shells-and-scripting/<br />
<br />
==== bcfg ====<br />
<br />
BCFG command is used to modify the UEFI NVRAM entries, which allow the user to change the boot entries or driver options. This command is described in detail in page 83 (Section 5.3) of "UEFI Shell Specification 2.0" pdf document.<br />
<br />
{{Note| Users are recommended to try {{ic|bcfg}} only if {{ic|efibootmgr}} fails to create working boot entries in their system.}}<br />
<br />
{{Note| UEFI Shell 1.0 does not support {{ic|bcfg}} command.}}<br />
<br />
To dump a list of current boot entries -<br />
<br />
Shell> bcfg boot dump -v<br />
<br />
To add a boot menu entry for grub2's grubx64.efi (for example) as 4th (numbeering starts from zero) option in the boot menu<br />
<br />
Shell> bcfg boot add 3 fs0:\EFI\arch\grubx64.efi "Arch Linux (GRUB2)"<br />
<br />
where fs0: is the mapping corresponding to the UEFI System Partition and \EFI\arch\grubx64.efi is the file to be launched.<br />
<br />
To remove the 4th boot option<br />
<br />
Shell> bcfg boot rm 3<br />
<br />
To move the boot option #3 to #0 (i.e. 1st or the default entry in the UEFI Boot menu)<br />
<br />
Shell> bcfg boot mv 3 0<br />
<br />
For bcfg help text<br />
<br />
Shell> help bcfg -v -b<br />
<br />
or<br />
<br />
Shell> bcfg -? -v -b<br />
<br />
==== edit ====<br />
<br />
EDIT command provides a basic text editor with an interface similar to nano text editor, but slightly less functional. It handles UTF-8 encoding and takes care or LF vs CRLF line endings.<br />
<br />
To edit, for example grub2's grub.cfg in the UEFI System Partition (fs0: in the firmware)<br />
<br />
Shell> fs0:<br />
FS0:\> cd \efi\grub<br />
FS0:\efi\grub\> edit grub.cfg<br />
<br />
== Hardware Compatibility ==<br />
<br />
Main page [[HCL/Firmwares/UEFI]]<br />
<br />
<br />
== Create UEFI bootable USB from ISO ==<br />
<br />
{{Note|dd'ing the ISO (isohybrid method) to the USB drive will not work for UEFI boot.}}<br />
<br />
=== Archiso ===<br />
<br />
1. Create a directory {{ic|/tmp/archiso}} and extract the archiso file contents to it (use file-roller or something similiar).<br />
<br />
2. Create a directory {{ic|/tmp/archiso_efiboot}} and extract {{ic|/tmp/archiso/EFI/archiso/efiboot.img}} to it using {{ic|7z}} command from {{Pkg|p7zip}} package (use file-roller, or 7z)<br />
<br />
Example for 7z:<br />
$ 7z e -opath efiboot.img # without space between -o and path<br />
<br />
3. Run the below commands:<br />
<br />
$ mkdir -p /tmp/archiso/EFI/{archiso,boot}<br />
$ cp /tmp/archiso/arch/boot/x86_64/vmlinuz /tmp/archiso/EFI/archiso/vmlinuz.efi<br />
$ cp /tmp/archiso/arch/boot/x86_64/archiso.img /tmp/archiso/EFI/archiso/archiso.img<br />
$ cp /tmp/archiso_efiboot/bootx64.efi /tmp/archiso/EFI/boot/bootx64.efi<br />
$ cp /tmp/archiso_efiboot/startup.nsh /tmp/archiso/EFI/boot/startup.nsh<br />
<br />
4. Find out the filesystem label to be used for the USB by reading "{{ic|1=archisolabel=}}" part in {{ic|/tmp/archiso/EFI/boot/startup.nsh}}. For example if {{ic|/tmp/archiso/EFI/boot/startup.nsh}} has {{ic|1=archisolabel=ARCH_201208}} then the filesystem label to be used is {{ic|ARCH_201208}} . <br />
<br />
5. Create a directory {{ic|/tmp/archisousb}} . Format the USB drive as FAT32 (or FAT16) (no other filesystem is supported) and set the filesystem label same as the one obtained in step 4, and mount it to {{ic|/tmp/archisousb}} .<br />
<br />
6. Copy the contents of {{ic|/tmp/archiso}} to {{ic|/tmp/archisousb}} and then umount {{ic|/tmp/archisousb}} .<br />
<br />
=== [[Archboot]] ===<br />
<br />
1. Create a directory {{ic|/tmp/archboot}} and extract the archiso file contents to it.<br />
<br />
{{Note|Follow steps 2 and 3 only if {{ic|/tmp/archboot/EFI/boot/bootx64.efi}} does not exist, even after extracting archboot iso to {{ic|/tmp/archboot}} .}}<br />
<br />
2. Create a directory {{ic|/tmp/archboot_efiboot}} and extract {{ic|/tmp/archboot/boot/grub/grub_uefi_x86_64.bin}} to it using {{ic|7z}} command from {{Pkg|p7zip}} package.<br />
<br />
3. Run the below commands:<br />
<br />
# mkdir -p /tmp/archboot/EFI/boot<br />
# cp /tmp/archboot_efiboot/EFI/boot/bootx64.efi /tmp/archboot/EFI/boot/bootx64.efi<br />
<br />
4. Create a directory {{ic|/tmp/archbootusb}} . Format the USB drive as FAT32 (or FAT16) (no other filesystem is supported) and mount it to {{ic|/tmp/archbootusb}} .<br />
<br />
5. Copy the contents of {{ic|/tmp/archboot}} to {{ic|/tmp/archbootusb}} and then umount {{ic|/tmp/archbootusb}} .<br />
<br />
== Remove UEFI boot support from ISO ==<br />
<br />
Most of the 32-bit EFI Macs and some 64-bit EFI Macs refuse to boot from a UEFI(X64)+BIOS bootable CD/DVD. In these cases the iso should be rebuilt without UEFI boot support, retaining only BIOS boot.<br />
<br />
=== Archiso ===<br />
<br />
1. Obtain the ISO label from the output of {{ic|file <path_to_iso>}}. Let it be {{ic|ARCH_201208}} for example.<br />
<br />
2. Create a directory {{ic|/tmp/archiso}} and extract the archiso file contents to it.<br />
<br />
3. Run {{ic|xorriso}} (part of {{Pkg|libisoburn}} package) as shown below:<br />
<br />
$ xorriso -as mkisofs -iso-level 3 \<br />
-full-iso9660-filenames \<br />
-volid "ARCH_201208" \<br />
-appid "Arch Linux Live/Rescue CD" \<br />
-publisher "Arch Linux <https://www.archlinux.org>" \<br />
-preparer "prepared by user" \<br />
-eltorito-boot isolinux/isolinux.bin \<br />
-eltorito-catalog isolinux/boot.cat \<br />
-no-emul-boot -boot-load-size 4 -boot-info-table \<br />
-isohybrid-mbr "/tmp/archiso/isolinux/isohdpfx.bin" \<br />
-output "/tmp/archiso.iso" "/tmp/archiso/"<br />
<br />
4. Burn {{ic|/tmp/archiso.iso}} to a CD and boot into your Mac using that CD.<br />
<br />
=== [[Archboot]] ===<br />
<br />
1. Create a directory {{ic|/tmp/archboot}} and extract the archboot iso file contents to it.<br />
<br />
2. Run {{ic|xorriso}} (part of {{Pkg|libisoburn}} package) as shown below:<br />
<br />
$ xorriso -as mkisofs -iso-level 3 -rock -joliet \<br />
-max-iso9660-filenames -omit-period \<br />
-omit-version-number -allow-leading-dots \<br />
-relaxed-filenames -allow-lowercase -allow-multidot \<br />
-volid "ARCHBOOT" -preparer "prepared by user" \<br />
-eltorito-boot boot/syslinux/isolinux.bin \<br />
-eltorito-catalog boot/syslinux/boot.cat \<br />
-no-emul-boot -boot-load-size 4 -boot-info-table \<br />
-isohybrid-mbr /tmp/archboot/boot/syslinux/isohdpfx.bin \<br />
-output "/tmp/archboot.iso" "/tmp/archboot/"<br />
<br />
3. Burn {{ic|/tmp/archboot.iso}} to a CD and boot into your Mac using that CD.<br />
<br />
== See also ==<br />
<br />
* Wikipedia's page on [http://en.wikipedia.org/wiki/UEFI UEFI]<br />
* Wikipedia's page on [http://en.wikipedia.org/wiki/EFI_System_partition UEFI SYSTEM Partition]<br />
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/x86_64/uefi.txt;hb=HEAD Linux Kernel UEFI Documentation]<br />
* [http://www.uefi.org/home/ UEFI Forum] - contains the official [http://www.uefi.org/specs/ UEFI Specifications] - GUID Partition Table is part of UEFI Specification<br />
* [http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Welcome_to_TianoCore Intel's Tianocore Project] for Open-Source UEFI firmware which includes DuetPkg for direct BIOS based booting and OvmfPkg used in QEMU and Oracle VirtualBox<br />
* [http://www.intel.com/technology/efi/ Intel's page on EFI]<br />
* [http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/efi-boot-process.html FGA: The EFI boot process]<br />
* [http://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx Microsoft's Windows and GPT FAQ] - Contains info on Windows UEFI booting also<br />
* [https://gitorious.org/tianocore_uefi_duet_builds/pages/Windows_x64_BIOS_to_UEFI Convert Windows Vista SP1+ or 7 x86_64 boot from BIOS-MBR mode to UEFI-GPT mode without Reinstall]<br />
* [https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB Create a Linux BIOS+UEFI and Windows x64 BIOS+UEFI bootable USB drive]<br />
* [http://rodsbooks.com/bios2uefi/ Rod Smith - A BIOS to UEFI Transformation]<br />
* [https://lkml.org/lkml/2011/6/8/322 UEFI Boot problems on some newer machines (LKML)]<br />
* [http://software.intel.com/en-us/articles/efi-shells-and-scripting/ EFI Shells and Scripting - Intel Documentation]<br />
* [http://software.intel.com/en-us/articles/uefi-shell/ UEFI Shell - Intel Documentation]<br />
* [http://www.hpuxtips.es/?q=node/293 UEFI Shell - bcfg command info]<br />
* [http://hackthejoggler.freeforums.org/download/file.php?id=28 Some useful 32-bit UEFI Shell utilities]</div>Geekbabyhttps://wiki.archlinux.org/index.php?title=Unified_Extensible_Firmware_Interface&diff=222435Unified Extensible Firmware Interface2012-09-10T13:20:12Z<p>Geekbaby: </p>
<hr />
<div>[[Category:Boot process]]<br />
[[ru:Unified Extensible Firmware Interface]]<br />
[[zh-CN:Unified Extensible Firmware Interface]]<br />
{{Article summary start}}<br />
{{Article summary text|An overview of the Unified Extensible Firmware Interface.}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|GUID Partition Table}}<br />
{{Article summary wiki|Master Boot Record}}<br />
{{Article summary wiki|Arch Boot Process}}<br />
{{Article summary end}}<br />
<br />
'''Unified Extensible Firmware Interface''' (or UEFI for short) is a new type of firmware that was initially designed by Intel (known as EFI then) mainly for its Itanium based systems. It introduces new ways of booting an OS that is distinct from the commonly used "MBR boot code" method followed for BIOS systems. It started as Intel's EFI in versions 1.x and then a group of companies called the UEFI Forum took over its development from which it was called Unified EFI starting with version 2.0 . As of 23 May 2012, UEFI Specification 2.3.1 is the most recent version.<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, these instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and therefore it is not a standard UEFI firmware.}}<br />
<br />
== Booting an OS using BIOS ==<br />
<br />
A BIOS or Basic Input-Output System is the very first program that is executed once the system is switched on. After all the hardware has been initialized and the POST operation has completed, the BIOS executes the first boot code in the first device in the device booting list. <br />
<br />
If the list starts with a CD/DVD drive, then the El-Torito entry in the CD/DVD is executed. This is how bootable CD/DVD works. If the list starts with a HDD, then BIOS executes the very first 440 bytes MBR boot code. The boot code then chainloads or bootstraps a much larger and complex bootloader which then loads the OS.<br />
<br />
Basically, the BIOS does not know how to read a partition table or filesystem. All it does is initialize the hardware, then load and run the 440-byte boot code.<br />
<br />
=== Multiboot on BIOS ===<br />
<br />
Since very little can be achieved by a program that fits into the 440-byte boot code area, multi-booting using BIOS requires a multi-boot capable bootloader (multi-boot refers to booting multiple operating systems, not to booting a kernel in the Multiboot format specified by the GRUB developers). So usually a common bootloader like [[GRUB]] or [[GRUB2]] or [[Syslinux]] or [[LILO]] would be loaded by the BIOS, and it would load an operating system by either chain-loading or directly loading the kernel.<br />
<br />
== Booting an OS using UEFI ==<br />
<br />
UEFI firmware does not support booting through the above mentioned method which is the only way supported by BIOS. UEFI has support for reading both the partition table as well as understanding filesystems. <br />
<br />
The commonly used UEFI firmwares support both MBR and GPT partition table. EFI in Apple-Intel Macs are known to support Apple Partition Map also apart from MBR and GPT. Most of the UEFI firmwares have support for accessing FAT12 (floppy disks) , FAT16 and FAT32 filesystems in HDD and ISO9660 (and UDF) in CD/DVDs. EFI in Apple-Intel Macs can access HFS/HFS+ filesystems also apart from the mentioned ones.<br />
<br />
UEFI does not launch any boot code in the MBR whether it exists or not. Instead it uses a special partition in the partition table called "EFI SYSTEM PARTITION" in which files required to be launched by the firmware is stored. Each vendor can store its files under <EFI SYSTEM PARTITION>/EFI/<VENDOR NAME>/ folder and can use the firmware or its shell (UEFI shell) to launch the boot program. An EFI System Partition is usually formatted as FAT32.<br />
<br />
Under UEFI, every program whether they are OS loaders or some utilities (like memory testing apps) or recovery tools outside the OS, should be a UEFI Application corresponding to the EFI firmware architecture. Most of the UEFI firmware in the market, including recent Apple Macs use x86_64 EFI firmware. Only some older macs use i386 EFI firmware while no non-Apple UEFI system is known to use i386 EFI firmware.<br />
<br />
A x86_64 EFI firmware does not include support for launching 32-bit EFI apps unlike the 64-bit Linux and Windows which include such support. Therefore the bootloader must be compiled for that architecture correctly.<br />
<br />
=== Multibooting on UEFI ===<br />
<br />
Since each OS or vendor can maintain its own files within the EFI SYSTEM PARTITION without affecting the other, multi-booting using UEFI is just a matter of launching a different UEFI application corresponding to the particular OS's bootloader. This removes the need for relying on chainloading mechanisms of one bootloader to load another to switch OSes.<br />
<br />
==== Linux Windows x86_64 UEFI-GPT Multiboot ====<br />
<br />
Windows Vista (SP1+) and 7 pr 8 x86_64 versions support booting natively using UEFI firmware. But for this they need [[GPT]] partitioning of the disk used for UEFI booting. Windows x86_64 versions support either UEFI-GPT booting or BIOS-MBR booting. Windows 32-bit versions support only BIOS-MBR booting. Follow the instructions provided in the forum link given in the references sections as to how to do this. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;2581408 for more info.<br />
<br />
This limitation does not exist in Linux Kernel but rather depends on the bootloader used. For the sake of Windows UEFI booting, the Linux bootloader used should also be installed in UEFI-GPT mode if booting from the same disk.<br />
<br />
== Boot Process under UEFI ==<br />
<br />
# System switched on - Power On Self Test, or POST process.<br />
# UEFI firmware is loaded.<br />
# Firmware reads its Boot Manager to determine which UEFI application to be launched and from where (ie. from which disk and partition).<br />
# Firmware launches the UEFI application from the FAT32 formatted UEFISYS partition as defined in the boot entry in the firmware's boot manager.<br />
# UEFI application may launch another application (in case of UEFI Shell or a boot manager like rEFInd) or the kernel and initramfs (in case of a bootloader like GRUB2) depending on how the UEFI application was configured.<br />
<br />
== Detecting UEFI Firmware Arch ==<br />
<br />
If you have a non-mac UEFI system, then you have a x86_64 (aka 64-bit) UEFI 2.x firmware.<br />
<br />
Some of the known x86_64 UEFI 2.x firmwares are Phoenix SecureCore Tiano, AMI Aptio, Insyde H2O.<br />
<br />
Some of the known systems using these firmwares are Asus EZ Mode BIOS (in Sandy Bridge P67 and H67 motherboards), MSI ClickBIOS, HP EliteBooks, Sony Vaio Z series, many Intel Server and Desktop motherboards<br />
<br />
<br />
Pre-2008 Macs mostly have i386-efi firmware while >=2008 Macs have mostly x86_64-efi. All macs capable of running Mac OS X Snow Leopard 64-bit Kernel have x86_64 EFI 1.x firmware.<br />
<br />
To find out the arch of the efi firmware in a Mac, boot into Mac OS X and type the following command<br />
<br />
<pre><br />
ioreg -l -p IODeviceTree | grep firmware-abi<br />
</pre><br />
<br />
If the command returns EFI32 then it is i386 EFI 1.x firmware. If it returns EFI64 then it is x86_64 EFI 1.x firmware. Macs do not have UEFI 2.x firmware as Apple's EFI implementation is not fully compliant with UEFI Specification.<br />
<br />
== UEFI Support in Linux Kernel ==<br />
<br />
=== Linux Kernel config options for UEFI ===<br />
<br />
The required Linux Kernel configuration options for UEFI systems are :<br />
<br />
CONFIG_EFI=y<br />
CONFIG_EFI_STUB=y<br />
CONFIG_RELOCATABLE=y<br />
CONFIG_FB_EFI=y<br />
CONFIG_FRAMEBUFFER_CONSOLE=y<br />
<br />
UEFI Runtime Variables/Services Support - 'efivars' kernel module . This option is important as this is required to manipulate UEFI Runtime Variables using tools like '''efibootmgr'''.<br />
<br />
CONFIG_EFI_VARS=m<br />
<br />
{{Note| This option is compiled as module in Arch core/testing kernel.}}<br />
<br />
{{Note|For Linux to access UEFI Runtime Services, the UEFI Firmware processor architecture and the Linux kernel processor architecture must match. This is independent of the bootloader used.}}<br />
<br />
{{Note|If the UEFI Firmware arch and Linux Kernel arch are different, then the "'''noefi'''" kernel parameter must be used to avoid the kernel panic and boot successfully. The "noefi" option instructs the kernel not to access the UEFI Runtime Services.}}<br />
<br />
GUID Partition Table [[GPT]] config option - mandatory for UEFI support<br />
<br />
CONFIG_EFI_PARTITION=y<br />
<br />
{{Note|All of the above options are required to boot Linux via UEFI, and are enabled in Archlinux kernels in official repos.}}<br />
<br />
Retrieved from http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/x86_64/uefi.txt;hb=HEAD .<br />
<br />
== UEFI Variables Support ==<br />
<br />
UEFI defines variables through which an operating system can interact with the firmware. UEFI Boot Variables are used by the boot-loader and used by the OS only for early system start-up. UEFI Runtime Variables allow an OS to manage certain settings of the firmware like the UEFI Boot Manager or managing the keys for UEFI Secure Boot Protocol etc.<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + x86 32-bit Kernel and vice-versa config will not work. This is true only for efivars kernel module and efibootmgr step. The other steps (ie. upto setting up <UEFISYS>/efi/arch/grub.{efi,cfg} ) can be done even in BIOS/Legacy boot mode.}}<br />
<br />
Access to UEFI Runtime services is provided by "efivars" kernel module which is enabled through the {{ic|<nowiki>CONFIG_EFI_VAR=m</nowiki>}} kernel config option. This module once loaded exposes the variables under the directory {{ic|/sys/firnware/efi/vars}}. One way to check whether the system has booted in UEFI boot mode is to load the "efivars" kernel module and check for the existence of {{ic|/sys/firnware/efi/vars}} directory with contents similar to :<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel):<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
The UEFI Runtime Variables will not be exposed to the OS if you have used "noefi" kernel parameter in the boot-loader menu. This parameter instructs the kernel to completely ignore UEFI Runtime Services.<br />
<br />
=== Userspace Tools ===<br />
<br />
There are few tools that can access/modify the UEFI variables, namely<br />
<br />
# efibootmgr - Used to create/modify boot entries in the UEFI Boot Manager - {{Pkg|efibootmgr}} or {{AUR|efibootmgr-git}}<br />
# uefivars - simply dumps the variables - {{AUR|uefivars-git}} - uses efibootmgr library<br />
# Ubuntu's Firmware Test Suite - fwts - {{AUR|fwts-git}} - uefidump command - {{ic|fwts uefidump}} <br />
<br />
=== Non-Mac UEFI systems ===<br />
<br />
==== efibootmgr ====<br />
<br />
{{Warning|Using {{ic|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs. Experimental "bless" utility for Linux by Fedora developers - {{AUR|mactel-boot}}.}}<br />
<br />
{{Note|{{ic|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Otherwise the message {{ic|Fatal: Couldn't open either sysfs or procfs directories for accessing EFI variables}} is shown.}}<br />
<br />
Initially the user may be required to manually launch the boot-loader from the firmware itself (using maybe the UEFI Shell) if the UEFI boot-loader was installed when the system is booted in BIOS mode. Then {{ic|efibootmgr}} should be run to make the UEFI boot-loader entry as the default entry in the UEFI Boot Manager.<br />
<br />
To use efibootmgr, first load the 'efivars' kernel module:<br />
<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables (noefi?).<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode, without the "noefi" kernel parameter.<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{ic|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB.<br />
<br />
{{Note| The below commands use grub-efi-x86_64 boot-loader as example.}}<br />
<br />
Assume the boot-loader file to be launched is {{ic|/boot/efi/efi/arch_grub/grubx64.efi}}. {{ic|/boot/efi/efi/arch_grub/grubx64.efi}} can be split up as {{ic|/boot/efi}} and {{ic|/efi/arch_grub/grubx64.efi}}, wherein {{ic|/boot/efi}} is the mountpoint of the UEFI System Partition, which is assumed to be /dev/sdXY (here X and Y are just placeholders for the actual values - eg:- in /dev/sda1 , X=a Y=1).<br />
<br />
To determine the actual device path for the UEFI System Partition, try :<br />
<br />
# cat /proc/self/mounts | grep /boot/efi | awk '{print $1}'<br />
/dev/sdXY<br />
<br />
Then create the boot entry using efibootmgr as follows :<br />
<br />
# efibootmgr --create --gpt --disk /dev/sdX --part Y --write-signature --label "Arch Linux (GRUB2)" --loader '\EFI\arch_grub\grubx64.efi'<br />
<br />
In the above command {{ic|/boot/efi/efi/arch_grub/grubx64.efi}} translates to {{ic|/boot/efi}} and {{ic|/efi/arch_grub/grubx64.efi}} which in turn translate to drive {{ic|/dev/sdX}} -> partition Y -> file {{ic|/EFI/arch_grub/grubx64.efi}}.<br />
<br />
UEFI uses backward slash as path separator (similar to Windows paths).<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README] .<br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{ic|\EFI\arch_grub\grubx64.efi}} or {{ic|\efi\arch_grub\grubx64.efi}} does not matter (this will change if the filesystem encoding is UTF-8).<br />
<br />
== Linux Bootloaders for UEFI ==<br />
<br />
See [[UEFI Bootloaders]].<br />
<br />
== Create an UEFI System Partition in Linux ==<br />
<br />
{{Note|The UEFISYS partition can be of any size supported by FAT32 filesystem. According to Microsoft Documentation, the minimum partition/volume size for FAT32 is 512 MiB. Therefore it is recommended for UEFISYS partition to be atleast 512 MiB. Higher partition sizes are fine, especially if you use multiple UEFI bootloaders, or multiple OSes booting via UEFI, so that there is enough space to hold all the related files. If you are using Linux EFISTUB booting, then you need to make sure there is adequate space available for keeping the Kernel and Initramfs files in the UEFISYS partition.}}<br />
<br />
=== For GPT partitioned disks ===<br />
Two choices:<br />
* Using GNU Parted/GParted: Create a FAT32 partition. Set "boot" flag on for that partition.<br />
* Using GPT fdisk (aka gdisk): Create a partition with gdisk type code "EF00". Then format that partition as FAT32 using {{ic|mkfs.vfat -F32 /dev/<THAT_PARTITION>}}<br />
<br />
{{Note|Setting "boot" flag in parted in a MBR partition marks that partition as active, while the same "boot" flag in a GPT partition marks that partition as "UEFI System Partition".}}<br />
<br />
{{Warning|Do not use util-linux fdisk, cfdisk or sfdisk to change the type codes in a GPT disk. Similarly do not use gptfdisk gdisk, cgdisk or sgdisk on a MBR disk, it will be automatically converted to GPT (no data loss will occur, but the system will fail to boot).}}<br />
<br />
=== For MBR partitioned disks ===<br />
Two choices:<br />
* Using GNU Parted/GParted: Create FAT32 partition. Change the type code of that partition to 0xEF using fdisk, cfdisk or sfdisk.<br />
* Using fdisk: Create a partition with partition type 0xEF and format it as FAT32 using {{ic|mkfs.vfat -F32 /dev/<THAT_PARTITION>}}<br />
<br />
{{Note|It is recommended to use always GPT for UEFI boot as some UEFI firmwares do not allow UEFI-MBR boot.}}<br />
<br />
== UEFI Shell ==<br />
<br />
The UEFI Shell is a shell/terminal for the firmware which allows launching uefi applications which include uefi bootloaders. Apart from that, the shell can also be used to obtain various other information about the system or the firmware like memory map (memmap), modifying boot manager variables (bcfg), running partitioning programs (diskpart), loading uefi drivers, editing text files (edit), hexedit etc. <br />
<br />
=== UEFI Shell download links === <br />
<br />
You can download a BSD licensed UEFI Shell from Intel's Tianocore UDK/EDK2 Sourceforge.net project.<br />
<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ShellBinPkg/UefiShell/X64/Shell.efi x86_64 UEFI Shell 2.0 (Beta)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/X64/Shell_Full.efi x86_64 UEFI Shell 1.0 (Old)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ShellBinPkg/UefiShell/Ia32/Shell.efi i386 UEFI Shell 2.0 (Beta)]<br />
* [https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/Ia32/Shell_Full.efi i386 UEFI Shell 1.0 (Old)]<br />
<br />
Shell 2.0 works only in UEFI 2.3+ systems and is recommended over Shell 1.0 in those systems. Shell 1.0 should work in all UEFI systems irrespective of the spec. version the firmware follows. More info at [http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=ShellPkg ShellPkg] and [http://sourceforge.net/mailarchive/message.php?msg_id=28690732 this mail]<br />
<br />
=== Launching UEFI Shell ===<br />
<br />
Few Asus and other AMI Aptio x86_64 UEFI firmware based motherboards (from Sandy Bridge onwards) provide an option called {{ic|"Launch EFI Shell from filesystem device"}} . For those motherboards, download the x86_64 UEFI Shell and copy it to your UEFI SYSTEM PARTITION as {{ic|<UEFI_SYSTEM_PARTITION>/shellx64.efi}} (mostly {{ic|/boot/efi/shellx64.efi}}) .<br />
<br />
Systems with Phoenix SecureCore Tiano UEFI firmware are known to have embedded UEFI Shell which can be launched using either F6, F11 or F12 key.<br />
<br />
{{Note|If you are unable to launch UEFI Shell from the firmware directly using any of the above mentioned methods, create a FAT32 USB pen drive with Shell.efi copied as (USB)/efi/boot/bootx64.efi . This USB should come up in the firmware boot menu. Launching this option will launch the UEFI Shell for you.}}<br />
<br />
=== Important UEFI Shell Commands === <br />
<br />
More info at http://software.intel.com/en-us/articles/efi-shells-and-scripting/<br />
<br />
==== bcfg ====<br />
<br />
BCFG command is used to modify the UEFI NVRAM entries, which allow the user to change the boot entries or driver options. This command is described in detail in page 83 (Section 5.3) of "UEFI Shell Specification 2.0" pdf document.<br />
<br />
{{Note| Users are recommended to try {{ic|bcfg}} only if {{ic|efibootmgr}} fails to create working boot entries in their system.}}<br />
<br />
{{Note| UEFI Shell 1.0 does not support {{ic|bcfg}} command.}}<br />
<br />
To dump a list of current boot entries -<br />
<br />
Shell> bcfg boot dump -v<br />
<br />
To add a boot menu entry for grub2's grubx64.efi (for example) as 4th (numbeering starts from zero) option in the boot menu<br />
<br />
Shell> bcfg boot add 3 fs0:\EFI\arch\grubx64.efi "Arch Linux (GRUB2)"<br />
<br />
where fs0: is the mapping corresponding to the UEFI System Partition and \EFI\arch\grubx64.efi is the file to be launched.<br />
<br />
To remove the 4th boot option<br />
<br />
Shell> bcfg boot rm 3<br />
<br />
To move the boot option #3 to #0 (i.e. 1st or the default entry in the UEFI Boot menu)<br />
<br />
Shell> bcfg boot mv 3 0<br />
<br />
For bcfg help text<br />
<br />
Shell> help bcfg -v -b<br />
<br />
or<br />
<br />
Shell> bcfg -? -v -b<br />
<br />
==== edit ====<br />
<br />
EDIT command provides a basic text editor with an interface similar to nano text editor, but slightly less functional. It handles UTF-8 encoding and takes care or LF vs CRLF line endings.<br />
<br />
To edit, for example grub2's grub.cfg in the UEFI System Partition (fs0: in the firmware)<br />
<br />
Shell> fs0:<br />
FS0:\> cd \efi\grub<br />
FS0:\efi\grub\> edit grub.cfg<br />
<br />
== Hardware Compatibility ==<br />
<br />
Main page [[HCL/Firmwares/UEFI]]<br />
<br />
<br />
== Create UEFI bootable USB from ISO ==<br />
<br />
{{Note|dd'ing the ISO (isohybrid method) to the USB drive will not work for UEFI boot.}}<br />
<br />
=== Archiso ===<br />
<br />
1. Create a directory {{ic|/tmp/archiso}} and extract the archiso file contents to it (use file-roller or something similiar).<br />
<br />
2. Create a directory {{ic|/tmp/archiso_efiboot}} and extract {{ic|/tmp/archiso/EFI/archiso/efiboot.img}} to it using {{ic|7z}} command from {{Pkg|p7zip}} package (use file-roller, or 7z)<br />
<br />
Example for 7z:<br />
$ 7z e -opath efiboot.img # without space between -o and path<br />
<br />
3. Run the below commands:<br />
<br />
$ mkdir -p /tmp/archiso/EFI/{archiso,boot}<br />
$ cp /tmp/archiso/arch/boot/x86_64/vmlinuz /tmp/archiso/EFI/archiso/vmlinuz.efi<br />
$ cp /tmp/archiso/arch/boot/x86_64/archiso.img /tmp/archiso/EFI/archiso/archiso.img<br />
$ cp /tmp/archiso_efiboot/bootx64.efi /tmp/archiso/EFI/boot/bootx64.efi<br />
$ cp /tmp/archiso_efiboot/startup.nsh /tmp/archiso/EFI/boot/startup.nsh<br />
<br />
4. Find out the filesystem label to be used for the USB by reading "{{ic|1=archisolabel=}}" part in {{ic|/tmp/archiso/EFI/boot/startup.nsh}}. For example if {{ic|/tmp/archiso/EFI/boot/startup.nsh}} has {{ic|1=archisolabel=ARCH_201208}} then the filesystem label to be used is {{ic|ARCH_201208}} . <br />
<br />
5. Create a directory {{ic|/tmp/archisousb}} . Format the USB drive as FAT32 (or FAT16) (no other filesystem is supported) and set the filesystem label same as the one obtained in step 4, and mount it to {{ic|/tmp/archisousb}} .<br />
<br />
6. Copy the contents of {{ic|/tmp/archiso}} to {{ic|/tmp/archisousb}} and then umount {{ic|/tmp/archisousb}} .<br />
<br />
=== [[Archboot]] ===<br />
<br />
1. Create a directory {{ic|/tmp/archboot}} and extract the archiso file contents to it.<br />
<br />
{{Note|Follow steps 2 and 3 only if {{ic|/tmp/archboot/EFI/boot/bootx64.efi}} does not exist, even after extracting archboot iso to {{ic|/tmp/archboot}} .}}<br />
<br />
2. Create a directory {{ic|/tmp/archboot_efiboot}} and extract {{ic|/tmp/archboot/boot/grub/grub_uefi_x86_64.bin}} to it using {{ic|7z}} command from {{Pkg|p7zip}} package.<br />
<br />
3. Run the below commands:<br />
<br />
# mkdir -p /tmp/archboot/EFI/boot<br />
# cp /tmp/archboot_efiboot/EFI/boot/bootx64.efi /tmp/archboot/EFI/boot/bootx64.efi<br />
<br />
4. Create a directory {{ic|/tmp/archbootusb}} . Format the USB drive as FAT32 (or FAT16) (no other filesystem is supported) and mount it to {{ic|/tmp/archbootusb}} .<br />
<br />
5. Copy the contents of {{ic|/tmp/archboot}} to {{ic|/tmp/archbootusb}} and then umount {{ic|/tmp/archbootusb}} .<br />
<br />
== Remove UEFI boot support from ISO ==<br />
<br />
Most of the 32-bit EFI Macs and some 64-bit EFI Macs refuse to boot from a UEFI(X64)+BIOS bootable CD/DVD. In these cases the iso should be rebuilt without UEFI boot support, retaining only BIOS boot.<br />
<br />
=== Archiso ===<br />
<br />
1. Obtain the ISO label from the output of {{ic|file <path_to_iso>}}. Let it be {{ic|ARCH_201208}} for example.<br />
<br />
2. Create a directory {{ic|/tmp/archiso}} and extract the archiso file contents to it.<br />
<br />
3. Run {{ic|xorriso}} (part of {{Pkg|libisoburn}} package) as shown below:<br />
<br />
$ xorriso -as mkisofs -iso-level 3 \<br />
-full-iso9660-filenames \<br />
-volid "ARCH_201208" \<br />
-appid "Arch Linux Live/Rescue CD" \<br />
-publisher "Arch Linux <https://www.archlinux.org>" \<br />
-preparer "prepared by user" \<br />
-eltorito-boot isolinux/isolinux.bin \<br />
-eltorito-catalog isolinux/boot.cat \<br />
-no-emul-boot -boot-load-size 4 -boot-info-table \<br />
-isohybrid-mbr "/tmp/archiso/isolinux/isohdpfx.bin" \<br />
-output "/tmp/archiso.iso" "/tmp/archiso/"<br />
<br />
4. Burn {{ic|/tmp/archiso.iso}} to a CD and boot into your Mac using that CD.<br />
<br />
=== [[Archboot]] ===<br />
<br />
1. Create a directory {{ic|/tmp/archboot}} and extract the archboot iso file contents to it.<br />
<br />
2. Run {{ic|xorriso}} (part of {{Pkg|libisoburn}} package) as shown below:<br />
<br />
$ xorriso -as mkisofs -iso-level 3 -rock -joliet \<br />
-max-iso9660-filenames -omit-period \<br />
-omit-version-number -allow-leading-dots \<br />
-relaxed-filenames -allow-lowercase -allow-multidot \<br />
-volid "ARCHBOOT" -preparer "prepared by user" \<br />
-eltorito-boot boot/syslinux/isolinux.bin \<br />
-eltorito-catalog boot/syslinux/boot.cat \<br />
-no-emul-boot -boot-load-size 4 -boot-info-table \<br />
-isohybrid-mbr /tmp/archboot/boot/syslinux/isohdpfx.bin \<br />
-output "/tmp/archboot.iso" "/tmp/archboot/"<br />
<br />
3. Burn {{ic|/tmp/archboot.iso}} to a CD and boot into your Mac using that CD.<br />
<br />
== See also ==<br />
<br />
* Wikipedia's page on [http://en.wikipedia.org/wiki/UEFI UEFI]<br />
* Wikipedia's page on [http://en.wikipedia.org/wiki/EFI_System_partition UEFI SYSTEM Partition]<br />
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/x86/x86_64/uefi.txt;hb=HEAD Linux Kernel UEFI Documentation]<br />
* [http://www.uefi.org/home/ UEFI Forum] - contains the official [http://www.uefi.org/specs/ UEFI Specifications] - GUID Partition Table is part of UEFI Specification<br />
* [http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Welcome_to_TianoCore Intel's Tianocore Project] for Open-Source UEFI firmware which includes DuetPkg for direct BIOS based booting and OvmfPkg used in QEMU and Oracle VirtualBox<br />
* [http://www.intel.com/technology/efi/ Intel's page on EFI]<br />
* [http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/efi-boot-process.html FGA: The EFI boot process]<br />
* [http://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx Microsoft's Windows and GPT FAQ] - Contains info on Windows UEFI booting also<br />
* [https://gitorious.org/tianocore_uefi_duet_builds/pages/Windows_x64_BIOS_to_UEFI Convert Windows Vista SP1+ or 7 x86_64 boot from BIOS-MBR mode to UEFI-GPT mode without Reinstall]<br />
* [https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB Create a Linux BIOS+UEFI and Windows x64 BIOS+UEFI bootable USB drive]<br />
* [http://rodsbooks.com/bios2uefi/ Rod Smith - A BIOS to UEFI Transformation]<br />
* [https://lkml.org/lkml/2011/6/8/322 UEFI Boot problems on some newer machines (LKML)]<br />
* [http://software.intel.com/en-us/articles/efi-shells-and-scripting/ EFI Shells and Scripting - Intel Documentation]<br />
* [http://software.intel.com/en-us/articles/uefi-shell/ UEFI Shell - Intel Documentation]<br />
* [http://www.hpuxtips.es/?q=node/293 UEFI Shell - bcfg command info]<br />
* [http://hackthejoggler.freeforums.org/download/file.php?id=28 Some useful 32-bit UEFI Shell utilities]</div>Geekbaby