Partitioning, MBR, and GPT
Partition Information (MBR and GPT)
- Partition information is stored on the disk in a small region.
- Read by the operating system at boot time.
- Master Boot Record (MBR) on the BIOS-based systems
- GUID Partition Table (GPT) on the UEFI-based systems.
- At system boot, the BIOS/UEFI:
- scans all storage devices,
- detects the presence of MBR/GPT areas,
- identifies the boot disks,
- loads the bootloader program in memory from the default boot disk,
- executes the boot code to read the partition table and identify the /boot partition,
- loads the kernel in memory, and passes control over to it.
- MBR and GPT store disk partition information and the boot code.
Master Boot Record (MBR)
-
Resides on the first sector of the boot disk.
-
was the preferred choice for saving partition table information on x86-based computers.
-
with the arrival of bigger and larger hard drives, a new firmware specification (UEFI) was introduced.
-
still widely used, but its use is diminishing in favor of UEFI.
-
allows the creation of three types of partition on a single disk.
-
primary, extended, and logical
-
only primary and logical can be used for data storage
-
extended is a mere enclosure for holding the logical partitions and it is not meant for data storage.
-
supports the creation of up to four primary partitions numbered 1 through 4 at a time.
-
In case additional partitions are required, one of the primary partitions must be deleted and replaced with an extended partition to be able to add logical partitions (up to 11) within that extended partition.
-
Numbering for logical partitions begins at 5.
-
supports a maximum of 14 usable partitions (3 primary and 11 logical) on a single disk.
-
Cannot address storage space beyond 2TB due to its 32-bit nature and its 512-byte disk sector size.
-
non-redundant; the record it contains is not replicated, resulting in an unbootable system in the event of corruption.
-
If your disk is smaller than 2TB and you don’t intend to build more than 14 usable partitions, you can use MBR without issues.
GUID Partition Table (GPT)
- ability to construct up to 128 partitions (no concept of extended or logical partitions)
- utilize disks larger than 2TB
- use 4KB sector size
- store a copy of the partition information before the end of the disk for redundancy
- allows a BIOS-based system to boot from a GPT disk using the bootloader program stored in a protective MBR at the first disk sector
- UEFI firmware also supports the secure boot feature, which only allows signed binaries to boot
MBR Storage Management with parted
parted (partition editor)
- can be used to partition disks
- run interactively or directly from the command prompt.
- understands and supports both MBR and GPT schemes
- can be used to create up to 128 partitions on a single GPT disk
- viewing, labeling, adding, naming, and deleting partitions.
print
Displays the partition table that includes disk geometry and partition number, start and end, size, type, file system type, and relevant flags.
mklabel
Applies a label to the disk. Common labels are gpt and msdos.
mkpart
Makes a new partition
name
Assigns a name to a partition
rm
Removes the specified partition
- use the
printsubcommand to ensure you created what you wanted. - /proc/partitions file is also updated to reflect the results of partition management operations.
Lab: Create an MBR Partition (server2)
- Assign partition type “msdos” to /dev/sdb for using it as an MBR disk
- create and confirm a 100MB primary partition on the disk.
1. Execute parted on /dev/sdb to view the current partition information:
There is an error on line 1 of the output, indicating an unrecognized label. disk must be labeled before it can be partitioned.
2. Assign disk label “msdos” to the disk with mklabel. This operation is performed only once on a disk.
To use the GPT partition table type, run “sudo parted /dev/sdb mklabel gpt” instead.
3. Create a 100MB primary partition starting at 1MB (beginning of the disk) using mkpart:
4. Verify the new partition with print:
Partition numbering begins at 1 by default.
5. Confirm the new partition with the lsblk command:
The device file for the first partition on the sdb disk is sdb1 as identified on the bottom line. The partition size is 95MB.
Different tools will have variance in reporting partition sizes. ignore minor differences.
6. Check the /proc/partitions file also:
Exercise 13-3: Delete an MBR Partition (server2)
delete the sdb1 partition that was created in Exercise 13-2 confirm the deletion.
1. Execute parted on /dev/sdb with the rm subcommand to remove partition number 1:
2. Confirm the partition deletion with print:
3. Check the /proc/partitions file:
can also run the lsblk command for further verification. T
EXAM TIP: Knowing either parted or gdisk for the exam is enough.
GPT Storage Management with gdisk
gdisk (GPT disk) Command
-
partitions disks using the GPT format.
-
text-based, menu-driven program
-
show, add, verify, modify, and delete partitions
-
can create up to 128 partitions on a single disk on systems with UEFI firmware.
-
Main interface of
gdiskcan be invoked by specifying a disk device name such as /dev/sdc with the command. Type help or ? (question mark) at the prompt to view available subcommands.
Exercise 13-4: Create a GPT Partition (server2)
- Assign partition type “gpt” to /dev/sdc for using it as a GPT disk.
- create and confirm a 200MB partition on the disk.
1. Execute gdisk on /dev/sdc to view the current partition information:
The disk currently does not have any partition table on it.
2. Assign “gpt” as the partition table type to the disk using the o subcommand. Enter “y” for confirmation to proceed. This operation is performed only once on a disk.
3. Run the p subcommand to view disk information and confirm the GUID partition table creation:
The output returns the assigned GUID and states that the partition table can hold up to 128 partition entries.
4. Create the first partition of size 200MB starting at the default sector with default type “Linux filesystem” using the n subcommand:
5. Verify the new partition with p:
6. Run w to write the partition information to the partition table and exit out of the interface. Enter “y” to confirm when prompted.
You may need to run the partprobe command after exiting the gdisk utility to inform the kernel of partition table changes.
7. Verify the new partition by issuing either of the following at the command prompt:
Exercise 13-5: Delete a GPT Partition(server2)
- Delete the sdc1 partition that was created in Exercise 13-4 and confirm the removal.
1. Execute gdisk on /dev/sdc and run d1 at the utility’s prompt to delete partition number 1:
2. Confirm the partition deletion with p:
3. Write the updated partition information to the disk with w and quit gdisk:
4. Verify the partition deletion by issuing either of the following at the command prompt:
Disk Partitions
- Be careful when adding a new partition to elude data corruption with overlapping an extant partition or wasting storage by leaving unused space between adjacent partitions.
- Disk allocated at the time of installation is recognized as sda (s for SATA, SAS, or SCSI device) disk a, first partition identified as sda1 and the second partition as sda2.
- Any subsequent disks added to the system will be known as sdb, sdc, sdd, and so on, and will use 1, 2, 3, etc. for partition numbering.
Use lsblk to list disk and partition information.
sr0 represents the ISO image mounted as an optical medium:
identifiers 83 and 8e are hexadecimal values for the partition types
Storage Management Tools
parted, gdisk, and LVM
Partitions created with a combination of most of these tools and toolsets can coexist on the same disk.
parted
understands both MBR and GPT formats.
gdisk
- support the GPT format only
- may be used as a replacement of parted.
LVM
- feature-rich logical volume management solution that gives flexibility in storage management.