Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 42

Chapter 5

Linux Filesystem Administration

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. M
ay not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Objectives
• After completing this chapter, you will be able to:
• Identify the structure and types of device files in the /dev directory
• Understand common filesystem types and their features
• Mount and unmount filesystems to and from the Linux directory tree
• Create and manage filesystems on hard disks, SSDs, and removable
media storage devices
• Create and use ISO images
• Use the LVM to create and manage logical volumes
• Monitor free space on mounted filesystems
• Check filesystems for errors
• Use hard disk quotas to limit user space usage

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The /dev Directory (1 of 3)
• Device file: a file representing a system device
• One file per device, typically found in /dev directory
• Specifies how to transfer data to and from the device
• Character devices: transfer data character-by-character to and
from the device
• Block devices: transfer chunks or blocks of data using physical
memory to buffer the transfer
• Faster data transfer than character devices
• CDs, DVDs, USB flash drives, hard disks, and SSDs

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The /dev Directory (2 of 3)
• Major number: a number in a device file that points to the
device’s driver in the Linux kernel
• Several different devices can share the same major number if they are of
the same general type
• Minor number: indicates the particular device
• The device file type (block or character), major number, and
minor number make up the unique characteristics of a device file

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The /dev Directory (3 of 3)
• The mknod command: can be used to re-create a corrupted
device file
• Must know file type, major, and minor numbers
• To see a list of devices currently used on the system and their
major numbers, view the contents of the /proc/devices files

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Filesystems
• Filesystem: organization and management imposed on physical
storage media
• Used to manage the storage and retrieval of data
• All filesystems share three common components
• Superblock
• Inode table
• Data blocks
• All storage media need to contain a filesystem before they can be
used

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Filesystem Types
• Many filesystems are available for use in the Linux operating
system
• Each has its own strengths and weaknesses
• Several devices formatted with different filesystems under the same
directory tree may be used

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Mounting (1 of 4)
• Mounting: making a device accessible to users via the logical
directory tree
• Mount point: directory to which a device is attached
• Mounted device temporarily covers up the contents of the mount point
• Any existing directory can be a mount point
• In order to prevent making files inaccessible, create empty
directories used specifically for mounting devices

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Mounting (2 of 4)

Figure 5-1: The directory structure prior to mounting

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Mounting (3 of 4)

Figure 5-2: The directory structure after mounting a USB flash memory drive

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Mounting (4 of 4)
• Root filesystem: when the Linux system is first turned on, a
filesystem on the hard drive is mounted to the / directory
• Contains most OS files
• The mount command: used to mount devices to mount point
directories
• The umount command: used to unmount devices from mount
point directories

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with USB Flash Memory Drives (1 of 3)
• Most common type of removable media
• Used to store small files
• Recognized as SCSI drives by operating systems
• Often ship with a single partition formatted with the DOS FAT or exFAT
filesystem
• The mkfs (make filesystem) command: used to create a new
filesystem on a USB flash memory drive
• Specify the filesystem type using the –t switch and the device file
representing the partition
• Specify a different filesystem after the –t option

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with USB Flash Memory Drives (2 of 3)
• After a USB flash memory drive has been formatted with a
filesystem, it must be mounted on the directory tree before use
• List of currently mounted filesystems can be obtained using the mount
command with no options or arguments
• Easier to see a list of currently mounted filesystems using the df (disk free
space) command
• To check whether the /media/USBdrive directory is being used by
any users, use the fuser command
• The umount command can take the name of the device to
unmount or the mount point directory as an argument

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with USB Flash Memory Drives (3 of 3)

Table 5-4: Useful commands when


mounting and unmounting filesystem

