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.
A History Lesson
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 losing 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.
|Firmware||HDD Size||Partition Table||Status||Guide|
|BIOS||<=2.0 TiB||MSDOS||Works||This Guide|
|BIOS||>2.0 TiB||MSDOS||Only the first 2.0TiB||This Guide|
|BIOS||<=2.0 TiB||GPT||Mostly Works||This Guide|
|BIOS||>2.0 TiB||GPT||Mostly Works||This Guide|
|(U)EFI||<=2.0 TiB||MSDOS||Not Supported||Fails by Design|
|(U)EFI||>2.0 TiB||MSDOS||Not Supported||Fails by Design|
|(U)EFI||<=2.0 TiB||GPT||Works||Covered in the Handbook|
|(U)EFI||>2.0 TiB||GPT||Works||Covered in the Handbook|
Not All Hardware Supports BIOS with GPT - Your Install May be Unbootable. Be prepared to put /boot onto a MSDOS partitioned volume.
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
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.
Its possible, sometimes even desirable to put an MSDOS disk label on the boot volume and use GPT on other volumes.
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
Replace the use of parted with a reference to the Handbook
In this chapter, the example partition layout mentioned earlier in the instructions will be used:
|/dev/sda1||BIOS boot partition|
Change the partition layout according to personal preference.
Viewing the current partition layout with parted
The parted application offers a simple interface for partitioning the disks and supports very large partitions (more than 2 TB). Fire up parted against the disk (in our example, we use /dev/sda). It is recommended to ask parted to use optimal partition alignment:
parted -a optimal /dev/sda
GNU Parted 2.3 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands.
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 help and press return.
Setting the Disk Label
Changing the Disk Label will remove all partitions from the disk. All data on the disk will be lost.
Using parted, the command to put a GPT label on the disk is mklabel gpt
To use an MBR label, use mklabel msdos.
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 print to view the current partitions, and rm <N> where
<N> is the number of the partition to remove.
Do not make any mistakes here - parted executes the changes immediately (unlike fdisk which stages them, allowing users to discard changes before saving or exiting fdisk).
parted 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 mkpart command for this, and inform parted to start from 1 MB and end at 3 MB (creating a partition of 2 MB in size).
mkpart primary 1 3
name 1 grub
set 1 bios_grub on
Model: Virtio Block Device (virtblk) Disk /dev/sda: 20480MiB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1.00MiB 3.00MiB 2.00MiB grub bios_grub
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).
mkpart primary 3 131
name 2 boot
mkpart primary 131 643
name 3 swap
mkpart primary 643 -1
name 4 rootfs
The end result looks like so:
Model: Virtio Block Device (virtblk) Disk /dev/sda: 20480MiB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1.00MiB 3.00MiB 2.00MiB grub bios_grub 2 3.00MiB 131MiB 128MiB boot 3 131MiB 643MiB 512MiB swap 4 643MiB 20479MiB 19836MiB rootfs
Use the quit command to exit parted.
With partitioning completed, jump down to the section on creating file systems.
fdisk -t dos /dev/sda
Welcome to fdisk (util-linux 2.24.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): a Partition number (1-4): 1 Command (m for help): w
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.
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.
Go to the handbook and complete those steps before continuing below
The boot loader is responsible for loading the kernel and optionally, one or more initrd files into RAM, then starting the kernel.
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.
When using a BIOS system no additional configuration is needed in order to emerge GRUB:
emerge --ask sys-boot/grub
The GRUB2 software has now been merged to the system, but not yet installed outside of the filesystem space.
Install the necessary GRUB2 files to the /boot/grub/ directory (and outside the filesystem) via the grub-install command. Presuming the first disk (the one where the system boots from) is /dev/sda, one of the following commands will do:
Generate the GRUB2 configuration based on the user configuration specified in the /etc/default/grub file and /etc/grub.d scripts. In most cases, no configuration is needed by users as GRUB2 will automatically detect which kernel to boot (the highest one available in /boot/) and what the root file system is. It is also possible to append kernel parameters in /etc/default/grub using the GRUB_CMDLINE_LINUX variable.
To generate the final GRUB2 configuration, run the grub-mkconfig command:
grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ... Found linux image: /boot/vmlinuz- Found initrd image: /boot/initramfs-genkernel-- done
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 genkernel was used to build the kernel, the correct initrd image should be detected as well. If this is not the case, go to /boot/ and check the contents using the ls command. If the files are indeed missing, go back to the kernel configuration and installation instructions.
The os-prober utility can be used in conjunction with GRUB2 to detect other operating systems from attached drives. Windows 7, 8.1, 10, and other distributions of Linux are detectable. Those desiring dual boot systems should emerge the sys-boot/os-prober package then re-run the grub-mkconfig command (as seen above). If detection problems are encountered be sure to read the GRUB article in its entirety before asking the Gentoo community for support.
Lilo development has stopped. It does not support GPT Disk Labels but it still works with MSDOS.
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.
emerge --ask sys-boot/lilo
To configure LILO, first create /etc/lilo.conf:
nano -w /etc/lilo.conf
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 the root filesystem is JFS, add an
append="ro"line after each boot item since JFS needs to replay its log before it allows read-write mounting.
boot=/dev/sda # Install LILO in the MBR prompt # Give the user the chance to select another section timeout=50 # Wait 5 (five) seconds before booting the default section default=gentoo # When the timeout has passed, boot the "gentoo" section compact # This drastically reduces load time and keeps the map file smaller; may fail on some systems image=/boot/vmlinuz- label=gentoo # Name we give to this section read-only # Start with a read-only root. Do not alter! root= # Location of the root filesystem image=/boot/vmlinuz- label=gentoo.rescue # Name we give to this section read-only # Start with a read-only root. Do not alter! root= # Location of the root filesystem append="init=/bin/bb" # Launch the Gentoo static rescue shell # The next two lines are for dual booting with a Windows system. # In this example, Windows is hosted on /dev/sda6. other=/dev/sda6 label=windows
If a different partitioning scheme and/or kernel image is used, adjust accordingly.
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:
image=/boot/vmlinuz- label=gentoo read-only append="root=" initrd=/boot/initramfs-genkernel--
If additional options need to be passed to the kernel, use an
append statement. For instance, to add the
video statement to enable framebuffer:
image=/boot/vmlinuz- label=gentoo read-only root= append="video=uvesafb:mtrr,ywrap,1024x768-32@85"
Users that used genkernel 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
doscsi as kernel option.
Now save the file and exit.
To finish up, run the /sbin/lilo executable so LILO can apply the /etc/lilo.conf settings to the system (i.e. install itself on the disk). Keep in mind that /sbin/lilo must be executed each time a new kernel is installed or a change has been made to the lilo.conf file in order for the system to boot the new kernel, even if the filename of the kernel has not changed.