Nothing Special   »   [go: up one dir, main page]

Linux Environment System Unit-1: Dr. S.MD - Farooq, Associate Professor, Dept of CSE, SREC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

LINUX ENVIRONMENT SYSTEM UNIT- 1

LINUX ENVIRONMENT SYSTEM

INTRODUCTION TO LINUX OPERATING SYSTEM: Introduction and Types of Operating


Systems, Linux Operating System, Features, Architecture Of Linux OS and Shell Interface,
Linux System Calls, Linux Shared Memory Management, Device and Disk Management
in Linux, Swap space and its management. File System and Directory Structure in Linux. Multi-
Processing, load sharing and Multi-Threading in Linux, Types of Users in Linux, Capabilities of
Super Users and equivalents.

I. Introduction to Linux Operating System:

Linux is a Unix-like computer operating system assembled under the model of free and open source
software development and distribution. The defining component of Linux is the Linux kernel, an
operating system kernel first released 5 October 1991 by Linus Torvalds.

Linux was originally developed as a free operating system for Intel x86-based personal computers. It
has since been ported to more computer hardware platforms than any other operating system. It is a
leading operating system on servers and other big iron systems such as mainframe computers and
supercomputers more than 90% of today's 500 fastest supercomputers run some variant of Linux,
including the 10 fastest. Linux also runs on embedded systems (devices where the operating system is
typically built into the firmware and highly tailored to the system) such as mobile phones, tablet
computers, network routers, televisions and video game consoles; the Android system in wide use on
mobile devices is built on the Linux kernel.

Linux Advantages

1.Low cost: You don’t need to spend time and money to obtain licenses since Linux andmuch of its
software come with the GNU General Public License. You can start to workimmediately without
worrying that your software may stop working anytime because thefree trial version expires.
Additionally, there are large repositories from which you canfreely download high quality software for
almost any task you can think of.

2.Stability: Linux doesn’t need to be rebooted periodically to maintain performance levels. Itdoesn’t
freeze up or slow down over time due to memory leaks and such. Continuous up-times of hundreds
of days (up to a year or more) are not uncommon.

3.Performance: Linux provides persistent high performance on workstations and onnetworks. It can
handle unusually large numbers of users simultaneously, and can make oldcomputers sufficiently
responsive to be useful again

4.Network friendliness: Linux was developed by a group of programmers over the Internet and has
therefore strong support for network functionality; client and server systems can be easily set up on
any computer running Linux. It can perform tasks such as network backups faster and more reliably
than alternative systems.
Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 1
LINUX ENVIRONMENT SYSTEM UNIT- 1

5.Flexibility: Linux can be used for high performance server applications, desktop applications, and
embedded systems. You can save disk space by only installing the components needed for a particular
use. You can restrict the use of specific computers by installing for example only selected office
applications instead of the whole suite.

6.Compatibility: It runs all common Unix software packages and can process all common file formats.

7.Choice: The large number of Linux distributions gives you a choice. Each distribution is developed
and supported by a different organization. You can pick the one you like best; the core functionalities
are the same; most software runs on most distributions

8.Fast and easy installation: Most Linux distributions come with user-friendly installation and setup
programs. Popular Linux distributions come with tools that make installation of additional software
very user friendly as well.

9.Full use of hard disk: Linux continues work well even when the hard disk is almost full.
10.Multitasking: Linux is designed to do many things at the same time; e.g., a large printing job in the
background won’t slow down your other work.

11.Security: Linux is one of the most secure operating systems. “Walls” and flexible file access
permission systems prevent access by unwanted visitors or viruses. Linux users have to option to select
and safely download software, free of charge, from online repositories containing thousands of high
quality packages. No purchase transactions requiring credit card numbers or other sensitive personal
information are necessary.

12.Open Source: If you develop software that requires knowledge or modification of the operating
system code, Linux’s source code is at your fingertips. Most Linux applications are Open Source as
well.

Linux Distribution (Operating System) Names

A few popular names:

1.Redhat Enterprise Linux

2.Fedora Linux

3.Debian Linux

4.Suse Enterprise Linux

5.Ubuntu Linux

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 2


LINUX ENVIRONMENT SYSTEM UNIT- 1

Common Things Between Linux & UNIX

Both share many common applications such as:

1.GUI, file, and windows managers (KDE, Gnome)

2.Shells (ksh, csh, bash)

3.Various office applications such as OpenOffice.org

4.Development tools (perl, php, python, GNU c/c++ compilers)

5.Posix interface

Types of Operating System:

Operating systems are there from the very first computer generation and they keep evolving with time.
In this chapter, we will discuss some of the important types of operating systems which are most
commonly used.

Batch operating system


The users of a batch operating system do not interact with the computer directly. Each user prepares
his job on an off-line device like punch cards and submits it to the computer operator. To speed up
processing, jobs with similar needs are batched together and run as a group. The programmers leave
their programs with the operator and the operator then sorts the programs with similar requirements
into batches.
The problems with Batch Systems are as follows −
 Lack of interaction between the user and the job.
 CPU is often idle, because the speed of the mechanical I/O devices is slower than the CPU.
 Difficult to provide the desired priority.

Time-sharing operating systems

Time-sharing is a technique which enables many people, located at various terminals, to use a
particular computer system at the same time. Time-sharing or multitasking is a logical extension of
multiprogramming. Processor's time which is shared among multiple users simultaneously is termed
as time-sharing. Multiple jobs are executed by the CPU by switching between them, but the switches
occur so frequently. Thus, the user can receive an immediate response. The operating system uses
CPU scheduling and multiprogramming to provide each user with a small portion of a time.
Computer systems that were designed primarily as batch systems have been modified to time-sharing
systems.

Advantages of Timesharing operating systems are as follows −


 Provides the advantage of quick response.
 Avoids duplication of software.
 Reduces CPU idle time.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 3


LINUX ENVIRONMENT SYSTEM UNIT- 1