Command Description
mount Displays mounted filesystems and their type
df -T
mount –t <type> <device> <mount point> Mounts a <device> of a certain <type> to a <mount point>
directory
fuser –u <directory> Displays the users using a particular directory
umount <mount point> or umount <device> Unmounts a <device> from its <mount point> directory

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with CDs, DVDs, and ISO Images (1 of
3)
• Most software not downloaded from the Internet is packaged on
CDs and DVDs
• Can be mounted using the mount command and unmounted using
umount command
• Different device file: depend on the technology used by the drive itself
• PATA drive configurations
• Primary master (/dev/hda)
• Primary slave (/dev/hdb)
• Secondary master (/dev/hdc)
• Secondary slave (/dev/hdd)

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with CDs, DVDs, and ISO Images (2 of
3)
• SATA or SCSI drives
• Linux may use many different names, depending on the actual CD or DVD
drive
• To make identification of CD/DVD drive easier, Fedora Linux
creates a file called /dev/cdrom
• Symbolic link to the correct device file for your first CD or DVD drive

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with CDs, DVDs, and ISO Images (3 of
3)
• CDs and DVDs typically use ISO 9660 or UDF filesystem type
and are read-only when accessed using Linux
• Mount with –r (read-only) option
• CDs and DVDs cannot be ejected until properly unmounted
• The ISO 9660 filesystem type is not limited to CDs and DVDs
• Image files, called ISO images, can be created and contain other files
• The mkisofs command: creates ISO image from a directory of
files

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with Removable Media Within a GUI
Environment (1 of 2)
• Process automatically mounts removable media to a directory
• Able to work with it immediately
• Insert USB flash memory drive, CD, or DVD while in a GUI
environment
• Automatically mounted by the system to a directory
• Many types of removable media devices
• External hard drives
• Digital cameras
• Media players
• Smartphones
• Tablets
Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with Removable Media Within a GUI
Environment (2 of 2)

Figure 5-3: Accessing removable


media within the GNOME desktop

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with Hard Disks and SSDs (1 of 2)
• Types of hard disks
• PATA, SATA, and SCSI/SAS
• PATA configurations
• Primary master (/dev/hda)
• Primary slave (/dev/hdb)
• Secondary master (/dev/hdc)
• Secondary slave (/dev/hdd)
• SATA and SCSI hard disks are well-suited to Linux servers
• Faster access speed
• Multiple hard drives can be attached to a controller

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with Hard Disks and SSDs (2 of 2)
• Associated with different device files
• First SCSI HDD (/dev/sda)
• Second SCSI HDD (/dev/sdb)
• Third SCSI HDD (/dev/sdc)
• Fourth SCSI hard disk drive (/dev/sdd)
• Fifth SCSI hard disk drive (/dev/sde)
• Sixth SCSI hard disk drive (/dev/sdf)
• And so on
• SSDs are a newer technology
• Use much faster NAND flash storage
• Provide a hard disk compatible interface
Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Standard Hard Disk Partitioning (1 of 4)
• Partition: physical division of a hard disk
• Can have its own filesystem
• Linux requires at least two partitions
• Root and swap
• It is good practice to use more than two partitions
• Segregate different types of data
• Allow for use of multiple filesystem types on one hard disk drive
• Reduce chance that filesystem corruption will render a system unusable
• Speed up access to stored data
• Allow for certain operating system features

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Standard Hard Disk Partitioning (2 of 4)
• Track: area on a hard disk that forms a concentric circle
• Sector: portion of a track containing information
• Block: combination of sectors
• Cylinder: series consisting of the same concentric track on all of
the metal platters inside a hard disk drive
• Partition definitions are stored in first readable sector of the hard
disk
• Master Boot Record (MBR) or master boot block (MBB)

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Standard Hard Disk Partitioning (3 of 4)

Figure 5-4: The physical areas of a hard disk

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Standard Hard Disk Partitioning (4 of 4)

Figure 5-5: A sample MBR partitioning strategy

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with Standard Hard Disk Partitions (1
of 4)
• The fdisk command: create partitions after installation
• Specify hard disk partition as an argument
• Variety of options for fdisk prompt to achieve different tasks
• The cfdisk command: interactive graphical utility for creating,
manipulating and deleting partitions
• Reboot computer after using the fdisk and cfdisk commands
• Ensures proper reloading into memory

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with Standard Hard Disk Partitions (2
of 4)
• The mkswap command: prepare the swap partition
• The swapon command: activate the swap partition
• The swapoff command: deactivate the swap partition
• Edit /etc/fstab file: ensure that new swap partition is activated as
virtual memory

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with Standard Hard Disk Partitions (3
of 4)
• Hard disk uses a GPT instead of a MBR
• Use fdisk or cfdisk commands to create and modify partitions before you
format them with a filesystem or prepare them for use as swap memory
• The gdisk (GPT fdisk) command: create and work with partitions
on GPT hard disk
• The parted (GNU Parted) command: create and modify partitions
on both MBR and GPT hard disks

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with Standard Hard Disk Partitions (4
of 4)
• After creating GPT partitions that should contain a filesystem:
• Format those partitions with a filesystem using mkfs
• Mount them to the directory tree with the mount command
• Update the /etc/fstab file to mount them automatically

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with the LVM (1 of 4)
• Logical Volume Manager (LVM): used to create logical volumes
• Can contain filesystems and can be mounted to directories
• More flexible than standard partitions; allows use of free space across
multiple hard disks
• LVM components
• Physical volumes (PVs)
• Volume groups (VGs)
• Logical volumes (LVs)

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with the LVM (2 of 4)

