User:Zulu Foxtrott/GentooOnARM/EasyInstall/RasPi4PartitionTable

From Gentoo Wiki
Jump to:navigation Jump to:search

Default partitioning scheme

TODO

Partitioning the storage device with fdisk

Note
Although recent fdisk should support GPT, it has still shown to have some issues with it. The instructions given below assume that the partition layout being used is MBR.

The following parts explain how to create the example partition layout using fdisk. The example partition layout was mentioned earlier:

Partition Description
/dev/mmcblk0p1 Firmware partition
/dev/mmcblk0p2 Bootloader partition
/dev/mmcblk0p3 Boot/EFI system partition
/dev/mmcblk0p4 Main partition

Change the partition layout according to personal preference.

Viewing the current partition layout

fdisk is a popular and powerful tool to split a disk into partitions. Fire up fdisk against the disk (in the example /dev/mmcblk0 is used):

root #fdisk /dev/sda
Note
To use GPT support, add -t gpt. It is recommended to closely investigate the fdisk output in case more recent developments in fdisk change its default behavior of defaulting to MBR. The remainder of the instructions assume an MBR layout.

Use the p key to display the disk's current partition configuration:

TODO: add output adjusted for SD card

Command (m for help):p

  
   Device Boot    Start       End    Blocks   Id  System
/dev/mmcblk0p1   *         1        14    105808+  83  Linux
/dev/mmcblk0p2            15        49    264600   82  Linux swap
/dev/mmcblk0p3            50        70    158760   83  Linux
/dev/mmcblk0p4            71      2184  15981840    5  Extended
/dev/mmcblk0p5            71       209   1050808+  83  Linux
/dev/mmcblk0p6           210       348   1050808+  83  Linux

This particular disk was configured to house four Linux filesystems (each with a corresponding partition listed as "Linux") as well as a swap partition (listed as "Linux swap").

Setting the DOS label

Use the o key to put a DOS label on the storage device::

Warning
Changing the partition type will remove all partitions from the storage device. All data on the device will be lost.

TODO: add output

Command (m for help):o


Removing all partitions with fdisk

First remove all existing partitions from the disk. Type d to delete a partition. For instance, to delete an existing /dev/sda1:

Command (m for help):d
Partition number (1-4): 1

The partition has now been scheduled for deletion. It will no longer show up when printing the list of partitions (p, but it will not be erased until the changes have been saved. This allows users to abort the operation if a mistake was made - in that case, type q immediately and hit Enter and the partition will not be deleted.

Repeatedly type p to print out a partition listing and then type d and the number of the partition to delete it. Eventually, the partition table will be empty:

Command (m for help):p
Disk /dev/sda: 30.0 GB, 30005821440 bytes
240 heads, 63 sectors/track, 3876 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
  
Device Boot    Start       End    Blocks   Id  System

Now that the in-memory partition table is empty, we're ready to create the partitions.

Creating the BIOS boot partition

First create a very small BIOS boot partition. Type n to create a new partition, then p to select a primary partition, followed by 1 to select the first primary partition. When prompted for the first sector, make sure it starts from 2048 (which is needed for the boot loader) and hit Enter. When prompted for the last sector, type +2M to create a partition 2 Mbyte in size:

Note
The start from sector 2048 is a fail-safe in case the boot loader does not detect this partition as being available for its use.
Command (m for help):n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (64-10486533532, default 64): 2048
Last sector, +sectors +size{M,K,G} (4096-10486533532, default 10486533532): +2M

Mark the partition for UEFI purposes:

Command (m for help):t
Selected partition 1
Hex code (type L to list codes): 4
Changed system type of partition 1 to 4 (BIOS boot)
Note
Using UEFI with MBR partition layout is discouraged. If an UEFI capable system is used, please use GPT layout.

Creating the boot partition

Now create a small boot partition. Type n to create a new partition, then p to select a primary partition, followed by 2 to select the second primary partition. When prompted for the first sector, accept the default by hitting Enter. When prompted for the last sector, type +128M to create a partition 128 Mbyte in size:

Command (m for help):n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 2
First sector (5198-10486533532, default 5198): (Hit enter)
Last sector, +sectors +size{M,K,G} (4096-10486533532, default 10486533532): +128M

Now, when pressing p, the following partition printout is displayed:

Command (m for help):p
Disk /dev/sda: 30.0 GB, 30005821440 bytes
240 heads, 63 sectors/track, 3876 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
  
   Device Boot    Start       End    Blocks   Id  System
/dev/sda1             1         3      5198+  ef  EFI (FAT-12/16/32)
/dev/sda2             3        14    105808+  83  Linux

Type a to toggle the bootable flag on a partition and select 2. After pressing p again, notice that an * is placed in the "Boot" column.

Creating the swap partition

To create the swap partition, type n to create a new partition, then p to tell fdisk to create a primary partition. Then type 3 to create the third primary partition, /dev/sda3. When prompted for the first sector, hit Enter. When prompted for the last sector, type +512M (or any other size needed for the swap space) to create a partition 512MB in size.

After all this is done, type t to set the partition type, 3 to select the partition just created and then type in 82 to set the partition type to "Linux Swap".

Creating the root partition

Finally, to create the root partition, type n to create a new partition, then p to tell fdisk to create a primary partition. Then type 4 to create the fourth primary partition, /dev/sda4. When prompted for the first sector, hit Enter. When prompted for the last sector, hit Enter to create a partition that takes up the rest of the remaining space on the disk. After completing these steps, typing p should display a partition table that looks similar to this:

Command (m for help):p
Disk /dev/sda: 30.0 GB, 30005821440 bytes
240 heads, 63 sectors/track, 3876 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
  
   Device Boot    Start       End    Blocks   Id  System
/dev/sda1             1         3      5198+  ef  EFI (FAT-12/16/32)
/dev/sda2   *         3        14    105808+  83  Linux
/dev/sda3            15        81    506520   82  Linux swap
/dev/sda4            82      3876  28690200   83  Linux

Saving the partition layout

To save the partition layout and exit fdisk, type w.

Command (m for help):w

With the partitions created, it is now time to put filesystems on them. Optionally, the storage device can be encrypted before.

Next

Optional: Using LUKS to encrypt the main partition

Creating file systems