User:NeddySeagoon/The Olde Way

= The Olde Way = This needs to be understood so that you can decide what is right for you. It may not be the process detailed here. This decision is difficult to change later.

In The Beginning
Once upon a time PCs only had 340kB floppy disk drives. Floppies are historically used without a partition table because the original MSDOS did not support the concept of partitions.

When hard drives were introduced, first 5MB and 10MB everything still worked. The FAT filesystem of the day could cope with 32MB. Once hard drives grew beyond 32MB, the space beyond was lost.

The Introduction of the Partition Table
To be able to use all of drives bigger than 32MB, the idea of breaking them into pieces "Partitions" was added to MSDOS, so the partition table was added and tools to manipulate it supplied too. A maximum of four partitions could be supported.

The Extended Partition
All was well until hard drives reached 128Mb. That required more than four partitions, so the Extended Partition, which is just a container for other partitions was added.

The End of the Road for the MSDOS Partiton Table
Over the years, the MSDOS Partiton Table has been extended to address more space. It has a hard limit at 2.0GiB, so cannot be used on drives bigger than 2.0GiB without loosing the space beyond.

It had to be replaced, since it could no longer be extended.

The Global Partition Table
The Global Partition Table was introduced as a replacement for the MSDOS partition table. At the same time, EFI replaced the traditional BIOS.

The Situation Today
There are older systems with BIOS, there are newer systems with EFI that have a Legacy BIOS option. There are MSDOS Partition Tables, there are GPT Partition tables and there are hard drives bigger and smaller than 2GiB. That's three boolean variables that result eight options.

It can be seen that all the useful EFI cases are covered in the handbook, leaving this guide to cover BIOS.

The four BIOS options fall nicely into two groups BIOS with MSDOS BIOS with GPT

Compatability Notes
When EFI/GPT was introduced, designers realised that it had to be forward compatible with BIOS/MSDOS. Thus making a GPT disk label actually makes a "Protective MSDOS" disk label too. This allows tools that are not GPT aware to alert users that GPT is in use.

The MSDOS disk label is stored in 66 bytes at the end of logical block 0 on the HDD as BIOS can only read block 0 of the HDD.

With GPT the Protective MSDOS disk label stays in LBA 0, the GPT disk label starts in LBA 1 (so BIOS cannot read it) and ends in LBA 2047. There is a backup copy of the GPT disk label stored at the end of the volume too.

In both cases, modern tools put the start of the first partition at LBA 2048. It wasn't always that way. Traditionally, with an MSDOS disk label, the MBR was at LBA 0 and the first partition stated at LBA 63, leaving LBA 1..62 free.

Designing The Partition Layout
The minimal Partition Layout is dictated by the disk label to be used, which in turn is dictated by the the size of the boot HDD.

The MSDOS Disk Label Minimal Partition Scheme
A minimal Gentoo install using an MSDOS disk label requires two partitions. Three is recommended as every now and again, hard drives get too big for older BIOSes to read, so a small /boot partition is used at the start of the drive to ensure that the BIOS can read all the files to boot the system.

This gives us boot swap root

The GPT Disk Label Minimal Partition Scheme
BIOS and GPT requires a fourth partition. When grub is installed into the MBR, its far to big to fit into the 446 available bytes, so with an MSDOS disk label, it uses the following, otherwise unallocated space, before the first partition.

From the above, with GPT in use, there is no unallocated space before the first partition, so grub needs a small partition identified for its own use.

This gives us bios_grub (for grub) boot swap root

= Making the Disk Label and Partitioning the Hard Drive=

Having determined the disk label and partition layout, the next step is to implement it.

Using parted to partition the disk
In this chapter, the example partition layout mentioned earlier in the instructions will be used:

Change the partition layout according to personal preference.

Viewing the current partition layout with parted
The application offers a simple interface for partitioning the disks and supports very large partitions (more than 2 TB). Fire up against the disk (in our example, we use ). It is recommended to ask to use optimal partition alignment:

Alignment means that partitions are started on well-known boundaries within the disk, ensuring that operations on the disk from the operating system level (retrieve pages from the disk) use the least amount of internal disk operations. Misaligned partitions might require the disk to fetch two pages instead of one even if the operating system asked for a single page.

To find out about all options supported by parted, type and press return.

Setting the GPT label
Most disks on the or  architectures are prepared using an msdos label. Using, the command to put a GPT label on the disk is :

To have the disk with MBR layout, use.

Removing all partitions with parted
If this isn't done yet (for instance through the operation earlier, or because the disk is a freshly formatted one), first remove all existing partitions from the disk. Type to view the current partitions, and  where   is the number of the partition to remove.

Do the same for all other partitions that aren't needed. However, make sure to not make any mistakes here - parted executes the changes immediately (unlike which stages them, allowing a user to "undo" his changes before saving or exiting fdisk).

Creating the partitions
Now will be used to create the partitions with the following settings:


 * The partition type to use. This usually is primary. If the msdos partition label is used, keep in mind that there can be no more than 4 primary partitions. If more than 4 partitions are needed, make one of the first four partitions extended and create logical partitions inside it.
 * The start location of a partition (which can be expressed in MB, GB, ...)
 * The end location of the partition (which can be expressed in MB, GB, ...)

First, tell parted that the size unit we work with is megabytes (actually mebibytes, abbreviated as MiB which is the "standard" notation, but we will use MB in the text throughout as it is much more common):

