CHAPTER 2. Managing Filesystems
Exam objectives in this chapter
■ Filesystem Types
■ Mounting and U(n)mounting Filesystems
■ Partitions
■ Directories
■ Filesystem Management

Introduction

This chapter presents the strategies for the creation of filesystems, the different types of filesystems, the tools used to create filesystems, and the tools used to administer filesystems.

Filesystem Types

A filesystem provides the operating system with a framework for the storage, organization, modification, removal, and retrieval of digital information. To achieve these requirements, filesystems are responsible for organizing and maintaining files, folders, metadata, and residual data as containers for storing digital information. Regardless of the selected filesystem type, data containers can be as large as terabytes (TB) in size or as small as a sector. The size of a sector can vary among the different filesystem types; however, it is the smallest amount of disk space that can be assigned to hold a file. The default size of a sector is typically 512 bytes.

Fast Facts
Filesystems organize and maintain the following data:
■ Files are sectors of allocated space within a filesystem used for storing digital information. The allocated space can be contiguous or noncontiguous. There are four different types of files: regular, links, first-in first-out, and sockets.
■ Directories (or folders) are sectors of allocated space within a filesystem used to group files. This association is performed and maintained within a File Allocation Table (FAT). Directories can be hierarchical structures, with directories containing subdirectories.
■ Metadata are data used by the operating system to further characterize files and folders. Typically, some form of indexing file is created and used. The indexing information can contain the file size, the file date and time stamp, sector location, and information pertaining to access permission and device type.
■ Residual data are a form of data remaining within the filesystem after the file, filename, folder, and folder name relationship has been severed and can vary in size. This typically occurs after deleting a file or folder and can be as small as a sector. Slack space is any residual data remaining on a disk not currently associated with any particular file.
For the various types of filesystems, the storage containers (also known as storage media types) can reside on many different storage devices. The storage devices can house static and dynamic generated data. As a result, different filesystem structures exist for the different types of containers. Not all operating systems provide support for the various storage containers.

Did You Know?
Listed below are descriptions of each of the storage media types supported by Linux:
■ The hard disk storage media type is used for storing data either on internal or on external hard disk drives. This filesystem storage is known as local filesystem storage.
■ The optical storage media type is divided into two different categories, supporting CDs and DVDs. Both CDs and DVDs are supported by the ISO 9660 filesystem standard, also known as the CD File System (CDFS). DVDs also support the Universal Disk Format (UDF), which is considered to be a CDFS replacement.
■ The network-based storage media type is an architectural model comprising client and server computers, for example, Server Message Block (SMB) and Network File System (NFS). The client establishes remote network connectivity to a server to access files.
■ The removable storage media type is a filesystem designed for storing files on flash memory devices. Flash memory devices are primarily used in memory cards and USB flash drives.
■ The random access memory (RAM) disk storage media type functions as a storage container by using a segment of main memory in RAM. The Compressed ROM Filesystem (cramfs) is used with many Linux distributions for initrd images.
■ Special-purpose storage media types are systems implemented to handle files, folders, and metadata dynamically. Special-purpose filesystems are created by an application or a software/system management tool.

Local Filesystems

Local filesystems alleviate many challenges that are typically associated with network-based filesystems, RAM disk-based filesystem, and removable filesystem. This includes performance challenges due to limit network bandwidth, access failure due to lost network connectivity, and nonpersistent filesystems (for example, RAM disk) that require reconfiguration once the electrical power is restored.
This section presents some additional filesystems that are somewhat common: FAT, New Technology File System (NTFS), and Virtual File Allocation Table (VFAT). FAT is a widely supported filesystem with a number of different standards including FAT12, FAT16, FAT32, and a variation called VFAT. These are summarized in Table 2.1.
Table 2.1. FAT Cluster and Partition Sizes

NameCluster Address SizePartition Size
FAT1212 bits16 MB
FAT1616 bits2 GB
FAT3232 bits2 TB

Exam Warning
Unlike VFAT, earlier Windows operating systems that used the FAT filesystem allowed files to be named with only eight alphanumeric characters with a period separating the name from a three alphanumeric character extension. VFAT supports long filenames, which allows files to have names up to 255 alphanumeric characters. VFAT is the preferred filesystem for mounting foreign filesystems.

