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.0TiB, due to working with 32 bit entries that represent 512B sectors, so cannot be used on drives bigger than 2.0TiB 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.

BIOS is totally unaware of the existence of a Global Partition Table, so this change breaks backwards compatibility.

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 boot partition can be formatted for any filesystem that is supported by the boot loader.

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 physical block 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 require the disk to fetch extra physical blocks instead of one even if the operating system asked for a single disk block. This slows disk access. On disk writes, the situation is worse. Drives cannot write a fraction of a block. Unaligned writes cause the drive to read a physical block, change the part that needs to be updated, then write it back. These read/modify/writes take an extra revolution of the drive platters are are to be avoided.

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

Setting the Disk Label
Using, the command to put a GPT label on the disk is

To use an MBR label, use.

This document will describe the use of the Lilo and GRUB2 boot loaders. Users intending to use the Lilo boot loader must choose to use an MBR label.

Removing Individual Partitions With Parted
This step may be required to change a partition created in error or to repurpose some disk space without removing all partitions as making a new disk label does.

Type to view the current partitions, and  where   is the number of the partition to remove.

Do not make any mistakes here - parted executes the changes immediately (unlike which stages them, allowing users to discard changes before saving or exiting fdisk).

Introduction
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, ...)

Users installing with a GPT disk label must create a 2 MB partition that will be used directly by the GRUB2 boot loader.

Users installing with an MSDOS disk label do not require this 2 MB partition.

Set the default size that parted will use to Megabytes, actually Megibytes (abbreviated as MiB) this text will use MB throughout.

Creating The Partitions
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).

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.

= Bootloaders =

Overview
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 loading the kernel and optionally, one or more initrd files into RAM, then starting the kernel.

Configuration of GRUB2 or LILO are documented below.

As parts of the boot loader is installed outside of any filesystem space, installing a boot loader is a two step process. Step 1 is emerging the boot loader in the normal way. This puts the boot loader binary files onto the filesystem but they cannot be used to boot from there.

Step 2 is copying the binary files to their final locations outside of the filesystem space.

In the case of Grub2 with a GPT disk label, that includes the 2M bios_grub partition.

Grub
The majority of BIOS based Gentoo systems rely upon GRUB2 (found in the package) Prerequisites section of the GRUB2 article.

Emerge
When using a BIOS system no additional configuration is needed in order to emerge GRUB:



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

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

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.

Install LILO to the filesystem.

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 the new kernel, even if the filename of the kernel has not changed.