0% found this document useful (0 votes)
19 views10 pages

Linux Unit 3.1

linux basics tutorials
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views10 pages

Linux Unit 3.1

linux basics tutorials
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Red Hat Enterprise Linux 9 Managing storage devices

CHAPTER 4. DISK PARTITIONS


To divide a disk into one or more logical areas, use the disk partitioning utility. It enables separate
management of each partition.

4.1. OVERVIEW OF PARTITIONS


The hard disk stores information about the location and size of each disk partition in the partition table.
Using information from the partition table, the operating system treats each partition as a logical disk.
Some of the advantages of disk partitioning include:

• Reduce the likelihood of administrative oversights of Physical Volumes

• Ensure sufficient backup

• Provide efficient disk management

Additional resources

• What are the advantages and disadvantages to using partitioning on LUNs, either directly or
with LVM in between?.

4.2. CONSIDERATIONS BEFORE MODIFYING PARTITIONS ON A DISK


Before creating, removing, or resizing any disk partitions, consider the following aspects.

On a device, the type of the partition table determines the maximum number and size of individual
partitions.

Maximum number of partitions:

• Ona device formatted with the Master Boot Record (MBR)partition table, you can have:

o Up to four primary partitions.

o Up to three primary partitions, one extended partition

■ Multiple logical partitions within the extended partition

• Ona device formatted with the GUID Partition Table (GPT) you can have:

o Up to 128 partitions, if using the parted utility.

■ Though the GPT specification allows more partitions by increasing the reserved size of
the partition table, the parted utility limits the area required for 128 partitions.

Maximum size of partitions:

• Ona device formatted with the Master Boot Record (MBR)partition table:

o While using 512b sector drives, the maximum size is 2 TiB.

o While using 4k sector drives, the maximum size is 16 TiB.

• Ona device formatted with the GUID Partition Table (GPT)

o While using 512b sector drives, the maximum size is 8 ZiB.

32
CHAPTER 4. DISK PARTITIONS

o While using 4k sector drives, the maximum size is 64 ZiB.

By using the parted utility, you can specify the partition size using multiple different suffixes:

• MiB, GiB, orTiB

o Size expressed in powers of 2.

o The starting point of the partition is aligned to the exact sector specified by size.

o The ending point is aligned to the specified size minus 1 sector.

• MB, GB, orTB:

o Size expressed in powers of 10.

o The starting and ending points are aligned within one half of the specified unit. For example,
±500KB when using the MB suffix.

NOTE

This section does not cover the DASD partition table, which is specific to the IBM Z
architecture.

Additional resources

• Configuring a Linux instance on IBM Z

• What you should know about DASD

4.3. COMPARISON OF PARTITION TABLE TYPES


To enable partitions on a device, format a block device with different types of partition tables. The
following table compares the properties of different types of partition tables that you can create on a
block device.

Table 4.1. Partition table types

Partition table Maximum number of partitions Maximum partition size

Master Boot Record (MBR) 4 primary, or 3 primary and 1 2TiB


extended partition with 12 logical
partitions

GUID Partition Table (GPT) 128 8ZiB

4.4. MBR DISK PARTITIONS


The partition table is stored at the very start of the disk, before any file system or user data. For a more
clear example, the partition table is shown as being separate in the following diagrams.

33
Red Hat Enterprise Linux 9 Managing storage devices

Figure 4.1. Disk with MBR partition table

Disk (MBR table)

Unused partition Unused partition Unused partition Unused partition

File system File system File system File system


(Unused) (Unused) (Unused) (Unused)

As the previous diagram shows, the partition table is divided into four sections of four unused primary
partitions. A primary partition is a partition on a hard disk drive that contains only one logical drive (or
section). Each logical drive holds the information necessary to define a single partition, meaning that
the partition table can define no more than four primary partitions.

Each partition table entry contains important characteristics of the partition:

• The points on the disk where the partition starts and ends

• The state of the partition, as only one partition can be flagged as active

• The type of partition

The starting and ending points define the size and location of the partition on the disk. Some of the
operating systems boot loaders use the active flag. That means that the operating system in the
partition that is marked "active" is booted.

The type is a number that identifies the anticipated usage of a partition. Some operating systems use
the partition type to:

• Denote a specific file system type

• Flag the partition as being associated with a particular operating system

• Indicate that the partition contains a bootable operating system

The following diagram shows an example of a drive with a single partition. In this example, the first
partition is labeled as DOS partition type:

34
CHAPTER 4. DISK PARTITIONS

Figure 4.2. Disk with a single partition

Disk (MBR table)

Primary partition Unused partition Unused partition Unused partition


(DOS)

File system File system File system File system


(FAT32) (Unused) (Unused) (Unused)

Additional resources

• MBR partition types

4.5. EXTENDED MBR PARTITIONS


To create additional partitions, if needed, set the type to extended.

