Skip to main content

An introduction to Linux filesystems

Linux File Systems.

https://libyphilip.files.wordpress.com/2015/06/linux-file-system-hierarchy-linux-file-structure-optimized1.jpg

A File system is a logical collection of files on a partition or disk.A partition is a container for information and can span an entire hard drive if desired.

Your hard drive can have various partitions usually contain only one file system, such as one file system housing the /file system or another containing the /home file system.

Everything in Unix is considered to be a file , including physical devices as DVD-ROMs, and USB drives.

File systems require an application Programming interface(API) that provides access to system function calls which manipulate file system objects like file directories. API provide for task such as creating, moving, and deleting files. It also algorithms that determine things like where a file on file system.

Modern File system provide a security model, which is a scheme fro defining access rights to files and directories.The linux file system security model helps to ensure that users only have access to their own files and not those of others or the operating system itself.


The final building block is the software requires to implement all  of these functions. Linux uses a two-part software implementation as away to improve both system and programmer efficiency.



The first part of this two-part implementation is the Linux virtual filesystem. This virtual filesystem provides a single set of commands for the kernel, and developers, to access all types of filesystems. The virtual filesystem software calls the specific device driver required to interface to the various types of filesystems. The filesystem-specific device drivers are the second part of the implementation. The device driver interprets the standard set of filesystem commands to ones specific to the type of filesystem on the partition or logical volume.

Directory Structure

In Linux and many other operating systems, directories can be structured in a tree-like hierarchy .The Linux directory structure is well defined and documented in the Linux Filesystem Hierarchy Standard (FHS).Accessin the directories is accomplished by using using the sequentially deeper directory names connected by forward slashes(/) I.E /var/www/html these are called paths.


/ (root filesystem)

The root filesystem is the top-level directory of the filesystem. It must contain all of the files required to boot the Linux system before other filesystems are mounted. It must include all of the required executables and libraries required to boot the remaining filesystems. After the system is booted, all other filesystems are mounted on standard, well-defined mount points as subdirectories of the root filesystem.


/bin

The /bin directory contains user executable files.

/boot

Contains the static bootloader and kernel executable and configuration files required to boot a Linux computer.

/dev

This directory contains the device files for every hardware device attached to the system. These are not device drivers, rather they are files that represent each device on the computer and facilitate access to those devices.


/etc

Contains the local system configuration files for the host computer.

/home

Home directory storage for user files. Each user has a subdirectory in /home.


/lib

Contains shared library files that are required to boot the system.

/media

A place to mount external removable media devices such as USB thumb drives that may be connected to the host.

/mnt

A temporary mountpoint for regular filesystems (as in not removable media) that can be used while the administrator is repairing or working on a filesystem.

/opt

Optional files such as vendor supplied application programs should be located here.

/root

This is not the root (/) filesystem. It is the home directory for the root user.

/sbin

System binary files. These are executables used for system administration.

/tmp

Temporary directory. Used by the operating system and many programs to store temporary files. Users may also store files here temporarily. Note that files stored here may be deleted at any time without prior notice.

/usr

These are shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation.

/var

Variable data files are stored here. This can include things like log files, MySQL, and other database files, web server data files, email inboxes, and much more.


The /media and /mnt directories are part of the root filesystem, but they should never contain any data. Rather, they are simply temporary mount points.


Linux unified directory structure

In some non-Linux PC operating systems, if there are multiple physical hard drives or multiple partitions, each disk or partition is assigned a drive letter. It is necessary to know on which hard drive a file or program is located, such as C: or D:. Then you issue the drive letter as a command, D:, for example, to change to the D: drive, and then you use the cd command to change to the correct directory to locate the desired file. Each hard drive has its own separate and complete directory tree.

The Linux filesystem unifies all physical hard drives and partitions into a single directory structure. It all starts at the top–the root (/) directory. All other directories and their subdirectories are located under the single Linux root directory. This means that there is only one single directory tree in which to search for files and programs.

This can work only because a filesystem, such as /home, /tmp, /var, /opt, or /usr can be created on separate physical hard drives, a different partition, or a different logical volume from the / (root) filesystem and then be mounted on a mountpoint (directory) as part of the root filesystem tree. Even removable drives such as a USB thumb drive or an external USB or ESATA hard drive will be mounted onto the root filesystem and become an integral part of that directory tree.

One good reason to do this is apparent during an upgrade from one version of a Linux distribution to another, or changing from one distribution to another. In general, and aside from any upgrade utilities like dnf-upgrade in Fedora, it is wise to occasionally reformat the hard drive(s) containing the operating system during an upgrade to positively remove any cruft that has accumulated over time. If /home is part of the root filesystem it will be reformatted as well and would then have to be restored from a backup. By having /home as a separate filesystem, it will be known to the installation program as a separate filesystem and formatting of it can be skipped. This can also apply to /var where database, email inboxes, website, and other variable user and system data are stored.

There are other reasons for maintaining certain parts of the Linux directory tree as separate filesystems. For example, a long time ago, when I was not yet aware of the potential issues surrounding having all of the required Linux directories as part of the / (root) filesystem, I managed to fill up my home directory with a large number of very big files. Since neither the /home directory nor the /tmp directory were separate filesystems but simply subdirectories of the root filesystem, the entire root filesystem filled up. There was no room left for the operating system to create temporary files or to expand existing data files. At first, the application programs started complaining that there was no room to save files, and then the OS itself started to act very strangely. Booting to single-user mode and clearing out the offending files in my home directory allowed me to get going again. I then reinstalled Linux using a pretty standard multi-filesystem setup and was able to prevent complete system crashes from occurring again.