Now create a 2 MB partition that will be used by the GRUB2 boot loader later. Use the command for this, and inform  to start from 1 MB and end at 3 MB (creating a partition of 2 MB in size).

Do the same for the boot partition (128 MB), swap partition (in the example, 512 MB) and the root partition that spans the remaining disk (for which the end location is marked as -1, meaning the end of the disk minus one MB, which is the farthest a partition can go).

When using the UEFI interface to boot the system (instead of BIOS), mark the boot partition as the EFI System Partition. Parted does this automatically when the boot option is set on the partition:

The end result looks like so:

Use the command to exit parted.

With partitioning completed, jump down to the section on creating file systems.

Setting the Bootable Flag
This may or may not be required but its harmless. BIOS systems can only read the MSDOS partition table, even when GPT is in use. Therefore, the bootable flag must be set in the MSDOS partition table.

Its documented as a separate step as GPT users will need to quit the partitiong tool to edit the Protective MSDOS partition table.

= Legacy Boot =

With the Linux kernel configured, system tools installed and configuration files edited, it is time to install the last important piece of a Linux installation: the boot loader.

The boot loader is responsible for firing up the Linux kernel upon boot - without it, the system would not know how to proceed when the power button has been pressed.

For, we document how to configure either GRUB2 or LILO for BIOS based systems, and GRUB2 or efibootmgr for UEFI systems.

In this section of the Handbook a delineation has been made between emerging the boot loader's package and installing a boot loader to a system disk. Here the term emerge will be used to ask Portage to make the software package available to the system. The term install will signify the boot loader copying files or physically modifying appropriate sections of the system's disk drive in order to render the boot loader activated and ready to operate on the next power cycle.

Grub
Previously, Gentoo Linux used what is now called GRUB Legacy as the recommended boot loader. As the name implies, the older GRUB package is no longer actively maintained and has been superseded by GRUB2. For more information about the legacy GRUB, please refer to its GRUB article.

By default, the majority of Gentoo systems now rely upon GRUB2 (found in the package), which is the direct successor to GRUB Legacy. With no additional configuration, GRUB2 gladly supports older BIOS ("pc") systems. With a small amount of configuration, necessary before build time, GRUB2 can support more than a half a dozen additional platforms. For more information, consult the Prerequisites section of the GRUB2 article.

Emerge
When using an older BIOS system supporting only MBR partition tables, no additional configuration is needed in order to emerge GRUB:



A note for UEFI users: running the above command will output the enabled GRUB_PLATFORMS values before emerging. When using UEFI capable systems, users will need to ensure  is enabled (as it is the case by default). If that is not the case for the setup,  will need to be added to the  file before emerging GRUB2 so that the package will be built with EFI functionality:






 * If GRUB2 was somehow emerged without enabling, the line (as shown above) can be added to  then and dependencies for the world package set re-calculated by passing the   options to :



The GRUB2 software has now been merged to the system, but not yet installed.

Install
Next, install the necessary GRUB2 files to the directory via the  command. Presuming the first disk (the one where the system boots from) is, one of the following commands will do:


 * When using BIOS:


 * When using UEFI:









Some motherboard manufacturers seem to only support the directory location for the .EFI file in the EFI System Partition (ESP). The GRUB installer can perform this operation automatically with the  option. Verify the ESP is mounted before running the following commands. Presuming the ESP is mounted at (as suggested earlier), execute:

This creates the default directory defined by the UEFI specification, and then copies the file to the 'default' EFI file location defined by the same specification.

Configure
Next, generate the GRUB2 configuration based on the user configuration specified in the file and  scripts. In most cases, no configuration is needed by users as GRUB2 will automatically detect which kernel to boot (the highest one available in ) and what the root file system is. It is also possible to append kernel parameters in using the GRUB_CMDLINE_LINUX variable.

To generate the final GRUB2 configuration, run the command:

The output of the command must mention that at least one Linux image is found, as those are needed to boot the system. If an initramfs is used or was used to build the kernel, the correct initrd image should be detected as well. If this is not the case, go to and check the contents using the  command. If the files are indeed missing, go back to the kernel configuration and installation instructions.

Emerge
LILO, the LInuxLOader, is the tried and true workhorse of Linux boot loaders. However, it lacks features when compared to GRUB. LILO is still used because, on some systems, GRUB does not work and LILO does. Of course, it is also used because some people know LILO and want to stick with it. Either way, Gentoo supports both bootloaders.

Installing LILO is a breeze; just use emerge.

Configure
To configure LILO, first create :

In the configuration file, sections are used to refer to the bootable kernel. Make sure that the kernel files (with kernel version) and initramfs files are known, as they need to be referred to in this configuration file.

If an initramfs is necessary, then change the configuration by referring to this initramfs file and telling the initramfs where the root device is located:

If additional options need to be passed to the kernel, use an  statement. For instance, to add the  statement to enable framebuffer:

Users that used should know that their kernels use the same boot options as is used for the installation CD. For instance, if SCSI device support needs to be enabled, add  as kernel option.

Now save the file and exit.

Install
To finish up, run the executable so LILO can apply the  settings to the system (i.e. install itself on the disk). Keep in mind that must be executed each time a new kernel is installed or a change has been made to the  file in order for the system to boot if the filename of the kernel has changed.