Disadvantages of Time-sharing operating systems are as follows −


 Problem of reliability.
 Question of security and integrity of user programs and data.
 Problem of data communication.

Distributed operating System

Distributed systems use multiple central processors to serve multiple real-time applications and
multiple users. Data processing jobs are distributed among the processors accordingly.
The processors communicate with one another through various communication lines (such as high-
speed buses or telephone lines). These are referred as loosely coupled systems or distributed systems.
Processors in a distributed system may vary in size and function. These processors are referred as
sites, nodes, computers, and so on.

The advantages of distributed systems are as follows

 With resource sharing facility, a user at one site may be able to use the resources available at
another.
 Speedup the exchange of data with one another via electronic mail.
 If one site fails in a distributed system, the remaining sites can potentially continue operating.
 Better service to the customers.
 Reduction of the load on the host computer.
 Reduction of delays in data processing

Network operating System

A Network Operating System runs on a server and provides the server the capability to manage data,
users, groups, security, applications, and other networking functions. The primary purpose of the
network operating system is to allow shared file and printer access among multiple computers in a
network, typically a local area network (LAN), a private network or to other networks.
Examples of network operating systems include Microsoft Windows Server 2003, Microsoft Windows
Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD.

The advantages of network operating systems are as follows

 Centralized servers are highly stable.


 Security is server managed.
 Upgrades to new technologies and hardware can be easily integrated into the system.
 Remote access to servers is possible from different locations and types of systems.

The disadvantages of network operating systems are as follows −


 High cost of buying and running a server.
 Dependency on a central location for most operations.
 Regular maintenance and updates are required.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 4


LINUX ENVIRONMENT SYSTEM UNIT- 1

Real Time operating System

A real-time system is defined as a data processing system in which the time interval required to
process and respond to inputs is so small that it controls the environment. The time taken by the
system to respond to an input and display of required updated information is termed as the response
time. So in this method, the response time is very less as compared to online processing.

There are two types of real-time operating systems.

Hard real-time systems

Hard real-time systems guarantee that critical tasks complete on time. In hard real-time systems,
secondary storage is limited or missing and the data is stored in ROM. In these systems, virtual
memory is almost never found.

Soft real-time systems

Soft real-time systems are less restrictive. A critical real-time task gets priority over other tasks and
retains the priority until it completes. Soft real-time systems have limited utility than hard real-time
systems. For example, multimedia, virtual reality, Advanced Scientific Projects like undersea
exploration and planetary rovers, etc

II. Linux Operating System, Features, Architecture Of Linux OS

Linux is one of popular version of UNIX operating System. It is open source as its source code is
freely available. It is free to use. Linux was designed considering UNIX compatibility. Its functionality
list is quite similar to that of UNIX.

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.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 5


LINUX ENVIRONMENT SYSTEM UNIT- 1

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 softwares can works on different types of hardwares 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 works 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.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 6


LINUX ENVIRONMENT SYSTEM UNIT- 1

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.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 7


LINUX ENVIRONMENT SYSTEM UNIT- 1

III. LINUX Shell Interface

A User Interface is a program that lets you interact with the computer. User interfaces have been
classified in different ways. A Graphical User Interface (GUI, often pronounced "gooey") allows a user
to use graphics, icons, menus, and windows to interact with the computer. Examples of GUI
interfaces include Microsoft Windows and the Apple Macintosh interface. GUIs were first developed
by Xerox's Palo Alto Research Center. Some GUIs exist for Unix/Linux environments as well,
including XWindows, KDE, and Gnome.

A Command Driven or Command Line interface offers a prompt (the command line) at which the
user enters commands

Shells:

The typical user interface on a Unix or Linux system is called a shell. This shell is the first thing a user
interacts with when he or she connects to a system via a telnet or secure connection. The shell takes
the user's commands and changes them into instructions for the operating system to execute. Several
shells have been developed for Unix, and these shells are generally consistent across different varieties
and distributions of Unix. Each Unix system typically comes with a "default" shell set up for users, but
also comes with a variety of other shells that a user can choose from.

The Bourne Shell

The Bourne shell (sh), written by Steve Bourne at AT&T Bell Labs, is the original UNIX shell. It is
the preferred shell for shell programming because of its compactness and speed. A Bourne shell
drawback is that it lacks features for interactive use, such as the ability to recall previous commands
(history). The Bourne shell also lacks built-in arithmetic and logical expression handling.

The Bourne shell is the Solaris OS default shell. It is the standard shell for Solaris system
administration scripts. 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 C Shell:

The C shell (csh):

 Is a UNIX enhancement written by Bill Joy at the University of California at Berkeley.

 Incorporated features for interactive use, such as aliases and command history.

 Includes convenient programming features, such as built-in arithmetic and a C-like expression
syntax.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 8


LINUX ENVIRONMENT SYSTEM UNIT- 1

For the C shell the:

 Command full-path name is /bin/csh.

 Non-root user default prompt is hostname %.

 Root user default prompt is hostname #.

The Korn Shell:

The Korn shell (ksh):

 Was written by David Korn at AT&T Bell Labs

 Is a superset of the Bourne shell.

 Supports everything in the Bourne shell.

 Has interactive features comparable to those in the C shell.

 Includes convenient programming features like built-in arithmetic and C-like arrays, functions,
and string-manipulation facilities.

 Is faster than the C shell.

 Runs scripts written for the Bourne shell.

For the Korn shell the:

 Command full-path name is /bin/ksh.

 Non-root user default prompt is $.

 Root user default prompt is #.

The GNU Bourne-Shell Again:

The GNU Bourne-Again shell (bash):

 Is compatible to the Bourne shell.

 Incorporates useful features from the Korn and C shells.

 Has arrow keys that are automatically mapped for command recall and editing.

For the GNU Bourne-Again shell the:

 Command full-path name is /bin/bash.

 Default prompt for a non-root user is bash-x.xx$. (Where x.xx indicates the shell version
number. For example, bash-3.50$)
Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 9
LINUX ENVIRONMENT SYSTEM UNIT- 1

 Root user default prompt is bash-x.xx#. (Where x.xx indicates the shell version number. For
