0% found this document useful (0 votes)
17 views

Module_1c_Disk_Partitions_File_Systems

Uploaded by

juliopetronilo
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)
17 views

Module_1c_Disk_Partitions_File_Systems

Uploaded by

juliopetronilo
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/ 13

INFO-3182- Operating systems - Linux

Module 1c Disks, Partitions, and File


Systems
Introduction

All physical machines, virtual machines and containers running Linux have some sort of file system
associated with them. For physical and virtual machines, these file systems may be directly attached
physical or virtual disk drives, block storage devices provided by Storage Area Network (SAN) or Network
Attached Storage (NAS) devices, or remote file shares. This document discusses the relationship
between directly attached disk drives, disk partitions and file systems for Linux physical and virtual
machines. Removable media of any type is not discussed in this course, except for the use of such media
for installing a Linux operating system.

Do not forget that Linux is strict about the case of letters used in the names of anything accessed by the
operating system. All the names of commands, devices, directories, etc. shown in the following sections
are case-sensitive.

NOTE: The virtual machines used to create the screenshots included in this document were created with
a single 40 GB virtual disk utilizing each operating system’s default disk configurations. The
configurations shown here are the most basic possible. To meet legal and industry standard
requirements for security, more complex storage configurations are often required, some of these are
covered in other parts of this course.

Disk Drives

The disk drives used on physical systems fall into two categories, Hard Disk Drives (HDD), and Solid-State
Drives (SSD). Linux systems can use both HDDs and SSDs on a physical system, the only significant
operational difference between the two types of drives is the higher performance achieved by most SSD
devices. At a low level in the operating system, Linux recognizes the difference between the two types
of drives and loads the appropriate device drivers.

Linux systems always name all devices, including disk drives. For physical machines, HDD devices usually
have names beginning with ‘hd’ and SSD devices usually begin with ‘sd.’ However, sometimes ‘sd’ and
‘hd’ are used interchangeably. Some Linux distributions will use ‘nvme’ instead of ‘sd’ when that variant
of SSD technology is detected.

Virtual disk drives for virtual machines, are files stored on the files system of the system providing
virtualization services. For Microsoft Windows systems running Hyper-V these files have an extension of

Page 1 of 13
INFO-3182- Operating systems - Linux

‘.vhd’ or .vhdx,’ and for VMWare products the disk file name has the extension ‘.vmdk’. The device
names for virtual disks in Linux do not correspond to the type of the actual file, they usually begin with
‘sd,’, ‘vd’ and sometimes nvme. The virtualization software being used can also affect the name of disk
devices. The following screenshots show some examples of drive names inside CentOS and Ubuntu
virtual machines using both Hyper-V and VMware Workstation Pro 17. The virtual machines used in
these examples all had 40 GB virtual disks attached to them. These screenshots contain more
information than just the disk drive names, some of this additional information will be discussed in this
document.

Figure 1 Screenshot of a CentOS Stream 9 server virtual machine running on Hyper-V. The second line of the lsblk command's
output shows the drives name is 'sda'.

Figure 2 Screenshot of a CentOS Stream 9 server virtual machine running on VMWare Workstation. The second line of the lsblk
command's output shows the drives name is 'nvme0n1.

Page 2 of 13
INFO-3182- Operating systems - Linux

Figure 3 Screenshot of an Ubuntu 22.04 server virtual machine running on Hyper-V. The fourth line of the lsblk command's
output shows the drives name is 'sda'. The output from this command for a VMWare Workstation virtual machine is the same.

Figure 4 Screenshot of an Ubuntu 24.04 server virtual machine running on VMWare Workstation. The first line of the lsblk
command's output shows the drives name is 'sda'. The output of the command on a Hyper-V virtual machine is the same.

The lsblk command used in the previous four screenshots lists the block devices connected to each
virtual machine. The output column titled ‘NAME’ gives the name of each device and the ‘TYPE’ column
lists the types of each device and their related items. Physical and virtual disks have a type of disk. There
is only one disk shown in each screenshot. Devices of type ‘rom’ are cd/DVD drives, in these
screenshots, virtual DVD drives named ‘sr0’ are shown that are used for mounting the installer ISO files.

The screenshot in Figure 1 shows that on Hyper-V the disk drive is named ‘sda’. The ‘a’ indicates that this
is the first disk drive (and in this case only disk drive) in the system. Drive names beginning with ‘sd’, ‘hd’
and ‘vd’ are followed by a third letter indicating the order of the drives in the system. For example, as
shown in Figure 1, the first drive is ‘sda’. If a second disk was then added it would be ‘sdb’, a third disk
would be ‘sdc’, etc.

