0% found this document useful (0 votes)
11 views

Unit 1 Linux

The document provides an overview of the Linux operating system, including its history, architecture, distributions, advantages, and disadvantages. It details the components of a Linux system, the differences between kernel mode and user mode, and various shell types. Additionally, it covers file management in Linux, including file types, listing files, and the directory structure.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Unit 1 Linux

The document provides an overview of the Linux operating system, including its history, architecture, distributions, advantages, and disadvantages. It details the components of a Linux system, the differences between kernel mode and user mode, and various shell types. Additionally, it covers file management in Linux, including file types, listing files, and the directory structure.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

BCA V SEMESTER

PAPER CODE CSA-CC-512


PAPER NAME LINEX PROGRAMMING

UNIT 1

Introduction to Linux Operating System


Linux is a community of open-source Unix like operating systems that are based on
the Linux Kernel. It was initially released by Linus Torvalds on September 17, 1991.
It is a free and open-source operating system and the source code can be modified
and distributed to anyone commercially or noncommercially under the GNU General
Public License.
Initially, Linux was created for personal computers and gradually it was used in other
machines like servers, mainframe computers, supercomputers, etc. Nowadays,
Linux is also used in embedded systems like routers, automation controls,
televisions, digital video recorders, video game consoles, smartwatches, etc. The
biggest success of Linux is Android(operating system) it is based on the Linux kernel
that is running on smartphones and tablets. Due to android Linux has the largest
installed base of all general-purpose operating systems. Linux is generally packaged
in a Linux distribution.

Linux Distribution

Linux distribution is an operating system that is made up of a collection of software


based on Linux kernel or you can say distribution contains the Linux kernel and
supporting libraries and software. And you can get Linux based operating system by
downloading one of the Linux distributions and these distributions are available for
different types of devices like embedded devices, personal computers, etc.
Around 600 + Linux Distributions are available and some of the popular Linux
distributions are:
 MX Linux
 Manjaro
 Linux Mint
 elementary
 Ubuntu
 Debian
 Solus
 Fedora
 openSUSE
 Deepin

Architecture of Linux

Linux architecture has the following components:

1. Kernel: Kernel is the core of the Linux based operating system. It virtualizes the
common hardware resources of the computer to provide each process with its
virtual resources. This makes the process seem as if it is the sole process
running on the machine. The kernel is also responsible for preventing and
mitigating conflicts between different processes. Different types of the kernel
are:
 Monolithic Kernel
 Hybrid kernels
 Exo kernels
 Micro kernels
2. System Library: Isthe special types of functions that are used to implement the
functionality of the operating system.
3. Shell: It is an interface to the kernel which hides the complexity of the kernel’s
functions from the users. It takes commands from the user and executes the
kernel’s functions.
4. Hardware Layer: This layer consists all peripheral devices like RAM/ HDD/
CPU etc.
5. System Utility: It provides the functionalities of an operating system to the use

Advantages of Linux

 The main advantage of Linux, is it is an open-source operating system. This


means the source code is easily available for everyone and you are allowed to
contribute, modify and distribute the code to anyone without any permissions.
 In terms of security, Linux is more secure than any other operating system. It
does not mean that Linux is 100 percent secure it has some malware for it but
is less vulnerable than any other operating system. So, it does not require any
anti-virus software.
 The software updates in Linux are easy and frequent.
 Various Linux distributions are available so that you can use them according to
your requirements or according to your taste.
 Linux is freely available to use on the internet.
 It has large community support.
 It provides high stability. It rarely slows down or freezes and there is no need to
reboot it after a short time.
 It maintain the privacy of the user.
 The performance of the Linux system is much higher than other operating
systems. It allows a large number of people to work at the same time and it
handles them efficiently.
 It is network friendly.
 The flexibility of Linux is high. There is no need to install a complete Linux suit;
you are allowed to install only required component
 Linux is compatible with a large number of file formats.
 It is fast and easy to install from the web. It can also install on any hardware
even on your old computer system.
 It performs all tasks properly even if it has limited space on the hard disk.