example, bash-3.50$#)

comparison of the all 4 shells and their properties

Default Prompt (non- Default Prompt


Shell Path
root user) (Root user)

The Bourne Shell (sh) /bin/sh and /sbin/sh $ #

The C Shell (csh) /bin/csh % #

The Korn Shell (ksh) /bin/ksh $ #

The GNU Bourne-Again


/bin/bash bash-x.xx$ bash-x.xx#
Shell (Bash)

IV. LINUX System Calls:

The operating system is responsible for

 Process Management (starting, running, stopping processes)

 File Management(creating, opening, closing, reading, writing, renaming files)

 Memory Management (allocating, deallocating memory)

 Other stuff (timing, scheduling, network management)

An application program makes a system call to get the operating system to perform a service for it,
like reading from a file.

System calls (often shorted to syscalls) are function invocations made from user space—your text
editor, favorite game, and so on—into the kernel (the core internals of the system) in order to request
some service or resource from the operating system. System calls range from the familiar, such as
read( ) and write( )Etc..

Invoking a System Call:

It is not possible to directly link user-space applications with kernel space. For reasons of security and
reliability, user-space applications must not be allowed to directly execute kernel code or manipulate
kernel data. Instead, the kernel must provide a mechanism by which a user-space application can
"signal" the kernel that it wishes to invoke a system call. The application can then trap into the kernel

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 10


LINUX ENVIRONMENT SYSTEM UNIT- 1

through this well-defined mechanism, and execute only code that the kernel allows it to execute. The
exact mechanism varies from architecture to architecture.

The application tells the kernel which system call to execute and with what parameters via machine
registers. System calls are denoted by number, starting at 0.

File system

The file is the most basic and fundamental abstraction in Linux. In order to be accessed, a file must
first be opened. Files can be opened for reading, writing, or both. An open file is referenced via a
unique descriptor, a mapping from the metadata associated with the open file back to the specific file
itself. Inside the Linux kernel, this descriptor is handled by an integer (of the C type int) called the file
descriptor, abbreviated fd. File descriptors are shared with user space, and are used directly by user
programs to access files. A large part of Linux system programming consists of opening, manipulating,
closing, and otherwise using file descriptors. Few Examples are Given below

1. File operations

Syscall Number Description

CLOSE 3 Close a file descriptor

CREAT 85 Open and possibly create a file

OPEN 2 Open and possibly create a file

RENAME 82 Rename a File

Directory operations

MKDIR 83 Create a directory

MKDIRAT 258 Create a directory relative to a directory file descriptor

RMDIR 84 Delete a directory

Link operations

LINK 86 Create a hard link to a file

LINKAT 265 Create a hard link to a file relative to directory file descriptors

SYMLINK 88 Create a symbolic link to a file

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 11


LINUX ENVIRONMENT SYSTEM UNIT- 1

2. Network

Like most other Unix-based operating systems, Linux supports TCP/IP as its native network
transport. Network system calls is the way to make communications between computes via different
kind of network interfaces: wired and wireless devices, fiber channel and etc. Most of network
operations are based on BSD sockets interface.

Sockets allow processes on different computers to exchange data through a network. Sockets can also
be used as a communication tool for processes located on the same host computer; the X Window
System graphic interface, for instance, uses a socket to allow client programs to exchange data with the
X server. the Following lists the network system calls

Socket operations Naming Send/Receive Packet filtering

Syscall Number Description

SOCKET 41 Create an endpoint for communication

SOCKETPAIR 53 Create a pair of connected sockets

SETSOCKOPT 54 Set options on sockets

Send/ Receive

RECVFROM 45 Receive a message from a socket

RECVMSG 47 Receive a message from a socket

RECVMMSG 299 Receive multiple messages from a socket

Naming

Syscall Number Description

SETHOSTNAME 170 Set hostname

SETDOMAINNAME 171 Set NIS domain name

Packet Filtering

BPF 321 Perform a command on an extended BPF map or program

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 12


LINUX ENVIRONMENT SYSTEM
STEM UNIT- 1

3. Time

4. Process Management

5.Signals

6. Interprocess Communication

7. Non-Uniform Memory Access

8. Linux Key Management

9. System Wide

V. LINUX Shared Memory Management

In computer science, shared memory is memory that may be simultaneously accessed by multiple
programs with an intent to provide communication among them or avoid redundant copies. Shared
memory is an efficient means of passing data between programs. Depending on context, programs
may run on a single processor or on multiple separate processors.

Using memory for communication inside a single program, e.g. among its multiple threads, is also
referred to as shared memory.

As its name implies, shared memory makes a segment of memory accessible to more than one
process. Special system calls, or requests to the UNIX kernel, allocate and free the memory and set
permissions; common read and write operations put and get data from the region.

Shared memory is not drawn from a process's own memory; that memory is always private. Instead,
shared memory is allocated from the system's free memory pool and is annexed by each process that
wants access. Annexation is called mapping, where the shared segment of memory is assigned local
addresses in each process' own address space. Figure 1, Figure 2, Figure 3, and Figure 4 depict the
process:

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 13


LINUX ENVIRONMENT SYSTEM
STEM UNIT- 1

1. Assume two processes, A and B, are running on the same system, as shown in Figure 1, and have
been specifically coded to coordinate and share information vvia ia shared memory. A and B have
disproportionate sizes in the figure to emphasize that the applications need not be identical.

Figure 1. Two processes running on a host, executing different code

2. In Figure 2, process A requests a segment of shared memor


memory.y. Process A initializes the memory
segment, preparing it for use. The process also names the segment so that other processes can find it.
Typically, a segment name is not dynamically assigned; instead, it is well known, such as a constant in
a header file,, and easily referenced from other code.

Figure 2. One process requests a shared memory segment