Network

Linux filesystems can also span across a network that allows them to function as a client/server model that provides file-sharing services to systems remotely. The server component provides shared directories that can be accessed via network connectivity. The client component, after obtaining access, connects the shared directories to a mount point on the local filesystem. Within the Linux environment, the two primary network-based filesystems are the NFS and the Server Message Block Filesystem (SMBFS).
NFS is a framework designed to allow a user on a client workstation to access remote files over a network on a network-based server. In this model, a NFS server shares one or more directories that can be accessed remotely by a network client. NFS uses registered ports TCP 2049 and UDP 2049.
SMBFS is a framework designed to allow workstations to access directory/file shares on a server. This model, implemented as client/server architecture, comprises two components. The first component, SMB protocol, provides mechanisms for performing interprocess communications and listens on port TCP 445. The second component, SMB service, is an application that resides on both the client-side and the server-side. The SMB service interoperates with the system's security authentication mechanisms and local filesystem, which allows the SMB environment to interoperate with various other SMB servers. The Microsoft version of the SMBFS is known as the Common Internet File System (CIFS). The Samba application, an open source client/server implementation, provides support for both SMBFS and CIFS.

Crunch Time
The difference between local and remote filesystems needs to be understood as well as the advantages and disadvantages of both.
■ Common network (remote) filesystems are NFS and SMB.
■ Connectivity with Microsoft systems is usually via SMB.
■ Local filesystems can reside on internal or external attached devices.
■ Local filesystems normally outperform network filesystems.

Mounting and U(n)Mounting Filesystems

Mounting is a form of attaching or joining a separate storage device to the existing root directory hierarchy. It makes physically separate disks accessible and/or partitions on a local or remote machine available, with the attached location on the client machine called a mount point. Linux users can manually mount a filesystem or have a filesystem automatically mounted when the system initially starts up.

The mount and umount Commands

To manually mount a filesystem to your existing root directory structure, you can establish a connection to a local mount point using the mount command, which can be used with or without any arguments. The mount command issued with no arguments lists all the currently mounted filesystems on the system. A unique feature about Linux is its treatment of devices (for example, storage devices and terminals) as directories (folders) with the /dev directory used to mount devices. To mount a device, use the mount command with, typically, two arguments. The first argument represents the storage device that you wish to attach to your root directory structure. The second argument represents the directory location where you want to attach it underneath, the mount point. The general directory locations for most Linux systems are the /mnt and /media directories. The /media directory is typically used for the mounting of removable media (for example, floppy disks, CD/DVD drives). In addition, prior to mounting any storage device, a mount point directory needs to exist before executing the mount command.
mount/dev/sdb1/mnt/morestorage
The mount command does include extra arguments (for example, sb for super-block and noload for turning off journaling) that can be used. To specify a specific filesystem type, the -t argument should be used. Normally, the Linux kernel typically will detect the type of filesystem of the storage device you are attaching.
To disconnect a device, use the umount command, specifying the mount point.
umount/mnt/morestorage

Fast Facts
Mounting and unmounting of partitions is an often used process by system administrators. Knowing the commands and options is very important.
■ The command to unmount a drive is umount not unmount.
■ Linux normally detects the type of filesystem you are attaching.
■ Add filesystems to be permanently mounted to the /etc/fstab file.

/etc/fstab

The /etc/fstab file is text-based file, which lists the filesystems that are mounted on a permanent basis whenever the system is booted. The structure for adding a filesystem to the /etc/fstab file so that it can be mounted automatically at bootup contains the disk partition to be mounted, the directories mount point, the filesystem type, and other filesystem options (for example, noload, noatime, and noauto). A typical structure is shown in Figure 2.1.
B9781597494977000050/f02-01.jpg is missing
FIGURE 2.1.
/etc/fstab file

Partitions

Partitioning is the allocation of electronic storage space within a storage device into separate data areas for a specific filesystem type. Whether implemented either via a partition editor tool or via the fdisk command, partitions can be created, deleted, or modified. The folder and file creation and placement process cannot occur until after the partitioning and formatting of the storage device. The decision to implement one or more partitions per storage device is based on certain advantages and disadvantages.