An extended partition is similar to a disk drive. It has its own partition table, which points to one or more
logical partitions, contained entirely within the extended partition. The following diagram shows a disk
drive with two primary partitions, and one extended partition containing two logical partitions, along with
some unpartitioned free space.

Figure 4.3. Disk with both two primary and an extended MBR partitions

Disk (MBR table)


Extended Partition

Primary partition Primary partition Logical partition Logical partition


(DOS) (Linux native) (DOS) (Linux native)

File system File system File system File system


(FAT32) (XFS) (FAT32) (XFS)

Free space Free space

You can have only up to four primary and extended partitions, but there is no fixed limit to the number
of logical partitions. As a limit in Linux to access partitions, a single disk drive allows maximum 15 logical
partitions.

4.6. MBR PARTITION TYPES

35
Red Hat Enterprise Linux 9 Managing storage devices

The table below shows a list of some of the most commonly used MBR partition types and hexadecimal
numbers to represent them.

Table 4.2. MBR partition types

MBR partition type Value MBR partition type Value

Empty 00 Novell Netware 386 65

DOS 12-bit FAT 01 PIC/IX 75

XENIX root 02 Old MINIX 80

XENIX usr 03 Linux/MINUX 81

DOS 16-bit <=32M 04 Linux swap 82

Extended 05 Linux native 83

DOS 16-bit >=32 06 Linux extended 85

OS/2 HPFS 07 Amoeba 93

AIX 08 Amoeba BBT 94

AIX bootable 09 BSD/386 a5

OS/2 Boot Manager Oa OpenBSD a6

Win95 FAT32 Ob NEXTSTEP a7

Win95 FAT32 (LBA) Oc BSDI fs b7

Win95 FAT16 (LBA) Oe BSDI swap b8

Win95 Extended (LBA) Of Syrinx c7

Venix 80286 40 CP/M db

Novell 51 DOS access el

PRep Boot 41 DOS R/O e3

GNU HURD 63 DOS secondary f2

Novell Netware 286 64 BBT ff

36
CHAPTER 4. DISK PARTITIONS

4.7. GUID PARTITION TABLE


The GUID partition table (GPT) is a partitioning scheme based on the Globally Unique Identifier (GUID).

GPT deals with the limitations of the Mater Boot Record (MBR) partition table. The MBR partition table
cannot address storage larger than 2 TiB, equal to approximately 2.2 TB. Instead, GPT supports hard
disks with larger capacity. The maximum addressable disk size is 8 ZiB, when using 512b sector drives,
and 64 ZiB, when using 4096b sector drives. In addition, by default, GPT supports creation of up to 128
primary partitions. Extend the maximum amount of primary partitions by allocating more space to the
partition table.

NOTE

A GPT has partition types based on GUIDs. Certain partitions require a specific GUID. For
example, the system partition for Extensible Firmware Interface (EFI) boot loaders
require GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B.

GPT disks use logical block addressing (LBA) and a partition layout as follows:

• For backward compatibility with MBR disks, the system reserves the first sector (LBA 0) of GPT
for MBR data, and applies the name "protective MBR".

• Primary GPT

o The header begins on the second logical block (LBA 1) of the device. The header contains
the disk GUID, the location of the primary partition table, the location of the secondary GPT
header, and CRC32 checksums of itself, and the primary partition table. It also specifies the
number of partition entries on the table.

o By default, the primary GPT includes 128 partition entries. Each partition has an entry size of
128 bytes, a partition type GUID and a unique partition GUID.

• Secondary GPT

o For recovery, it is useful as a backup table in case the primary partition table is corrupted.

o The last logical sector of the disk contains the secondary GPT header and recovers GPT
information, in case the primary header is corrupted.

o It contains:

■ The disk GUID

■ The location of the secondary partition table and the primary GPT header

■ CRC32 checksums of itself

■ The secondary partition table

■ The number of possible partition entries

37
The original Linux system used a simple file system that mimicked the functionality of the
Unix file system. In this tutorial, we will discuss the basic file system used in Linux.

The ext file system


The original file system introduced with the Linux operating system is called the extended
file system (or just ext for short). It provides a basic Unix- like file system for Linux, using
virtual directories to handle physical devices, and storing data in fixed-length blocks on the
physical devices.

The ext file-system uses a system called inodes to track information about the files stored in
the virtual directory. The inode system creates a separate table on each physical device, called
the inode table, to store the file information. Each stored file in the virtual directory has an
entry in the inode table. The extended part of the name comes from the additional data that it
tracks on each file, which consists of:

• The file name


• The file size
• The owner of the file
• The group the file belongs to
• Access permissions for the file
• Pointers to each disk block that contains data from the file

Linux references each inode in the inode table using a unique number (called the inode
number), assigned by the file system as data files are created. The file system uses the inode
number to identify the file rather than having to use the full file name and path.

The ext2 files system


The original ext file system had quite a few limitations, such as limiting files to only 2GB in
size. Not too long after Linux was first introduced, the ext file system was upgraded to create
the second extended file system, called ext2. As you can guess, the ext2 file system is an
expansion of the basic abilities of the ext file system but maintains the same structure. The
ext2 file system expands the inode table format to track additional information about each file
on the system.