Page 3 of 13
INFO-3182- Operating systems - Linux

Figure 2 shows a similarly configured CentOS Stream 9 virtual machine running on VMWare
Workstation. This time the disk drive name is ‘nvme0n1’ indicating that VMWare Workstation passed
sufficient information to the virtual machine for it to identify that the first drive is NVME, and that it is
connected to the first drive controller (0) as device 1. For this type of drive, additional drives can be
added to an existing controller with the second drive being 2, the third 3, etc. Additional controllers
may also be added with each new controller being assigned a higher number.

Figure 3 shows an Ubuntu 22.04 server virtual machine running on Hyper-V, while Figure 4 shows an
Ubuntu 24.04 virtual machine running on VMWare workstation. Both these screenshots show the disk
name as ‘sda’. The same drive names are shown on the other hypervisor for both versions of Ubuntu
server.

Interestingly, both laptops (one for Hyper-V and the other for VMWare Workstation) used to take the
screenshots have NVME drives supporting the virtual machines. This indicates that both the
virtualization software and the virtualized operating system must recognize the different types of drives.

Figure 3 shows three drives names loop0, loop1 and loop2. These are virtual disks created during the
Ubuntu installation process for use by Ubuntu 22.04 itself. They are stored on the ‘sda’ drive. Ubuntu
24.04 does not use these loop drives as shown in Figure 4.

The output from the lsblk command shown in Figures 1 through 4 include a column labelled ‘MAJ:MIN’ .
This column contains the Major and Minor device numbers for each device. Each drive in a system will
have its own Major device number (8 or 259 in the screenshots) and a Minor device number of 0. These
numbers provide the mapping between the drives name and the actual physical or virtual device.

The use of Redundant Array of Inexpensive Disk (RAID) techniques for improving data protection, high
availability and, sometimes, performance is common. Linux supports hardware RAID controllers, and
through the Logical Volume Manager and Device Mapper software, it supports software RAID. When
RAID is needed on a system, always use hardware Raid, if it is available. Modern hardware RAID
controllers usually provide better performance and failed disk recovery options than software RAID
does. This course includes material on using the Logical Volume Manager software, including its RAID
capabilities.

Master Boot Record

Every physical or Virtual machine has a Master Boot Record on one of the disk drives provided to the
operating system. This record is always the first 512 bytes of the disk drive used to start the operating
system boot process.

Page 4 of 13
INFO-3182- Operating systems - Linux

Figure 5 The master boot record for a physical or virtual system showing the three parts of the record: Boot Loader, Partition
table and Magic Number.

The Master Boot Record consists of three parts:

• Boot Loader – 446 bytes - part of the software used to start the operating system (discussed in
a later module).
• Partition Table – 64 bytes – the partition table for the disk drive the MBR is on. This record can
have one of two formats. The choice of format is determined by the size of the drive, the
system’s firmware, and the operating system being used (most modern versions of Linux
support both formats).
o MBR (Master Boot record) – the original format which supports drives up to 2 TB in
size. A disk with a MBR partition table can have up to four primary partitions, or up to
three primary partitions and one extended partition. All partition information is stored
within the partition table. The MBR format is used with BIOS firmware.
o GPT (GUID Partition Table) – this is a newer partition table format that supports all
currently available disks of any size. Any number of partitions can be created. If there is
not enough space within the Master Boot record, additional disk space will be allocated
to store the partition table. The GPT format is used with UEFI firmware.
• Magic Number – 2 bytes – a checksum for detecting errors within the MBR.

The Master Boot Record for a system and the operating system software are usually located on the
same drive but they do not have to be. A common case for separating the Master Boot Record and the
operating system is for systems that are configured for dual boot ( allowing the user to choose between
two or more pre-installed operating systems during system startup).

Disk Partitions

Every HDD and SSD is divided into parts known as partitions. These partitions are where data is stored
once an appropriate file system has been defined within a given partition. File systems can be placed
directly into partitions or a tool like Logical Volume Manager can be used to break a partition into
volumes into which file systems are placed.

In Figures 1 through 4 above, each systems disk drive (‘sda’ or ‘nvme0n1’) had been divided into three
partitions. In Figures 1, 3 and 4 these partitions are named ‘sda1’, ‘sda2’, and ‘sda3’, identifying each
partition by adding a digit to the end of the drive name. In Figure 2, ‘p1’, ‘p2’, and ‘p3’ are added to the

Page 5 of 13
INFO-3182- Operating systems - Linux

drive name to give the partition names. The TYPE column of the lsblk command indicates that these
items are partitions with the value ‘part’.

In all four Figures, the first two partitions (sda1, sda2, nvme0n1p1, and nvme0n1p2) have the file
systems created directly on the partitions. This is indicated by the MOUNTPOINTS column not being
empty. There is no indication of what type of file system in being used in this command’s output. These
two partitions contain the remaining boot loader code (recall from above that part of it is in the Master
Boot Record) and the Linux operating system kernel and other required startup files. These two
partitions always have the file systems created directly on them this is critical for proper system start.
NOTE: Ubuntu 22.04, Ubuntu 24.04, and CentOS Stream 9 require both partitions for proper startup
when using UEFI firmware, some other Linux distributions (e. g. Linux mint, see Figure 6) only require
one partition configured for the type of firmware being used.

The third partition (‘sda3’ or ‘nvme0n1p3) shown in each of Figures 1 through 4 does not have a value
shown in the MOUNTPOINTS column meaning that there is no file system created directly on the
partition. In the lsblk command output in each Figure, there is at least one item of type ‘lvm’
immediately following these partition items. In Figures 1 and 2, these ‘lvm’ items have mount points
assigned to them, ‘/’ indicates the root of the main file system for the system and [SWAP] indicates a
specially formatted file system used as memory swap space. Figures 3 and 4 only have one ‘lvm’ item
that is the root of the file system (Ubuntu 22.04 and 24.04 use a swap file rather than a separate file
system by default).

Figure 6 shows that Linux Mint does not use Logical Volume Manager for its root file system by default
since it has ‘/’ as a mount point for sda2.

Figure 6 Screenshot of the lsblk command on a Linux Mint virtual machine. The command's output shows that there are only two
partitions. The first is used for system startup and the second for the root file system without using Logical Volume Manager.

Page 6 of 13
INFO-3182- Operating systems - Linux

Logical Volume Manager