Disadvantages of Linux

 It is not very user-friendly. So, it may be confusing for beginners.


 It has small peripheral hardware drivers as compared to windows.
Components of Linux System
Linux Operating System has primarily three components
 Kernel − Kernel is the core part of Linux. It is responsible for all major activities
of this operating system. It consists of various modules and it interacts directly
with the underlying hardware. Kernel provides the required abstraction to hide
low level hardware details to system or application programs.
 System Library − System libraries are special functions or programs using
which application programs or system utilities accesses Kernel's features.
These libraries implement most of the functionalities of the operating system
and do not requires kernel module's code access rights.
 System Utility − System Utility programs are responsible to do specialized,
individual level tasks.

Kernel Mode vs User Mode


Kernel component code executes in a special privileged mode called kernel
mode with full access to all resources of the computer. This code represents a single
process, executes in single address space and do not require any context switch and
hence is very efficient and fast. Kernel runs each processes and provides system
services to processes, provides protected access to hardware to processes.
Support code which is not required to run in kernel mode is in System Library. User
programs and other system programs works in User Mode which has no access to
system hardware and kernel code. User programs/ utilities use System libraries to
access Kernel functions to get system's low level tasks.

Basic Features
Following are some of the important features of Linux Operating System.
 Portable − Portability means software can works on different types of
hardware in same way. Linux kernel and application programs supports their
installation on any kind of hardware platform.
 Open Source − Linux source code is freely available and it is community
based development project. Multiple teams work in collaboration to enhance
the capability of Linux operating system and it is continuously evolving.
 Multi-User − Linux is a multiuser system means multiple users can access
system resources like memory/ ram/ application programs at same time.
 Multiprogramming − Linux is a multiprogramming system means multiple
applications can run at same time.
 Hierarchical File System − Linux provides a standard file structure in which
system files/ user files are arranged.
 Shell − Linux provides a special interpreter program which can be used to
execute commands of the operating system. It can be used to do various types
of operations, call application programs. etc.
 Security − Linux provides user security using authentication features like
password protection/ controlled access to specific files/ encryption of data.

Architecture
The following illustration shows the architecture of a Linux system −
The architecture of a Linux System consists of the following layers-
 Hardware layer − Hardware consists of all peripheral devices (RAM/ HDD/
CPU etc).
 Kernel − It is the core component of Operating System, interacts directly with
hardware, provides low level services to upper layer components.
 Shell − An interface to kernel, hiding complexity of kernel's functions from
users. The shell takes commands from the user and executes kernel's
functions.
 Utilities − Utility programs that provide the user most of the functionalities of
an operating systems.
Different Shells in Linux
SHELL is a program which provides the interface between the user and an operating
system. When the user logs in OS starts a shell for user. Kernel controls all
essential computer operations, and provides the restriction to hardware access,
coordinates all executing utilities, and manages Resources between process. Using
kernel only user can access utilities provided by operating system.
Types of Shell:
 The C Shell –
Denoted as csh
Bill Joy created it at the University of California at Berkeley. It incorporated
features such as aliases and command history. It includes helpful programming
features like built-in arithmetic and C-like expression syntax.
In C shell:
Command full-path name is /bin/csh,
Non-root user default prompt is hostname %,
Root user default prompt is hostname #.
 The Bourne Shell –
Denoted as sh
It was written by Steve Bourne at AT&T Bell Labs. It is the original UNIX shell. It
is faster and more preferred. It lacks features for interactive use like the ability
to recall previous commands. It also lacks built-in arithmetic and logical
expression handling. It is default shell for Solaris OS.

 For the Bourne shell the:


 Command full-path name is /bin/sh and /sbin/sh,
 Non-root user default prompt is $,
Root user default prompt is #.
 The Korn Shell
