Pages

Sunday, December 13, 2015

Understanding File system in Linux OS

Home

Overview of the Directory Tree is as shown below,


Basic understanding of directories specified in above diagram can be achieved using information given below,

/ ---- Root (slash)

Every single file and directory starts from the root directory. Only root user has write privilege under this directory.
Please note that /root is root user’s home directory, which is not same as /.
The root filesystem should generally be small, since it contains very critical files and a small infrequently modified filesystem has a better chance of not getting corrupted. \
A corrupted root filesystem will generally mean that the system becomes unbootable except with special measures (e.g., from a floppy, live CD)

/bin ---- User Binaries

Contains binary executables.
Common linux commands you need to use in single-user modes are located under this directory.
Commands used by all the users of the system are located here i.e. Commands needed during bootup that might be used by normal users (probably after bootup).
For example: ps, ls, ping, grep, cp.

/sbin ---- System Binaries

Just like /bin, /sbin also contains binary executables.
But, the linux commands located under this directory are used typically by system aministrator, for system maintenance purpose.
For example: iptables, reboot, fdisk, ifconfig, swapon
 /sbin is not usually in the default path of normal users, but will be in root's default path.

/etc ---- Configuration Files

Contains configuration files required by all programs.
This also contains startup and shutdown shell scripts used to start/stop individual programs.
For example: /etc/resolv.conf, /etc/logrotate.conf
Some of them are described below

/etc/rc or /etc/rc.d or /etc/rc*.d

Scripts or directories of scripts to run at startup or when changing the run level

/etc/passwd

The user database, with fields giving the username, real name, home directory, and other information about each user present on OS

/etc/shadow

It is an encrypted file the holds user passwords.

/etc/fdprm

Floppy disk parameter table. Describes what different floppy disk formats look like. Used by setfdprm .

/etc/fstab

Lists the filesystems mounted automatically at startup by the mount -a command (in /etc/rc or equivalent startup file).
Also contains information about swap areas used automatically by swapon -a

/etc/group

The group database It describes groups instead of users

/etc/inittab

Configuration file for init process

/etc/issue

Contains a short description or welcoming message to the system.

/etc/magic

The configuration file for file. Contains the descriptions of various file formats based on which file guesses the type of the file.

/etc/motd

The message of the day often used for getting information to every user, such as warnings about planned downtimes

/etc/mtab

List of currently mounted filesystems.
Initially set up by the bootup scripts, and updated automatically by the mount command
Used when a list of mounted filesystems is needed, e.g., by the df command

/etc/login.defs

Configuration file for the login command.

/etc/printcap

This is intended for printers. However it uses different syntax.

/etc/profile, /etc/bash.rc, /etc/csh.cshrc

Files executed at login or startup time by the Bourne, BASH , or C shells
These allow the system administrator to set global defaults for all users
Users can also create individual copies of these in their home directory to personalize their environment

/etc/securetty

Identifies secure terminals, i.e., the terminals from which root is allowed to log in
Typically only the virtual consoles are listed, so that it becomes impossible (or at least harder) to gain superuser privileges by breaking into a system over a modem or a network.
Do not allow root logins over a network. Prefer to log in as an unprivileged user and use su or sudo to gain root privileges.

/etc/security/access.conf

A list of what users are allowed to login and from what host for example, using telnet.

/etc/security/limits.conf

This file contains various system limits, such as maximum number of processes. Yes, these are really related to security!

/etc/shells

Lists trusted shells. The chsh command allows users to change their login shell only to shells listed in this file.
The user's shell is is always checked whether its listed in /etc/shells or not during login of user through any protocol and will not let people log in unless the shell is listed there.

/etc/lilo

In some Linux distributions you will find the /etc/lilo directory, which is used for the Linux loader lilo. This directory contains a single file, install, which is a link to /sbin/lilo.
This file is used among other things to install the boot configuration options. On some systems, the lilo configuration file lilo.conf is found directly in the /etc directory

/etc/cron*

There several directories named /etc/cron*. As you might guess these are used by the cron daemon. The /etc/cron.d contains configuration files used by cron. Typically what is here are various system related cron jobs, such as /etc/cron.d/seccheck, which does various security checks.

/etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly

These directories contain files with cron jobs which run hourly, daily, weekly and monthly, respectively. There is a cron job listed in /etc/crontab that runs the program /usr/lib/cron/run-crons, which checks the other files.

/etc/init.d

The /etc/init.d directory contains scripts that the system uses when starting up or shutting down. Which files are read depends on whether the system is being started or shut down.
We’ll talk more about these directories and their associated files in the section on starting up and shutting down the system. You may also find that these files are located in /etc/rc.d.