3. Process A annexes, or maps, the shared memory segment into its own address space. Process B
finds the segment via its named pipe and also maps the segment into its address space. This is shown
in Figure 3. Both processes are enlarged by the size of the shared memory segment.

Figure 3. Both processes annex, or map, the shared memory segment

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 14


LINUX ENVIRONMENT SYSTEM
STEM UNIT- 1

4. Finally, in Figure 4, processes A and B can read and write from the shared memory segment freely.
The shared memory is treated the same as local process memory. read() and write() operate as
normal.

Figure 4. Two or more processes can now share data via common memory

Much of the work shown in these figures is captur


captured
ed in the UNIX shared memory API. In fact, there
are two variants of the shared memory API: the POSIX API and the older (but no less effective)
System V API. Because POSIX is the ratified standard likely found on UNIX and Linux® and
derivations of those systems using this version. Additionally, the POSIX API uses simple file
descriptors for read and write and so should seem much more familiar.

POSIX provides five entry points to create, map, synchronize, and undo shared memory segments:

shm_open(): Creates a shared memory region or attaches to an existing, named region. This system
call returns a file descriptor.

shm_unlink(): Deletes a shared memory region given a file descriptor (returned from shm_open()).
The region is not actually removed until all processes
processes accessing the region exit, much like any file in

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 15


LINUX ENVIRONMENT SYSTEM UNIT- 1

UNIX. However, once shm_unlink() is called (typically by the originating process), no other processes
can access the region.

mmap(): Maps a shared memory region into the process's memory. This system call requires the file
descriptor from shm_open() and returns a pointer to memory. (In some cases, you can also map a file
descriptor to a plain file or another device into memory. A discussion of those options is beyond the
scope of this introduction; consult the mmap() documentation for your operating system for specifics.)

munmap(): The inverse of mmap().

msync(): Used to synchronize a shared memory segment with the file system—a technique useful when
mapping a file into memory.

The pattern for shared memory is to create a segment with shm_open(), size it with write() or
ftruncate(), map it into process memory with mmap(), and do the work required with one or more
additional participants. To finish, the originating process calls munmap() and shm_unlink(), and then
exits.

V. Shared Memory

Shared memory allows one or more processes to communicate via memory that appears in all of their
virtual address spaces. The pages of the virtual memory is referenced by page table entries in each of
the sharing processes' page tables. It does not have to be at the same address in all of the processes'
virtual memory. As with all System V IPC objects, access to shared memory areas is controlled via
keys and access rights checking. Once the memory is being shared, there are no checks on how the
processes use it. They must rely on other mechanisms, for example System V semaphores, to
synchronize access to the memory

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 16


LINUX ENVIRONMENT SYSTEM
STEM UNIT- 1

Shared memory system calls:

shm_open() creates and opens a new, or opens an existing, POSIX shared memory object. A POSIX
shared memory object is in effect a handle which can be used by unrelated processes to mmap(2) the
same region of shared memory.

Syntax: int shm_open(const char *name,


name, int oflag, mode_t mode);

The shm_unlink() function performs the converse operation, removing an object previously created
by shm_open().

Syntax: int shm_unlink(const char *name);

munmap() creates a new mapping in the virtual address space of the ccalling
alling process. The starting
address for the new mapping is specified in addr. The length argument specifies the length of the
mapping.

Syntax: void *mmap(void *addr, size_t lengthint " prot ", int " flags , int fd, off_t offset);
int munmap(void
nmap(void *addr, size_t length);

VI. Device and Disk Management

Device files

Device files are also known as device special files.. Device files are employed to provide the operating
system and users an interface to the devices that they represent. All Linux device files are located in
the /dev directory, which is an integral part of the root (/) filesystem because these device files must be
available to the operating system during the boot process.

One of the most important things to remember about these device files is that they are most definitely
not device drivers. They are more accurately described as portals to the device drivers. Data is passed
from an application or the operating system to the device file which then passes it to the device driver
which then sends it to the physical device. The reverse data path is also used, from the physical device
through the device
vice driver, the device file, and then to an application or another device.

Let's look at the data flow of a typical command to visualize this.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 17


LINUX ENVIRONMENT SYSTEM UNIT- 1

Disk management: fdisk stands (for “fixed disk or format disk“) is an most commonly used
command-line based disk manipulation utility for a Linux/Unix systems. With the help of fdisk
command you can view, create, resize, delete, change, copy and move partitions on a hard drive using
its own user friendly text based menu driven interface.

This tool is very useful in terms of creating space for new partitions, organising space for new drives,
re-organising an old drives and copying or moving data to new disks. It allows you to create a
maximum of four new primary partition and number of logical (extended) partitions, based on size of
the hard disk you have in your system.

1. View all Disk Partitions in Linux


The following basic command list all existing disk partition on your system. The ‘-l‘ argument stand
for (listing all partitions) is used with fdisk command to view all available partitions on Linux. The
partitions are displayed by their device’s names. For example: /dev/sda, /dev/sdb or /dev/sdc.

[root@tecmint.com ~]# fdisk -l

Disk /dev/sda: 637.8 GB, 637802643456 bytes

255 heads, 63 sectors/track, 77541 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sda1 * 1 13 104391 83 Linux

/dev/sda2 14 2624 20972857+ 83 Linux

2. View Specific Disk Partition in Linux


To view all partitions of specific hard disk use the option ‘-l‘ with device name. For example, the
following command will display all disk partitions of device /dev/sda. If you’ve different device names,
simple write device name as /dev/sdb or /dev/sdc.

[root@tecmint.com ~]# fdisk -l /dev/sda

Disk /dev/sda: 637.8 GB, 637802643456 bytes

255 heads, 63 sectors/track, 77541 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 18


LINUX ENVIRONMENT SYSTEM UNIT- 1

/dev/sda1 * 1 13 104391 83 Linux

/dev/sda2 14 2624 20972857+ 83 Linux

/dev/sda3 2625 4582 15727635 83 Linux

/dev/sda4 4583 77541 586043167+ 5 Extended

3. Check all Available fdisk Commands


If you would like to view all commands which are available for fdisk. Simply use the following
command by mentioning the hard disk name such as /dev/sda as shown below. The following
command will give you output similar to below.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help):

Type ‘m‘ to see the list of all available commands of fdisk which can be operated on /dev/sda hard
disk. After, I enter ‘m‘ on the screen, you will see the all available options for fdisk that you can be
used on the /dev/sda device

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): m


Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 19
LINUX ENVIRONMENT SYSTEM UNIT- 1