Fast Facts
Creating multiple partitions on your storage device:
■ Improves access time for data and applications colocated on the same partition
■ Supports the separation of user files and operating system files
■ Provides dedicated operating system swap or system paging file space
■ Protects operating system files from the rapid growth of system data files (for example, logging and system cache) that may consume all available disk space quickly
■ Provides support for multibooting environments
■ Provides a layer of isolation to prevent or protect one partition's system resources from another partition's system resources
■ Allows the implementation of various filesystems and different disk geometry strategies to improve read and/or write performance
After creating a partition, a filesystem must be assigned to it via a partition editor tool or via the mkfs command. A directory structure would then need to be created for the allocation and organization of files and folders. The balancing of the size and structure of the partitions, filesystems, and directories must be addressed, with decisions based on.
■ Initial boot access: During the installation process, it is critical the system BIOS (basic input/output system) and GRUB (grand unified bootloader) functions are able to access a partition. The system BIOS will access the primary partition to execute the bootloader, GRUB, which must be able to access the /boot partition to retrieve the Linux kernel and other critical configuration files. As a result, for some installations, placing the initial boot applications and configuration files on a separate partition makes the installation process easier, especially as, during the initial boot process, the Linux kernel and initrd will have limited access to disk device drivers.
■ Disk space growth: The design and implementation of a Linux system require disk space growth projections. The amount of disk space needed for current and future use needs to be calculated, and the projections should include installed applications and application data and user files. If a fixed partition-based implementation is used, space limitations or quotas should be used. The introduction of logical volume management (LVM) reduces disk growth limitations by allowing data in volumes to expand across separate physical disks.
■ Security and permissions: Information stored on the same partition opens the door for various security risks. For example, if the partition is corrupted, all the data could be lost. In addition, directories not properly secured could give unauthorized users access to sensitive data (for example, everybody's HR records in a company). Creating separate partitions to segregate system resources from user files allows you to place more stringent access controls around system resources.
■ Backup/restore: Creating several partitions provides greater backup flexibility, reduces backup performance impacts, and can improve restoration times.
■ System repair/rescue: Creating a separate partition for critical partitions makes it easier to repair and/or rescue a corrupted partition.
■ Logging/monitoring: Log files must be accessed, reviewed, and in most cases saved for security purposes. The creation of a separate partition for log files will make it easy to backup, restore, and secure these.
■ Volatile/temporary data: Computers and associated applications are constantly creating volatile and temporary data. The Linux system automatically creates a swap partition to hold some of this data. However, there are other directories (for example, /tmp) that traditionally reside underneath the root directory. These other directories can also outgrow the disk space capacity of the partition.
■ System maintenance: The creation of separate partitions for system administration and maintenance purposes can also make the job easier.
The decision to create a partition or not to create a partition is difficult. Clearly, a single partition system is not a sound system design; however, creating a partition for every directory is not feasible either. Table 2.2 provides more insight into why some directories are put on separate partitions.
Table 2.2. Linux Directories and Partitions

Linux DirectoryBenefits of Separate Partition
/swapThe /swap directory is used as swap space and functions as virtual memory. This directory provides additional memory to your system to run large programs.
/bootThe /boot directory contains files and configuration information needed during the Linux boot process. The implementation of /boot under a different partition would make system rescues and repairs easier.
/homeThe /home directory normally hosts users' account directories and user-specific files. This directory should be assigned a separate partition as the multiuser file may fill the partition. In addition, performing backup and restore functions is a lot easier if dynamically changing user files reside on a separate partition.
/tmpThe /tmp directory is used to support programs that require temporary file space that is volatile. It can reside under the root directory, but if temporary files grow quickly than your root directory, they may run out of disk space, perhaps from system or application core dumps.
/varThe /var directory contains system and application-generated information as a result of spooling, logging, and system temporary files. The /var directory should be placed on a separate partition, if possible. It is normally a subdirectory underneath the root directory. The primary reason why it should be separated is due to the possible growth of the log files and user mailboxes.
The recommended partitioning schema is to have two primary partitions and one extended partition. The two primary partitions support the Linux root partition and the Linux swap partition. The extended partition supports the home partition.

Exam Warning
When deciding on the size of the partitions, bear in mind that the BIOS in some older computers may be able to access the first 1024 cylinders of a disk drive, approximately 528 MB.

Directories

The purpose of this section is to provide an overview of the key directories, as shown in Table 2.3. As a hierarchical tree structure, the filesystem starts at the top with a directory indicated by a forward slash called the root directory and contains all the underlying files and directories.
Table 2.3. Critical Linux Directories

Linux DirectoryPurpose
/The root directory is the top tier directory and is the most important directory in the Linux system. It contains core directories and files, which include utilities, configuration files, bootloader information, and start-up information required for the initialization of the Linux system.
/binContains Linux commands used by the system administrator and users, which are also accessible when the system is in single-user mode
/devUsed within the Linux environment to mount devices
/etcTo control the execution of programs and support the dynamic Linux environment, the /etc directory is used. It contains system and application configuration files.
/mediaUsed to mount removable media (for example, fl oppy disks, CD/DVD drives, and USB/thumb drives) for access by the system administrator and users
/mntSimilar to the /media directory, this is used to temporarily mount filesystems.
/procFunctions as a virtual filesystem for system processes and the Linux kernel
/rootThe /root directory, not to be confused with the root directory, is the home directory assigned to the root user account.
/sbinUsed to contain Linux utilities that are used only by the system administrator (for example, root). It contains executables for critical booting, restoring, recovering, and/or repairing the Linux system.
/usr/binContains the primary executable commands on the system. Linux users and the root user can execute the commands in this directory.
/usr/libThis contains software libraries and packages for programs, including object files and internal binaries that are platform specific.
/usr/lib64Performs the same function as the /usr/lib directory but supports the 64-bit architecture
/usr/localLocation for locally installed applications. Software installed in this directory typically is not affected by system software updates. In addition, software installed in this directory can be shared.
/usr/shareUsed to store read-only architecture neutral files. The files contained in this directory are platform independent.
/var/logContains data files generated as a result of spooling, logging, and system temporary files

Fast Facts
The Linux filesystems can be considered as follows:
■ A hierarchical structure to organize files and directories
■ A directory structure based on the Filesystem Hierarchy Standard (FHS)
■ Ordered consistently (due to FHS) to enable files and directories to be easily located by users and applications
When addressing all other second tier directories and files, using the full path naming convention, all subsequent files and folders use the forward slash to indicate their hierarchical position to prevent confusion with other directories that could have the same name but located at a different sublayer tiers (for example, third level and fourth level).

Filesystem Management

There are tools to manage filesystems either locally or remotely, and these will be used by all system administrators, often on a daily or weekly basis.

Fast Facts
The filesystem tools that you will need to learn for the exam and will likely use on a regular basis are
du provides a summary of disk space used per file in the current directory and disk space allocated for files contained in any subdirectories.
df provides a summary of the amount of disk space available on a filesystem in many different ways by using different arguments.
df –i displays information about inodes rather than file blocks.
df –h presents a disk space summary in an easy-to-understand output format using kilobytes, megabytes, and/or gigabytes.
■ Filesystems need to be maintained and should be checked and, if necessary, repaired using the fsck command.
■ Filesystems need to be unmounted prior to running fsck.

Quotas

Users and errant applications, without limitations, can continue to add data to a folder that would eventually use up all the available disk space on a partition. Once a partition is full of data, not only will users and applications be unable to save information to disk but damage to system or application files may also occur. The implementation of disk quotas can provide valuable filesystem management support to allow you to specify limits on disk storage that may be allocated to a user or a group of users.
To implement disk quotas, you must add the following qualifiers “usrquota” or “grpquota” to each desired partition in the /etc/fstab file and then reboot the system. Then, the quotacheck command needs to be executed to examine the quota-selected filesystems and build a table of the current disk usage for each filesystem with disk quota enabled. This information is stored in aquota.group and aquota.user files. Finally, the edquota command, a quota editor, is used to display and change the various quota settings for one or more users or groups.
After the disk quota system is implemented, a summarized disk quota review for a filesystem is available using the repquota command, which creates a summarized disk quota report. The report includes a summary of the disk quotas for the specified filesystems and summaries for the current number of files and amount of disk space per user. Finally, in case of a system crash and other filesystem failures, the quotacheck command is used to scan a filesystem for disk quota use and to create, check, and, if necessary, repair disk quota systems.

Loopback Device

Linux offers support for a loopback device, which supports the transformation of a special file containing an image of another filesystem into a device that can be used like any other Linux partition or device. Linux loopback devices are commonly used for CD/DVD ISO images. The disk image created of the CD/DVD disc contains the UDF or ISO 9660 filesystem format. Prior to accessing the loopback device, the ISO image must be downloaded and mounted. The Linux mount command is used to attach the virtual filesystem image.

NFS

NFS is a client/server model designed to make specified directories on a server available to a select subset of clients or all clients on a network. The server-side must configure directories for sharing, known as exports, and the client-side must be configured for mounting the exports. The shares (exports) made available via NFS are listed in the /etc/exports file. This file contains a listing of directories (exports) and the client machines that may mount the exports. Each line represents a shared directory and any associated options (for example, permissions).
The parameters for each line are as follows:
exported_directory <client1> (<options>) <clientN> (<options>)
■ exported_directory is the directory being exported on the server.
■ <client1> is the host or network to which the export is being shared for access. The client1 parameter can be based on Internet Protocol (IP) address, host name, or domain name for a single host; a wildcard (*) for a group of machines; or an IP network range.
■ <options> are those imposed on the connection, which include read-only (ro), read-write (rw), root_squash (to prevent remote root access), no_root_squashing (to allow remote root access), and others.
To activate the access of shared directories (exports), the exportfs command can be used. The following set of arguments can be used with the command:
-a To load and export all directories listed in the /etc/exports file
-r Rereads the /etc/exports file after changes have been made to the share permissions
-i Ignores the /etc/exports file and exports a directory not listed in the file
-u Removes (unexport) currently listed exported directories
-auRemoves all currently exported directories
The showmount command can be used to determine information about the shared directories (exports) on a server and will list any exports currently shared including those listed in the /etc/exports file, if they are currently being shared on the server. The showmount command syntax is showmount [options] [server1].
The default value for server1 is the value returned by the hostname command. With no options, showmount shows the clients that have mounted directories from the host. Some of the available options are shown in Table 2.4.
Table 2.4. Showmount Options

Showmount OptionPurpose
-a, --allUses the format hostname:directory, where hostname is the name of the client and directory is the mounted directory
-d, --directoriesList client mounted directories
-e, --exportsPrints the servers list of exported filesystems
-h, --helpProvides help summary
To establish a connection to the share, the client can use the mount command. The following demonstrates the way a client can establish a NFS connection:
mount server1:/share /mount_point
This makes accessible all the files underneath the directory /share on the server1 by changing to the /mount_point directory. An automatic mounted connection to the NFS share is established at boot time by inserting a line entry to the /etc/fstab file.

Swap

Linux requires virtual memory to ensure its successful performance, which can exist as a file or as an entire partition for storage. Virtual memory is accomplished by dividing the system's physical RAM into units known as pages and transferring less frequently used physical units of RAM (pages) to the hard disk drive using a process known as swapping. When the system swaps out pages of memory to the hard disk drive, the system's RAM is freed up to perform additional functions.
Although swapping offers advantages by extending its access to more memory, pages stored and retrieved on the hard disk drive are accessed slower than pages that only resided in physical memory (RAM). For the Linux system to use swap space, a special file or swap partition must be created first. The creation of a swap file entails the creation of a special file, which must be designated to function as a swap file and is created with the dd command. Below is an example of the creation of empty Linux swap file.
dd if=/dev/zero of=/newswapfile bs=1024 count=1048576
The command creates a swap file named newswapfile. The input file /dev/zero is a special Linux file that provides null characters. The newly created swap file is 1 GB in size.
To designate a partition or special file to be used as swap space, use the mkswap command. This command sets up a swap area on a partition or special file. The following commands prepare first a partition and then a special file as a swap file:
mkswap /dev/hdb1
mkswap /newswapfile
The swapon command is used to designate the specific devices or files on which paging and swapping is to take place. For the partition, you would need to prepare it using the swapon command as root:
swapon/dev/hdb1
To disable or turn off the swap files or swap partitions, the swapoff command can be used. The swapoff command disables swapping on the specified partition or file. When the -a flag is used, swapping is disabled on all known swap devices and files. The swapon –s command will display the current status.

Summary of Exam Objectives

Linux filesystems provide the operating system with a framework for the storage, organization, modification, removal, and retrieval of digital information. File-systems are responsible for organizing and maintaining files, folders, metadata, and residual data as containers for storing digital information. In addition, you learned that different filesystem types are available for local and network access (for example, SMB and NFS).
You learned about the mounting and unmounting of filesystems using the mount and umount commands. Automatically mounted filesystems are defined in the /etc/fstab file. After creating a partition, a filesystem must be assigned to the filesystem. The Linux mkfs command assigns filesystem to the partition. The Linux filesystem is a hierarchical structure used to organize directories (folders) and files and is based on the FHS. Filesystem management described the tools needed to manage local and remote filesystems. Commands to determine the amount of disk space used and remaining (for example, du and df) and the various commands for implementing and managing disk space limitations for users (for example, edquota, quotacheck, and repquota) were discussed. Additionally, the repairing of corrupted filesystems using fsck command, the mounting of unique loopback filesystems, the accessing of remote NFS filesystems, and the preparation of swap files or partitions using the Linux commands mkswap, swapon, swapoff, and swapinfo were described.
1. You need to use fdisk to establish a partition for a new SCSI disk drive you want to add for extra storage space. The original drives are all IDE drives. Which is the correct syntax?
A. fdisk /dev/SCSI1
B. fdisk /dev/IDE
C. fdisk /dev/sda
D. fdisk /dev/sdb
2. Which file, when the system initially starts up, will automatically mount filesystems?
A. /etc/fstab
B. /boot/fstab
C. /dev/devices.map
D. /etc/grub.conf
3. What is an ISO loopback device?
A. The transformation of special file into a virtual Linux filesystem
B. A device that returns feedback tests to the monitor
C. The /null driver device
D. The IP address 127.0.0.1
4. Which Linux command is used to designate a specific file or partition for swapping?
A. /swap
B. fileswap
C. swapon
D. GRUB
5. What is the purpose of the Linux exportfs command?
A. To function as the Linux bootloader
B. To partition a storage device
C. To designate a specific file or partition for swapping
D. To activate the access of shared NFS directories
Answers
1. Correct answer and explanation: C. Answer C is correct; the SCSI device notation for the first disk is /dev/sda.
Incorrect answers and explanations: A, B, and D. Answers A and B are incorrect because both do not exist as valid default Linux device names. Answer D is incorrect; the SCSI device notation for the second SCSI disk is /dev/sdb. The system indicated that this is the first SCSI drive added.
2. Correct answer and explanation: A. Answer A is correct; the /etc/fstab file is used to define and automatically mount filesystems.
Incorrect answers and explanations: B, C, and D. Answer B is incorrect because the file does not exist. Answers C and D are files used during the loading of the Linux Kernel by GRUB.
3. Correct answer and explanation: A. Answer A is correct. The Linux operating system offers support for an additional unique type of filesystem known as the loopback device. This allows the mounting of an ISO image, so you can view/edit the files before burning a CD or DVD.
Incorrect answers and explanations: B, C, and D. Answer B is incorrect because the Linux echo command will return feedback to the monitor. Answer C does not exist. Answer D is the network adaptor loopback address for testing network connectivity.
4. Correct answer and explanation: C. Answer C is correct; swapon is the Linux command used to designate a specific file or partition for swapping.
Incorrect answers and explanations: A, B, and D. Answer A is incorrect; /swap is a precreated swap partition created during the initial installation. Answer B is incorrect because it is an invalid Linux command. Answer D is incorrect; GRUB is the Linux bootloader program.
5. Correct answer and explanation: D. Answer D is correct; exportfs is the Linux command used to activate the access of shared NFS directories on the NFS server.
Incorrect answers and explanations: A, B, and C. Answer A is incorrect; GRUB is the Linux bootloader program. Answer B is incorrect; fdisk is the Linux command used to partition a storage device. Answer C is incorrect; swapon is the Linux command used to designate a specific file or partition for swapping.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.104.127