It is denoted as ksh
It Was written by David Korn at AT&T Bell LabsIt is a superset of the Bourne
shell.So it supports everything in the Bourne shell.It has interactive features. It
includes features like built-in arithmetic and C-like arrays, functions, and string-
manipulation facilities.It is faster than C shell. It is compatible with script written
for C shell.
For the Korn shell the:
Command full-path name is /bin/ksh,
Non-root user default prompt is $,
Root user default prompt is #.
 GNU Bourne-Again Shell –
Denoted as bash
It is compatible to the Bourne shell. It includes features from Korn and Bourne
shell.
For the GNU Bourne-Again shell the:
Command full-path name is /bin/bash,
Default prompt for a non-root user is bash-g.gg$
(g.ggindicates the shell version number like bash-3.50$),
 Root user default prompt is bash-g.gg#.

File Management in Linux


In Linux, most of the operations are performed on files. And to handle these files
Linux has directories also known as folders which are maintained in a tree-like
structure. Though, these directories are also a type of file themselves. Linux has 3
types of files:
1. Regular Files: It is the common file type in Linux. it includes files like – text files,
images, binary files, etc. Such files can be created using the touch command. They
consist of the majority of files in the Linux/UNIX system. The regular file contains ASCII
or Human Readable text, executable program binaries, program data and much more.
2. Directories: Windows call these directories as folders. These are the files that store
the list of file names and the related information. The root directory(/) is the base of the
system, /home/ is the default location for user’s home directories, /bin for Essential
User Binaries, /boot – Static Boot Files, etc. We could create new directories with mkdir
command.
3. Special Files: Represents a real physical device such as a printer which is used for IO
operations. Device or special files are used for device Input/Output(I/O) on UNIX and
Linux systems. You can see them in a file system like an ordinary directory or file.

Listing Files
To list the files and directories stored in the current directory, use the following
command −
$ls
Here is the sample output of the above command −
$ls

bin hosts lib res.03


ch07 hw1 pub test_results
ch07.bak hw2 res.01 users
docs hw3 res.02 work
The command ls supports the -l option which would help you to get more information
about the listed files −
$ls -l
total 1962188

drwxrwxr-x 2 amrood amrood 4096 Dec 25 09:59 uml


-rw-rw-r-- 1 amrood amrood 5341 Dec 25 08:38 uml.jpg
drwxr-xr-x 2 amrood amrood 4096 Feb 15 2006 univ
drwxr-xr-x 2 root root 4096 Dec 9 2007 urlspedia
-rw-r--r-- 1 root root 276480 Dec 9 2007 urlspedia.tar
drwxr-xr-x 8 root root 4096 Nov 25 2007 usr
drwxr-xr-x 2 200 300 4096 Nov 25 2007 webthumb-1.01
-rwxr-xr-x 1 root root 3192 Nov 25 2007 webthumb.php
-rw-rw-r-- 1 amrood amrood 20480 Nov 25 2007 webthumb.tar
-rw-rw-r-- 1 amrood amrood 5654 Aug 9 2007 yourfile.mid
-rw-rw-r-- 1 amrood amrood 166255 Aug 9 2007 yourfile.swf
drwxr-xr-x 11 amrood amrood 4096 May 29 2007 zlib-1.2.3
$
Here is the information about all the listed columns −
 First Column − Represents the file type and the permission given on the file.
Below is the description of all type of files.
 Second Column − Represents the number of memory blocks taken by the file
or directory.
 Third Column − Represents the owner of the file. This is the Unix user who
created this file.
 Fourth Column − Represents the group of the owner. Every Unix user will
have an associated group.
 Fifth Column − Represents the file size in bytes.
 Sixth Column − Represents the date and the time when this file was created
or modified for the last time.
 Seventh Column − Represents the file or the directory name.
In the ls -l listing example, every file line begins with a d, -, or l. These characters
indicate the type of the file that's listed.

Sr.No. Prefix & Description

1
-
Regular file, such as an ASCII text file, binary executable, or hard link.

2
b
Block special file. Block input/output device file such as a physical hard drive.

3
c
Character special file. Raw input/output device file such as a physical hard drive.
4
d
Directory file that contains a listing of other files and directories.

5
l
Symbolic link file. Links on any regular file.