n add a new partition


o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):

4. Print all Partition Table in Linux


To print all partition table of hard disk, you must be on command mode of specific hard disk
say /dev/sda.

[root@tecmint ~]# fdisk /dev/sda

From the command mode, enter ‘p‘ instead of ‘m‘ as we did earlier. As I enter ‘p‘, it will print the
specific /dev/sda partition table.
Command (m for help): p
Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2624 20972857+ 83 Linux
/dev/sda3 2625 4582 15727635 83 Linux
/dev/sda4 4583 77541 586043167+ 5 Extended
/dev/sda5 4583 5887 10482381 83 Linux
/dev/sda6 5888 7192 10482381 83 Linux
/dev/sda7 7193 7845 5245191 83 Linux
/dev/sda8 7846 8367 4192933+ 82 Linux swap / Solaris
/dev/sda9 8368 77541 555640123+ 8e Linux LVM
Command (m for help):
5. How to Delete a Partition in Linux
If you would like to delete a specific partition (i.e /dev/sda9) from the specific hard disk such
as /dev/sda. You must be in fdisk command mode to do this.

[root@tecmint ~]# fdisk /dev/sda

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 20


LINUX ENVIRONMENT SYSTEM UNIT- 1

Next, enter ‘d‘ to delete any given partition name from the system. As I enter ‘d‘, it will prompt me to
enter partition number that I want to delete from /dev/sda hard disk. Suppose I enter number ‘4‘
here, then it will delete partition number ‘4‘ (i.e. /dev/sda4) disk and shows free space in partition
table. Enter ‘w‘ to write table to disk and exit after making new alterations to partition table. The new
changes would only take place after next reboot of system. This can be easily understood from the
below output.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): d


Partition number (1-4): 4
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
You have new mail in /var/spool/mail/root

6. How to Create a New Partition in Linux


If you’ve free space left on one of your device say /dev/sda and would like to create a new partition
under it. Then you must be in fdisk command mode of /dev/sda. Type the following command to
enter into command mode of specific hard disk.

[root@tecmint ~]# fdisk /dev/sda

After entering in command mode, now press “n” command to create a new partition
under /dev/sda with specific size. This can be demonstrated with the help of following given output.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 21


LINUX ENVIRONMENT SYSTEM UNIT- 1

Command (m for help): n


Command action
e extended
p primary partition (1-4)
e

While creating a new partition, it will ask you two options ‘extended‘ or ‘primary‘ partition creation.
Press ‘e‘ for extended partition and ‘p‘ for primary partition. Then it will ask you to enter following
two inputs.
 First cylinder number of the partition to be create.
 Last cylinder number of the partition to be created (Last cylinder, +cylinders or +size).
You can enter the size of cylinder by adding “+5000M” in last cylinder. Here, ‘+‘ means addition
and 5000Mmeans size of new partition (i.e 5000MB). Please keep in mind that after creating a new
partition, you should run ‘w‘ command to alter and save new changes to partition table and finally
reboot your system to verify newly created partition.
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

7. How to Format a Partition in Linux


After the new partition is created, don’t skip to format the newly created partition using ‘mkfs‘
command. Type the following command in the terminal to format a partition. Here /dev/sda4 is my
newly created partition.

[root@tecmint ~]# mkfs.ext4 /dev/sda4

8. How to Check Size of a Partition in Linux


After formatting new partition, check the size of that partition using flag ‘s‘ (displays size in blocks)
with fdisk command. This way you can check size of any specific device.

[root@tecmint ~]# fdisk -s /dev/sda2

5194304

9. How to Fix Partition Table Order

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 22


LINUX ENVIRONMENT SYSTEM UNIT- 1

If you’ve deleted a logical partition and again recreated it, you might notice ‘partition out of order‘
problem or error message like ‘Partition table entries are not in disk order‘.
For example, when three logical partitions such as (sda4, sda5 and sda6) are deleted, and new
partition created, you might expect the new partition name would be sda4. But, the system would
create it as sda5. This happens because of, after the partition are deleted, sda7 partition had been
moved as sda4 and free space shift to the end.
To fix such partition order problems, and assign sda4 to the newly created partition, issue the ‘x‘ to
enter an extra functionality section and then enter ‘f‘ expert command to fix the order of partition
table as shown below.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): x


Expert command (m for help): f
Done.
Expert command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
After, running ‘f‘ command, don’t forget to run ‘w‘ command to save and exit from fdisk command
mode. Once it fixed partition table order, you will no longer get error messages

VII. SWAP SPACE AND ITS MANAGEMENT :

Linux divides its physical RAM (random access memory) into chucks of memory called pages.
Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard
disk, called swap space, to free up that page of memory. The combined sizes of the physical memory
and the swap space is the amount of virtual memory available.
Swapping is necessary for two important reasons. First, when the system requires more memory than
is physically available, the kernel swaps out less used pages and gives memory to the current
application (process) that needs the memory immediately. Second, a significant number of the pages
used by an application during its startup phase may only be used for initialization and then never used
again. The system can swap out those pages and free the memory for other applications or even for
the disk cache.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 23


LINUX ENVIRONMENT SYSTEM UNIT- 1

Linux has two forms of swap space: the swap partition and the swap file. The swap partition is an
independent section of the hard disk used solely for swapping; no other files can reside there. The
swap file is a special file in the filesystem that resides amongst your system and data files.
To see what swap space you have, use the command swapon -s. The output will look something like
this:
Filename Type Size Used Priority
/dev/sda5 partition 859436 0 -1
NOTE: 'Priority' tells Linux which swap space to use first.

