Introduction To Mounting Filesystems In Linux
Introduction to Linux filesystems and files. Depending on /etc/fstab or mount command options, Linux may run fsck on the filesystem when its dirty bit is set. I n this article we are going to learn How to mount and unmount Linux file system. In Linux operating system after create a fresh partition we have to.
In This Chapter. Finding, Checking, and Mounting Filesystems. Introduction to Journaling Filesystems. Advantages of Journaling Filesystems. Chapter 1, 'Introduction.
In This Chapter. Finding, Checking, and Mounting Filesystems. Introduction to Journaling Filesystems. Advantages of Journaling Filesystems Chapter 1, 'Introduction to Filesystems,' introduced 'journaling filesystem' as the general term for a specific type of local filesystem that helps reduce system restart times. They do this by reducing the amount of information that a system has to examine to verify the integrity of a filesystem. This chapter begins by providing a detailed overview of how Linux identifies filesystems, verifies that they are usable, and makes them available to users. This discussion builds on the basics of standard Linux/Unix filesystem organization explained in Chapter 1.
Understanding how Linux makes filesystems available to users and what's involved in verifying the structure of a 'standard' Linux filesystem (ext2fs) provides a firm foundation for discussing journaling filesystems. The remainder of the chapter explains the differences between journaling and non-journaling local filesystems, shows how journaling filesystems track filesystem changes, and highlights the major reasons why these types of filesystems are becoming more common on today's computer systems. Finding, Checking, and Mounting Filesystems To explain many of the performance and design advantages of different types of filesystems, it's useful to first understand how a Linux system identifies the filesystems available to it; determines their types; and mounts, supports, and uses them.
This section provides a general overview of these topics, which are relevant to any type of filesystem regardless of whether they are local or available over a network. Filesystem Consistency As discussed in Chapter 1, filesystems are the mechanism for successfully storing and retrieving data on a computer system. The data structures that define the organization of a filesystem must be correct when a filesystem is being used. To users, filesystems are hierarchical collections of files and directories. To Linux and other Unix systems, filesystems consist of many inodes that contain information about files and directories (known as filesystem metadata, data about data) and the data blocks that actually contain the directory entries and file data. It's easy to see the confusion that could arise if multiple inodes in a filesystem thought that some specific data block was a part of the file that they represented. Suppose that you were editing a status report for your manager and I was working on a file containing my collection of ribald drinking songs.
If the inode that identified the blocks in your presentation and the one that pointed to the blocks in my drinking song archive each claimed that a specific data block belonged to its file, one of us is going to be surprised when we actually look at our file. Filesystems whose internal data structures are correct are referred to as being consistent. It is always the responsibility of the system that hosts a filesystem (that is, on which the filesystem is physically stored) to verify the consistency of that filesystem before making it available to the operating system and to users. This is true regardless of whether the filesystem is a standard local filesystem, a journaling filesystem, or a networked filesystem.
In the case of networked filesystems, the server that exports the networked filesystem and manages the physical media on which it is stored must verify its consistency before making it available over the network. The primary characteristics of consistent filesystems are the following:. A bit in the filesystem's superblock is set to indicate that the filesystem was successfully unmounted when the system was last shut down. All the filesystem metadata is correct. Verifying the consistency of a filesystem would be fast if those two points could be verified quickly. Unfortunately, verifying that filesystem metadata is correct actually involves checking a number of different points:. Each allocation unit (whether it is a block or an extent) belongs only to a single file or directory, or is marked as being unused.
The list of which blocks are allocated and unused (free) in a filesystem is usually stored in a bitmap for that filesystem, where each bit represents a specific data block. Filesystems that allocate and manage extents rather than just blocks also maintain information about free extents and their size and range. No file or directory contains a data block marked as being unused in the filesystem bitmap. Each file or directory in the filesystem is referenced in some other directory in that filesystem. From a user's point of view, this means that there is a directory path to each file or directory in the filesystem.
Each file has only as many parent directories as the reference count in its inode indicates. Although each file exists only in a single physical location on the disk, multiple directories can contain references to the inode that holds information about this file. These references are known as hard links. The file can therefore be accessed through any of these directories, and deleting it from any of these directories decrements the link count. A file is actually deleted only when its link count is 0in other words, when it is no longer referenced by any directory. Verifying all these relationships may take a while if it's necessary to manually check each of them. Whether this consistency check is necessary is the fundamental difference between journaling and non-journaling filesystems.
Locating and Identifying Filesystems When your system boots, the boot block on your primary disk identifies the root filesystem and the location of the kernel to boot. As discussed in the previous section, when your system boots, it needs to verify the consistency of each of its local filesystems. The root filesystem initially is mounted read-only for standard processes so that its consistency can be verified. After this is done, it is remounted in read-write mode, and your system verifies the existence and consistency of any other filesystems that it will be using. The list of filesystems available to your system is contained in the file /etc/fstab. Each line in /etc/fstab provides information about one of the filesystems that should be available to your system.
Note Several fairly fundamental types of filesystems, such as iso9660 (CD-ROM) filesystems aren't listed. It would be highly unlikely that I wouldn't want support for CD-ROM filesystems, but because I use CDs with filesystems on them infrequently, I specified that they be supported as a loadable module when I configured and built the kernel for this system. This helps keep the kernel as small as possible without sacrificing performance. Devices supported through loadable modules work slightly slower than devices directly supported in the kernel, largely because of the overhead of locating, loading, and placing external calls to the module. The fourth field contains a comma-separated list of any options to the mount command that should be used when the filesystem is mounted. Many mount options are filesystem-specific, but some common generic ones are the following:.
asyncWrites to the filesystem should be done asynchronously. autoThe filesystem should be automatically mounted when detected or when a command such as mount -a is executed. defaultsUse the default options: async, auto, dev, exec, nouser, rw, suid. devThe character or block device containing the filesystem is local to the system.
execYou can execute programs, scripts, or anything else whose permissions indicate that it is executable from that filesystem. gid=valueSet the group ID of the mounted filesystem to the specified numeric group ID when the filesystem is mounted. noautoDon't automatically mount when a filesystem is detected or when the command mount -a is issued. Usually used with removable media such as floppies and CD-ROMs.
nouserYou must be root to mount the filesystem; the filesystem can't be mounted by any nonroot user. ownerThe ownership of the filesystem is set to the user who mounted itusually root if the filesystem is automatically mounted by the system. roMount the filesystem read-only. rwMount the filesystem read-write. suidAllow programs on the filesystem to change the user's user or group ID when it is executed if the user's permission bits indicate that they should do this.
Francis poulenc flute sonata pdf. Be careful when using this option with imported filesystems that you don't actually administer, because running a program that sets the UID to root is a common way of hacking into a system. uid=valueSet the user ID of the mounted filesystem to the specified numeric user ID when the filesystem is mounted.
For more information on generic options available to the mount command, see the man page for the mount command in section 8 of the online Linux manual. When discussing each of the filesystems covered in this book, I'll also explain any filesystem-specific mount options associated with that filesystem. Note Like the fsck command discussed in the next section, the mount command executes filesystem-specific versions of mount whenever necessary. For example, when filesystems of types smb, smbfs, ncp, or ncpfs are mounted (which use filesystem adapters to access DOS Server Message Block and NetWare Core Protocol filesystems), the mount command attempts to execute files in /sbin with the names /sbin/mount.smb, /sbin/mount.smbfs, /sbin/mount.ncp, and /sbin/mount.ncpfs, respectively. The fifth field is used by the dump command, a standard Linux/Unix filesystem backup command, to identify filesystems that should be backed up when the dump command is executed. If the fifth field contains a 0 (or is missing), the dump command assumes that the filesystem associated with that /etc/fstab entry does not need to be backed up. The sixth field is used by the Linux/Unix filesystem consistency checker (discussed in the next section) to identify filesystems whose consistency should be verified when the system is rebooted, and the order in which the consistency of those filesystems should be checked.
If the sixth field contains a 0 (or is missing), the fsck program assumes that the filesystem associated with that /etc/fstab entry does not need to be checked. Verifying Filesystem Consistency Verifying that a standard filesystem is consistent requires a special utility that checks each filesystem to guarantee that all the items listed in the previous section are true. This is known as the fsck (filesystem consistency check) utility. (Truly ancient Unix folks like myself will fondly remember its conceptual parents, dcheck, icheck, and ncheck.) Each type of filesystem has its own version of fsck that understands the organization of a specific type of filesystem. On Linux systems, all these versions of fsck live in the directory /sbin, and typically have names of the form fsck.filesystem-type. Note When administering a Linux system, you may occasionally see the df command report that 100 percent of a filesystem is in use even though you can still read and write files on that filesystem. This is due to the fact that most filesystems reserve a certain amount of space for use during crises such as when a filesystem fills up.
Otherwise, any user who was editing a file when someone else accidentally filled up the filesystem could easily lose his work. The amount of space reserved for such unhappy occasions is set by the command used to create the filesystem. For example, ext2 filesystems reserve 5 percent of the space on an ext2 filesystem when it is created. (You can change this percentage using the mke2fs program's -m option.) For information about the amount of space reserved by other types of filesystems, see the man page for the application used to create filesystems of that type. The following is sample output from running the df command on one of my systems: wvh@journal wvh$ df Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda5 1237 21% / /dev/hda1 47250 9% /boot /dev/hdc1 510 5087100 1% /reisertest /dev/hdc2 5115336 1 1% /xfstest /dev/test/vol1 310 3112788 2% /lvmreisertest /dev/test/vol2 5238080 1 1% /lvmxfstest When used on other types of Unix systems, the df command may report filesystem sizes in terms of different-sized blocks. For this reason, it's a good idea to get into the habit of executing the df command on any Unix system as 'df -k', which forces the output to be given in terms of 1K blocks (even though this is the default on Linux systems).
You don't want to find yourself accidentally miscalculating the amount of space remaining on a filesystem just because the df command for that version of Unix uses a different default block size. Some other options often used with the df command are shown in Table 3.1. Table 3.1 Options used with the df command df Option Meaning h Displays size information in human-readable form, such as 1.2G, 53M, 348K, and so on I Displays size and usage information in terms of inodes rather than data blocks l Limits the df command to only displaying information about local filesystems m Displays size information in megabytes These are my favorite df options or the ones that I've seen people using with some frequency. For complete information about all the options available to the df command, see the online manual page.
You can follow the df command and its options with the mountpoint of a specific filesystem if you want information only about that filesystem. You also can provide the name of the device on which a specific filesystem is located to get information about that filesystem regardless of whether it is mounted. Using the du command The df command is primarily used by system administrators to verify that the amount of space remaining on various partitions is sufficient for the needs of their users. Both users and system administrators often use the related du (disk usage) command to find out the amount of space used by specific files and directories. Although you can obtain this information about files by simply using ls, the du command provides some convenient options for summarizing the disk usage associated with all the files and subdirectories of a specific directory. These options make it easy to identify users (or system directories) using an inappropriately large amount of disk space. You can largely eliminate the ability of users to use more disk space than they 'should' by using quotas on the filesystems where users can create files and directories, but that's another topic that I will discuss later in this section.
Popular options for the du command are shown in Table 3.2. Table 3.2 Options used with the du command du Option Meaning c Lists the disk usage of the specified files and directories and then displays a total of those values. H Displays size in human-readable form such as 1.2G, 53M, 348K, and so on. K Displays size information in terms of 1K blocks. L Counts the size of each hard link to another file. For example, if a certain directory contains six hard links to a specific file, using the -l option counts the size of the file each time a link is encountered and adds that to the total disk space associated with a directory. By default, multiple hard links to a file are ignored in a disk usage summary, and the size of that file is only added to the disk usage total once.
L Follows symbolic links when calculating sizes. By default, the size of a symbolic link is the size of the link itself, which is essentially the length of the name of the file or directory to which the link points. S Does not include the size of subdirectories. This option is useful to determine the amount of disk space consumed by all the files in the current directory only. S Only prints a summary of the disk usage for files and directories specified as arguments to the du command. By defaultwith no argumentsthe du -s command summarizes disk usage in the current directory.
For a complete list of all the options available for use with the du command (including some truly arcane ones!), see the online manual page.
Contents. Introduction to File systems File systems are one of the things any newcomer to linux must become acquainted with. In the world of Microsoft you never really have to worry about it, the default being NTFS. Linux however, being built on a world of open source and differing opinions, is not limited in this way and so the user should have an understanding of what a file system is, and how it affects the computer. At the core of a computer, it's all 1s and 0s, but the organization of that data is not quite as simple. A bit is a 1 or a 0, a byte is composed of 8 bits, a kibibyte is 1024 (i.e. 2^10) bytes, a mebibyte is 1024 kibibytes and so on and so forth.
Linux Mounting Drives
All these bits and bytes are permanently stored on a Hard Drive. A hard drive stores all your data, any time you save a file, you're writing thousands of 1s and 0s to a metallic disc, changing the magnetic properties that can later be read as 1 or 0.
There is so much data on a hard drive that there has to be some way to organize it, like a library of books and the old card drawers that indexed all of them, without that index, we'd be lost. Libraries, for the most part, use the Dewey Decimal System to organize their books, but there exist other systems to do so, none of which have attained the same fame as Mr.
Dewey's invention. File systems are the same way. The ones most users are aware of are the ones Windows uses, the vFat or the NTFS systems, these are the Windows default file systems. There are several different attributes which are necessary in defining file systems, these include their max file size, max partition size, whether they journal or not. Journaling A journaling file system is more reliable when it comes to data storage. Journaling file systems do not necessarily prevent corruption, but they do prevent inconsistency and are much faster at file system checks than non-journaled file systems.
If a power failure happens while you are saving a file, the save will not complete and you end up with corrupted data and an inconsistent file system. Instead of actually writing directly to the part of the disk where the file is stored, a journaling file system first writes it to another part of the hard drive and notes the necessary changes to a log, then in the background it goes through each entry to the journal and begins to complete the task, and when the task is complete, it checks it off on the list. Thus the file system is always in a consistent state (the file got saved, the journal reports it as not completely saved, or the journal is inconsistent (but can be rebuilt from the file system)).
Some journaling file systems can prevent corruption as well by writing data twice. Table Now below is a very brief comparison of the most common file systems in use with the Linux world. File System Max File Size Max Partition Size Journaling Notes Fat16 2 GiB 2 GiB No Legacy Fat32 4 GiB 8 TiB No Legacy NTFS 2 TiB 256 TiB Yes (For Windows Compatibility) NTFS-3g is installed by default in Ubuntu, allowing Read/Write support ext2 2 TiB 32 TiB No Legacy ext3 2 TiB 32 TiB Yes Standard linux filesystem for many years. Best choice for super-standard installation.
Ext4 16 TiB 1 EiB Yes Modern iteration of ext3. Best choice for new installations where super-standard isn't necessary. ReiserFS 8 TiB 16 TiB Yes No longer well-maintained.
JFS 4PiB 32PiB Yes (metadata) Created by IBM - Not well maintained. XFS 8 EiB 8 EiB Yes (metadata) Created by SGI.
Best choice for a mix of stability and advanced journaling. GiB = Gibibyte (1024 MiB):: TiB = Tebibyte (1024 GiB):: PiB = Pebibyte (1024 TiB):: EiB = Exbibyte (1024 PiB) Above you'll see a brief comparison of two main attributes of different filesystems, the max file size and the largest a partition of that data can be.
Of the above file systems the only one you cannot install Linux on is the NTFS. It is not recommended to install Linux on any type of FAT file system, because FAT does not have any of the permissions of a true Unix FS. Editing Files Those used to a Windows file system (NTFS, FAT) know that it isn't normally possible to change files while they are open. This restriction does not exist in a Unix file system. This is because in Unix file systems, files are indexed by a number, called the inode, and each inode has several attributes associated with it, like permissions, name, etc.
When you delete a file, what really happens is the inode is unlinked from the filename, but if some other program is using the file, it still has a link open to the OS, and will continue to be updated. A file is not really deleted until all links have been removed (even then, the data is still on the disk, but not indexed in anyway and thus very hard to recover). All of this means that you can delete executing programs while they're running without crashing and move files before they're finished downloading without corruption. Fragmentation Another common Windows practice that is not needed in Unix is defragmenting the hard drive. When NTFS and FAT write files to the hard drive, they don't always keep pieces (known as blocks) of files together. Therefore, to maintain the performance of the computer, the hard drive needs to be 'defragged' every once in a while. This is unnecessary on Unix File systems due to the way it was designed.
When ext3 was developed, it was coded so that it would keep blocks of files together or at least near each other. No true defragmenting tools exist for the ext3 file system, but tools for defragmenting will be included with the ext4 file system. See Also - A guide for converting existing EXT3 filesystems to EXT4. Other Resources. Different File Systems on the same disk If you are migrating from Windows and have more than one ntfs partition on the same disk, you might be tempted to convert one of the partitions to ext3 or 4 and install there the Linux files while leaving the ntfs partition as /home. It's ok to have two partitions on for Linux system files and another for home files in the same disk but they should be both the same filesystem.