Default partitioning scheme
Throughout the remainder of the instructions, the following partitioning scheme will be used as a simple example layout:
|/dev/mmcblk0p3||btrfs (or fat32 if UEFI is being used)||128M||Boot/EFI system partition|
|/dev/mmcblk0p4||btrfs (or crypto_LUKS if disk encryption is being used)||Rest of the disk||Main partition (or encrypted main partition)|
What is the firmware partition?
In contrast to legacy and more traditional hardware, some systems, especially embedded and single board computers, ship without preinstalled firmware (software that performs some of the first steps of hardware initialization upon powering on the system). What used to be readily available as BIOS or UEFI (and thus often stayed untouched by the average user) now needs to be installed as part of the setup process.
The firmware generally used to be provided by the hardware vendor in form of closed source proprietary binary blobs out of the users' control. However, for a growing - but still small - number of systems opensource software can provide the same functionality.
For most systems built around Rockchip SoCs open source U-Boot can be used to bring up the hardware. Still a tiny closed source software blob residing on the SoCs' supposedly immutable integrated BootROM performs the very first steps of initialization and takes care of loading the U-Boot TPL (Tertiary Program Loader), whose main task it is to train the DDR RAM. The TPL then loads the U-Boot SPL (Secondary Program Loader), which in turn is capable of loading the proper bootloader.
The firmware partition is going to house the U-Boot TPL and SPL.
What is the bootloader partition?
The bootloader partition is the partition where the bootloader is installed. In case U-Boot is used, U-Boot Proper - the main U-Boot program - resides here.
U-Boot can provide the UEFI services necessary to comply with EBBR (Embedded Base Boot Requirements).
What is the EFI System Partition (ESP)?
When installing Gentoo on a system that is going to use UEFI to boot the operating system, then it is important that an EFI System Partition (ESP) is created. The instructions for parted below contain the necessary pointers to correctly handle this operation.
The ESP must be a FAT variant (sometimes shown as vfat on Linux systems). The official UEFI specification denotes FAT12, 16, or 32 filesystems will be recognized by the UEFI firmware, although FAT32 is recommended for the ESP.
If a FAT variant is not used for the ESP, the system's UEFI firmware is not guaranteed to find the bootloader (or Linux kernel) and most likely be unable to boot the system!
TODO: move rootcmd from https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Disks#What_is_the_EFI_System_Partition_.28ESP.29.3F to section where filesystems are actually created
TODO: rm Next: Default Btrfs filesystem layout
Partitioning the storage device with parted
To partition storage devices the partitioning utility parted can be used, which was one of the first to support GPT partitions on Linux.
In this chapter, the example partition layout mentioned earlier in the instructions will be used to partition the storage device that is going to house the new Gentoo installation:
|/dev/mmcblk0p3||Boot/EFI system 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 storage media like disks and supports very large partitions (more than 2 TB). Fire up parted against the storage device of choice (in the example /dev/mmcblk0 is used). It is recommended to ask parted to use optimal partition alignment:
parted -a optimal /dev/mmcblk0
GNU Parted 2.3 Using /dev/mmcblk0 Welcome to GNU Parted! Type 'help' to view a list of commands.
Alignment means that partitions are started on well-known boundaries within the storage device, ensuring that operations on the storage device from the operating system level (retrieve pages from the device) use the least amount of internal device operations. Misaligned partitions might require the device 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 help and press return.
Setting the GPT label
With parted, the command to put a GPT label on the storage device is mklabel gpt:
Changing the partition type will remove all partitions from the storage device. All data on the device will be lost.
Removing all partitions with parted
If this isn't done yet (for instance through the mklabel operation earlier, or because the storage device is a freshly formatted one), first remove all existing partitions from the device. Type print to view the current partitions, and rm <N> where
<N> 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 the traditional fdisk which stages them, allowing a user to "undo" his changes before saving or exiting fdisk).
Creating the partitions
Now parted will be used to create the partitions with the following settings:
- The name of a partition
- The start location of a partition (which can be expressed in MiB, GiB, ...)
- The end location of the partition (which can be expressed in MiB, GiB, ...)
First, tell parted that the size unit we work with is kibibytes (abbreviated as KiB in the "standard" notation):
Then create a 4096 KiB partition (called "firmware" according to the example partition layout) that can be used for software taking care of initializing the target system's hardware, and inform parted to start from 32 KiB and end at 4128 KiB (creating a partition of 4096 KiB in size).
mkpart firmware 32 4128
Model: Virtio Block Device (virtblk) Disk /dev/mmcblk0: 20480MiB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 32KiB 4128KiB 4096KiB firmware
TODO: instructions how to deal with alignment warning
Do the same for the bootloader partition (starting at 8192KiB, size 4096KiB).
mkpart bootloader 8192 12288
After these two rather small partitions are created, it is time to create the bigger ones. To make things easier, change the size unit for parted to work with to mebibytes (abbreviated as MiB).
Now create a 128 MiB partition that will serve as the boot partition. Tell parted with the mkpart command to start from 16 MiB and end at 144 MiB (creating a partition of 128 MiB in size). Then turn on the boot flag for the newly created third partition.
TODO: disk model? TODO: 16MiB or 16.0MiB?
mkpart boot 16 144
set 3 boot on
Last, create the main partition that spans the remaining space on the storage device (for which the end location is marked as -1, meaning the end of the disk minus one MiB, which is the farthest a partition can go).
mkpart main 136 -1
The end result looks like so:
TODO: 12/16MiB or 12.0/16.0?
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 0.03MiB 4.03MiB 4.00MiB firmware 2 8.00MiB 12MiB 4.00MiB bootloader 3 16MiB 144MiB 128MiB boot boot 4 144MiB 20479MiB 20335MiB main
On an UEFI installation, the boot and the esp flag should show up on the boot partition.
Use the quit command to exit parted.
With the partitions created, it is now time to put filesystems on them. Optionally, the storage device can be encrypted before.
Optional: Using LUKS to encrypt the main partition