One great thing about the Linux swapping subsystem is that if you mount two (or more) swap spaces
(preferably on two different devices) with the same priority, Linux will interleave its swapping activity
between them, which can greatly increase swapping performance.

To add an extra swap partition to your system, you first need to prepare it. Step one is to ensure that
the partition is marked as a swap partition and step two is to make the swap filesystem. To check that
the partition is marked for swap, run as root:
fdisk -l /dev/hdb
Replace /dev/hdb with the device of the hard disk on your system with the swap partition on it. You
should see output that looks like this:

Device Boot Start End Blocks Id System


/dev/hdb1 2328 2434 859446 82 Linux swap / Solaris
If the partition isn't marked as swap you will need to alter it by running fdisk and using the 't' menu
option.
Once a partition is marked as swap, you need to prepare it using the mkswap (make swap) command
as root:
mkswap /dev/hdb1
If you see no errors, your swap space is ready to use. To activate it immediately, type:
swapon /dev/hdb1
You can verify that it is being used by running swapon -s.
To check that your swap space is being automatically mounted without having to reboot, you can run
the swapoff -a command (which turns off all swap spaces) and then swapon -a (which mounts all swap
spaces listed in the /etc/fstab file) and then check it with swapon -s.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 24


LINUX ENVIRONMENT SYSTEM UNIT- 1

Swap file :
As well as the swap partition, Linux also supports a swap file that you can create, prepare, and mount
in a fashion similar to that of a swap partition. The advantage of swap files is that you don't need to
find an empty partition or repartition a disk to add additional swap space.
To create a swap file, use the dd command to create an empty file. To create a 1GB file, type:
dd if=/dev/zero of=/swapfile bs=1024 count=1048576
/swapfile is the name of the swap file, and the count of 1048576 is the size in kilobytes (i.e. 1GB).
Prepare the swap file using mkswap just as you would a partition, but this time use the name of the
swap file:
mkswap /swapfile
And similarly, mount it using the swapon command: swapon /swapfile.
The /etc/fstab entry for a swap file would look like this:
/swapfile none swap sw 0 0

VIII. File System and Directory Structure in linux

The Linux File System

All users including the superuser have their own home directories where all private data, like
documents, bookmarks, or e-mail, are stored. System directories holding central configuration files or
executable files can only be modified by the superuser. A file manager provides a graphical and more
intuitive way to handle these tasks. Learn more about the file managers of GNOME and KDE
in GNOME User Guide and KDE User Guide. Whatever method you choose: the following sections
provide you with some basic knowledge of the file system and provide an overview of the default
directory structure in Linux.

In Linux, all files and directories are located in a tree-like structure. The topmost directory is referred
to as the file system root or just / (not to be confused with the root user). The counterpart of / in a
Windows system would probably be C:\. All other directories in Linux can be accessed from the root
directory and are arranged in a hierarchical structure.

Specifying Paths : As opposed to Windows, Linux does not use backslashes to separate the
components of a pathname, it uses slashes instead. For example, the private data of users in Windows
may be stored under C:\My Documents\Letters, whereas in Linux it would be stored
under /home/username/Letters.

Partitions, Drives/Devices and Directories :Linux does not use drive letters as Windows does. From
the mere appearance of a pathname in Linux you can not tell whether you are addressing a partition,
a drive/device, a network device or an “ordinary” directory.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 25


LINUX ENVIRONMENT SYSTEM UNIT- 1

Mounting and Unmounting : Another crucial difference between Windows/DOS and Linux is the
concept of mounting andunmounting partitions, drives or directories. Windows detects partitions and
drives during the boot process and assigns a drive letter to them. In Linux however, partitions or
devices are usually not visible in the directory tree unless they are mounted, that means integrated into
the file system at a specific location in the directory tree.

During the installation of your system, you can define partitions to be mounted automatically when
the system is started. Removable devices are usually also detected and mounted automatically by your
system the desktop environments such as KDE or GNOME will inform you about the appearance of
a new device.

Case-Sensitivity : Linux distinguishes between uppercase and lowercase letters in the file system. For
example, whether you name a file test.txt, TeST.txt or Test.txt make a difference in Linux. This also
holds true for directories: You cannot access a directory named Letters by the name letters.

File Extensions : As opposed to Windows, files in Linux may have a file extension, such as .txt, but do
not need to have one. When you start working with the shell this sometimes makes it difficult for
beginners to differentiate between files and folders, depending on the command you use to list the
contents of a directory.

Hidden Files :Similar to Windows, Linux also distinguishes between “normal” files and hidden
files which are often configuration files that you usually do not want to access or see as a normal user.
In Linux, hidden files are indicated by a dot in front (for example, .hiddenfile).

File System Permissions : Because Linux is a multiuser system, every file in a Linux file system
belongs to a user and a group. Only the owner of a file or directory (or, of course, root) can grant
other users access permission to it. Linux basically distinguishes between three different types of
access permissions: write permission, read permission and execute permission.

The Directory Structure

The following table provides a short overview of the most important higher-level directories you find
on a Linux system. Find more detailed information about the directories and important subdirectories
in the following list.

Table 7.1. Overview of a Standard Directory Tree

Directory Contents
/ Root directory—the starting point of the directory tree.
Essential binary files, such as commands that are needed by both the system administrator
/bin
and normal users. Usually also contains the shells, such as Bash.
/boot Static files of the boot loader.
/dev Files needed to access host-specific devices.
/etc Host-specific system configuration files.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 26


LINUX ENVIRONMENT SYSTEM UNIT- 1

Directory Contents
/lib Essential shared libraries and kernel modules.
/media Mount points for removable media.
/mnt Mount point for temporarily mounting a file system.
/opt Add-on application software packages.
/root Home directory for the superuser root.
/sbin Essential system binaries.
/srv Data for services provided by the system.
/tmp Temporary files.
/usr Secondary hierarchy with read-only data.
/var Variable data such as log files
Only available if you have both Microsoft Windows* and Linux installed on your system.
/windows
Contains the Windows data.