6
p
Named pipe. A mechanism for interprocess communications.

7
s
Socket used for interprocess communication.

Metacharacters
Metacharacters have a special meaning in Unix. For example, * and ? are
metacharacters. We use * to match 0 or more characters, a question mark (?)
matches with a single character.
For Example −
$ls ch*.doc
Displays all the files, the names of which start with ch and end with .doc −
ch01-1.doc ch010.doc ch02.doc ch03-2.doc
ch04-1.doc ch040.doc ch05.doc ch06-2.doc
ch01-2.doc ch02-1.doc c
Here, * works as meta character which matches with any character. If you want to
display all the files ending with just .doc, then you can use the following command −
$ls *.doc
Hidden Files
An invisible file is one, the first character of which is the dot or the period character
(.). Unix programs (including the shell) use most of these files to store configuration
information.
Some common examples of the hidden files include the files −
 .profile − The Bourne shell ( sh) initialization script
 .kshrc − The Korn shell ( ksh) initialization script
 .cshrc − The C shell ( csh) initialization script
 .rhosts − The remote shell configuration file
To list the invisible files, specify the -a option to ls −
$ ls -a
. .profile docs lib test_results
.. .rhosts hosts pub users
.emacs bin hw1 res.01 work
.exrc ch07 hw2 res.02
.kshrc ch07.bak hw3 res.03
$
 Single dot (.) − This represents the current directory.
 Double dot (..) − This represents the parent directory.

Linux directory structure

Linux is based on UNIX and hence it borrows its filesystem hierarchy from UNIX. You’ll
fine a similar directory structure in UNIX-like operating systems such as BSD and
macOS. I’ll be using the term Linux hereafter instead of UNIX though.

/ – The root directory

Everything, all the files and directories, in Linux are located under ‘root’ represented by
‘/’. If you look at the directory structure, you’ll realize that it is similar to a plant’s root.

Linux Directory Structure

Since all other directories or files are descended from root, the absolute path of any file
is traversed through root. For example, if you have a file in /home/user/documents, you
can guess that the directory structure goes from root->home->user->documents.
/bin – Binaries

The ‘/bin’ directly contains the executable files of many basic shell commands like
ls, cp, cd etc. Mostly the programs are in binary format here and accessible by all the
users in the Linux system.

/dev – Device files

This directory only contains special files, including those relating to the devices. These
are virtual files, not physically on the disk.

Some interesting examples of these files are:

 /dev/null: can be sent to destroy any file or string


 /dev/zero: contains an infinite sequence of 0
 /dev/random: contains an infinite sequence of random values

/etc – Configuration files

The /etc directory contains the core configuration files of the system, use primarily by
the administrator and services, such as the password file and networking files.

If you need to make changes in system configuration (for example changing the
hostname), this is where you’ll find the respective files.

/usr – User binaries and program data

in ‘/usr’ go all the executable files, libraries, source of most of the system programs. For
this reason, most of the files contained therein is readonly (for the normal user)

 ‘/usr/bin’ contains basic user commands


 ‘/usr/sbin’ contains additional commands for the administrator
 ‘/usr/lib’ contains the system libraries
 ‘/usr/share’ contains documentation or common to all libraries, for example
‘/usr/share/man’ contains the text of the manpage

/home – User personal data

Home directory contains personal directories for the users. The home directory
contains the user data and user-specific configuration files. As a user, you’ll put your
personal files, notes, programs etc in your home directory.

When you create a user on your Linux system, it’s a general practice to create a home
directory for the user. Suppose your Linux system has two users, Alice and Bob. They’ll
have a home directory of their own at locations /home/alice and /home/bob.

Do note that Bob won’t have access to /home/alice and vice versa. That makes sense
because only the user should have access to his/her home. You may read about file
permissions in Linux to know more on this topic.
/lib – Shared libraries

Libraries are basically codes that can be used by the executable binaries. The /lib
directory holds the libraries needed by the binaries in /bin and /sbin directories.

Libraries needed by the binaries in the /usr/bin and /usr/sbin are located in the
directory /usr/lib.

