104.1. Create partitions and filesystems
104.1 Create partitions and filesystems
Weight: 2
Description: Candidates should be able to configure disk partitions and then create filesystems on media such as hard disks. This includes the handling of swap partitions.
Key Knowledge Areas:
Manage MBR partition tables
Use various mkfs commands to create various filesystems such as:
ext2/ext3/ext4
XFS
VFAT
Awareness of ReiserFS and Btrfs
Basic knowledge of gdisk and parted with GPT
Terms and Utilities:
fdisk
gdisk
parted
mkfs
mkswap
BIOS
The Basic Input/Output System (BIOS), (also known as System BIOS, ROM BIOS ) is a standard for defining a firmware interface. The BIOS software is built into the PC, and is the first software run by a PC when powered on.
The fundamental purposes of the BIOS are to initialize and test the system hardware components, and to load a bootloader or an operating system from a mass memory device.
UEFI
The Unified Extensible Firmware Interface (UEFI) is a specification that defines a software interface between an operating system and platform firmware. UEFI is meant to replace the Basic Input/Output System (BIOS) firmware interface. In practice, most UEFI images provide legacy support for BIOS services. UEFI can support remote diagnostics and repair of computers, even without another operating system!
The original EFI (Extensible Firmware Interface) specification was developed by Intel. UEFI is still not widespread and major hardware companies have switched over almost exclusively to UEFI use. Many older and less expensive motherboards also still use the BIOS system.
MBR
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.
The MBR holds the information on how the logical partitions, containing file systems, are organized on that medium. Besides that, the MBR also contains executable code to function as a loader for the installed operating system—usually by passing control over to the loader's second stage. This MBR code is usually referred to as a boot loader.
Master Boot records has some short comings:
MBR puts all information in first sector of hard disk so if any problem ocures for that sectore, system won't be able to boot up.
MBR contains only four entries (slots) for four Primary partitions, one of which can be an Extended partition. This partition will contain unallocated space within it where we can create unlimited number of Logical partitions.
The organization of the partition table in the MBR limits the maximum addressable storage space of a disk to 2 TB.
Therefore, the MBR-based partitioning scheme is in the process of being superseded by the GUID Partition Table (GPT) scheme in new computers. A GPT can coexist with an MBR in order to provide some limited form of a backwards compatibility for older systems.
GPT
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, it is also used on some BIOS systems because of the limitations of master boot record (MBR) partition tables.
MBR vs GBT
Both GPT disk and MBR disk can be basic or dynamic.
BIOS vs UEFI
Usually, MBR and BIOS (MBR + BIOS), and GPT and UEFI (GPT + UEFI) go hand in hand. This is required for some systems (Windows), while optional for others (Linux).
Block devices
A block device is an abstraction layer for any storage device that can be formatted in fixed-size blocks and blocks should be able to be access randomly.
Examples of block devices include the first IDE or SATA hard drive on our system (/dev/sda or /dev/hda) or the second SCSI, IDE, or USB drive (/dev/sdb). Use the ls -l
command to display /dev entries.
The first character on each output line is b for a block device, such as floppy, CD drive, IDE hard drive, or SCSI hard drive; and c for a character device, such as a or terminal (tty) or the null device.
Disk Partitioning
Now that we are introduced you to hard drive layouts (MBR & GPT) , lets learn how to create MBR partitions using fdisk and GPT partitions using gdisk.
fdisk
fdisk also known as format disk is a dialog-driven command in Linux used for creating and manipulating disk partition table. It is used for the view, create, delete, change, resize, copy and move partitions on a hard drive using the dialog-driven interface. fdisk allows us to create a maximum of four primary partitions and the number of logical partition depends on the size of the hard disk you are using. It allows the user:
To Create space for new partitions.
Organizing space for new drives.
Re-organizing old drives.
Copying or Moving data to new disks(partitions)
The first thing to do before doing any thing with the disks and partition is to view basic details about all available partition in the system using -l
option(ubuntu 16.04):
as you can see we have two disk drives (sda,sdb) sda has some partitions on it but sdb is row.
Boot : The Boot column shows that the first partition, /dev/sda1, has an asterisk (*) indicating that this partition contains the files required by the boot loader to boot the system.
Start and End : The start and end columns list the starting and ending sectors of each partition.
Blocks : The blocks column lists the number of blocks allocated to the partition.
Id and System : These columns identify the partition type.
Viewing Partition(s) on a Specific Disk (sda) :
Lets start interactive mode and see all available commands (sdb):
okey creating partion:
next we need to specify partition type based on the future use we have considered for:
Partition Types
The partition types can be displayed and changed by using the fdisk utility. A partial list (most commonly used) of partition types are: 83: Linux 82: Linux swap 5: Extended 8e: Linux LVM
and use -p option inorder to print partition table:
fdisk does not write any changes on hard disk until we ask it using w
switch, if you are not sure use q
to quit and hard disk stays untouched!
use -d for delete a partition bu be care full!
To see the help message and listing of all options, use fdisk -h command.
gdisk
We can Manage GPT Partitions with gdisk. like fdisk, gdisk is a text-mode menu-driven program for creation and manipulation of partition tables. It will automatically convert an old-style Master Boot Record (MBR) partition table to the newer Globally Unique Identifier (GUID) Partition Table (GPT) format, or will load a GUID partition table.
parted
The parted
command is a partition editor that will work with both MBR and GPT formatted disks.
File System
Linux File System or any file system generally is a layer which is under the operating system that handles the positioning of your data on the storage, without it; the system cannot knows which file starts from where and ends where.
File system types
Linux supports several different file systems. Each has strengths and weaknesses and its own set of performance characteristics.
Ext, Ext2, Ext3, Ext4, JFS, XFS, btrfs and swap
One important attribute of a filesystem is journaling
What is journaling?
Journaling is designed to prevent data corruption from crashes and sudden power loss. Let’s say your system is partway through writing a file to the disk and it suddenly loses power. Without a journal, your computer would have no idea if the file was completely written to disk. The file would remain there on disk, corrupt.
With a journal, your computer would note that it was going to write a certain file to disk in the journal, write that file to disk, and then remove that job from the journal. If the power went out partway through writing the file, Linux would check the file system’s journal when it boots up and resume any partially completed jobs. This prevents data loss and file corruption.
Journaling does slow disk write performance down a tiny bit, but it’s well-worth it on a desktop or laptop.
Which File System is perfect for you?
Generally, a journaling filesystem is preferred over a non-journaling one when you have a choice. You may also want to consider whether your chosen filesystem supports Security Enhanced Linux (or SELinux).
Following is a brief summary of the types you need to know about for the LPI exam:
We must create a file system before you can use any data storage device connected to a Linux computer.
partitioning
Linux uses the mkfs
command to create filesystems and mkswap
command to make swap space.
Before you start modifying partitions, there are some important things to remember. You risk losing your existing data if you do not follow these guidelines:
Back up important data before you start
Do not change partitions that are in use
Know your tool
Stop if you do make a mistake
Linux uses the mkfs
command to create filesystems and mkswap
command to make swap space
mkfs
The mkfs (make filesystem) command is used to create a filesystem.
The mkfs
command is actually a front end to several filesystem-specific commands such as mkfs.ext3
for ext3, mkfs.ext4
for ext4 and mkfs.btrfs
for btrfs.
various forms of some commands. mke2fs, mkfs.ext2, and mkfs.ext3 are all the same file, while mkfs.msdos and mkfs.vfat are usually symbolic links to mkdosfs.
In order to build the filesystem using mkfs command, the required arguments are filesystem-type and device-filename:
We can either use mkfs.fstype commands mkfs.ext3 /dev/sdb1
or we can use mkfs via -t
option to specify the format mkfs -t ext3 /dev/sdb1
and both would have the same results.
If we want to assign a label to the partition during format progress we should use -L labelname with that : mkfs -t ext3 -L MyData /dev/sdb1
For mounting Formatted partition we can either use Partition label or UUID. UUID is a unique identifier used in partitions to uniquely identify partitions. to get the UUID of recent created partition try : blkid /dev/sdb1
mkswap
mkswap
command makes swap space on a device or in a file.
The device argument will usually be a disk partition (something like /dev/sdb1) but can also be a file.
The Linux kernel does not look at partition IDs, but many installation scripts will assume that partitions of hex type 82 (LINUX_SWAP) are meant to be swap partitions.
So in order to make a swap space first create a partition using fdisk via partition type 82 and then use mkswap:
Using the created partition as a swap space requires further step which will be discussed in later lessons.
that's all!
.
.
.
https://wiki.manjaro.org/index.php?title=Some_basics_of_MBR_v/s_GPT_and_BIOS_v/s_UEFI
https://developer.ibm.com/tutorials/l-lpic1-104-1/
https://www.geeksforgeeks.org/file-systems-in-operating-system/
https://likegeeks.com/linux-file-system/
https://developer.ibm.com/tutorials/l-lpic1-102-1/
https://www.computerhope.com/jargon/p/partition.htm
https://www.geeksforgeeks.org/fdisk-command-in-linux-with-examples/
https://www.tecmint.com/what-is-ext2-ext3-ext4-and-how-to-create-and-convert-linux-file-systems/
https://www.howtogeek.com/howto/33552/htg-explains-which-linux-file-system-should-you-choose/
https://developer.ibm.com/tutorials/l-lpic1-104-1/
https://jadi.gitbooks.io/lpic1/content/1041_create_partitions_and_filesystems.html
.
Last updated