IX.MULTIPROCESSING:
A multiprocessing system consists of a number of processors communicating via a bus or a
network. There are two types of multiprocessing systems: loosely coupled and tightly coupled.

Loosely-coupled multiprocessing architecture

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 27


LINUX ENVIRONMENT SYSTEM UNIT- 1

Loosely coupled systems consist of processors that operate stand-alone. Each processor has its own
bus, memory, and I/O subsystem, and communicates with other processors through the network
medium. Loosely coupled systems can be either homogeneous or heterogeneous.

Tightly-coupled multiprocessing architecture


Tightly coupled systems consist of processors that share the memory, bus, devices, and sometimes
cache. Tightly coupled systems run a single instance of the operating system. Tightly coupled systems
can be classified into symmetric and asymmetric systems. Asymmetric systems are configured so that
each processor is assigned a specific task. Asymmetric systems have a single "master" processor that
controls all others. Symmetric systems treat all processors the same way—processes have equal access
to all system resources. In the symmetric model, all tasks are spread equally across all processors.

Symmetric systems are subdivided into further classes consisting of dedicated and shared cache
systems. Symmetrical Multiprocessing (SMP) systems have become very popular and have become
the default choice for many large servers.

X.LOAD SHARING AND MULTI THREADING IN LINUX

Thread is an execution unit which consists of its own program counter, a stack, and a set of registers.
Threads are also known as Lightweight processes. Threads are popular way to improve application
through parallelism. The CPU switches rapidly back and forth among the threads giving illusion that
the threads are running in parallel.
As each thread has its own independent resource for process execution, multpile processes can be
executed parallely by increasing number of threads.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 28


LINUX ENVIRONMENT SYSTEM UNIT- 1

Types of Thread: There are two types of threads :

 User Threads
 Kernel Threads

User threads, are above the kernel and without kernel support. These are the threads that application
programmers use in their programs.
Kernel threads are supported within the kernel of the OS itself. All modern OSs support kernel level
threads, allowing the kernel to perform multiple simultaneous tasks and/or to service multiple kernel
system calls simultaneously.
Multithreading Models:

The user threads must be mapped to kernel threads, by one of the following strategies.

 Many-To-One Model
 One-To-One Model
 Many-To-Many Model

Many-To-One Model

 In the many-to-one model, many user-level threads are all mapped onto a single kernel thread.
 Thread management is handled by the thread library in user space, which is efficient in nature.

One-To-One Model

 The one-to-one model creates a separate kernel thread to handle each and every user thread.
 Most implementations of this model place a limit on how many threads can be created.
 Linux and Windows from 95 to XP implement the one-to-one model for threads.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 29


LINUX ENVIRONMENT SYSTEM UNIT- 1

Many-To-Many Model

 The many-to-many model multiplexes any number of user threads onto an equal or smaller
number of kernel threads, combining the best features of the one-to-one and many-to-one models.
 Users can create any number of the threads.
 Blocking the kernel system calls does not block the entire process.
 Processes can be split across multiple processors.

Thread Libraries

Thread libraries provides programmers with API for creating and managing of threads.
Thread libraries may be implemented either in user space or in kernel space. The user space involves
API functions implemented solely within user space, with no kernel support. The kernel space
involves system calls, and requires a kernel with thread library support.

There are three types of thread :

 POSIX Pitheads, may be provided as either a user or kernel library, as an extension to the POSIX
standard.
 Win32 threads, are provided as a kernel-level library on Windows systems.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 30


LINUX ENVIRONMENT SYSTEM UNIT- 1

 Java threads - Since Java generally runs on a Java Virtual Machine, the implementation of threads is
based upon whatever OS and hardware the JVM is running on, i.e. either Pitheads or Win32
threads depending on the system

Benefits of Multithreading

1. Responsiveness
2. Resource sharing, hence allowing better utilization of resources.
3. Economy. Creating and managing threads becomes easier.
4. Scalability. One thread runs on one CPU. In Multithreaded processes, threads can be distributed
over a series of processors to scale.
5. Context Switching is smooth. Context switching refers to the procedure followed by CPU to change
from one task to another.

Multithreading Issues

1. Thread Cancellation: Thread cancellation means terminating a thread before it has finished
working. There can be two approaches for this, one is Asynchronous cancellation, which terminates
the target thread immediately. The other is Deferred cancellation allows the target thread to
periodically check if it should be cancelled.
2. Signal Handling: Signals are used in UNIX systems to notify a process that a particular event has
occurred. Now in when a Multithreaded process receives a signal, to which thread it must be
delivered? It can be delivered to all, or a single thread.
3. fork() System Call: fork() is a system call executed in the kernel through which a process creates a
copy of itself. Now the problem in Multithreaded process is, if one thread forks, will the entire
process be copied or not?
4. Security Issues because of extensive sharing of resources between multiple threads.

There are many other issues that you might face in a multithreaded process, but there are appropriate
solutions available for them.

XI. TYPES OF USERS IN LINUX:

User :From the beginning, Linux has been designed as a multiuser system: Any number of users can
simultaneously work on one machine. These users can connect to the system via different terminals
or network connections. Usually users need to log in to the system before starting a session. Personal
information and individual desktop configuration are stored separately for any user.

Distinct User Roles

Among the users working on a machine, Linux distinguishes between different kinds of user roles:
you can log in to a Linux machine as “normal” user or as superuser (administrator), traditionally
called root in Linux and group users.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 31


LINUX ENVIRONMENT SYSTEM UNIT- 1

The superuser has privileges which authorize him to access all parts of the system and to execute
administrative tasks: He has the unrestricted capacity to make changes to the system and has
unlimited access to all files. If you are logged in as a normal user you lack these privileges. User
and root can of course be the same physical person but acting in different roles.