/sbin – System binaries

This is similar to the /bin directory. The only difference is that is contains the binaries
that can only be run by root or a sudo user. You can think of the ‘s’ in ‘sbin’ as super or
sudo.

/tmp – Temporary files

As the name suggests, this directory holds temporary files. Many applications use this
directory to store temporary files. Even you can use directory to store temporary files.

But do note that the contains of the /tmp directories are deleted when your system
restarts. Some Linux system also delete files old files automatically so don’ store
anything important here.

/var – Variable data files

Var, short for variable, is where programs store runtime information like system
logging, user tracking, caches, and other files that system programs create and manage.

The files stored here are NOT cleaned automatically and hence it provides a good place
for system administrators to look for information about their system behavior. For
example, if you want to check the login history in your Linux system, just check the
content of the file in /var/log/wtmp.

/boot – Boot files

The ‘/boot’ directory contains the files of the kernel and boot image, in addition to LILO
and Grub. It is often advisable that the directory resides in a partition at the beginning
of the disc.

/proc – Process and kernel files

The ‘/proc’ directory contains the information about currently running processes and
kernel parameters. The content of the proc directory is used by a number of tools to get
runtime system information.

For example, if you want to check processor information in Linux, you can simply refer
to the file /proc/cpuinfo. You want to check memory usage of your Linux system, just
look at the content of /proc/meminfo file.
/opt – Optional software

Traditionally, the /opt directory is used for installing/storing the files of third-party
applications that are not available from the distribution’s repository.

The normal practice is to keep the software code in opt and then link the binary file in
the /bin directory so that all the users can run it.

/root – The home directory of the root

There is /root directory as well and it works as the home directory of the root user. So
instead of /home/root, the home of root is located at /root. Do not confuse it with the
root directory (/).

/media – Mount point for removable media

When you connect a removable media such as USB disk, SD card or DVD, a directory is
automatically created under the /media directory for them. You can access the content
of the removable media from this directory.

/mnt – Mount directory

This is similar to the /media directory but instead of automatically mounting the
removable media, mnt is used by system administrators to manually mount a
filesystem.

/srv – Service data

The /srv directory contains data for services provided by the system. For example, if
you run a HTTP server, it’s a good practice to store the website data in the /srv
directory.

I think this much information is enough for you to understand the Linux directory
structure and its usage.

In the end, if you want, you can download and save this image for quick reference to the
directory structure in Linux systems.
Linux System Directories
What is System Call in Operating System?
A system call is a mechanism that provides the interface between a process
and the operating system. It is a programmatic method in which a computer
program requests a service from the kernel of the OS.

System call offers the services of the operating system to the user programs
via API (Application Programming Interface). System calls are the only entry
points for the kernel system.

Services Provided by System Calls :


1. Process creation and management
2. Main memory management
3. File Access, Directory and File system management
4. Device handling(I/O)
5. Protection
6. Networking, etc.

Types of System Calls


There are mainly five types of system calls. These are explained in detail as follows −

Here are the types of system calls −


Process Control
These system calls deal with processes such as process creation, process termination
etc.
File Management
These system calls are responsible for file manipulation such as creating a file, reading
a file, writing into a file etc.
Device Management
These system calls are responsible for device manipulation such as reading from
device buffers, writing into device buffers etc.
Information Maintenance
These system calls handle information and its transfer between the operating system
and the user program.
Communication
These system calls are useful for interprocess communication. They also deal with
creating and deleting a communication connection.
Some of the examples of all the above types of system calls in Windows and Unix are
given as follows −

Types of System Calls Windows Linux

Process Control CreateProcess() fork()


ExitProcess() exit()
WaitForSingleObject() wait()

File Management CreateFile() open()


ReadFile() read()
WriteFile() write()
CloseHandle() close()

Device Management SetConsoleMode() ioctl()


ReadConsole() read()
WriteConsole() write()

Information Maintenance GetCurrentProcessID() getpid()


SetTimer() alarm()
Sleep() sleep()
Types of System Calls Windows Linux