Figure 5-8: A sample LVM configuration

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with the LVM (3 of 4)
• The pvcreate command: create PVs
• The pvdisplay command: display detailed information about each
PV
• The vgcreate command: create a VG that uses the space in PVs
• Physical extent (PE) size: block size for saving data
• The vgdisplay command: display detailed information about each
VG

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Working with the LVM (4 of 4)
• The lvcreate command: create LVs from available space in a VG
• The lvdisplay command: display information about each LV
• You work with mount points of LVs as you would work with any
other had disk partition device file
• The pvscan, vgscan, and lvscan commands: display information
about PVs, VGs, and LVs, respectively
• The vgextend command: add a new PV to an existing VG
• The lvextend command: increase the size of an LV

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Monitoring Filesystems
• Check mounted filesystems periodically
• Errors
• Disk space usage
• Inode usage
• Minimizes problems that can occur as a result of a damaged
filesystem
• Reduces the likelihood that a file cannot be saved due to insufficient disk
space

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Disk Usage (1 of 2)
• Using more filesystems typically results in less hard disk space
per filesystem
• May result in errors when filesystems fill up with data
• The df (disk free space) command:mMonitor free space used by
mounted filesystems
• –h option: more user friendly format
• To get information about different filesystems, mount them prior to using df
command

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Disk Usage (2 of 2)
• The du (directory usage) command: view size of a directory and
contents in kilobytes
• –s option: summarizes output
• –h option: more user friendly format
• dumpe2fs command: view total number of inodes and free inodes
for an ext2, ext3, or ext4 filesystem
• Use –h option

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Checking Filesystems for Errors (1 of 2)
• Filesystem corruption: errors in filesystem
• Commonly occurs due to improper system shutdown
• Syncing: saving data to the hard disk
• Bad blocks: unusable areas of a disk
• Cannot hold a magnetic charge

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Checking Filesystems for Errors (2 of 2)
• The fsck (filesystem check) command: check filesystem for errors
• Filesystem must be unmounted
• –f option used to perform full check
• The e2fsck command: check an ext2, ext3, or ext4 filesystem
• -c option checks for bad blocks
• The tune2fs command: used to change filesystem parameters
• -i option sets interval to forcing full system

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Disk Quotas (1 of 2)
• If several users on a system, must be enough hard disk space for
each user’s files
• Disk quotas: user limits on filesystem usage
• Quotas can restrict number of files/directories a user creates
• Soft limit: user may exceed quota briefly
• For a certain period of time (seven days by default)
• Hard limit: limit cannot be exceeded

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Disk Quotas (2 of 2)
• The quotaon and quotaoff commands: turns quotas on and off
• The edquota command: edit user quotas
• The repquota command: report user quotas
• The quota command: allows regular users to view their own
quotas and current usage

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Summary (1 of 2)
• Disk devices are represented by device files that reside in the
/dev directory
• Each disk drive must contain a filesystem, which is then mounted
to the Linux directory tree for usage using the mount command
• Hard disks must be partitioned into distinct sections before
filesystems are created on those partitions
• Many different filesystems available to Linux

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Summary (2 of 2)
• The LVM can be used to create logical volumes from the free
space within multiple partitions
• Most removable media devices are recognized as SCSI disks by
the Linux system and are automounted by GUI environments
• Important to monitor disk usage using the df, du, and dumpe2fs
commands to avoid running out of storage space
• If hard disk space is limited, you can use hard disk quotas to limit
the space that each user has on filesystems

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

You might also like