Day 5: Storage Basics
Introduction to storage basics:
What is Block Device?
First we will take a look at block devices.
Block device is type of file that can be found under /dev/ directory. It usually represents a piece of hardware that can store data. Traditionally spinning hard disk or solid state disk SSD.
It is called block storage because it reads and write data in a blocks or checks of space.
To see list of block devices in your system run lsblk or ls -l /dev/ and look for files that has b as first character :
What is Major and Minor number in lsblk command output?
Major: Major number is used to Identify type of block devices. For instance RAM,SCSI Disk , parallel printers etc.
Minor: Minor number are used to distinguish individual, physical or logical device.
What is partition?
The entire disk can be broken down into smaller segments of usage space called called partitions.
In the lsblk command output we can see xvda disk have 4 partitions named xvda1, xvda14, xvda15 and xvda16.
The concept of partition allows us to segment space and use partition for specific purpose.
If you inspect xvda1 is used for root partition and xvda15 is consumed as a system partition mounted at /boot/efi which is used during system boot process and contains boot loader for the installed OS.
Note:
You don't necessary have to partition a disk, it can be used as is without carving out partitions. However it is always recommended to partition a disk wherever possible as it offers greater flexibility.
Commands to list partition informations:
The information about partition is saved in partition table. The information can be read in many ways:
Another popular tool is fdisk command, it can be used to list partition information but can also be used to create or delete partition.
This will print the information quite similar to lsblk command but also provide additional information such as partition type used , the size of the disk in bytes and sectors.
Three types of disk partitions:
Primary partition:This type of partition can be used to boot an operating system. Traditionally, disk were limited to not more than 4 primary partition per disk.
Extended disk:
Extended partition is the type of partition that can not be used on its own but can host logical partition
With the restriction of maximum 4 partition you can opt to create extended partition and carve out logical partition inside it.
Extended partition is like a disk in its own right, it has a partition table that points to one or more logical partition.
Logical Partition:
Logical partitions are the partitions that are created on extended partition.
Partitioning Scheme:
How a disk is partitioned is defined by partitioning scheme also know as partition table.
MBR Partition Scheme:
MBR stands for Master Boot Record and has been around 30 years now. MBR partition scheme restricts maximum of 4 partition . If you want more than 4 partition per disk then we need to create 4th partition as extended partition and carve out logical partitions within it.
GPT Partition Scheme:
GPT stands for GUID Partition table and is the most recent partitioning scheme and this was created to address limitation of MBR.
Theoretically GPT have unlimited number of partitions per disc. This is only limited by restrictions imposed by operating system itself. For example, RHEL allows only 128 partitions per disc
How to create partition on a disk.
Screen of partitions before creating one:
Here we will create partition on disk xvda. So for creating partition use gdisk command
Type 'n' to create new partition, then provide the asked values for hex code go with default.
Type p to print the partition table .
Type 'w' to "write table to disk and exit".
Type y:
Then reboot the system to reflect the partition in lsblk command
lsblk command before reboot:
lsblk command after reboot: