CPTR 325: System Administration
CHAPTER 3: Filesystem and Disk Management
CPTR 325: System Administration
Chapter Introduction
Linux's robust support for various file systems, including its native ext2,
ext3, and ext4, as well as those from other operating systems,
facilitates compatibility in multi-boot environments. Understanding
how Linux mounts and unmounts filesystems is crucial for accessing
data stored on removable media and hard disks. Disk quotas in Linux
allow users to be allocated specific limits on disk usage, including
restrictions on disk blocks and inodes.
CPTR 325: System Administration
OBJECTIVES
Upon completion of this unit, you should be able to:
• Demonstrate knowledge of the different file systems Linux uses and supports
• Manage file system of Linux
• Set, manage, and view disk quotas
KEY TERMS
• Disk quota: amount of disk space allocated for a user
• File system: a disk− or network−based data structure used for storing files or
hierarchy of directories and files on a disk.
• Inode: A data structure that stores various information about a file in Linux, such as
the access mode (read, write, execute permissions), ownership, file type, file size,
group, number of links, etc.
• The kernel is the central component of an operating system that manages system
resources and facilitates communication between software and hardware.
CPTR 325: System Administration
Lesson 1:
Files System
CPTR 325:Ch3-L1
What is File system?
The file system dictates the structure of disks, keeping individual disks
hidden from ordinary users. Access to files relies on the directory structure,
while file permissions regulate user access. Disks with various file systems
must be mounted into the directory structure for access, with each mounted
disk or partition linked to a specific directory known as the mount point.
CPTR 325:Ch3-L1
Linux File system
In Linux, the file system follows an Inverted Tree Structure, anchored by the
root directory (/). All file and device access within a Linux system is
managed through this hierarchical file system. Disks, whether fixed or
removable, and partitions on the same disk, are integrated into the directory
hierarchy using the mount command.
CPTR 325:Ch3-L1
CPTR 325:Ch3-L1
Directory Structure
Directories, also known as folders, are used to store files and organize them
for easy access. They can be thought of as virtual containers where files are
kept, similar to physical folders on a desktop.
In Linux and many other operating systems, directories are organized in a
tree-like structure. This structure is well-documented and defined by the
Linux Filesystem Hierarchy Standard (FHS). Each directory has a specific
purpose and contains files related to that purpose.
When accessing directories in Linux, we use paths, which are sequences of
directory names separated by forward slashes (`/`). For example,
`/var/spool/mail` and `/var/log` are paths to specific directories. These paths
help us navigate through the directory structure to locate the files we need.
CPTR 325:Ch3-L1
Directory Structure
The below table gives a very short standard, defined, and well-known top-
level Linux directory list and their purposes:
• / (root filesystem): It is the top-level filesystem directory. It must include
every file needed to boot the Linux system before another filesystem is
mounted. Every other filesystem is mounted on a well-defined and
standard mount point because of the root filesystem directories after the
system is started.
• /boot: It includes the static kernel and bootloader configuration and
executable files needed to start a Linux computer.
• /bin: This directory includes user executable files.
CPTR 325:Ch3-L1
Directory Structure
• /dev: It includes the device file for all hardware devices connected to the
system. These aren't device drivers; instead, they are files that indicate all
devices on the system and provide access to these devices.
• /etc: It includes the local system configuration files for the host system.
• /lib: It includes shared library files that are needed to start the system.
• /home: The home directory storage is available for user files. All users have
a subdirectory inside /home.
• /mnt: It is a temporary mount point for basic filesystems that can be used
at the time when the administrator is working or repairing a filesystem.
• /media: A place for mounting external removable media devices like USB
thumb drives that might be linked to the host.
CPTR 325:Ch3-L1
Directory Structure
• /opt: It contains optional files like vendor supplied application programs that
must be placed here.
• /root: It's the home directory for a root user. Keep in mind that it's not the '/'
(root) file system.
• /tmp: It is a temporary directory used by the OS and several programs for storing
temporary files. Also, users may temporarily store files here. Remember that
files may be removed without prior notice at any time in this directory.
• /sbin: These are system binary files. They are executables utilized for system
administration.
• /usr: They are read-only and shareable files, including executable libraries and
binaries, man files, and several documentation types.
• /var: Here, variable data files are saved. It can contain things such as MySQL, log
files, other database files, email inboxes, web server data files, and much more.
CPTR 325:Ch3-L1
Chapter 3 Laboratory Activity 5
Lesson Refresher: This is your previous lessons during your lower year level.
Instruction:
1. Enter the account “teacher” and create a folder name “Lesson” and
“Test”.
2. Enter “Lesson” folder and create a text file.
3. Add a content to the file text saying, “Good day to y’all!”
4. Display the output.
5. Move the text file to test folder and display the output and present to
your instructor.
CPTR 325:Ch3-L1
The Super Block
The Superblock holds crucial details about the file system installed on the
disk, such as the initial free blocks and inodes. These lists, which cater to the
immediate needs of the OS, are replenished automatically when depleted by
scanning the free block or inode list. Inodes define files within the file
system, with each file linked to an allocated inode storing file information,
excluding the filename. File names are stored in the directory where the file
resides. Additionally, inodes include a list of the first ten blocks allocated to
the file, with subsequent block numbers listed in an indirect block list. For
handling larger files, inodes may feature double-indirect and triple-indirect
block pointers.
CPTR 325:Ch3-L1
File System Type
A file system type defines how the disk data is structured. Linux supports
many different file system types (typically twelve or more). The ext2fs and
ext4 are standards across all Linux distributions. All Linux systems can
include support for Microsoft’s FAT, VFAT, FAT32, and NTFS for use with
DOS/Windows systems as well as OS/2 and NFS.
CPTR 325:Ch3-L1
Making a File system
The mkfs (make file system) command is used to create a file system on a disk or partition.
Making a file system is similar to formatting, as shown in the following examples:
1. Format a hard disk hda5 as an ext2 disk:
# mkfs -t ext2 /dev/hda5 102400
2. Format a flash memory sda1 as an ext2 disk:
# mke2fs /dev/sda1
In the examples, the -t flag is utilized to override the default file system type. The command
necessitates the raw disk device name (/dev/hda5, /dev/fd0), with additional parameters varying
based on the file system type. Upon execution, the command generates a superblock and an
inode list, with the inodelist being fixed in size and unextendable, though the initial number of
inodes created can be overridden.
CPTR 325:Ch3-L1
Making a File system
To change the number of inodes, you need to determine the physical size of
the disk and convert it to the number of logical blocks. Typically, a diskblock
is 512 bytes, and a logical block is 1,024 blocks. For example, a 64-MB disk
has 65,536 logical blocks and 128-KB physical blocks (131,072). Stick to the
default number of inodes unless you plan to create many small files or a few
large ones. Choosing a larger block size (2,048) improves disk performance
but may waste space, while smaller block sizes (512) conserve space but
may reduce performance.
CPTR 325:Ch3-L1
Making a File system
You don't need to match the size of the filesystem with the entire disk; you
can leave unused space for other filesystems or future needs. Once a
filesystem is created, you can't change its size without losing all the data
stored on it. If you run out of inodes (data structures that hold information
about files), you'll need to back up all the data, create a new filesystem with
more inodes, and then restore the data.
CPTR 325:Ch3-L1
Mounting a File System
A Linux file system can only be accessed if it is mounted on the file system
hierarchy (tree structure). The directory used to mount the file system is
called the mount point. Any directory can act as a mount point for any type
of file system, and mounted file systemscan contain other mounted file
systems. Since mounting a file system will hide the previous contents of the
mount point directory, it is customary to choose an empty directory for the
mount point. The /mnt directory is provided as a temporary mount point.
CPTR 325:Ch3-L1
Mounting a File System
The mount command is used to add any disk containing a file system to the
tree structure.
# mount -t ext2 /dev/hda2 /home/mydisk
# ls /home/mydisk
CPTR 325:Ch3-L1
Mounting a File System
File systems that are no longer needed can be removed from the root file
structure using the umount command. File systems with open files or
containing other mount points cannot be unmounted. The fuser command
can be used to determine which processes (and users) are using the file
system and can be used to kill these processes if necessary.
# umount /home/mydisk
# ls /home/mydisk
CPTR 325:Ch3-L1
Mounting a File System
As long as the kernel understands the format (type) of the file system, it can be
mounted onto the hierarchy. An MS-DOS (Microsoft Disk Operating System) file
system mounted in this way is accessed as though it was a normal Linux file
system. Linux uses file system type msdos (or vfat for Windows). The mount
mechanism is also the way network disk systems, such as NFS or RFS, are
accessed.
The mount command, without any parameters, lists the mounted file systems. The
df command provides a different view, showing percentages used and available.
The mount command maintains the /etc/mtab file with information concerning
the currently mounted files. Corrupting this file will upset the mount and umount
commands.
CPTR 325:Ch3-L1
File System Configuration Files
The /etc/fstab file is maintained by the system administrator and is used to
define the standard mountable disks on the local system. The system startup
and the commands use the information in this file to mount file systems
automatically.
CPTR 325:Ch3-L1
File System Configuration Files
Entries in /etc/fstab consist of one line per file system, with space- or tab-
separated fields of the following form:
Block device mountpoint Fstype mount options dump fsck order
# cat /etc/fstab
/dev/hda5 / ext2 defaults 1 1
/dev/hda1 /boot ext2 defaults 1 2
/dev/hda6 swap swap defaults 0 0
/dev/fd0 /mnt/floppy ext2 noauto 0 0
/dev/cdrom /mnt/cdrom iso9660 noauto,ro 0 0
none /proc proc defaults 0 0
/dev/hdb5 /daj ext2 defaults 0 3
CPTR 325:Ch3-L1
File System Configuration Files
Use a hyphen for fields that do
not require the following values:
no raw device, no fsck pass
number, or no mount options.
Lines starting with a # symbol are
ignored and can be used for
comments.
The fields in /etc/fstab are listed
in the following table.
CPTR 325:Ch3-L1
Free Disk Space
The df command, short for "disk free" is used to display information about
the available disk space on mounted filesystems in Unix-like operating
systems such as Linux. Here's a breakdown of its usage:
By default, df reports disk space in blocks of 1K (1024 bytes) each.
Use the -k option to report disk space in kilobytes instead of the default
block size.
The -m option reports disk space in megabytes.
You can use the -t option followed by a filesystem type to filter the output
to show only filesystems of that type.
CPTR 325:Ch3-L1
Free Disk Space
When setting up a new system, the df command is crucial for determining the
appropriate sizes for filesystems. After the system is up and running smoothly, df can
also be used to keep an eye on filesystem space usage. By scheduling df to run hourly as
a cron job and filtering its output using a shell script, you can easily identify filesystems
that are nearing 10% or 5% of their capacity.
Some Linux systems provide administration utilities that do this automatically. Example
of df usage:
# df -k
File system 1024-blocks Used Available Capacity Mounted on
/dev/hda5 642009 446269 162579 73% /
/dev/hda1 16554 593151 06 4% /boot
/dev/hdb5 1189119 1311 27670 0% /daj
CPTR 325:Ch3-L1
Chapter 3 Laboratory Activity 6
Instruction: Create an ext2 file system on a 200-MB disk hda5.
a. Mount this file system on /usr.
Expected output:
Filesystem 1k-Blocks Used Avail Use% Mounted on
/dev/hda5 200M 32K 200M 1% /usr
Get in Touch
With Us
Send us a message or
visit us
City of Batac, Ilocos Norte,
Philippines
(63) 77-600-0459
op@mmsu.edu.ph
Follow us for updates
facebook.com/MMSUofficial
www.mmsu.edu.ph