/etc/skel

The /etc/skel directory is used when you create a new user with the adduser command. This is the "skeleton" of files that is copied to the user’s home directory when it’s created hence the name "skel". If you want to ensure that each user gets other files at startup, place them in here. For example, you may want everyone to have a configuration file for vi .exrc or for mail .mailrc.

/etc/sysconfig or /etc/rc.config.d

Depending on your Linux distribution, either the /etc/sysconfig or /etc/rc.config.d directory contains default system configuration information. For example, the keyboard file defines which keyboard table is to be used and the network file contains network parameters, such as the hostname.

/etc/pam.d

The /etc/pam.d directory contains configuration files used by the Pluggable Authentication Modules PAM. PAM is a system of libraries that are responsible for authentication tasks of applications and services on your system. These libraries provide an Application Programming Interface API allowing for a standardization of authorization functions. Previously, where necessary each program did its own authorization/authentication. With PAM, a single set of configuration files allows for a more consistent security policy. In some cases, a /etc/pam.conf file is used instead of the /etc/pam.d directory.

/etc/profile.d

The /etc/profile.d directory contains default configuration for many of the shells that Linux provides. As we talk about in the section on shells, each shell has an environment which contains a number of different characteristics. Many of the defaults are defined in the files under /etc/profile.d. The name of each file gives an indication of the appropriate shell.

/dev ---- Device Files

It contains the special device files for all the devices
The device files are created during installation, and later with the /dev/MAKEDEV script.
These include terminal devices, usb, or any device attached to the system.
Some of them are described below.

/dev/dsp

Digital Signal Processor interface between software which produces sound and your soundcard

/dev/fd0

The first floppy drive. If you are lucky enough to have several drives then they will be numbered sequentially.

/dev/fb0

The first framebuffer device which is an abstraction layer between software and graphics hardware
This means that applications do not need to know about what kind of hardware you have but merely how to communicate with the framebuffer driver's API (Application Programming Interface) which is well defined and standardized.
The framebuffer is a character device and is on major node 29 and minor 0.

/dev/hda, /dev/hdb

This is the master and slave IDE drive on the primary IDE controller.

/dev/hdc, /dev/hdd 

These are the master and slave devices on the secondary controller respectively.

/dev/ht0

The first IDE tape drive

/dev/js0

The first analogue joystick.

/dev/lp0

The first parallel printer device.

/dev/loop0

The first loopback device. Loopback devices are used for mounting filesystems which are not located on other block devices such as disks.

/dev/md0

First metadisk group. Metadisks are related to RAID (Redundant Array of Independent Disks) devices.

/dev/mixer

This is part of the OSS (Open Sound System) driver.

/dev/null

The bit bucket. A black hole where you can send data for it never to be seen again. Anything sent to /dev/null will disappear.

/dev/psaux

The PS/2 mouse port

/dev/pda

Parallel port IDE disks

/dev/pcd0

Parallel port CD ROM drives

/dev/pt0

Parallel port tape devices.

/dev/parport0

The raw parallel ports. Most devices which are attached to parallel ports have their own drivers.

/dev/random or /dev/urandom

These are kernel random number generators.

/dev/sda

The first SCSI drive on the first SCSI bus.

/dev/ttyS0

The first serial port. Many times this it the port used to connect an external modem to your system.

/dev/zero

This is a simple way of getting many 0s. Every time you read from this device it will return 0.

/proc ---- Process Information

Contains information about system process.
This filesystem contains an illusionary filesystem. It does not exist on a disk. Instead, the kernel creates it in memory. It is used to provide information about the system (originally about processes, hence the name). Some of the more important files and directories are explained below. The /proc filesystem is described in more detail in the proc manual page.
This is a pseudo filesystem contains information about running process. For example: /proc/{pid} directory contains information about the process with that particular pid.
This is a virtual filesystem with text information about system resources. For example: /proc/uptime

/proc/1 

A directory with information about process number 1. Each process has a directory below /proc with the name being its process identification number.

/proc/cpuinfo

Holds information about the processor, such as its type, make, model, and performance.

/proc/devices

Holds list of device drivers configured into the currently running kernel.

/proc/dma

Shows which DMA channels are being used at the moment.

/proc/filesystems

Filesystems configured into the kernel.

/proc/interrupts

Shows which interrupts are in use, and how many of each there have been.

/proc/ioports

Which I/O ports are in use at the moment?

/proc/kcore

An image of the physical memory of the system. This is exactly the same size as your physical memory, but does not really take up that much memory; it is generated on the fly as programs access it. (Remember: unless you copy it elsewhere, nothing under /proc takes up any disk space at all.)