The ext2 inode table adds the created, modified, and last accessed time values for files to help
system administrators track file access on the system. The ext2 file system also increases the
maximum file size allowed to 2TB (then in later versions of ext2, that was increased to
32TB) to help accommodate large files commonly found in database servers.

In addition to expanding the inode table, the ext2 file system also changed the way in which
files are stored in the data blocks. A common problem with the ext file system was that as a
file is written to the physical device, the blocks used to store the data tend to be scattered
throughout the device (called fragmentation ). Fragmentation of data blocks can reduce the
performance of the file system, as it takes longer to search the storage device to access all of
the blocks for a specific file.
The ext2 file system helps reduce fragmentation by allocating disk blocks in groups when
you save a file. By grouping the data blocks for a file, the file system doesn’t have to search
all over the physical device for the data blocks to read the file. The ext2 file system was the
default file system used in Linux distributions for many years, but it, too, had its limitations.
The inode table, while a nice feature that allows the file system to track additional
information about files, can cause problems that can be fatal to the system. Each time the file
system stores or updates a file, it has to modify the inode table with the new information. The
problem is that this isn’t always a fluid action.

If something should happen to the computer system between the file being stored and the
inode table being updated, the two would become out of sync. The ext2 file system is
notorious for easily becoming corrupted due to system crashes and power outages. Even if
the file data is stored just fine on the physical device, if the inode table entry wasn’t
completed, the ext2 file system wouldn’t even know that the file existed! It wasn’t long
before developers were exploring a different avenue of Linux file systems.

Journaling file systems


Journaling file systems provide a new level of safety to the Linux system. Instead of writing
data directly to the storage device and then updating the inode table, journaling file systems
write file changes into a temporary file (called the journal) first. After data is successfully
written to the storage device and the inode table, the journal entry is deleted.

If the system should crash or suffer a power outage before the data can be written to the
storage device, the journaling file system just reads through the journal file and processes any
uncommitted data left over. There are three different methods of journaling commonly used
in Linux, each with different levels of protection. These are shown below in the table.

Journaling File system Methods:

Method Description
Both inode and file data are journaled. Low risk of losing data, but poor
Data mode
performance.
Ordered Only inode data written to the journal, but not removed until file data is
mode successfully written. Good compromise between performance and safety.
Writeback Only inode data written to the journal, no control over when the file data is
mode written. Higher risk of losing data, but still better than not using journaling.

Limitation

The data mode journaling method is by far the safest for protecting data, but it is also the
slowest. All of the data written to a storage device must be written twice, once to the journal,
then again to the actual storage device. This can cause poor performance, especially for
systems that do a lot of data writing. Over the years, a few different journaling file systems
have appeared in Linux. The following sections describe the popular Linux journaling file
systems available.

The extended Linux journaling filesystems


The same group that developed the ext and ext2 file systems as part of the Linux project also
created journaling versions of the file systems. These journaling file systems are compatible
with the ext2 file system, and it’s easy to convert back and forth between them. There are
currently two separate journaling file systems based on the ext2 file system.

Th ext3 file system


The ext3 file system was added to the Linux kernel in 2001, and up until recently was the
default file system used by just about all Linux distributions. It uses the same inode table
structure as the ext2 filesystem, but adds a journal file to each storage device to journal the
data written to the storage device.

By default, the ext3 file system uses the ordered mode method of journaling, only writing the
inode information to the journal file, but not removing it until the data blocks have been
successfully written to the storage device. You can change the journaling method used in the
ext3 filesystem to either data or writeback modes with a simple command-line option when
creating the file system.

While the ext3 file system added basic journaling to the Linux file system, there were still a
few things it lacked. For example, the ext3 file system doesn’t provide any recovery from
accidental deletion of files, there’s no built-in data compression available (although there is a
patch that can be installed separately that provides this feature), and the ext3 file system
doesn’t support encrypting files. For those reasons, developers in the Linux project choose to
continue work on improving the ext3 file system.

The ext4 file system


The result of expanding the ext3 file system was (as you probably guessed) the ext4 file
system. The ext4 file system was officially supported in the Linux kernel in 2008, and is now
the default file system used in most popular Linux distributions, such as Fedora and Ubuntu.

In addition, to support compression and encryption, the ext4 file system also supports a
feature called extents. Extents allocate space on a storage device in blocks, and only store the
starting block location in the inode table. This helps save space in the inode table by not
having to list all of the data blocks used to store data from the file.

The ext4 file system also incorporates block pre-allocation. If you want to reserve space on a
storage device for a file that you know will grow in size, with the ext4 file system it’s
possible to allocate all of the expected blocks for the file, not just the blocks that physically
exist. The ext4 file system fills in the reserved data blocks with zeroes, and knows not to
allocate them for any other file.

You might also like