Communication CreatePipe() pipe()


CreateFileMapping() shmget()
MapViewOfFile() mmap()

There are many different system calls as shown above. Details of some of those
system calls are as follows −

wait()
In some systems, a process may wait for another process to complete its execution.
This happens when a parent process creates a child process and the execution of the
parent process is suspended until the child process executes. The suspending of the
parent process occurs with a wait() system call. When the child process completes
execution, the control is returned back to the parent process.

exec()
This system call runs an executable file in the context of an already running process.
It replaces the previous executable file. This is known as an overlay. The original
process identifier remains since a new process is not created but data, heap, stack
etc. of the process are replaced by the new process.

fork()
Processes use the fork() system call to create processes that are a copy of
themselves. This is one of the major methods of process creation in operating
systems. When a parent process creates a child process and the execution of the
parent process is suspended until the child process executes. When the child process
completes execution, the control is returned back to the parent process.

exit()
The exit() system call is used by a program to terminate its execution. In a
multithreaded environment, this means that the thread execution is complete. The
operating system reclaims resources that were used by the process after the exit()
system call.

kill()
The kill() system call is used by the operating system to send a termination signal to a
process that urges the process to exit.However, kill system call does not necessary
mean killing the process and can have various meanings.
S
system Calls in Operating System
Example of System Call
For example if we need to write a program code to read data from one file,
copy that data into another file. The first information that the program
requires is the name of the two files, the input and output files.

In an interactive system, this type of program execution requires some system


calls by OS.

 First call is to write a prompting message on the screen


 Second, to read from the keyboard, the characters which define the two
files.
How System Call Works?
Here are steps for System Call:

Architecture of the System Call

As you can see in the above-given diagram.

Step 1) The processes executed in the user mode till the time a system call
interrupts it.

Step 2) After that, the system call is executed in the kernel-mode on a priority
basis.

Step 3) Once system call execution is over, control returns to the user mode.,

Step 4) The execution of user processes resumed in Kernel mode.

Why do you need System Calls in OS?


Following are situations which need system calls in OS:

 Reading and writing from files demand system calls.


 If a file system wants to create or delete files, system calls are required.
 System calls are used for the creation and management of new
processes.
 Network connections need system calls for sending and receiving
packets.
 Access to hardware devices like scanner, printer, need a system call.

Linux File System


A Linux file system is a structured collection of files on a disk drive or a partition. A partition is a

segment of memory and contains some specific data. In our machine, there can be various

partitions of the memory. Generally, every partition contains a file system.

The general-purpose computer system needs to store data systematically so that we can easily

access the files in less time. It stores the data on hard disks (HDD) or some equivalent storage

type. There may be below reasons for maintaining the file system:

o Primarily the computer saves data to the RAM storage; it may lose the data if it gets
o turned off. However, there is non-volatile RAM (Flash RAM and SSD) that is available to
o maintain the data after the power interruption.
o Data storage is preferred on hard drives as compared to standard RAM as RAM costs more
o than disk space. The hard disks costs are dropping gradually comparatively the RAM.

The Linux file system contains the following sections:

o The root directory (/)


o A specific data storage format (EXT3, EXT4, BTRFS, XFS and so on)
o A partition or logical volume having a particular file system.

What is the Linux File System?


Linux file system is generally a built-in layer of a Linux operating system used to handle the data

management of the storage. It helps to arrange the file on the disk storage. It manages the file

name, file size, creation date, and much more information about a file.

If we have an unsupported file format in our file system, we can download software to deal with it.
Linux File System Structure
Linux file system has a hierarchal file structure as it contains a root directory and its subdirectories.
the root directory. A partition usually has only one file system, but it may have more than one

file system.

A file system is designed in a way so that it can manage and provide space for non-volatile storage

data. All file systems required a namespace that is a naming and organizational methodology.

The namespace defines the naming process, length of the file name, or a subset of characters

that can be used for the file name. It also defines the logical structure of files on a memory