The Logical Volume Manager (LVM software is a set of tools that permit a lot of flexibility when
managing data storage on Linux systems. It can be used both by Linux installation processes, and by
system administrators. Figures 1 through 4 above show the results of using LVM automatically during
the installation process to set up simple LVM configurations.

Logical Volume Manager uses a hierarchical object structure to manage storage. For each disk partition
that is to be managed by Logical Volume Manager, a Physical Volume (PV) object is defined. Then one or
more Physical Volumes are grouped together into a Volume Group (VG). A Physical volume can only be
part of one Volume Group. One or more Logical Volume (LV) objects are then created on top of each
Volume Group. A Logical volume can only be associated with one Volume Group. A logical volume can
be configured to use part or all the space available in a Volume Group. Depending on the number of
Physical volumes in the Volume Group, a Logical Volume can be configured as a software RAID array.
Logical Volumes appear to be standard disk partitions to the rest of the operating system.

Logical Volume Manager can be used to add additional disk partitions and Physical Volumes to an
existing Volume Group and the to grow the file system in the associated logical Volume(s) This is a lot
simpler process than having to replace an existing disk with a larger one.

Logical Volume Manager is also useful when designing and implementing backup processes.

The use of Logical Volume Manager during Linux system installation is discussed in the next module.
Other uses for Logical Volume Manager are found in later modules of this course.

File Systems

When referring to storage in Linux the term File System can have two meanings. It can refer to the
overall view of the storage as seen by a user, or it can refer to the storage structure used on a single
disk partition or Logical Volume. This section looks at both meanings.

File systems provide the logical structure for storing data in a disk partition or LVM LV. The process of
creating a file system is called ‘make file system’ in Linux, (formatting a drive in Windows). The file
systems for the example virtual machines discussed in this document were all setup during the
operating system installation process using the default settings. The file systems are listed below by
virtual machine and partition:

• CentOS Stream 9 on Hyper-V


o sda1 - vfat
o sda2- xfs
o sda3 – None but the Logical Volumes stored on this partition have the files system types
of xfs and swap.

Page 7 of 13
INFO-3182- Operating systems - Linux

• CentOS Stream 9 on VMWare Workstation


o nvme0n1p1 -vfat
o nvme0n1p2 - xfs
o nvme0n1p3 – None but the Logical Volumes stored on this partition have the files
system types of xfs and swap.
• Ubuntu 22.04 (Hyper-V and VMware Workstation)
o sda1 - vfat
o sda2 – ext4
o sda3 – None but the Logical Volume stored on this partition uses ext4.
• Ubuntu 24.04 (Hyper-V and VMware Workstation)
o sda1 – vfat
o sda2 – ext4
o sda3 – None but the Logical Volume stored on this partition uses ext4.
• Linux Mint. (Hyper-V and VMware Workstation)
o sda1 - vfat
o sda2 – ext4

The vfat (or fat32) file system type is part of the older DOS/Windows FAT files system format family. All
partitions directly used to boot a system with UEFI firmware must be of this type, no matter what
operating system is being used. FAT file systems have a very simple structure and are therefore easier
for the firmware and bootloader code to use.

The ext4 and xfs file systems are the two most popular for Linux systems at the present time. By default,
the Debian family of distributions, including Ubuntu and Linux Mint, use the ext4 format. RedHat family
distributions (e. g. CentOS Stream and Rocky Linux) default to the xfs file system. Both ext4 and xfs are
part of a group of file systems known as journaling file systems. One of the most important features of a
journaling file system is that it saves part of the change history for the file system so that it can attempt
to perform a self-healing operation when an error is detected. Another journaling file system is zfs. The
zfs file system is not used for the root file system very often, it is more popular as the file system for very
large disk partitions storing application data.

From a user’s perspective, the storage available on a Linux system appears to be a single file system, or
unified file system, no matter how many drives, partitions, or LVM LVs make up the actual storage. The
root of the file system is represented by a single forward slash ‘/’. For the example virtual machines
discussed in this document, the root of the file system is associated with a file system in an LVM LV
except for the Linux Mint virtual machine where it is associated with the file system on the sda2
partition. The file systems that are combined to make up the single file system seen by users of a Linux
system do not need to have the same file system format (all the example systems use at least vfat and
either xfs or ext4).

Page 8 of 13
INFO-3182- Operating systems - Linux

Figure 7 Screenshot showing a directory listing of the root of the file system on the example Ubuntu 24.04 virtual machine.

Figure 7 shows the directory listing of the example Ubuntu 24.04 virtual machine’s file system root
immediately after installation. The full meaning of the data included in this screenshot will be discussed
in a later module. For now, the first character in the first column of data and the entire last column are
of interest.

On each line of output from the ls -al command, the first character of the first column gives some
information about the type of object that line describes. In this directory listing there are three types of
objects listed.

• ‘d’ indicates that the information on that line is about a directory (folder). Many Linux systems
use colour coding for different types of objects, notice that the name of the object in the right-
hand column is blue for most of the directories in the listing. The exception to this is the /tmp
directory shown three lines up from the bottom of the listing which is in reverse green video.
This is indicating some special security settings that will be discussed in a later module.

Page 9 of 13
INFO-3182- Operating systems - Linux

• ‘l’ indicates that the line is describing a symbolic link (a link to a file or directory located
elsewhere on the system). For example, the name ‘bin’ is a symbolic link to the directory
/usr/bin.
• ‘-‘ indicates a ‘regular’ file. Most files are regular files in Linux including text files, executable
program binaries, shell scripts, pictures, work processing documents, HTML files. In the
screenshot, the only regular file is the swap file with the extension ‘.img’, a virtual disk format
used in Linux.

This directory listing shows nothing but files, directories, and symbolic links. However, looking back at
Figure 3, partition sda1 has a mount point /boot/efi and partition sda2 has a mount point /boot. This is
also shown towards the bottom of the df command’s output in Figure 8.

Figure 8 Screenshot of the Ubuntu 24.04 virtual machine showing the df command and its output in human readable format.

What this means is that the /boot directory is not being used to store files and other directories, it is
used at the point where the file system on the sda2 partition is mounted on (or connected to) the root
file system. Users can then access the files and directories stored in the file system on sda2 by changing
into the /boot directory. Similarly, the file system on the sda1 partition is mounted on the /boot/efi
directory and its contents can be access by changing into that directory.

CAUTION: The /boot and /boot/efi mount point directories are discussed here because they are the only
mount points present on many systems other than the root of the file system (/). The contents of these
mount points should never be manually changed, a simple mistake in modifying one of the files in these
mount points could render a system completely useless. There are tools that will be discussed later to
help make changes to the contents of these mount points safely.

CAUTION: There are also several references to mounts using tmpfs and efivarsfs in the output shown in
Figure 8. These are internal system file systems that users should never make changes in. There are
some circumstances when retrieving data from them, especially the one mounted on /run may be
acceptable. These file systems are all recreated every time the system is rebooted.

Most people are familiar with the drive letters used by Microsoft Windows systems, where each drive
letter represents a separate file system. As mentioned above, Linux file systems use the ‘/’ symbol to
represent the root of the file system for a given Linux system with all partitions and LVM LVs mounted
on directories somewhere in what users see as a single file system. This means that the absolute path to

Page 10 of 13
INFO-3182- Operating systems - Linux

any object (e. g. files and directories) stored on a Linux file system begins with a slash (/). For example,
the ssh program (interactive client for the SecureShell remote communications protocol) can be found
at /usr/bin/ssh, that is, the ssh program is in the bin directory within the usr directory at the root of the
file system. Most Linux systems have a symbolic link /bin to /usr/bin, so the ssh program can also be
found at /bin/ssh. This symbolic link is present for historic reasons and may be removed at some point in
the future.

How do all these file systems get put together?

There are several answers to this question:

• For the internal file systems (e. g. tmpfs) the system takes care of these automatically, so there
is no user action needed.
• For file systems (e. g. sda2 on /boot) that need to be mounted on the same mount point every
time the system starts, an entry is added to the /etc/fstab configuration file. The configuration
in this file is processed every time the system is started and there is a manual way to process
them if necessary.
• The ‘mount’ command can be used to manually mount file systems.

The /etc/fstab file

The /etc/fstab file is the configuration file that contains the information necessary to set up the desired
file system structure when a Linux system is booted. Figure 9 shows one of the /etc/fstab files for the
CentOS Stream 9 systems used to create the examples in this document.

The lines at the beginning of the fstab file shown in Figure 9 are comments, this is indicated by the ‘#’ at
the beginning of each line. Many Linux configuration files use ‘#’ as the symbol to begin a comment line.

Page 11 of 13
INFO-3182- Operating systems - Linux

Figure 9 Screenshot showing the contents of the /etc/fstab file on a CentOS Stream 9 virtual machine.

The remaining four lines at the end of the fstab file shown in Figure 9 provide file system mounting
information. Each of these lines consists of 6 pieces of information, described in order below:

• fs_spec – the file system specification for the file system to be mounted. This may be the path to
the device file (not often used anymore), the UUID of the device (shown in Figure 9), the LVM
mapper device file (shown in Figure 9),the fully qualified path to a virtual disk, or the device
label (not often used).
• fs_file – the mount point or target for the file system identified by fs_spec. This must be an
existing directory in the root file system or one of the other file systems specified in the file.
When the configuration line is referring to a swap partition, use the value of ‘none.’
• fs_vfstype – the type of the files system being mounted. Some common values are ext4,xfs,vfat
and swap.
• fs_mntops – A list of file system mounting options. The values specified for this item will vary
depending on the type of file system being mounted. A value of ‘defaults’ is used to specify the
default options fora file system.
• fs_freq – Used to indicate if the file system should be included in a system dump (a debugging
tool for major system failures. Usually set of 0 (zero), meaning do not dump.
• fs_passno – specifies the order in which the fsck program checks file systems at system boot.
Root file systems that are created directly on partitions should have a value of 1, all other file
systems created on partitions should have a value of 2. All LVM file systems and any partitions
that should not be checked must have a value of 0.

The fstab file shown in Figure 9 was created by the CentOS Stream 9 installer program. System
administrators can modify this installer-generated configuration or add their own configuration lines to
this file, as necessary.

Page 12 of 13
INFO-3182- Operating systems - Linux

CAUTION: Modifying the /etc/fstab file incorrectly can result in an unusable system. Most system
administrators will test any upcoming changes manually using the mount command prior to adding
them to the fstab file, that way a reboot will restore the system to its previous state.

The block ID for a partition or Logical Volume can be found using the blkid command. Block IDs are
hash values that uniquely identify a given block device, partitions or Logical Volumes and are
automatically generated when the device is created. Figure 10 shows the blkid command being used
to display the IDs for all bock devices on an Ubuntu 24.04 server system.

Figure 10 Screenshot of the blkid command and its output on an Ubuntu 24.04 server.

Conclusion

This document has discussed the basic structure of files systems for Linux systems. It is possible to
perform basic Linux system installations without knowing about file system structures. However, any
installations having more than the /, /boot, and /boot/efi file systems requires the use of non-default
file system configurations. These additional configurations may be done during system installation or
once the system is up and running depending on what is required.

Page 13 of 13

You might also like