This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.
Please visit our production wiki at https://wiki.gentoo.org
GRUB2: Difference between revisions
m (Refer to Hybrid partition table) |
(Installing GRUB2 from within a chroot: is troubleshooting, not extended feature) |
||
Line 489: | Line 489: | ||
Other issues that might come up are documented below together with their resolutions. | Other issues that might come up are documented below together with their resolutions. | ||
=== Installing GRUB2 from within a chroot === | |||
When a separate {{Path|/boot}} partition exists, be sure to mount the target root partition before chrooting, but do not the {{Path|/boot}} partition until ''after'' chrooting to the new environment. This is required because <tt>grub2-mkconfig</tt> will not detect {{Path|/boot}} as a separate partition and will assume {{Path|/boot}} and root are on the same partition. | |||
=== Repopulating EFI boot manager entries === | === Repopulating EFI boot manager entries === |
Revision as of 17:54, 1 January 2015
GRUB2 is a boot loader with support for modern day computer systems. It is meant to replace the older GRUB boot loader (now referred to as "GRUB Legacy"). GRUB2 has an entirely separate code base from GRUB Legacy and boasts features such as a new shell-like syntax which permits advanced scripting capabilities. Current GRUB Legacy users are encouraged to migrate their systems to GRUB2.
Upgrading to GRUB 2 might be done out of necessary, as it allows:
- Booting from UEFI platforms.
- Booting from GPT partitioned drives without needing a hybrid MBR (hybrid MBR can enabled as needed for compatibility or portability).
- Booting from a btrfs formatted /boot partition.
- Booting directly from a btrfs raid set without needing an initramfs for early mount setup.
- Booting directly from logical volume management (such as LVM2).
- Booting with support for DM-RAID (RAID 0, 1, 4, 5, 6, 9 and 10).
- Booting from encrypted devices (LUKS).
For a shotgun approach, see GRUB2 Quick Start.
Installation
The sys-boot/grub package is slotted. Both grub-0.97 (GRUB Legacy) and grub-2.00 may be installed at the same time, however only one version of GRUB may be installed in a MBR at a time. In this article, we focus on GRUB2.
By default, GRUB2 will guess a default platform target at build time. This may be overridden by setting the GRUB_PLATFORMS
variable in make.conf.
/etc/portage/make.conf
Example of setting GRUB_PLATFORMS variable for EMU, EFI, and PC supportGRUB_PLATFORMS="emu efi-32 efi-64 pc"
The following platforms are supported depending on the target CPU:
Target | |||||||
---|---|---|---|---|---|---|---|
Platform | i386 | ia64 | mips | mipsel | powerpc | spac64 | x86_64 |
arc | No | No | No | Yes | No | No | No |
coreboot | Yes | No | No | No | No | No | 32-bit |
efi | Yes | Yes | No | No | No | No | Yes |
emu | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
ieee1275 | Yes | No | No | No | Yes | Yes | 32-bit |
loongson | No | No | No | Yes | No | No | No |
multiboot | Yes | No | No | No | No | No | 32-bit |
qemu | Yes | No | No | No | No | No | 32-bit |
qemu-mips | No | No | Yes | No | No | No | No |
pc | Yes | No | No | No | No | No | 32-bit |
To install GRUB2 use the normal emerge syntax:
root #
emerge --ask --newuse sys-boot/grub:2
Optionally, install the os-prober utility (provided through the sys-boot/os-prober package) to have GRUB2 probe for other operating systems when running the grub2-mkconfig command. In most instances, this will enable GRUB2 to automatically detect other operating systems (Windows 7, Windows 8.1, etc.).
root #
emerge --ask --newuse sys-boot/os-prober
The GRUB2 (and optionally sys-boot/os-prober) installations do not automatically enable the boot loader. These only install the software on the operating system, but to install the boot loader to the system itself (so that it is used when booting the system), additional steps need to be taken, which are covered in the Configuration section.
Configuration
There are two important aspects to the configuration of GRUB2:
- installation of GRUB2 software as the boot loader of the system
- configuration of the GRUB2 boot loader itself
The installation of GRUB2 software is specific to the type of system, and is covered in Installing the boot loader. First we cover the configuration of the boot loader itself.
Main configuration file
GRUB2 does not require the administrator to manually maintain a boot option configuration (as is the case with boot loaders such as GRUB Legacy and LILO). Instead it can generate its configuration file (/boot/grub/grub.cfg) using the grub2-mkconfig command. This utility will use the scripts in /etc/grub.d/ and the settings in /etc/default/grub.
The grub2-mkconfig utility does not work properly when using software RAID. Manual configuration of the scripts in /etc/grub.d/ is necessary, as otherwise after installation the system will be left in a non-bootable state.
After modifying one or more settings, run the grub2-mkconfig utility with the -o option pointing to the output file located at /boot/grub/grub.cfg (this is GRUB2's default output location):
root #
grub2-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ... Found linux image: /boot/vmlinuz-3.3.0-gentoo done
Each time the grub2-mkconfig utility is called a new configuration will be generated.
If grub2-mkconfig does not report any found entries then no entries were found. In this case GRUB2 will offer no boot selections when upon system restart which may be a tricky, time consuming situation to resolve. Make sure the output is satisfactory before restarting the system.
Setting configuration parameters
GRUB2 uses /boot/grub/grub.cfg as its configuration file. However, it is advised to automatically generate this file based on the configuration entries in /etc/default/grub. The file uses key/value pairs which are used by the scripts in /etc/grub.d to generate a working configuration file.
The following variables can be set to control how GRUB2 will function:
Variable | Explanation | Default value |
---|---|---|
GRUB_FONT
|
Sets a path to a PF2 font for GRUB2 to use. PF2 fonts can be created using the grub2-mkfont utility.
For example, to create a GRUB2 PF2 font from a TTF (True Text Font) called DroidSansMonoSlash.ttf run: root # grub2-mkfont /usr/share/fonts/droid/DroidSansMonoSlashed.ttf --size=20 --output /boot/grub/fonts/DroidSansMonoSlashed20.pcf To use the newly created font, set the |
|
GRUB_DEFAULT
|
Defines the default menu entry selected on boot. May be a numeric index, a menu title, or "saved". | Defaults to first detected entry. |
GRUB_TIMEOUT
|
Delay (in seconds) before booting default menu entry. Set to 0 to wait indefinitely.
|
The default is 5 seconds. |
GRUB_DISABLE_RECOVERY
|
If set to true, recovery menu entries will not be generated. On Linux, recovery entries pass "single" on the kernel command line. | |
GRUB_CMDLINE_LINUX
|
Parameters to be passed on the kernel command line for all Linux menu entries. | |
GRUB_CMDLINE_LINUX_DEFAULT
|
Parameters to be passed on the kernel command line for non-recovery Linux menu entries. | |
GRUB_DISABLE_LINUX_UUID
|
If true, ${GRUB_DEVICE} is passed in the root= parameter on the kernel command line. If false, ${GRUB_DEVICE_UUID} is passed in the root= parameter on the kernel command line when an initramfs is available.
|
|
GRUB_GFXPAYLOAD_LINUX
|
Controls the video mode in which the Linux kernel starts. May be set to "text", "keep", or a display resolution. | |
GRUB_DEVICE
|
The initial root device (i.e. the kernel's root= parameter). Set this to override the grub2-mkconfig command's root device auto-detection. For example, GRUB_DEVICE=/dev/ram0 will force root=/dev/ram0 to be used in the kernel command line.
|
|
GRUB_DISABLE_SUBMENU
|
Set to y to list all kernel options instead of compacting them under an "Advanced options" section
|
After modifying the parameters, regenerate the GRUB2 configuration file with grub2-mkconfig.
Enabling or disabling configuration scripts
The directory /etc/grub.d/ contains the scripts that grub2-mkconfig uses to generate a grub.cfg file. By default the contents of this directory should be similar to the following:
user $
ls /etc/grub.d/
00_header 10_linux 20_linux_xen 30_os-prober 40_custom 41_custom README
GRUB2 will use all installed scripts that are marked as executable (which by default, they all are). To disable any of the scripts simply remove the executable bit from the script's file permissions using the chmod command. In the following example every script but 00_header and 10_linux are disabled:
root #
chmod -x /etc/grub.d/{20_linux_xen,30_os-prober,40_custom,41_custom}
After modifying the scripts (or removing the executable bit), regenerate the GRUB2 configuration file using grub2-mkconfig.
Installing the boot loader
Installing GRUB2 as the system's boot loader depends on how the system is meant to boot (through BIOS or UEFI) and how the disk on which the boot loader should be installed is partitioned (using MBR or GPT partition layout).
This article covers the following situations:
Select the installation instructions appropriate for the system.
BIOS with MBR
When the system is meant to dual-boot with Microsoft Windows, make sure that the system itself does not have an EFI firmware. Even when such systems are booted in 'legacy BIOS' mode, Microsoft Windows will refuse to boot.
Make sure that the /boot location is available - if this uses a separate partition, make sure that it is mounted:
root #
mount /boot
Run the grub2-install command to copy the relevant files to /boot/grub. On the PC platform, this also installs a boot image to the Master Boot Record (MBR) or a partition's boot sector. If all goes well, after running the grub2-install command an output such as the one below is to be expected:
root #
grub2-install /dev/sda
Installation finished. No error reported.
grub2-install accepts a --target option to set the CPU architecture and system platform. If unspecified, grub2-install will attempt to guess the proper values; on an AMD64/x86 system it will use i386-pc by default. grub2-install also accepts a --boot-directory option to tell the GRUB2 installer which directory to look for GRUB2's boot files. This defaults to the current /boot but is useful when trying to move a root partition.
Partitioning for BIOS with MBR
Be sure to leave enough free space before the first partition. Starting the first partition at sector 2048 leaves at least 1 MiB of disk space for the master boot record. It is recommended (but not mandatory) to create an additional partition for GRUB called the BIOS boot partition. This partition just needs to be defined, but not formatted.
If the Gentoo installation instructions were followed, this BIOS boot partition will already be avaialble.
BIOS with GPT
When the system is meant to dual-boot with Microsoft Windows, make sure that the system itself does not have an EFI firmware. Even when such systems are booted in 'legacy BIOS' mode, Microsoft Windows will refuse to boot. Also, older Microsoft Windows systems might not support GPT. It is possible to use a hybrid MBR-GPT approach, see Hybrid partition table.
If a /boot partition is needed, start by mounting the /boot partition:
root #
mount /boot
If all goes well, after running the grub2-install command an output such as the one below is to be expected:
root #
grub2-install /dev/sda
Installation finished. No error reported.
grub2-install accepts a --target option to set the CPU architecture and system platform. If unspecified, grub2-install will attempt to guess the correct at the correct values; on an AMD64/x86 system it will use i386-pc by default. grub2-install also accepts a --boot-directory option to tell the GRUB2 installer which directly to look for GRUB2's boot files. This defaults to the current /boot but is useful when trying to move a root partition.
Partitioning for BIOS with GPT
When a GPT partition table is present on the system, a small BIOS boot partition (with type FE02
, which is different from the EFI System Partition (ESP) which has type EF00
) will need to be available. 1 MiB will be enough to work but 2-4 MiB is a more safe option. This BIOS boot partition will hold the stage 2 of the bootloader. BIOS boot partitions do not need formatted with a filesystem; the grub2-install command will overwrite any pre-existing filesystem with one of it's own.
To set a partition as a BIOS partition use the command line tool parted (sys-block/parted) by typing (change 1
to the number of the partition to mark as a BIOS Boot partition!):
(parted)
set 1 bios_grub on
With sys-apps/gptfdisk's cgdisk utility, this is accomplished by setting the partition type to 0xEF02
and give it a label of gptbios
.
Next to a BIOS partition, an EFI System Partition must be available (which is FAT-formatted).
The following is the output of pressing the p key using the gdisk utility on a GPT partitioned disk with both a BIOS boot [0xEF02] partition and an EFI [0xEF00] partition:
root #
gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.1 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): p Disk /dev/sdc: 976773168 sectors, 465.8 GiB Logical sector size: 512 bytes Disk identifier (GUID): AA369F4D-37A4-4C0D-A357-DC24B99A6337 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 976773134 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 828377087 395.0 GiB 8E00 Linux LVM 2 828377088 891291647 30.0 GiB 0700 Microsoft basic data 3 891291648 975177727 40.0 GiB 0700 Microsoft basic data 4 975177728 976754687 770.0 MiB 8300 Linux filesystem 5 976754688 976756735 1024.0 KiB EF02 BIOS boot partition 6 976756736 976773134 8.0 MiB EF00 EFI System Command (? for help):
The
0x
hexadecimal prefix does not need to be entered for GPT when using fdisk.Using the same setup, the parted utility gives an output with slightly different syntax:
root #
parted /dev/sdc
GNU Parted 3.0 Using /dev/sdc (parted) print ... Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 424GB 424GB Linux LVM lvm 2 424GB 456GB 32.2GB Microsoft basic data 3 456GB 499GB 42.9GB Microsoft basic data 4 499GB 500GB 807MB ext2 Linux filesystem 5 500GB 500GB 1049kB BIOS boot partition bios_grub 6 500GB 500GB 8396kB EFI System boot (parted)
Creating partitions in gdisk is straight forward for users already familiar with the fdisk partitioning utility. After starting gdisk, type n (for new) in the main menu, provide beginning and end sectors (if needed), then set the partition type EF00
for an EFI system partition.
Users who have followed the Gentoo installation instructions will already have the proper partitioning layout set up.
UEFI with GPT
Make sure that the /boot location is available - if this uses a separate partition, make sure that it is mounted:
root #
mount /boot
Run the grub2-install command to copy the relevant files to /boot/grub. This should install Grub2 in /boot/grub, copy the core image to /boot/efi/EFI/gentoo/grubx64.efi, and call efibootmgr to add a boot entry.
root #
grub2-install --target=x86_64 /dev/sda
Installation finished. No error reported.
grub2-install accepts a --target option to set the CPU architecture and system platform. If unspecified, grub2-install will attempt to guess the proper values; on an AMD64/x86 system it will use i386-pc by default. grub2-install also accepts a --boot-directory option to tell the GRUB2 installer which directory to look for GRUB2's boot files. This defaults to the current /boot but is useful when trying to move a root partition.
Partitioning for UEFI with GPT
For UEFI GPT boot using GRUB2, the system must have a dedicated EFI partition containing a FAT filesystem.
The EFI partition can replace having a /boot partition on /dev/sda1 by having a /boot/efi partition on /dev/sda1. This is to say a successful EFI boot scenario using GRUB2 can operate with two partitions total (three total if a swap partition is needed): a root partition and an EFI partition. Using this configuration, the /boot folder will be located in the root / partition (at /boot) and the EFI partition will mount in the boot folder (at /boot/efi). For further clarification, see the example /etc/fstab file below.
/etc/fstab
Example of an UEFI capable /etc/fstab file with a swap partition:/dev/sda1 /boot/efi vfat noauto,noatime 1 2 /dev/sda2 none swap sw 0 0 /dev/sda3 / ext4 noatime 0 1
Generating a 100MB partition for /boot/efi should provide plenty of space for holding multiple
- .efi files (multiple entries will most likely not be needed; most systems will only use one).
Create the partition using the partitioning tool of choice. The gdisk (sys-apps/gptfdisk) and parted (sys-block/parted) tools fit nicely for this purpose. When using the gdisk utility, be sure to use type EF00
.
Proceed to create a FAT filesystem on the EFI system partition using mkdosfs and add it to /etc/fstab by following the example below:
root #
mkdosfs -F 32 -n efi-boot /dev/sda1
root #
mkdir /boot/efi
/etc/fstab
Adding the /boot/efi mount entry/dev/sda1 /boot/efi vfat noauto,noatime 1 2
root #
mount /boot/efi
It is helpful to set the
GRUB_PLATFORMS
variable in /etc/portage/make.conf. This will assist GRUB2 in determining what options to use when detecting the proper EFI target. For 32-bit EFI systems use efi-32
. For 64-bit use efi-64
.In order for GRUB2 to install properly, the EFI directory must be mounted and the efivars kernel module must be loaded before the grub2-install command will complete successfully.
Alternative: using the default UEFI firmware location
If the system's UEFI firmware fails to find GRUB2's EFI bootloader file, using the default boot loader location should provide a working solution. This circumvents the boot menu managed by efibootmgr and thus offers reduced functionality, but is less error prone. Do do this, verify the EFI partition is mounted at /boot/efi then copy the file grubx64.efi located at /boot/efi/EFI/gentoo/grubx64.efi to /boot/efi/EFI/BOOT/BOOTX64.EFI. This example assumes a 64-bit EFI system, adjust accordingly for 32-bit EFI systems.
Extended features
Chainloading
GRUB2 was built with a truly improved chainload mode when compared to GRUB Legacy. To chainload another boot loader, use the chainloader
option.
/boot/grub/grub.cfg
Chainloading another bootloadermenuentry "Custom Super Bootloader Example" { insmod part_msdos insmod chain chainloader (hd1,1)+1 }
For more information on chainloading, please see the Chainloading sub-page.
Enabling resume swap for suspend
Open up /etc/default/grub with root privileges and add:
/etc/default/grub
Enabling resume swapGRUB_CMDLINE_LINUX="resume=/dev/sdXY"
Where XY is the swap partition location, which can be found by running the fdisk
command:
root #
fdisk -l
If it appears UUID labels are being used in /etc/default/grub instead of a device path then enter the UUID instead. In order to update the menu list with the startup information that was changed in GRUB2's configuration file (/etc/default/grub) run:
root #
grub2-mkconfig -o /boot/grub/grub.cfg
Installing GRUB2 from within a chroot
When a separate /boot partition exists, be sure to mount the target root partition before chrooting, but do not the /boot partition until after chrooting to the new environment. This is required because grub2-mkconfig will not detect /boot as a separate partition and will assume /boot and root are on the same partition.
Booting from the network (PXE)
For more information on network booting with GRUB2, read the official "Network (PXE)" section from the GNU software manual.
Using framebuffer display
To have GRUB2 use a framebuffer graphical display, re-emerge GRUB with the truetype
USE flag enabled. This will install a default True Type font as well as a font conversion utility.
root #
emerge --ask --newuse sys-boot/grub:2
Proceed to configure the default GRUB2 configuration file located at /etc/default/grub. For example:
/etc/default/grub
Framebuffer related settings… # Set resolution and color depth GRUB_GFXMODE=1366x768x32 # Keep resolution when loading the kernel GRUB_GFXPAYLOAD_LINUX=keep # Set a background image GRUB_BACKGROUND="/boot/grub/bg.png" # Use a custom font, converted using grub2-mkfont utility GRUB_FONT="/boot/grub/fonts/roboto.pf2"
In order to find out what display modes the system's graphics card supports, use the following commands on the GRUB2 shell:
(grub)
insmod all_video
(grub)
videoinfo
Troubleshooting
Most of the issues can be resolved by ensuring that the partition layout is correct. Make sure enough space is available before the first partition of the disk, or optionally make sure that a BIOS boot partition is available. Also verify that /boot/grub/grub.cfg was correctly generated with grub2-mkconfig, or generate one with a custom menu entry.
Other issues that might come up are documented below together with their resolutions.
Installing GRUB2 from within a chroot
When a separate /boot partition exists, be sure to mount the target root partition before chrooting, but do not the /boot partition until after chrooting to the new environment. This is required because grub2-mkconfig will not detect /boot as a separate partition and will assume /boot and root are on the same partition.
Repopulating EFI boot manager entries
The following examples presumes a 32-bit EFI GRUB2 install, adjust accordingly for 64-bit EFI.
In case the Boot Manager entries need to be restored, they can be re-added without invoking grub-install. Load the efivars
kernel module and install sys-boot/efibootmgr:
root #
modprobe efivars
root #
emerge --ask sys-boot/efibootmgr
Next add a boot menu entry:
root #
efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "gentoo" --loader "\\EFI\\gentoo\\grubx86.efi"
Installation errors
grub2-install: error: cannot find EFI directory.
The following examples presumes a 64-bit EFI GRUB2 install, adjust accordingly for 32-bit EFI.
Error message:
root #
grub2-install --target=x86_64-efi
grub2-install: error: cannot find EFI directory.
Resolution:
Properly setting the GRUB_PLATFORMS
variable in /etc/portage/make.conf (the first time!) as listed above would have resolved this error. Set the GRUB_PLATFORMS
variable then re-emerge GRUB2 using the following command:
root #
emerge --ask --newuse
This template uses deprecated syntax.
In the case this error persists try forcing the install to the EFI directory by issuing the grub2-install command with correct parameters for the <kdb>--target and --efi-directory options:
root #
grub2-install --target=x86_64-efi --efi-directory=/boot
Attempting to install GRUB2 to a disk or partition
Error message:
root #
grub2-install /dev/sda1
Attempting to install GRUB to a partition disk or to a partition. This is a BAD idea. Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged.
Possible explanations followed by resolutions:
- A /boot partition is not mounted, run (as root): mount /boot
- Attempting to install GRUB2 with a traditional BIOS - GPT setup. This could mean there is not any
EF02
orbios_boot
partition to embed the core.img file. Creating a little partition of a few hundreds kilobytes may be enough, although it is good practice to align this partition to 2048 sectors to avoid a performance penalty with the disk. A 1 MiB partition should work well.
- Attempting to install GRUB2 in a partition e.g. /dev/sda5 using a BIOS - MBR setup (who did try it to BIOS - GPT?), simply add --force option switch to force install. It should behave with enough gap before the first sector of first partition or by using the chattr command (as described in the BIOS - MBR instructions above). It is also possible to destroy the partition boundary and the LUKS or LVM2 header (if one exists).
- If grub2-install does not print any errors message or if the error message is about scanning disk files and several platforms are enabled in /etc/portage/make.conf while nothing is installed on the disk, then edit the /sbin/grub2-install script with a text editor of choice. Change the
platform
variable to appropriate platform for the current use case. The platform must be rightly set when emerging sys-boot/grub, else it will be incorrectly configured in the /sbin/grub2-install script. For example, to set the platform for "PC", changeplatform=qemu
toplatform=pc
.
Step 4 is true for sys-boot/grub-1.99x only... for sys-boot/grub-2.x the correct file to investigate can be found at /etc/grub.d/00_header, transform="s,grub,grub2-qemu," to transform="s,grub,grub2," for example, to install rightly with grub2-$platform-install.
No post-MBR gap (free space)
Error message:
root #
grub2-bios-setup
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible! grub2-bios-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and its use is discouraged. grub2-bios-setup: error: If you really want blocklists, use --force.
Explanation:
This error means, that GRUB2 could not find the usual gap between the MBR and first partition of a disk. It is possible that the gap does not exist. Some tools (e.g. LiveUSB disk installer) format disks so that the first partition starts at sector 1 instead of 2048.
Resolution:
Repartitioning the disk should resolve the issue.
Some visualization-based block devices can also cause problems. See this post from the Arch Linux forum for more information.
Embedding area is unusually small
Error message:
root #
grub2-install /dev/sda
grub2-install: warn: Your embedding area is unusually small. core.img won't fit in it. grub2-install: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged. grub2-install: error: will not proceed with blocklists.
Explanation:
There is not enough room at the beginning of the disk before the first partition.
Resolution:
In general this is a bit of trouble to fix. One or more partitions need to be resized in order to leave some free space at the beginning of the drive. The GParted LiveCD or Gentoo-based [SystemRescueCD] are excellent tools to make this job less difficult.
If the swap partition is the first partition on the disk (e.g. /dev/sda1) it is possible to simply remove the existing swap space partition and re-partition the space. This resolution would avoid the need for booting into a live medium in order to resize a root (/) partition.
Begin by disabling the swap partition and launching fdisk:
root #
swapoff /dev/sda1
root #
fdisk /dev/sda
This should bring up the fdisk prompt, where the following commands can be entered to shrink the partition found on /dev/sda1:
- x - extra functionality
- b - move beginning of data in a partition
- 1 - Choose the first partition
- 4096 - New beginning of data (1-8000369, default 63)
- w - write table to disk and exit
A number smaller than 4096 may work, but 4096 is a wise choice.
Next, reformat the swap partition, and re-enable it:
root #
mkswap /dev/sda1
root #
swapon /dev/sda1
It should now be possible to install GRUB2 onto /dev/sda.
DualBoot Gentoo and FreeBSD [MBR]
Change the /etc/grub.d/40_custom script to:
/etc/grub.d/40_custom
Adding DualBootmenuentry "FreeBSD" --class freebsd --class bsd --class os { insmod ufs2 insmod bsd set root=(hd0,1) kfreebsd /boot/kernel/kernel kfreebsd_loadenv /boot/device.hints set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ada0s1a set kFreeBSD.vfs.root.mountfrom.options=rw set kFreeBSD.hw.psm.synaptics_support=1 }
/dev/sda1 or (hd0,1)
is the partition in which FreeBSD resides. If the normal UFS install was used for the FreeBSD partition then /dev/sda1 is a container (something like a logical partition). It consists of the swap and root partition. Verify the 40_custom script is executable by running ls -la /etc/grub.d/40_custom. If the executable bit is not set then set it using the chmod u+x 40_custom command.
Next install GRUB2 using the grub2-install command and update GRUB2's configuration file:
root #
grub2-install /dev/sda
root #
grub2-mkconfig -o /boot/grub/grub.cfg
Unless modified by the end user, script files in located in /etc/grub.d are executable and will be read by GRUB2 to create boot configuration files (grub.cfg).
See also
There are a few specific GRUB2 resources available:
- In Chainloading the use of GRUB2 to boot other boot loaders is described. This is important to read when dual-booting systems, or when GRUB2 needs to be configured to boot ISO files.
- In Advanced storage the necessary steps are documented on how to install and use GRUB2 on more advanced storage situations, such as software RAID, logical volumes or encrypted file systems.
- In Hybrid partition table the use of a mixed MBR/GPT setup is documented, as well as how to use such hybrid partition layout with GRUB2.
External resources
- GNU GRUB 2 manual page
- Legacy BIOS issues with GPT article
- GPT and Hybrid MBR article
- GPT fdisk utility page
- Arch Linux GRUB2 wiki article
- Fedora GRUB2 wiki article : Encountering the dreaded GRUB2 boot prompt
- ubuntu UEFI booting help
- http://unix.stackexchange.com/questions/109272/dualboot-freebsd-gentoo-with-grub2-mbr