segment, such as the use of directories for organizing the specific files. Once a namespace is

described, a Metadata description must be defined for that particular file.

The data structure needs to support a hierarchical directory structure; this structure is used to

describe the available and used disk space for a particular block. It also has the other details

about the files such as file size, date & time of creation, update, and last modifiedAlso, it stores

advanced information about the section of the

disk, such as partitions and volumes.

The advanced data and the structures that it represents contain the information about the file

system stored on the drive; it is distinct and independent of the file system metadata.

Linux file system contains two-part file system software implementation architecture. Consider

the below image:


The file system requires an API (Application programming interface) to access the function calls

to interact with file system components like files and directories. API facilitates tasks such as

creating, deleting, and copying the files. It facilitates an algorithm that defines the arrangement

of files on a file system.

The first two parts of the given file system together called a Linux virtual file system. It provides
and developers to access the file system. This virtual file system requires the specific system driver t

Linux File System Features


In Linux, the file system creates a tree structure. All the files are arranged as a tree and its

branches. The topmost directory called the root (/) directory. All other directories in Linux

can be accessed from the root directory.

Some key features of Linux file system are as following:

o Specifying paths: Linux does not use the backslash (\) to separate the components;
o it uses forward slash (/) as an alternative. For example, as in Windows, the data may be

stored in C:\ My Documents\ Work, whereas, in Linux, it would be stored in /home/


My Document/ Work.

o Partition, Directories, and Drives: Linux does not use drive letters to organize the

drive as Windows does. In Linux, we cannot tell whether we are addressing a partition, a netw
and a Drive.

o Case Sensitivity: Linux file system is case sensitive. It distinguishes between lowercase

and uppercase file names. Such as, there is a difference between test.txt and Test.txt in

Linux. This rule is also applied for directories and Linux commands.

o File Extensions: In Linux, a file may have the extension '.txt,' but it is not necessary that

a file should have a file extension. While working with Shell, it creates some problems for

the beginners to differentiate between files and directories. If we use the graphical file

manager, it symbolizes the files and folders.

o Hidden files: Linux distinguishes between standard files and hidden files, mostly the

configuration files are hidden in Linux OS. Usually, we don't need to access or read the

hidden files. The hidden files in Linux are represented by a dot (.) before the file name

(e.g., .ignore). To access the files, we need to change the view in the file manager or

need to use a specific command in the shell.

Types of Linux File System


When we install the Linux operating system, Linux offers many file systems such as Ext, Ext2,

Ext3, Ext4, JFS, ReiserFS, XFS, btrfs, and swap.


Let's understand each of these file systems in detail:

1. Ext, Ext2, Ext3 and Ext4 file system

The file system Ext stands for Extended File System. It was primarily developed for MINIX OS.

The Ext file system is an older version, and is no longer used due to some limitations.

Ext2 is the first Linux file system that allows managing two terabytes of data. Ext3 is developed

through Ext2; it is an upgraded version of Ext2 and contains backward compatibility.

The major drawback of Ext3 is that it does not support servers because this file system does not

support file recovery and disk snapshot.

Ext4 file system is the faster file system among all the Ext file systems. It is a very compatible

option for the SSD (solid-state drive) disks, and it is the default file system in Linux distribution.

2. JFS File System

JFS stands for Journaled File System, and it is developed by IBM for AIX Unix. It is an
alternative to the Ext file system. It can also be used in place of Ext4, where stability is needed

with few resources. It is a handy file system when CPU power is limited.

3. ReiserFS File System

ReiserFS is an alternative to the Ext3 file system. It has improved performance and advanced

features. In the earlier time, the ReiserFS was used as the default file system in SUSE Linux,

but later it has changed some policies, so SUSE returned to Ext3. This file system dynamically

supports the file extension, but it has some drawbacks in performance.

4. XFS File System

XFS file system was considered as high-speed JFS, which is developed for parallel I/O processing.

NASA still using this file system with its high storage server (300+ Terabyte server).

5. Btrfs File System

Btrfs stands for the B tree file system. It is used for fault tolerance, repair system, fun