/proc/kmsg

Messages output by the kernel. These are also routed to syslog.

/proc/ksyms

Symbol table for the kernel.

/proc/loadavg

The `load average' of the system; three meaningless indicators of how much work the system has to do at the moment.

/proc/meminfo

Information about memory usage, both physical and swap.

/proc/modules

Which kernel modules are loaded at the moment?

/proc/net

Status information about network protocols.

/proc/self

A symbolic link to the process directory of the program that is looking at /proc. When two processes look at /proc, they get different links. This is mainly a convenience to make it easier for programs to get at their process directory.

/proc/stat

Various statistics about the system, such as the number of page faults since the system was booted.

/proc/uptime

The time the system has been up.

/proc/version

The kernel version.

/var ---- Variable Files

var stands for variable files.
Content of the files that are expected to grow can be found under this directory.
This includes — system log files (/var/log); packages and database files (/var/lib); emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp);
It contains data that is changed when the system is running normally. It is specific for each system, i.e., not shared over the network with other computers.

/var/cache/man

A cache for man pages that are formatted on demand. The source for manual pages is usually stored in /usr/share/man/man?/ (where ? is the manual section. See the manual page for man in section 7); some manual pages might come with a pre-formatted version, which might be stored in

/var/games

Any variable data belonging to games in /usr should be placed here. This is in case /usr is mounted read only.

/var/lib

Files that change while the system is running normally.

/var/local

Variable data for programs that are installed in /usr/local (i.e., programs that have been installed by the system administrator). Note that even locally installed programs should use the other /var directories if they are appropriate, e.g., /var/lock.

/var/lock

Lock files. Many programs follow a convention to create a lock file in /var/lock to indicate that they are using a particular device or file. Other programs will notice the lock file and won't attempt to use the device or file.

/var/log

Log files from various programs, especially login (/var/log/wtmp, which logs all logins and logouts into the system) and syslog(/var/log/messages, where all kernel and system program message are usually stored). Files in /var/log can often grow indefinitely, and may require cleaning at regular intervals.

/var/mail

This is the FHS approved location for user mailbox files. Depending on how far your distribution has gone towards FHS compliance, these files may still be held in /var/spool/mail.

/var/run

Files that contain information about the system that is valid until the system is next booted. For example, /var/run/utmp contains information about people currently logged in.

/var/spool

Directories for news, printer queues, and other queued work. Each different spool has its own subdirectory below /var/spool, e.g., the news spool is in /var/spool/news . Note that some installations which are not fully compliant with the latest version of the FHS may have user mailboxes under /var/spool/mail.

/var/tmp

Temporary files that are large or that need to exist for a longer time than what is allowed for /tmp . (Although the system administrator might not allow very old files in /var/tmp either.)

/tmp ---- Temporary Files

Directory that contains temporary files created by system and users.
Files under this directory are deleted when system is rebooted.

/usr ---- User Programs

Contains binaries, libraries, documentation, and source-code for second level programs.

/usr/bin

Contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp

/usr/sbin

Contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel

/usr/lib

Contains libraries for /usr/bin and /usr/sbin

/usr/local

Contains users programs that you install from source. For example, when you install apache from source, it goes under

/usr/X11R6

The X Window System, all files. To simplify the development and installation of X

/usr/share/man 

Manual pages

/usr/share/info

GNU Info documents

/usr/share/doc

Miscellaneous other documentation files

/usr/include

Header files for the C programming language.

/usr/lib

Unchanging data files for programs and subsystems, including some site-wide configuration files The name lib comes from library; originally libraries of programming subroutines were stored in /usr/lib.

/home ---- Home Directories

Home directories for all users to store their personal files.
For example: /home/sandeep, /home/sachin

/boot ---- Boot Loader Files

Contains boot loader related files.
Kernel initrd, vmlinux, grub files are located under /boot
For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic

/lib ---- System Libraries

Contains library files that supports the binaries located under /bin and /sbin
Library filenames are either ld* or lib*.so.*
For example: ld-2.11.1.so, libncurses.so.5.7

/opt ---- Optional add-on Applications

opt stands for optional.
Contains add-on applications from individual vendors.
Add-on applications should be installed under either /opt/ or /opt/ sub-directory.

/mnt ---- Mount Directory

Temporary mount directory where sysadmins can mount filesystems.

/media ---- Removable Media Devices

Temporary mount directory for removable devices.
For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer

/srv ---- Service Data

srv stands for service.
Contains server specific services related data.
For example, /srv/cvs contains CVS related data.


Back To Top
Home

No comments:

Post a Comment