The root user account is always created on your Linux system by default — during installation you are
therefore requested to specify a password for root. Which other users can log in to your system
depends on the method of authentication you choose during installation.

For your daily work, you usually log in to your system as normal user. Performing some administrative
tasks or running certain programs such as require root permissions. You can easily switch from your
normal account to root and back to your normal user account after accomplishing the administrative
task.

If you are working with a graphical user interface you are usually prompted to enter
the root password when necessary. Closing the application which required root permissions results in
withdrawal of the root privileges: you automatically switch back to your normal user account.

Groups

Every user in a Linux system belongs at least to one group. A group, in this case, can be defined as a
set of connected users with certain collective privileges. Groups are usually defined according to
functional roles or the data and resources the members of the group need to access. When a new user
account is created on your system, the user is usually assigned to a default, primary group. The system
administrator can change this primary group or assign the user to an additional group, if necessary.

Managing Users and Groups


There are four main user administration files −
 /etc/passwd −Keeps the user account and password information. This file holds the majority of
information about accounts on the Unix system.
 /etc/shadow − Holds the encrypted password of the corresponding account. Not all the systems
support this file.
 /etc/group −This file contains the group information for each account.
 /etc/gshadow −This file contains secure group account information.
To add a user:
Syntax : sudo adduser username
Ex: $: sudo adduser ramu
$ sudo vim /etc/passwd or $ cat /etc/ passwd ( to display the existing users)
To delete a user:
Syntax : sudo userdel username
Ex: $: sudo userdel ramu

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 32


LINUX ENVIRONMENT SYSTEM UNIT- 1

$ sudo vim /etc/passwd or $ cat /etc/ passwd ( to display the existing users)
To create a user group:
Syntax : sudo addgroup groupname
Ex: $: sudo addgroup srec
$ sudo vim /etc/ group or $ cat /etc/ group ( to display the existing groups, group
users)
To delete a user group:
Syntax : sudo groupdel groupname
Ex: $: sudo groupdel srec
$ sudo vim /etc/group or $ cat /etc/ group ( to display the existing groups)
To add a user to group:
Syntax : sudo adduser –G username groupname
Ex: $: sudo adduser ramu srec
$ sudo vim /etc/group or $ cat /etc/ group ( to display the existing groups, group
users)
To delete a user from group:
Syntax : sudo deluser username groupname
Ex: $: sudo deluser ramu srec
$ sudo vim /etc/group or $ cat /etc/ group ( to display the existing groups, group
users)
FILE PERMISSIONS: In linux, different users has different file permissions. To know the file
permissions of various users, the following command can be used.
$ ls –l file1.txt
-rwxr-xr-x . 2 srec srec 4096 jan 10:05 downloads
To change permissions, we can use chmod command.
$ sudo chmod desired file permissions file name.
File permissions can be
DECIMAL BINARY PERMISSION DESCRIPTION
R W X
0 0 0 0 User do not have any permissions
1 0 0 1 User has execute permission.
2 0 1 0 User has only write permission.
3 0 1 1 User has both write and execute

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 33


LINUX ENVIRONMENT SYSTEM UNIT- 1

permission.
4 1 0 0 User has only read permission.
5 1 0 1 User has read and execute permission.
6 1 1 0 User has read and write permission.
7 1 1 1 User has read, write and execute
permission.

Example: $ chmod 777 file1.txt , it sets every user ( owner, group, others ) can have all the three
permissions.
$ ls –l file1.txt
-rwxrwxrwx . 2 srec srec 4096 jan 10:05 downloads.

XII. CAPABILITIES OF SUPER USER


The Linux super user, or root user, is a special user that has tremendous power, with the ability to
access and modify all files on the operating system. This is necessary at times, but there is a potential
for accidental errors to cause a great deal of destruction, so you have to be careful. Fot the times when
the super user’s power is necessary, we’ll look at safer ways to be the super user on your Linux
dedicated server.

Super User and Sudo


A really important feature of Linux is privileges. It’s part of the security, and controls which users can
access, manipulate or even be aware of what files. Logged in with the user account we’ve created will
allow safe usage of the operating system, but there are times when the privileges of the root, or super
user are required.

There are two ways to access super user privileges. The first is with the su command.

$ su –

If you enter this command, and note the hyphen, then you will be prompted for the root user’s
password. Enter it correctly, and you will be logged in as the super user. You can then perform what
tasks you need to, but with care! When you’ve finished, log out immediately using the exit command.

The second way to get super user privileges is to use sudo. This is a method by which a regular user
can gain a temporary privilege boost. It takes a little setting up, but once done it is probably safer than
the su command method.

First, log in to your server. Then, log in as root using the su command. Then, enter the following.

$ vi sudo

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 34


LINUX ENVIRONMENT SYSTEM UNIT- 1

This will open up a text file that contains information for sudo. A little way down the file you’ll see the
following text.

# User privilege specification

root ALL=(ALL) ALL

You need to add yourself to the file in order to get your privileges. To do this, you need to do a little
editing. Use the arrow keys to move the cursor to this line, then press i on the keyboard. You’re now
editing the file, so enter the following line:

YourUserName ALL=(ALL) ALL

Of course substitute your user name for YourUserName, then press escape, and type ZZ (capital Z
twice). This will save the file, and that’s it. If you’ve done it right, you can now use sudo. To test this,
log out as the root user (type exit, hit return), then try the following.

$ ls /root

You should receive an error message telling you that permission is denied. So, try it with sudo.

$ sudo ls /root

Now you will be asked for a password. Enter your own password at this point (not the root password)
and hey presto, you’ll be presented with a listing of the root user’s directory. So, any time that you
wish to do something that requires root user privileges, remember that you can use the sudo
command, saving you from logging in as the root user.

Logging out
To log out of your ssh session, and so your server, at any time, type:

$ exit

If you are logged in as the super user having used the su command, remember that you may need to
type this twice.

Dr. S.Md.Farooq, Associate Professor, Dept of CSE, SREC Page 35

You might also like