I once had a situation where a Linux host continued to run, but prevented the user from logging in using the GUI desktop. I was able to log in using the command line interface (CLI) locally using one of the virtual consoles, and remotely using SSH. The problem was that the /tmp filesystem had filled up and some temporary files required by the GUI desktop could not be created at login time. Because the CLI login did not require files to be created in /tmp, the lack of space there did not prevent me from logging in using the CLI. In this case, the /tmp directory was a separate filesystem and there was plenty of space available in the volume group the /tmp logical volume was a part of. I simply expanded the /tmp logical volume to a size that accommodated my fresh understanding of the amount of temporary file space needed on that host and the problem was solved. Note that this solution did not require a reboot, and as soon as the /tmp filesystem was enlarged the user was able to login to the desktop.

Another situation occurred while I was working as a lab administrator at one large technology company. One of our developers had installed an application in the wrong location (/var). The application was crashing because the /var filesystem was full and the log files, which are stored in /var/log on that filesystem, could not be appended with new messages due to the lack of space. However, the system remained up and running because the critical / (root) and /tmp filesystems did not fill up. Removing the offending application and reinstalling it in the /opt filesystem resolved that problem.



Filesystem types

Linux supports reading around 100 partition types; it can create and write to only a few of these. But it is possible—and very common—to mount filesystems of different types on the same root filesystem. In this context we are talking about filesystems in terms of the structures and metadata required to store and manage the user data on a partition of a hard drive or a logical volume. The complete list of filesystem partition types recognized by the Linux fdisk command is provided here, so that you can get a feel for the high degree of compatibility that Linux has with very many types of systems.


The main purpose in supporting the ability to read so many partition types is to allow for compatibility and at least some interoperability with other computer systems' filesystems. The choices available when creating a new filesystem with Fedora are shown in the following list.

  • btrfs
  • cramfs
  • ext2
  • ext3
  • ext4
  • fat
  • gfs2
  • hfsplus
  • minix
  • msdos
  • ntfs
  • reiserfs
  • vfat
  • xfs

Other distributions support creating different filesystem types. For example, CentOS 6 supports creating only those filesystems highlighted in bold in the above list.

Mounting

The term "to mount" a filesystem in Linux refers back to the early days of computing when a tape or removable disk pack would need to be physically mounted on an appropriate drive device. After being physically placed on the drive, the filesystem on the disk pack would be logically mounted by the operating system to make the contents available for access by the OS, application programs and users.

A mount point is simply a directory, like any other, that is created as part of the root filesystem. So, for example, the home filesystem is mounted on the directory /home. Filesystems can be mounted at mount points on other non-root filesystems but this is less common.

The Linux root filesystem is mounted on the root directory (/) very early in the boot sequence. Other filesystems are mounted later, by the Linux startup programs, either rc under SystemV or by systemd in newer Linux releases. Mounting of filesystems during the startup process is managed by the /etc/fstab configuration file. An easy way to remember that is that fstab stands for "file system table," and it is a list of filesystems that are to be mounted, their designated mount points, and any options that might be needed for specific filesystems.

Filesystems are mounted on an existing directory/mount point using the mount command. In general, any directory that is used as a mount point should be empty and not have any other files contained in it. Linux will not prevent users from mounting one filesystem over one that is already there or on a directory that contains files. If you mount a filesystem on an existing directory or filesystem, the original contents will be hidden and only the content of the newly mounted filesystem will be visible.

Comments

Post a Comment

Popular posts from this blog

TTY in linux and how to use it

Ok, how about we start with what is TTY.It stands for “teletypewriter.” What can tty tell us. In Linux, there is a pseudo-teletype multiplexor which handles the connections from all of the terminal window pseudo-teletypes (PTS). The multiplexor is the master, and the PTS are the "slaves". The multiplexor is addressed by the kernel through the device file located at /dev/ptmx. The tty command will print the name of the device file that your pseudo-teletype slave is using to interface to the master. And that, effectively, is the number of your terminal window. The output shows that we are connected to to the device file at /dev/pts/4. Our terminal window, which is a software emulation of a teletype (TTY), is interfaced to the pseudo-teletype multiplexor as a pseudo-teletype (PTS). And it happens to be number four.For the number at the end shows that. The Silent Option . The -s (silent) option causes tty to generate no output. This is how it will look on your terminal It do...

Virtualization Technology

    Virtualization is the process of running a virtual instance of a computer system in an abstract layer of the physical hardware.     It ensures efficient utilization of physical computer hardware and is the foundation of cloud computing.     Virtualization uses a software to create an abstraction layer over computer hardware that allows the hardware  elements of a single computer  such as processor, memory , storage and more to be divided into multiple virtual computers , commonly called virtual machines(VMs)     Each VM  runs its own operating system and behaves like an independent computer, even though it is running on just a portion of the actual underlying hardware.     This is the technology that drives the cloud computing economics. This enables cloud providers to serve users with their existing physical computer hardware; it enables cloud users to purchase only the computer in resources they need when ...

What are browser cookies and how they work

INTRODUCTION. Most internet users are familiar with the term Cookie because we see it pop up in most websites but do we know the purpose it serves. Let us start with what it is ,   a cookie (  also known as browser cookie , internet cookie , web cookie or HTTP cookie ) is small piece of data that websites store on your disk in the form of a text file.Cookies allow websites to store specific information helpful to remember each visitor uniquely. What do browser cookies do. The purpose of the computer cookie is to help the website track of your visits and activity and is not a bad thing.A good example are the online retailers to keep track of the items in user's shopping cart as they explore the site, without the cookies the shopping cart would reset to zero with every click. A website also uses the cookies to store information about you recent visits or record you login information which i do not really recommend from a security perspective Types of browser cookies. Session co...