administration, extensive storage configuration, and more. It is not a good suit for the

production system.

6. Swap File System

The swap file system is used for memory paging in Linux operating system during the system

hibernation. A system that never goes in hibernate state is required to have swap space equal

to its RAM size.


Layout of the file system:
 Each physical drive can be divided into
several partitions
 Each partition can contain one file system
 Each file system contains:
1. boot block(s);
2. superblock;
3. inode list;
4. data blocks.
 A boot block may contain the bootstrap code that is read
into the machine upon booting.

Boot Block in Operating System


Basically for a computer to start running to get an instance when it is powered up or
rebooted it need to have an initial program to run. And this initial program which is
known as bootstrap need to be simple. It must initialize all aspects of the system,
from CPU registers to device controllers and the contents of the main memory and
then starts the operating system.
To do this job the bootstrap program basically finds the operating system kernel on
disk and then loads the kernel into memory and after this, it jumps to the initial
address to begin the operating-system execution.
Why ROM:
For most of today’s computer bootstrap is stored in Read Only Memory (ROM).

1. This location is good for storage because this place doesn’t require initialization
and moreover location here it is fixed so that processor can start executing
when powered up or reset.

2. ROM is basically read-only memory and hence it cannot be affected by the


computer virus.

The problem is that changing the bootstrap code basically requires changes in the
ROM hardware chips.Because of this reason, most system nowadays has the tiny
bootstrap loader program in the boot whose only job is to bring the full bootstrap
program from the disk. Through this now we are able to change the full bootstrap
program easily and the new version can be easily written onto the disk.
Full bootstrap program is stored in the boot blocks at a fixed location on the disk. A
disk which has a boot partition is called a boot disk. The code in the boot ROM
basically instructs the read controller to read the boot blocks into the memory and
then starts the execution of code. The full bootstrap program is more complex than
the bootstrap loader in the boot ROM, It is basically able to load the complete OS
from a non-fixed location on disk to start the operating system running. Even though
the complete bootstrap program is very small.

 A superblock describes the state of the file system:


 how large it is;

 how many files it can store;

 where to find free space on the file system;

 who has ownership of it;

 and more.

 The inode list is an array of "information nodes"


analogous to the FAT (File Allocation Table) system in MS-
DOS.

Linux Inodes
An Inode number is a uniquely existing number for all the files in Linux and all Unix
type systems.

When a file is created on a system, a file name and Inode number is assigned to it.

Generally, to access a file, a user uses the file name but internally file name is first
mapped with respective Inode number stored in a table.

Note: Inode doesn't contain the file name. Reason for this is to maintain hard-links
for the files. When all the other information is separated from the file name then only
we can have various file names pointing to the same Inode.

Inode Contents
An Inode is a data structure containing metadata about the files.

Following contents are stored in the Inode from a file:


o User ID of file
o Group ID of file
o Device ID
o File size
o Date of creation
o Permission
o Owner of the file
o File protection flag
o Link counter to determine number of hard links

Example:

1. ls -ld new1

Look at the above snapshot, it shows some of the Inode contents.

Inode Table
The Inode table contains all the Inodes and is created when file system is created.
The df -i command can be used to check how many inodes are free and left unused in
the filesystem.

Look at the above snapshot, the command "df -i" shows the usage of several file
systems.
Inode Number
Each Inode has a unique number and Inode number can be seen with the help of ls -
li command.

Look at the above snapshot, Directory Disk1 has the three files and each file has a
different Inode number.

Note: The Inode doesn't contain file content, instead it has a pointer to that data.

 data blocks start at the end of the inode list and contain
file data and directory blocks.

The term file system can mean a single disk, or it can mean
the entire collection of devices on a system. It's held together
in this second sense by the directory structure.
The directory "tree" usually spans many disks and/or
partitions by means of mount points. For example, in Red Hat
Linux, there are pre-defined mount points for floppy disks and
CD-ROMs at floppy and cdrom in /mnt. See
also fstab and mtab in /etc.

You might also like