Introduction to Linux. Lesson 6 . File Systems. Part 2.
0
The fsck tool (short for File System Check) is used to diagnose and repair file systems that may have become damaged in the course of daily operations. Such repairs might be necessary after a system crash in which the system did not get a chance to fully flush all of its internal buffers to disk. Usually, the system runs the fsck tool automatically during the boot process as it deems necessary (much in the same way Windows runs ScanDisk). If it detects a file system that was not cleanly unmounted, it runs the utility. A file system check will also be run once the system detects that a check has not been performed after a predetermined threshold (e.g., number of mounts or time passed between mounts). Linux makes an impressive effort to automatically repair any problems it runs across and, in most instances, does take care of itself. At this point, you need to run fsck by hand and answer its prompts yourself. If you do find that a file system is not behaving as it should (log messages are an excellent hint of this type of anomaly), you may want to run fsck yourself on a running system. The only downside is that the file system in question must be unmounted in order for this to work. If you choose to take this path, be sure to remount the file system when you are done. The name fsck isn’t the actual title for the ext3 repair tool; it’s actually just a wrapper. The fsck wrapper tries to determine what kind of file system needs to be repaired and then runs the appropriate repair tool, passing any parameters that were passed to fsck. In ext2, the real tool is called fsck.ext2. For the ext3 file system, the real tool is fsck.ext3; for the VFAT file system, the tool is fsck.vfat; and for a ReiserFS file system, the utility is called fsck.reiserfs. For example, when a system crash occurs on an ext2-formatted partition, you may need to call fsck.ext2 directly rather than relying on other applications to call it for you automatically. For example, to run fsck on the /dev/mapper/VolGroup00-LogVol02 file system mounted at the /home directory, you will run the following commands. First, to unmount the file system, type [root@fedora-serverA ~]# umount /home NOTE The preceding step assumes that the /home file system is not currently being used or accessed by any process. Since we know that this particular file system is ext3, we can call the correct utility (fsck.ext3) directly or simply use the fsck utility. Type [root@fedora-serverA ~]# fsck /dev/mapper/VolGroup00-LogVol02 fsck 1.40.8 (12-Jul-2017) e2fsck 1.40.8 (12-Jul-2017) /dev/mapper/VolGroup00-LogVol02: clean, 11/655360 files, 37896/655360 blocks The preceding output shows that the file system is marked clean. To forcefully check the file system and answer yes to all questions in spite of what your operating system (OS) thinks, type [root@fedora-serverA ~]# fsck.ext3 -f -y /dev/mapper/VolGroup00-LogVol02 What If I Still Get Errors? First, relax. The fsck check rarely finds problems that it cannot correct by itself. When it does ask for human intervention, telling fsck to execute its default suggestion is often enough. Very rarely does a single pass of e2fsck not clear up all problems. On the rare occasions when a second run is needed, it should not turn up any more errors. If it does, you are most likely facing a hardware failure. Remember to start with the obvious: Check for reliable power and well-connected cables. Anyone running SCSI systems should verify that they’re using the correct type of terminator, that cables aren’t too long, that SCSI IDs aren’t conflicting, and that cable quality is adequate. (SCSI is especially fussy about the quality of the cables.)
Another rare situation is when fsck finds file segments that it cannot rejoin with the original file. In those cases, it will place the fragment in the partition’s lost+found directory. This directory is located where the partition is mounted, so if /dev/mapper/ VolGroup00-LogVol02 is mounted on /home, for example, then /home/lost+found correlates to the lost+found directory for that particular file system. Anything can go into a lost+found directory—file fragments, directories, and even special files. When normal files wind up there, a file owner should be attached, and you can contact the owner and see if they need the data (typically, they won’t). If you encounter a directory in lost+found, you’ll most likely want to try to restore it from the most recent backups rather than trying to reconstruct it from lost+found. At the very least, lost+found tells you if anything became dislocated. Again, such errors are extraordinarily rare.
The process of adding a disk under Linux on the Intel (x 86) platform is relatively easy. Assuming you are adding a disk that is of similar type to your existing disks (for example, adding an IDE disk to a system that already has IDE drives or adding a SCSI disk to a system that already has SCSI drives), the system should automatically detect the new disk at boot time. All that is left is partitioning it and creating a file system on it. If you are adding a new type of disk (like a SCSI disk on a system that only has IDE drives), you may need to ensure that your kernel supports the new hardware. This support can either be built directly into the kernel or be available as a loadable module (driver). Note that the kernels of most Linux distributions come with support for many popular SCSI controllers, but you will occasionally come across troublesome kernel and hardware combinations, especially with the new motherboards that have exotic chipsets. Once the disk is in place, simply boot the system, and you’re ready to go. If you aren’t sure about whether the system can see the new disk, run the dmesg command and see whether the driver loaded and was able to find your disk. For example, [root@fedora-serverA ~]# dmesg | egrep -i "hd|sd|disk"
For the sake of clarity, and in case you need to know what a partition is and how it works, let’s do a brief review of this subject. Every disk must be partitioned. Partitions divide the disk into segments, and each segment acts as a complete disk by itself. Once a partition is filled, it cannot automatically overflow onto another partition. Various things can be done with a partitioned disk, such as installing an OS into a single partition that spans the entire disk, installing several different operating systems into their own separate partitions in what is commonly called a “dual-boot” configuration, and using the different partitions to separate and restrict certain system functions into their own work areas. This last reason is especially relevant on a multiuser system, where the content of users’ home directories should not be allowed to overgrow and disrupt important OS functions. Traditional Disk- and Partition-Naming Conventions Under Linux, each disk is given its own device name. The device files are stored under the /dev directory. IDE disks start with the name hdX, where X can range from a through z, with each letter representing a physical device. For example, in an IDE-only system with one hard disk and one CD-ROM, both on the same IDE chain, the hard disk would be /dev/hda and the CD-ROM would be /dev/hdb. Some standard devices are automatically created during system installation, and others are created as they are connected to the system. SCSI disks follow the same basic scheme as IDE, except that instead of starting with hd, they start with sd. Therefore, the first partition on the first SCSI disk would be /dev/ sda1, the second partition on the third SCSI disk would be /dev/sdc2, and so on. NOTE Most newer Linux distributions have replaced the old IDE subsystem with libata. The implication of this is that drive device names that previously started with /dev/hdX are now named /dev/sdX instead. The information provided previously is for legacy systems. When partitions are created, new devices are used. They take the form of /dev/ sdXY, where X is the device letter (as described in the preceding paragraph) and Y is the partition number. Thus, the first partition on the /dev/sda disk is /dev/sda1, the second partition would be /dev/sda2, and so on.
You may have noticed earlier that we use the terms partition and volume interchangeably in parts of the text. While they are not exactly the same things, the concepts carry over. Volume management is a new approach to dealing with disks and partitions. Instead of viewing a disk or storage entity along partition boundaries, the boundaries are no longer there and everything is now seen as volumes. That made perfect sense, didn’t it? Don’t worry if it didn’t; this is a tricky concept. Let’s try this again with more detail. This new approach to dealing with partitions is called Logical Volume Management (LVM) in Linux. It lends itself to several benefits and removes the restrictions, constraints, and limitations that the concept of partitions imposes. Some of the benefits are ▼ Greater flexibility for disk partitioning ■ Easy online resizing of volumes ■ Easy increases in storage space by simply adding new disks to the storage pool ▲ Use of snapshots Following are some important volume management terms. ▼ Physical Volume (PV) This typically refers to the physical hard disk(s) or other physical storage entity, such as a hardware Redundant Array of Inexpensive Disks (RAID) array or software RAID device(s). There can be only a single storage entity (e.g., one partition) in a PV. ■ Volume Group (VG) Volume groups are used to house one or more physical volumes and logical volumes into a single administrative unit. A volume group is created out of physical volumes. VGs are simply a collection of PVs; however, VGs are not mountable. They are more like virtual raw disks. ■ Logical Volume (LV) This perhaps is the trickiest LVM concept to grasp, because logical volumes (LVs) are the equivalent of disk partitions in a non- LVM world. The LV appears as a standard block device. It is on the LV that we put file systems. It is the LV that gets mounted. It is the LV that gets fsck-ed if necessary. LVs are created out of the space available in VGs. To the administrator, an LV appears as one contiguous partition independent of the actual PVs that make it up. ▲ Extents There are two kinds of extents: physical extents and logical extents. Physical volumes (PVs) are said to be divided into chunks, or units of data, called “physical extents.” And logical volumes (LVs) are said to be divided into chunks, or units of data, called “logical extents.” Creating Partitions and Logical Volumes During the installation process, you probably used a “pretty” tool with a nice graphical user interface (GUI) front-end to create partitions. The GUI tools available across the various Linux distributions vary greatly in looks and usability. One tool that can be used to perform most partitioning tasks, and that has a unified look and feel, regardless of the Linux flavor, is the venerable fdisk utility. Though it’s small and somewhat awkward, it’s a reliable partitioning tool. Furthermore, in the event you need to troubleshoot a system that has gone really wrong, you should be familiar with basic tools such as fdisk. Other powerful command-line utilities for managing partitions are sfdisk, cfdisk, and the much newer parted utility: parted is much more user-friendly and has a lot more built-in functionalities than the other tools have. In fact, a lot of the GUI partitioning tools call the parted program in their back-end. During the installation of the OS as covered in Chapter 2, you were asked to leave some free unpartitioned space. We will now use that free space to demonstrate some LVM concepts by walking through the steps required to create a logical volume. In particular, we will create a logical volume that will house the contents of our current /var directory. Because a separate “/var” volume was not created during the OS installation, the contents of the /var directory are currently stored under the volume that holds the root (“/”) tree. The general idea is that because the /var directory is typically used to hold frequently changing and growing data (such as log files), it is prudent to put its content on its own separate file system. The steps involved with creating a logical volume can be summarized this way:
Used for creating a new logical volume in a volume group by allocating logical extents from the free physical extent pool of that volume group.
Displays the attributes of a logical volume, such as read/write status, size, and snapshot information.
Initializes a physical volume for use with the LVM system.
Displays the attributes of physical volumes, such as size and PE size.
Used for creating new volume groups from block devices created using the pvcreate command.
Used for adding one or more physical volumes to an existing volume group to extend its size.
Displays the attributes of volume groups.
We will be using the free unpartitioned space on the main system disk, /dev/sda.
No tags have been pushed to this repository yet.