# What & How & Why

### Partition in Liunx

#### Hardrive format in Linux

For SATA, USB, SAS, these type of devices are showing in Linux like:

/dev/sd[a-]
the a after sd indicates the currently number of harddisk. The order of these number is only associate with the computer checking sequence for harddrives. First is a , then b… For older IDE, the old version of Linux call them:
/dev/hd[a-]
Since IDE harddrives is no longer used in new generation computers, some new version Linux just put them into sd aslo.

#### Other devices format

Devices Name in Liunx
SCSI / SAS / USB / SATA /dev/sd[a-p]
IDE /dev/hd[a-p](Only in older Liunx)
Virtual I/O(included in Liunx /dev/vd[a-p]
Floppy Disk /dev/fd[a-p]
Printer /dev/lp[0-2](25pin) # /dev/lp[0-15](USB)
Mouse /dev/mouse(currently in use) # /dev/psaux(PS/2) # /dev/input/mouse[0-15](general)
CD/DVD ROM /dev/scd[0-1](general) # /dev/sr[0-1](CentOS) # /dev/cdrom(currently in use)

#### MBR

MBR: Master boot record
A master boot record (MBR) is a special type of boot sector at the very beginning of partitioned computer mass storage devices like fixed disks or removable drives intended for use with IBM PC-compatible systems and beyond. The concept of MBRs was publicly introduced in 1983 with PC DOS 2.0.
MBR infos are usually stored at the first sector of hardrive. It take space of one sector(usually 512Bytes). In this space, there are two mainly data are stored in it:

• MBR (446Bytes in classic MBR)
• Partition Table(64 Bytes, Divided into 4 parts)

So partition in Liunx usually is shown like:

/dev/sd[hardrive number][partition number]

##### Primary Partition

A primary partition contains one file system. In DOS and all early versions of Microsoft Windows systems, Microsoft required what it called the system partition to be the first partition.

##### Extended Partition

Partition is used for keeping data safe by separating sectors into different range. Because Partition table only supports 4 partitions, for getting more partitions, people use a record called extended boot record (EBR) to create a new partition that we called Extended partition.In Extended Partition, the space could be divided into 4 or more pieces. Each pieces is called Logical partition. Extended partition response for recording partition table for each logical partition.

##### Devices Numbers

In MBR, the frist 4 numbers are reserved by primary partition and extended partition. Thus, the devices for partition should be like this:

/dev/sda[1-4] // primary partition and extended partition
/dev/sda[5-]  // logical partition

sda[1-4] are fully reserved by primary partition and extended partition even they don't exist. Thus the number of logical partition has to start from number 5. Only one extended partition could exist at the same time.

Never combine Primary partition and Logical partition into a new partition, because it will damage partition record in extended partition. Extended partition usually store partition info at the beginning of each logical partition.

#### GPT

GPT: GUID partition table
GUID Partition Table (GPT) is a standard for the layout of the partition table on a physical hard disk, using globally unique identifiers (GUID). Although it forms a part of the Unified Extensible Firmware Interface (UEFI) standard (Unified EFI Forum proposed replacement for the PC BIOS), it is also used on some BIOS systems because of the limitations of master boot record (MBR) partition tables, which use 32 bits for storing logical block addresses (LBA) and size information on a traditionally 512 byte disk sector.

##### LBA0

Traditionally, in IBM PC compatible systems the first sector of the disk holds the Master Boot Record (MBR), containing the drive's partitioning information and the code of the first stage boot loader for BIOS-based systems.For limited backward compatibility, the space of the legacy MBR is still reserved in the GPT specification, but it is now used in a way that prevents MBR-based disk utilities from misrecognizing and possibly overwriting GPT disks. This is referred to as a protective MBR.

The partition table header defines the usable blocks on the disk. It also defines the number and size of the partition entries that make up the partition table. The header contains the disk globally unique identifier (GUID). It records its own size and location (always LBA 1) and the size and location of the secondary GPT header and table (always the last sectors on the disk). Importantly, it also contains a CRC32 checksum for itself and for the partition table, which may be verified by the firmware, bootloader and/or operating system on boot.

##### LBA2-33

This area is used for recording partitions informations. Each LBA has 4 records, total equal to 4 by 32 = 128. Every LBA has 64Bytes space to store number of start / end sectors, Thus, GPT could provide 264 512Bytes = 263 1KBytes = 233TB = 8 ZB space.

• Unordered List ItemUses GUIDs (UUIDs) to identify partition types - No collisions.
• Provides a unique disk GUID and unique partition GUID for each partition - A good filesystem-independent way of referencing partitions and disks.
• Arbitrary number of partitions - depends on space allocated for the partition table - No need for extended and logical partitions. By default the GPT table contains space for defining 128 partitions. However if the user wants to define more partitions, he/she can allocate more space to the partition table (currently only gdisk is known to support this feature).
• Uses 64-bit LBA for storing Sector numbers - maximum addressable disk size is 2 ZiB. MBR is limited to addressing 2 TiB of space per drive.
• Stores a backup header and partition table at the end of the disk that aids in recovery in case the primary ones are damaged.
• CRC32 checksums to detect errors and corruption of the header and partition table.

Fdisk is not support GPT.

Warning: For Windows, there is no support for booting from a BIOS/GPT partitioning scheme. If you have already installed Windows with a BIOS/MBR partitioning scheme do not convert the drive to GPT! Windows will fail to boot if this is done - irrespective of the bootloader used to chainload Windows. One can either install Windows in UEFI mode and use an UEFI bootloader (which uses GPT), or possibly restore/install Windows on a BIOS/GPT hybrid MBR.

#### BIOS / UEFI

BIOS(basic input/output system) is the program a personal computer's microprocessor uses to get the computer system started after you turn it on. It also manages data flow between the computer's operating system and attached devices such as the hard disk, video adapter, keyboard, mouse and printer.
UEFI (Unified Extensible Firmware Interface) is a standard firmware interface for PCs, designed to replace BIOS (basic input/output system).
The interface defined by the EFI specification includes data tables that contain platform information, and boot and runtime services that are available to the OS loader and OS. UEFI firmware provides several technical advantages over a traditional BIOS system:

• Ability to boot from large disks (over 2 TB) with a GUID Partition Table (GPT)
• CPU-independent architecture
• CPU-independent drivers
• Flexible pre-OS environment, including network capability
• Modular design
##### BIOS + MBR / GPT

Because GPT also have boot loader in LBA0(MBR compatible), BIOS is also able to boot from GPT.(it requires boot loader support GPT).

##### UEFI Booting

UEFI is designed to support GPT boot and replace BIOS. It developed by C language, so it can be easily supported by 3rd party software. Moreover, it has better user interface compare with BIOS, and could load driver before starting OS.

Seurty boot in UEFI will cause unbootable. Try to turn this function of if you can not boot normally.