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

Linux Complete BCA Notes PDF

The document provides an overview of Linux, detailing its history, structure, advantages, and disadvantages. It explains the evolution from UNIX to Linux, highlighting key figures like Linus Torvalds and the significance of the GNU project. Additionally, it discusses Linux's components, such as the kernel, system libraries, and tools, along with various file systems like FAT, NTFS, and ext, emphasizing Linux's open-source nature and its applications across diverse devices.

Uploaded by

vedratnab9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Linux Complete BCA Notes PDF

The document provides an overview of Linux, detailing its history, structure, advantages, and disadvantages. It explains the evolution from UNIX to Linux, highlighting key figures like Linus Torvalds and the significance of the GNU project. Additionally, it discusses Linux's components, such as the kernel, system libraries, and tools, along with various file systems like FAT, NTFS, and ext, emphasizing Linux's open-source nature and its applications across diverse devices.

Uploaded by

vedratnab9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 110

Unit I: Introduction of Linux - Linux

History of Linux:
In earlier days, computers were as big as houses or parks. So we can imagine how
difficult it was to operate them. Moreover, every computer has a different operating
system which made it completely worse to operate on them.
Every software was designed for a specific purpose and was unable to operate on
another computer. It was extremely costly and normal people neither can afford it nor
can understand it.
In 1969, a team of developers of Bell Labs started a project to make a common software
for all the computers
and named it as
'Unix'. It was simple
and elegant, used 'C'
language instead of
assembly language
and its code was
recyclable.
As it was recyclable, a
part of its code now
commonly called
'kernel' was used to
develop the
operating system and
other functions and
could be used on
different systems. Also, its source code was open source.
Initially, UNIX was only found in large organizations like government, university, or
larger financial corporations with mainframes and minicomputers (PC is a
microcomputer).

Fig: History of Linux Operating System


In the eighties, many organizations like IBM, HP and a dozen other companies started
creating their own UNIX. It results in a mess of UNIX dialects (vocabulary). Then in 1983,
Richard Stallman developed GNU project intending to make it freely available UNIX
like operating system and to be used by everyone.
But his project failed in gaining popularity. Many other UNIX like operating system came
into existence but none of them was able to gain popularity.
In 1991, Linus Torvalds a student at the University of Helsinki, Finland, thought to
have a freely available academic version of Unix started writing its own code.

www.ckundan.com.np 1

Later this project became the Linux kernel. He wrote this program especially for his
own PC as he wanted to useUnix 386 Intel computer but couldn't afford it. He did it on
MINIX using GNU C compiler.
GNU C compiler is still the main choice to compile Linux code but other compilers are
also used like Intel C compiler. He started it just for fun but ended up with such a large
project. Firstly he wanted to name it as 'Freax' but later it became 'Linux'.
He published the Linux kernel under his own license and was restricted to use as
commercially. Linux uses most of its tools from GNU software and is under GNU
copyright. In 1992, he released the kernel under GNU General Public License.
Today, supercomputers, smartphones, desktop, web servers, tablet, laptops and home
appliances like washing machines, DVD players, routers, modems, cars, refrigerators, etc.
use the Linux Operating System.

Introduction of Linux:
In the simple language Linux is an operating system. We all are familiar with other
operating systems like Microsoft Windows, Apple Mac OS, iOS, Google android, etc. just
like them, Linux is also an operating system.
An operating system is a software that enables communication between computer
hardware and software. It conveys input to get processed by the processor and brings
output to the hardware to display it. This is the basic function of an operating system.
Linux is around us since the mid-90s. It can be used from wristwatches to
supercomputers. It is everywhere in our phones, laptops, PCs, cars and even in
refrigerators. It is very much famous among developers and normal computer users.

Fig: Linux Distributions

www.ckundan.com.np 2

Structure of the Linux Operating System:


An operating system is a collection of software, each designed for a specific function.
Linux OS has the following components:
Fig: Structures of Linux Operating System

1. Kernel:
Kernel is the core of the operating system. It establishes communication between
devices and software. Moreover, it manages system resources. Basically, it has four
responsibilities:
A. Device Management:
A the system has many devices connected to it like CPU, a memory device, sound cards,
graphic cards, etc. A kernel stores all the data related to all the devices in device driver
(without this kernel won't be able to control the devices).
Thus kernel knows what a device can do and how to manipulate it to bring out the best
performance. It also manages communication between all the devices. The kernel has
certain rules that have to be followed by all the devices.

B. Memory Management:
Another a function that kernel has to manage is the memory management. Kernel keeps
a track of used and unused memory and make sure that processes shouldn't manipulate
data of each other using virtual memory address.

www.ckundan.com.np 3

C. Process Management:
In process management kernel assign enough time and gives priorities to processes
before handling CPU to another process. It also deals with security and ownership
information.

D. Handling System Calls:


Handling system calls mean a programmer can write a query or ask the kernel to
perform a task.

2. System Libraries:
System libraries are special programs that help in accessing the kernel's features. A
kernel has to be triggered to perform a
task and this triggering is done by
the applications. But applications must
know how to place a system call because
each kernel has a different set of
system calls.
Programmers have developed a standard
library of procedures to communicate with
the kernel. Each operating system
supports these standards and then
these are transferred to system calls for that
operating system. Most well-known
system library for Linux is Glibc (GNU C
library).

3. System Tools:
Linux OS has a set of utility tools which are usually simple commands. It is a software
which GNU project has written and publish under their open source license so that
software is freely available to everyone.
With the help of commands, we can access our files, edit and manipulate data in our
directories or files, change the location of files or anything.

4. Development Tools:
With the above three components our OS is running and working. But to update our
system we have additional tools and libraries. These additional tools and libraries are
written by the programmers and are called toolchain. A toolchain is a vital development
tool used by the developers to produce a working application.

5. End-User Tools:
These end tools make a system unique for a user. End tools are not required for the
operating system but are necessary for a user. Some examples of end tools are graphic
design tools, office suites, browsers, multimedia players, etc.

www.ckundan.com.np 4

Advantages of Linux:
1. Low Cost:
We don’t need to spend time and money to obtain licenses since Linux and much of its
software come with the GNU General Public License.
We can start to work immediately without worrying that our software may stop working
anytime because the free trial version expires. Additionally, there are large repositories
from which we can freely download high-quality software for almost any task we can
think of.

2. Stability:
Linux doesn’t need to be rebooted periodically to maintain performance levels. It doesn’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 on networks. It can
handle unusually large numbers of users simultaneously, and can make old computers
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.

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

6. Choice:
A large number of Linux distributions gives us a choice. Each distribution is developed
and supported by a different organization. We can pick the one we like best; the core
functionalities are the same; most software runs on most distributions.

www.ckundan.com.np 5

7. 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.

8. 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 our other work.

9. 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.

10. Open Source:


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

Disadvantages of Linux:
1. No Standard Edition:
There’s no standard edition of Linux. Whereas Microsoft offers several different editions
of each version of Windows, there are countless variations of Linux. For a new user, it can
be confusing to work out which is best for us.

2. Patchier Support for Drivers:


Linux has patchier support for drivers (the software which coordinates our hardware
and our operating system). This means we’ll sometimes find it trickier to get a new
device set up.

www.ckundan.com.np 6

3. Not User-Friendly:
Linux is, for new users at least, not as easy to use as Windows. That’s largely because
Linux gives us more control but does mean we’ll have to spend some time getting used to
the way it works.

4. Hard to Get Desired Help:


Because Linux is neither as popular as Windows, nor a commercial product, support
works in a different way. We may have to look harder to find the answer to a problem
and, while Linux supporters are more likely to offer help, it may not always match our
own level of technical understanding.
FAT (File Allocation
Table):
This a file system is one of the most
simple types of file systems. It consists of
a file system descriptor sector
(boot sector or superblock), file
system block allocation table
(referenced as File Allocation Table) and
plain storage space to store files and
folders.
The files on FAT are stored in directories.
Each directory is the array of 32-byte
records, each defines file or file extended attributes (like long filename). File record
references the first block of the file. Any next block could be found through block
allocation table by using it as linked-list.
Block allocation table contains an array of block descriptors. Zero value indicates the
block is not used and non-zero indicates a reference to the next block of the file or
special value for end of the file.
The number in FAT12, FAT16, and FAT32 file system name means how many bits are
used to number file system block. This means that FAT12 may use up to 4096 different
block references, FAT16 - 65536 and FAT32 - 4294967296. Actual maximum count of
blocks is even less and depends on file system driver implementation.

Version of FAT File System:


a. FAT 12: The initial version of FAT introduced in 1977. Primary file system for
Microsoft System up to MS-DOS 4.0

b. FAT 16: Introduced in 1988, a primary file system for MS-DOS 4.0 up to Windows
95. Support drive size up to 2 GB.

c. FAT 32: Latest version of FAT, introduced in 1996 for Windows 95 OSRL Users.
Support drive size up to 8TB.

www.ckundan.com.np 7

Applications:
FAT12 was used for old floppy disks. FAT16 (or simply FAT) and FAT32 are widely used
for flash memory cards, USB flash sticks and so on. It is supported by mobile phones,
digital cameras and other portable devices.
FAT or FAT32 could be identified as the file system, used on Windows compatible
external storages or disk partitions with size below 2GB (for FAT) or 32GB (for FAT32).
Windows cannot create even FAT32 file system over 32GB (however Linux supports
FAT32 up to 2TB).

NTFS (New Technology File System):


It was introduced in Windows NT and at present is the main file system for Windows. It
is default file system for disk partitions and
the only one file system that is
supported for disk partitions over 32GB.
The file system is quite extensible and
supports many file properties, including
access control, encryption etc. Each
file on NTFS has stored as file
descriptor in Master File Table and file
content. Master file table contains all
information about the file: size,
allocation, name and so on.
The first and the last sectors of the file
system contain file system settings (the
boot record or superblock). The file
system uses 48 and 64-bit values to
reference files thus it supports quite large disk storages.

Features:
a. It uses 64-bit disk addresses and can support disk partitions up to 264 bytes. b.
Individual file names in NTFS are limited to 255 characters. Case sensitive names. c.
Encryption & Data recovery.
d. Compression.
e. File-level security.
f. File Encryption: Encrypting file system is used to encrypt files in NTFS. Generally,
Public Key cryptography is used.
g. Data Recovery: It offers a data recovery mechanism.
h. File Compression: NTFS can perform data compression on individual files or on
all data files in a directory.
i. Security: NTFS allows for file-level security. With NTFS permissions, one can
control which users have what kind of access to which files. Security can be
assigned at two different levels: Per user basis and on a group basis Network File
System (NFS)

www.ckundan.com.np 8
Network File System (protocol):
Network File System (NFS) is a network file system protocol originally developed by
Sun Microsystems in 1984, allowing a user on a client computer to access files over a
network in a manner similar to how local storage is accessed.
NFS, like many other protocols, builds on the Open Network Computing Remote
Procedure Call (ONC RPC) system. The Network File The system is an open standard
defined in RFCs, allowing anyone to implement the protocol.

NFS Protocols:
NFS accomplishes two client-server protocol:
a. The Mount Protocol: It handles mounting.
b. The NFS Protocols: Which is for
directory & file access.
Daemons NFS server
daemons (NFSD) Accept RPC
calls from client.

Extended File
System (Ext):
Introduction of
Extended File
System (Ext):
The extended file system (ext), was released on April 1992 as the first file system using
the VFS API and was included in Linux version 0.96c.

Features:
a. Allowed 2 gigabytes of data.
b. Filenames of up to 255 characters.
c. Limitation of Ext: There was no support for separate access i-node modification
and data modification timestamps.

Solution:
A new file systems were developed in January 1993 by RémyCard.
Second Extended File System (Ext2):
The Second Extended File system was devised as an extensible and powerful file system
for Linux. It is also the most successful file system so far in the Linux community and is
the basis for all of the currently shipping Linux distributions.

www.ckundan.com.np 9

a. Ext2 data structures


b. Physical Layout of the EXT2 File system
c. i-node structure of ext-2

Features of Ext2:
a. POSIX, ACL and extended attribute were first introduced.
b. Journaling not allowed with flash drives.

Disadvantages:
a. Limit of sublevel directory 32768.
b. Cannot handle file larger than 2TB.
c. Block size is limited by architecture.

Third Extended File


System (Ext3):
The ext3 or third extended file system is a
journaled file system that is commonly
used by the Linux kernel. It is the default file
system for many popular Linux
distributions, including Debian.
Stephen Tweedie first revealed that he was
working on extending ext2 in
Journaling the Linux ext2fs File system in
a 1998 paper and later in a February 1999
kernel mailing list posting, and the file system was merged with the mainline Linux
kernel in November 2001 from 2.4.15 onward.

Disadvantages:
a. Functionality
b. Defragmentation
c. Compression
d. No check summing in a journal.

Fourth Extended File System (Ext4):


Ext4 is the evolution of the most used Linux file system Ext3. In many ways, Ext4 is a
deeper improvement over Ext3 than Ext3 was over Ext2.
Ext3 was mostly about adding journaling to Ext2, but Ext4 modifies important data
structures of the file system such as the ones destined to store the file data. The result is
a file system with an improved design, better performance, reliability, and features.

www.ckundan.com.np 10

Features:
a. Compatibility (the file system can continue to be mounted as ext3). This allows
users to still read the file system from other distributions/operating systems
without ext4 support (e.g. Windows with ext3 drivers).
b. Improved performance (though not as much as a fully-converted ext4 partition)

Culture of Free Software:


The culture of free software development from which Linux has thrived (flourished) and
will continue to thrive. The copyright for Fedora and Red Hat Enterprise Linux systems
is covered under the GNU public license.
Fig: The Culture of Free Software

Free Software Provides The


Following: 1. Author Rights:
The original author retains the rights to his or her software.

2. Free Distribution:
People can use the GNU software in their own software, changing and redistributing it as
they please. They do, however, have to include the source code with their distribution (or
make it easily available).

3. Copyright Maintained:
Even if we were to repackage and resell the software, the original GNU agreement must
be maintained with the software. This means that all future recipients of the software
must have the opportunity to change the source code, just as we did.
www.ckundan.com.np 11

It is important to remember that there is no warranty on GNU software. If something


goes wrong, the original developer of the software has no obligation to fix the problem.
However, the Linux culture has provided resources for that event.
Experts on the Internet can help us iron out our problems, or we can access one of the
many Linux newsgroups or forums to read how others have dealt with their problems
and to post our own questions about how to fix ours. Chances are that someone will
know what to do, maybe even going so far as to provide the software or configuration
file we need.

NOTE:
The GNU project uses the term free software to describe the software that is covered by
the GNU license. Many Linux proponents tend to use the term open-source software to
describe software. Although source code
availability is part of the GNU license, the
GNU project claims that software-defined
as open-source is not the same as free
software because it can encompass
semi-free programs and even some
proprietary programs.
www.ckundan.com.np 12

Unit II: Basics of Linux - Linux

Linux Commands:
A. Common Linux Commands:
Fig: Common Linux Commands

1. pwd
When we first open the terminal, we are in the home directory of our user. To know
which directory we are in, we can use the “pwd” command. It gives us the Absolute Path,
which means the path that starts from the root.
The root is the base of the Linux filesystem. It is denoted by a forward slash (/). The user
directory is usually something like /home/username.
2. ls
The “Is” command is used to know what files are there in the directory we are in. We can
see all the hidden files by using the command “ls -a”.

www.ckundan.com.np 1

3. cd
“cd” is the command used to go to a directory. For example, if we are in the home folder,
and we want to go to the Downloads folder, then we can type in “cd Downloads”.
Remember, this command is case sensitive and we have to type in the name of the folder
exactly as it is. But there is a problem with these commands. Imagine we have a folder
named “Raspberry Pi”.
In this case, when we type in “cd Raspberry Pi”, the shell will take the second argument
of the command as a different one, so we will get an error saying that the directory does
not exist. Here, we can use a backward slash.
That is, we can use “cd Raspberry\ Pi” in this case. Spaces are denoted like this: If we
just type “cd” and press Enter, it takes us to the home directory. To go back from a folder
to the folder before that, we can type “cd ..”. The two dots represent back.
4. mkdir and rmdir
The mkdir command is used when we need to create a folder or a directory. For
Example, if we want to make a directory called “DIY”, then we can type “mkdir DIY”.
Remember, as told before, if we want to create a directory named “DIY Hacking”, then
we can type “mkdir DIY\ Hacking”. rmdir is the command used for deleting a directory.
But, rmdir can only be used to delete an empty directory. To delete a directory
containing files, rm is used.

5. rm
The rm command is used to delete files and directories. rm cannot simply delete a
directory. “rm -r” is used to delete a directory. In this case, it deletes both the folder and
the files in it.

www.ckundan.com.np 2
6. touch
The touch command is used to create a file. It can be anything, from an empty txt file to
an empty zip file. For example: “touch new.txt”

7. man and –help


To know more about command and on how to use it, the man command is used. It shows
the manual pages of the command.
For Example, “man cd” shows the manual pages of the cd command. Typing in the
command name and the argument helps it show which ways the command can be used
(Example – cd –help).
8. cp
The cp command is used to copy files through the command line. It takes two arguments,
the first one is the location of the file to be copied, and the second is where to copy.

www.ckundan.com.np 3

9. mv
The mv command is used to move files through the command line. We can also use the
mv command to rename a file.
For example, if we want to rename the file “text” to “new”, we can use “mv text new”. It
takes the two arguments just like the cp command.
10.locate
The locate command is used to locate a file in a Linux system, just like the search
command in Windows.
This command is useful when we don’t know where a file is saved or the actual name of
the file. Using the –i argument with the command, helps to ignore the case (it doesn’t
matter if it is Capital or Small).
So, if we want a file that has the word “hello”, it gives the list of all the files in our Linux
System containing the word “hello” when we type in “locate -i hello”.
If we remember two words, we can separate it using an asterisk (*). For example, to
locate a file containing the words “hello” and “this”, we can use the command “locate – i
*hello*this”

B.Intermediate Commands:
1. echo
“echo” is a command that helps us move some data, usually text into a file. For example,
if we want to create a new text file or add into an already made text file, then we just
need
www.ckundan.com.np 4

to type in “echo hello, my name is alok>> new.txt”. We do not need to separate the
spaces by using the backward slash here because we put in two triangular brackets when
we finish what we need to write.

2. cat
The cat command is used to display the contents of a file, usually used to easily view
programs.

3. nano, vi, jed


nano and vi are already installed text editors in the Linux command line. nano is a good
text editor which denotes keywords with colour and can recognize most of the
languages. vi is simpler than nano. We can create a new file or modify one using this
editor.
For example, if we need to make a new file named “check.txt”, we can create it by using
the command “nano check.txt”. We can save our files after editing by using the
sequence, Ctrl+X, then Y (or N for no).
In my experience, using nano for HTML editing doesn’t seem so good, because of its
colour, so I recommend jed text editor. We will come to installing packages soon.

www.ckundan.com.np 5

4. sudo
sudo is a widely used command in the Linux command line. sudo stands for “SuperUser
Do”. So, if we want any command to be done with administrative or root privileges, then
we can use the sudo command.
For Example, if we want to edit a file like viz. alsa-base.conf which needs root
permissions, we can use the command sudonanoalsa-base.conf. We can enter the root
command line using the command “sudo bash”, then type in our user password.
We can also use the command “su” to do this, but we need to set a root password before
that. For that, we can use the command “sudo passwd”(it wasn’t misspelt, it is passwd).
Then type in the new root password.
5. df
The df command is used to see the available disk space in each of the partitions in our
system. We can just type in df in the command line and we can see each mounted
partition and they are used/available space in % and in KBs. If we want it shown in
megabytes, we can use the command “df -m”

6. du
du is a command to know the disk usage of a file in our System. If we want to know the
disk usage for a particular folder or file in Linux, then we can type in the command df
and the name of the folder or file.
For example, if we want to know the disk space used by the folder Documents in Linux,
we can use the command “du Documents”. We can also use the command “ls -lah” to
view the file sizes of all the files in a folder.
www.ckundan.com.np 6

7. tar
tar is a command used to work with tarballs (or files compressed in a tarball archive) in
the Linux Command-Line. It has a long list of uses. It can be used to compress and
uncompress different types of tar archives like .tar, .tar.gz, .tar.bz2.etc.
It works based on the arguments given to it. For example, tar -cvf for creating a .tar
archive, -xvf to untar a tar archive, -tvf to list the contents of the archive.etc.

8. zip, unzip

zip is a command used to compress files into a zip archive, unzip is used to extract files
from a zip archive.

9. uname
uname is a command used to show the Information about the system our Linux distro is
running. Using the command “uname -a” prints most of the information about the
system. This prints the Kernel release date, version, processor type, etc.
10.apt-get
apt is a command used to work with packages in the Linux command line. apt-get is a
command used to install packages. This requires root privileges, so we use the sudo
command with it.

www.ckundan.com.np 7

For example, if we want to install the text editor jed (as mentioned earlier), we can type
in the command “sudo apt-get install jed”. Similarly, any packages can be installed like
this. It is good to update our repository each time we try to install a new package.
We can do that by typing “sudo apt-get update”. We can upgrade the system by typing
“sudo apt-get upgrade”. We can also upgrade the distro by typing “sudo apt-get
dist-upgrade”. The command “apt-cache search” is used to search for a package. If we
want to search for one, we can type in “apt-cache search jed”(This doesn’t require
root).

11.chmod
chmod is the command used to make a file executable and to change the permissions
granted to it in Linux. Imagine we have a python code-named numbers.py in our
computer, we’ll need to run “python numbers.py” every time we need to run it.
Instead of that, when we make it
executable, we’ll just need to run
“numbers.py” in the terminal to run the
file. To make a file executable, we can
use the command “chmod +x
numbers.py” in this case. We can use
“chmod 755 numbers.py” to give
it root permissions or “sudochmod +x
numbers.py” for root executable.
12. hostname
The hostname is a command used to know our name in our host or our network.
Basically, it displays our hostname and IP address. Typing just “hostname” gives the
output, our hostname. Typing in “hostname -I” gives us our IP address in our network.

13.ping
ping is a command used to check our connection to a server. Wikipedia says that “Ping is
a computer network administration software utility used to test the reachability of a
host on an Internet Protocol (IP) network”.
Simply, when we type in, for example, “ping google.com”, it checks if it can connect to
the server and come back. It measures this round-trip time and gives us the details about

www.ckundan.com.np 8

it. The use of this command for simple users like us is to check our internet connection. If
it pings the Google server (in this case), we can confirm that our internet connection is
active!

C.Linux Important Commands:


Fig: Linux Important Commands

1. Aspell
GNU Aspell is a free and open-source spell checker designed to replace Ispell. It can
either be used as a library or as an independent spell checker.

2. chown
Chown changes file or group ownership and has the option to change ownership of all
objects within a directory tree, as well as having the ability to view information on
objects processed.

3. cmp
The cmp utility compares two files of any type and writes the results to the standard
output. By default, cmp is silent if the files are the same; if they differ, the byte and line
number at which the first difference occurred is reported.

www.ckundan.com.np 9
4. comm
Comm compares lines common to file1 and file2. The output is in three columns; from
left to right: lines unique to file1 lines unique to file2 and lines common to both files.

5. cpio
Cpio copies files into or out of a cpio or tar archive. A tar archive is a file that contains
other files, plus information about them, such as their file name, owner, timestamps and
access permissions. The archive can be another file on the disk, a magnetic tape or a
pipe. Cpio has three operating modes and is a more efficient alternative to tar.

6. CRON
CRON is a Linux system process that
will execute a program at a preset
time. To use CRON, a user must prepare a
text file that describes the
program to be executed and the
times at which CRON should execute them.
Then the crontab program can be used
to load the text file that describes the
CRON jobs into CRON.

7. date
Date sets a system's date and time. This is
also a useful way to output/print current
information when working in a script
file.

8. declare
Declare declares variables, gives them attributes or modifies properties of variables.

9. enable
Enable will stop or start printers or classes.

10.env
Env runs a program in a modified environment or displays the current environment and
its variables.
11.eval
Eval evaluates several arguments, concatenates them into a single command and then
reports on that argument's status.

www.ckundan.com.np 10

12.exec
Exec replaces the parent process with whatever command is typed. This command treats
its arguments as the specification of one or more sub processes to execute.

13.exit
The exit command terminates a script and can return a value to the parent script.

14.expect
Expect talks to other interactive programs according to a script and waits for a response,
often from any string that matches a given pattern.

15.export
Export converts a file into a different format
than the one in which it is currently. Once
a file is exported, it can be accessed by any
application that uses its format.

16. find
Find searches the directory tree to find
particular groups of files that meet specified
conditions, including --name and
--type, -exec and --size and --mtime and --user.

17. for, while


For and while are used to execute or loop items repeatedly as long as certain conditions
are met.
18. free
Free displays the total amount of free and used physical memory and swap space in the
system, as well as the buffers and cache used by the kernel.

19.grep
Grep searches files for a given character string or pattern and can replace the string with
another. This is one method of searching for files within Linux.

www.ckundan.com.np 11

20.gzip
Gzip is the GNU project's open-source program used for file compression, compressing
web pages on the server end for decompression in the browser. This is popular for
streaming media compression and can concatenate and compress several streams
simultaneously.

21.ifconfig
Ifconfig is used to configure the kernel-resident network interfaces. It is used at boot
time to set up interfaces. After that, it is usually only needed when debugging or when
system tuning is needed.

22.ifup
Ifup configures a network interface/enables
a network connection.

23.ifdown
Ifdown shuts down a network
interface/disables a
network connection.

24.less, more
The less command lets an admin scroll through configuration and error log files,
displaying text files one screen at a time, with backwards or forward-moving available in
files. There is more mobility within files. Similar to less, more pages through text one
screen at a time, but is more limited in moving in files.

25.lft
Lft is similar to traceroute in determining connection routes, but provides a lot more
information for debugging connections or finding where a box/system is. Lft also
displays route packets and file types.

26.ln
The ln command creates a new name for a file through hard linking, allowing multiple
users to share one file.

www.ckundan.com.np 12

27.mc
A visual shell, a text-based file manager for UNIX systems.

28. neat
Neat is a GNOME GUI admin tool which allows admins to specify the information needed
to set up a network card, among other features? Setting up an NTL Cable Modem using
neat.

29. netconfig/netcfg
Netconfig configures a network, enables network products and displays a series of
screens that ask for configuration
information.

30. netstat
Netstat provides information and
statistics about protocols in use and
current TCP/IP network connections.
It is a helpful forensic tool in figuring out
which processes and programs are active
on a computer and are involved in
network communications.
31. nslookup
Nslookup allows a user to enter a hostname and find the corresponding IP address. A
reverse of that process to find the hostname is also possible.

32.od
Od is used to dump binary files in octal (or hex/binary) format to standard output.

33.passwd
Passwd updates a user's authentication tokens (changes their current password).

34. read
Read is used to read lines of text from standard input and to assign values of each field in
the input line to shell variables for further processing.

www.ckundan.com.np 13

35.RPM
Red Hat Package Manager (RPM) is a command-line driven program capable of
installing, uninstalling and managing software packages in Linux.

36. rsync
Rsync syncs data from one disk or file to another across a network connection. Rsync is
similar to rcp but has more options.

37.screen
The GNU screen utility is a terminal multiplexor in which a user can use a single terminal
window to run multiple terminal applications or windows.

38.sdiff
Sdiff finds differences between two
files by producing a side-by-side listing
indicating dissimilar lines. Sdiff then
merges the files and outputs results to the
outfile.

39.sed
Sed is a stream editor that is used to filter text in a pipeline, distinguishing it from other
editors. Sed takes text input, performs operations on it and outputs the modified text.
Sed is typically used to extract part of a file using pattern matching or to substitute
multiple occurrences of a string within a file.

40.shutdown
Shutdown is a command that turns off the computer and that can be combined with
variables such as -h, for halt after shutdown, or -r, for a reboot after shutdown.

41. Snort
Snort is an open-source network intrusion detection system and packet sniffer that
monitors network traffic, looking at each packet to detect dangerous payloads or
suspicious anomalies. Snort is based on libpcap. Stopping hackers with Snort.

42.sort
Used to sort lines of text alphabetically or numerically according to fields; multiple sort
keys can also be used.

www.ckundan.com.np 14

43. SSH
SSH is a command interface used for securely gaining access to a remote computer and is
used by network admins to control servers remotely.

44.TOP
TOP is a set of protocols for networks that perform distributed information processing in
offices and displays the tasks on the system that takes up the most memory. TOP can sort
tasks by CPU usage, memory usage and runtime.

45. tr
Tr is used to translate
or delete characters
from a text stream.
Tr writes to standard
output, but does not accept filenames as arguments, it only accepts inputs from standard
input.

46. traceroute
Traceroute determines and records a route through the internet between two computers
and is useful for troubleshooting network/router issues. If the domain does not work or
is not available, an IP can be tracerouted.

47. uniq
Uniq compares adjacent lines in a file and removes/reports any duplicate lines.

48.vmstat
vmstat is used to get a snapshot of everything in a system and to report information on
such items as processes, memory, paging and CPU activity. This is a good method for
admins to use to determine where issues/slowdown in a system maybe occurring.

49.wc
Wc counts the number of words, lines and characters in text files and produces a count
for multiple files if several files are selected.

www.ckundan.com.np 15

50.wget
Wget is a network utility that retrieves files from the web that supports HTTP, https and
FTP protocols. Wget works non-interactively in the background while a user is logged off.
This can create local versions of remote websites, re-creating directories of original sites.

51.whoami
Whoami prints or writes the user/login name associated with the current user ID to the
standard output.

52.xargs
xargs reads build and execute arguments
from standard input; blank lines in the
input is ignored.

Tips and Tricks in


Using Linux Command
Line:
a. We can use clear command to
clear the terminal if it gets
filled up with too many commands!

b. TAB can be used to fill up in


Terminal. For example, we just need
to type “cd Doc” and then TAB and the terminal fills the rest up and makes it “cd
Documents”.

c. Ctrl+C can be used to stop any command in terminal safely. If it doesn’t stop with
that, then Ctrl+Z can be used to force stop it.

d. We can exit from the terminal by using the exit command.

e. We can power off or reboot the computer by using the command sudo halt and
sudo reboot.

Linux Shell:
Shell is a UNIX term for the interactive user interface with an operating system. The shell
is a user program or it is an environment provided for user interaction. It is a command
language interpreter that executes commands read from the standard input device such
as a keyboard or from a file.

www.ckundan.com.np 16

The shell gets started when we log in or open a console (terminal). It is a quick and dirty
way to execute utilities.
A shell usually implies an interface with a command syntax (think of the DOS operating
system and its "C:>" prompts and user commands such as "dir" and "edit").The shell is
not part of system kernel but uses the system kernel to execute programs, create files
etc.
Several Shells Are Available For Linux Including:
1. Bourne Shell:
The original Bourne shell is named after its developer at Bell Labs, Stephen Bourne. It
was the first shell used for the UNIX operating system, and it has been largely surpassed
in functionality by many of the more recent shells.
However, all UNIX and many Linux
versions allow users to switch to the
original Bourne Shell, known simply
as “sh,” if they choose to forgo features such
as file name completion and
command histories that later shells have
added.

Fig: Bourne Shell

2. C Shell:
The C shell, as its name might imply, was designed to allow users to write shell script
programs using a syntax very similar to that of the C programming language. It is known
as "csh."
Fig: C Shell

www.ckundan.com.np 17

3. TC Shell:
TC shell is an expansion upon the C shell. It has all the same features but adds the ability
to use keystrokes from the Emacs word processor program to edit text on the command
line. For example, users can press Esc-D to delete the rest of the highlighted word. It is
also known as "tcsh."
Fig: TC Shell

4. Korn Shell:
Korn Shell was also written by a developer at Bell Labs, David Korn. It attempts to merge
the features of the C shell, TC shell and Bourne shell under one package. It also includes
the ability for developers to create new shell commands as the need arises. It is known
as "ksh."
Fig: Korn Shell

www.ckundan.com.np 18

5. Bourne-Again Shell:
The Bourne-Again shell is an updated version of the original Bourne shell that was
created by the Free Software Foundation for its open-source GNU project. For this
reason, it is a widely used shell in the open-source community.
Fig: Bourne Again Shell

Its syntax is similar to that used by the Bourne shell, however, it incorporates some of
the more advanced features found in the C, TC and Korn shells.
Among the added features that Bourne lacked are the ability to complete file names by
pressing the TAB key, the ability to remember a history of recent commands and the
ability to run multiple programs in the background at once. It is known as "bash."

Text Editor Vi and Pico:


1.Vi Text Editor:
Vi is often the default editor that pops up when we're ready to write an e-mail message
or when we're posting a News message. Vi is complicated and seems difficult to learn at
first. However, it is often the default for UNIX and Linux systems.

www.ckundan.com.np 19

Start the Vi editor by typing vi at the prompt. Typing vi followed by a file name will
automatically name the file so we don't have to worry about it later.
On several other occasions, programs use Vi for text editing. When we post to a
Newsgroup or send e-mail, the system may default to Vi. How do we know when we're
in Vi and when we can use Vi commands?

Vi Has Two Modes:


Command mode that lets us use commands to edit, save, or quit; and Text mode that
lets us type. If we attempt to do something in the wrong mode, the system beeps
furiously at us until we either stop pressing keys or scream (the louder they scream the
more beeps we muffle). Use the Esc key to change from one mode to the other.

Simple Example of
Using Vi:
Vi starts in the Command mode. To
switch to text mode press i. Type out the
text. To make corrections, move to a
location in the text, or save the file, switch
to the command mode by pressing Esc.
In command mode we may edit, save, or
exit (see Command Mode below for
details).To switch back to Text mode,
type i again. Getting the hang of switching
between modes may take a while, so be
patient.
Occasionally, when we're typing quickly, some of our text may seem to disappear.
Actually, our text is still there but has become blacked out. This black-out is usually
caused by a slow screen update, and Vi is notorious for this.
Because the information on our screen is coming through our modem, it needs to be
updated (refreshed) occasionally, or parts of the information disappear from our screen.
To update our screen's information, hold down the Ctrl key and press l (that’s an L, not a
1) while in the Command mode. Do this whenever chunks of our text black-out.

Text Writing Mode:


The Vi editor starts in the Command mode. To switch to the Text mode and begin typing,
press i. If we hear several beeps and we're unable to type, then press i twice to switch to
the text mode.

Command Mode:
Press the Esc key to switch from Text mode to Command mode.

www.ckundan.com.np 20

Moving Around:

Saving and Exiting:


a. Quit Vi without saving anything
(we'll lose any changes we made
when using this command) type:
:q!
b. Save/write the file we're
working on without exiting
type: :w followed by a filename
c. Save/write the file and quit
the vi editor in one step by typing:
:wq
2.Vi Troubleshooting:
Trying to use a command if we’re trying to use a Move, Save, or Edit command but the
command isn’t working, switch from Text mode to Command mode by pressing the Esc
key.
If the backspace key doesn’t work, then hold down the Ctrl key and press backspace.
Trying to save If we get the message No current filename, type :w followed by a filename.
The message appears only if a filename has not been specified. If we get the message is a
directory, we’re trying to write to a directory, not a file. Use a different name for the file
to save it properly.

Pico Text Editor:


Pico is a fairly simple text editor that provides straight-forward options and easy-to-use
commands. Although some programmers have frowned at Pico's simplicity and limited
options, most folks find that it provides everything necessary to write long documents
with minimal hassles.
However, Pico is not very good when manipulating certain types of files such as making
changes to .cgi files etc.

www.ckundan.com.np 21

Start the Pico editor by typing pico at the prompt. Typing pico followed by a file name
automatically names the file so we don't
have to worry about it later. Example: pico
newfile.txt
Using Pico is fairly straight-forward. The blinking cursor indicates where we may begin
typing. We type out our message without worrying about line breaks or page breaks.
Pico takes care of these for us.
When we're finished typing, or anytime we're ready to use a Pico command, refer to the
Pico menu options, listed at the bottom of the screen.
To use an option, hold down the Ctrl key and press the letter indicated. The ^ symbol
represents the Ctrl key. Example: To use the option ^G Get Help, hold down the Ctrl key
(designated by the ^ character) and press g.
Always refer to the bottom two lines of Pico to see what options are available to us.
Depending on what we're doing in Pico, our options change.

Editing Text:
We can edit our document by using the arrow keys and the backspace key on our
keyboard. Sometimes, when we're typing quickly, our text may seem to disappear. Our
text is still there but has become blacked out. This black-out is usually caused by a slow
screen update.
Because the information on our screen is coming through our modem, it needs to be
updated (refreshed) occasionally, or parts of the information disappear from our screen.
To update our screen's information, hold down the Ctrl key and press l (that’s L, not the
number 1). Do this whenever chunks of text we're working on become blacked out.

www.ckundan.com.np 22

Movement Commands:
Depending on our system, the arrow keys or the backspace key may not work. Instead,
we can use these commands to perform the same tasks.
Smorgasbord of Pico Options:
1. ^C Cancel allows us to stop a process at any time. If we make a mistake, just hold
down the Ctrl key and press c.

2. ^G Get Help Get clear and concise assistance from the Pico help, in case something
unexpected happens or we need additional information about a command.

3. ^X Exit Pico at any time. If we've made changes to a file or we've worked on a new
file, but we haven't saved the changes, we see this message: Save modified buffer
(ANSWERING "No" WILL DESTROY CHANGES) (y/n)? Answering no (press n) will
close Pico and bring us back to the prompt without saving our file. Answering yes
(press y) will allow us to save the file we've been working on (see WriteOut
section below for details).
4. ^O WriteOut Save our file without hassles or worries. Fill in the name of the file
beside the File Name to write: prompt. If our file already has a name, then press
enter.

5. ^T To Files option lets us save our text over a file that exists in our directory. By
choosing the To Files option, Pico takes us to a directory Browser.

Browser Options:
To alter a file or directory, first use the arrow keys or the optional movement keys to
highlight a particular name. We can also press w to find and highlight a file or directory
quickly. Once we've highlighted a particular file or directory, we can use any one of these
options.

www.ckundan.com.np 23

a. Type e to Exit the Browser.


b. Type r to rename a directory or file.
c. Type d to delete a file.
d. Type m to create an additional copy of a file.
e. Type g to move to another directory where the file is located.
f. Type s or press to write over the file with a text we just wrote in Pico.
^R Read File Insert text from another file into our current text file. This option allows us
to search through our directories for a file that we would like to add to our text.
This option is especially handy if we've saved a document and would like to add its
content to the new file we're working on. Text from the file we select is placed on the line
directly above our cursor.
At The Insert File Prompt, We May Either Type A File Name Or Use The Browser
Options.
1. ^T To Files option lets us import a
text file directly into the file we're
currently typing. By choosing the
To Files option, Pico takes us to a
directory Browser.

2. ^Y PrevPg Move quickly to the


previous page. Although we could
just as easily press the up arrow
key several times, this
command quickly jumps our cursor
up one page.

3. ^V Next Pg Move quickly to the next


page. Although we could just as
easily press the down arrow key several times, this command quickly jumps our
cursor down one page.

4. ^K Cut Text Cut a line of text. This option allows us to cut a full line of text. By
using the uncut command and our arrow keys, we can then paste the cut text at
another location in our document. To cut specific text in a line or to cut several
lines of text, first select the text.

Selecting Text:
To select text for cutting and pasting use the following steps:
1. Move the cursor to the beginning of the text we want to select.

2. Hold down the Ctrl key and press ^

3. Use the right arrow key or hold down Ctrl and press f to highlight text. When we
have highlighted the appropriate text, hold down the Ctrl key and press k to cut it.
Paste the text we cut, anywhere in our document, using UnCut Text

www.ckundan.com.np 24

4. ^U UnCutText Paste text that we previously cut. We can use this option to undo an
accidental cut of text or place cut text at another location in our document. The
text we cut is pasted on the line directly above our cursor.

5. ^C Cur Pos Indicate the current position of our cursor, relative to the entire
document. This is a helpful option if we'd like to check exactly where in our
document we are. The status line indicates the following items: [line 8 of 18
(44%), character 109 of 254 (42%)]

6. ^J Justify Even outlines of text. This command is handy when we accidentally type
extra spaces between words or press the key before reaching the end of a line.
The option evens the length of our text lines automatically.

7. ^U UnJustify UnJustify lines of text. For the messy line look we can always select
the UnJustify option.

8. ^W Where is Find a particular


string of text quickly? This option
allows us to do a word search in our
text. This option is especially
handy for longer documents. If the
word we designated at the Search:
prompt is found, it places the cursor
beside it.

9. ^T To Spell Check for spelling errors. The spell check option allows us to correct
spelling errors throughout our document. If spell checker finds a misspelt word
or a word it doesn't recognize (don't worry, this rarely happens), it will let us
correct the word. At the Edit a replacement: prompt, type in the correct spelling
of a word. However, if we don't want to make any changes, simply press the enter
key.

10. Any words that we've corrected but re-occurred in the document can be
automatically replaced. At the Replace a with b? [y]: prompt press y to replace all
occurrences of the misspelt word or n to ignore.

File System of Linux:


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.
The Linux file system contains the following sections:
a. The root directory (/)
b. A specific data storage format (EXT3, EXT4, BTRFS, XFS and so on)

www.ckundan.com.np 25

c. A partition or logical volume having a particular file system.

Linux File System Structure:


Linux file system has a hierarchal file structure as it contains a root directory and its
subdirectories. All other directories can be accessed from 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 modified.
Also, 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.

Fig: Linux File System Structure


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 a single set of commands for the kernel and developers to access the file
system. This virtual file system requires the specific system driver to give an interface to
the file system.

www.ckundan.com.np 26

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.

1. Specifying paths:
Linux does not use the backslash (\) to separate the components; 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.

2. 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 network device, or an "ordinary" directory and a Drive.

3. 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.

4. 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.

5. 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.

www.ckundan.com.np 27

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.

Fig: Types of Linux File System


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.

www.ckundan.com.np 28

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.

Directories
and Their Special
Purpose:
The directory structure of
Linux/other Unix-like systems is
very intimidating for the new user, especially if he/she is migrating from Windows.
In Windows, almost all programs install their files (all files) in the directory named:
`Program Files.’ Such is not the case in Linux.
The directory system categories all installed files. All configuration files are in /etc, all
binary files are in /bin or /usr/bin or /usr/local/bin.

Directory Structure:
1. /(Root):

a. Every single file and directory starts from the root directory.
b. The only root user has write privilege under this directory.
c. Please note that /root is root user’s home directory, which is not same as /.

2. /bin (User Binaries):

a. Contains binary executable.

www.ckundan.com.np 29

b. Common Linux commands we need to use in single-user modes are located under
this directory.
c. Commands used by all the users of the system are located here.
d. For example: ps, ls, ping, grep, cp.

3. /sbin (System Binaries):

a. Just like /bin, /sbin also contains binary executable.


b. But, the Linux commands located under this directory are used typically by a
system administrator, for system maintenance purpose.
c. For example: iptables, reboot, fdisk, ifconfig, swapon

4. /etc (Configuration Files):

a. Contains configuration files


required by all programs.
b. This also contains startup and
shutdown shell scripts used to
start/stop individual programs.
c. For example: /etc/resolv.conf,
/etc/logrotate.conf

5. /dev (Device Files):

a. Contains device files.


b. These include terminal
devices, USB, or any device
attached to the system. c. For example: /dev/tty1, /dev/usbmon0

6. /proc (Process Information):

a. Contains information about the system process.


b. This is a pseudo filesystem contains information about the running process. For
example: /proc/{pid} directory contains information about the process with that
particular pid.
c. This is a virtual filesystem with text information about system resources. For
example: /proc/uptime

7. /var (Variable Files):

a. var stands for variable files.


b. Content of the files that are expected to grow can be found under this directory. c.
This includes system log files (/var/log); packages and database files (/var/lib);
emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files
needed across reboots (/var/tmp);

www.ckundan.com.np 30
8. /tmp (Temporary Files):

a. The directory that contains temporary files created by system and users.
b. Files under this directory are deleted when the system is rebooted.

9. /usr (User Programs):

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


programs.
b. /usr/bin contains binary files for user programs. If we can’t find a user binary
under /bin, look under /usr/bin. For example: at, awk, cc, less, scp c. /usr/sbin
contains binary files for system administrators. If we can’t find a system binary
under /sbin, look under /usr/sbin. For example: atd, cron, sshd, user add, userdel
d. /usr/lib contains libraries for
/usr/bin and /usr/sbin
e. /usr/local contains users programs
that we install from source. For
example, when we install apache
from source, it goes under
/usr/local/apache2

10./home
(Home Directories):

a. home directories for all users to


store their personal files.
b. For example: /home/john,
/home/nikita

11./boot (Boot Loader Files):

a. Contains boot loader related files.


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

12./lib (System Libraries):

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

13./opt (Optional add-on Applications):


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

www.ckundan.com.np 31

14./mnt (Mount Directory):

a. Temporary mount directory where sysadmins can mount file systems.

15./media (Removable Media Devices):

a. Temporary mount directory for removable devices.


b. For examples:
❖ /media/cdrom for CD-ROM;
❖ /media/floppy for floppy drives;
❖ /media/cdrecorder for CD writer

16./srv (Service Data):

a. srv stands for service.


b. Contains server-specific services
related data.
c. For example, /srv/cvs
contains CVS related data.
Fig: Linux Directories and Their Special Purpose

www.ckundan.com.np 32

Unit III: Installation of Linux - Linux

Partitioning:
Disk partitioning or disk slicing is the creation of one or more regions on a hard disk or
other secondary storage so that an operating system can manage information in each
region separately.
Partitioning is typically the first step in preparing a newly manufactured disk before any
files or directories has been created. The disk stores the information about the
partitions' locations and sizes in an area known as the partition table that the
operating system reads before any other part of the disk.
Each partition then appears in the operating system as a distinct "logical" disk that uses
part of the actual disk. System administrators use a program called a partition editor to
create, resize, delete, and manipulate the partitions.
When a hard drive is installed on a computer, it must be partitioned before we can
format and use it. Partitioning a drive is when we divide the total storage of a drive into
different pieces.
These pieces are called partitions. Once a partition is created, it can then be formatted so
that it can be used on a computer.

Hard Drive Naming Convention:


The first thing we need to know is there is no “C drive” or “D drive” in Linux. There are
equivalents, but when we come across a reference to a hard drive in a modern Linux
system, we will typically see something like /dev/sda, /dev/sdb, /dev/sdc, … etc.
The “dev” is short for the device, and in this case, a block storage device. The “sd” is short
for SCSI mass-storage driver. (SCSI stands for Small Computer System Interface.)

www.ckundan.com.np 1
The first hard drive detected by a Linux system carries the sda label. In numerical terms,
it is hard drive 0 (zero; counting begins from 0, not 1). The second hard drive is sdb, the
third drive, sdc, and so on. In the screenshot below, there are two hard drives: sda and
sdb, detected by the installer.

This screenshot comes from an installation attempt where three hard drives were
attached to the system.
Partition Tables:
A partition table describes the partitions of a hard drive or any storage device. And there
are two standards for the layout of the partition table: MBR (Master Boot Record) and
GPT (GUID Partition Table).
MBR, also known as MS-DOS, is what we might call the first standard. GPT came much
later. While MBR is still the most widely used partition table, it comes with two major
limitations which led to the development of GPT. They are:

www.ckundan.com.np 2

1. It does not allow the configuration of more than four main partitions. Those
partitions are called primary partitions.
2. Disk partitions may not exceed 2TB

Partitions and Partition Numbering:


To install an operating system on a hard drive, it must first be subdivided into distinct
storage units. Those storage units are called partitions. Under the MBR partitioning
scheme, which is the default on virtually all Linux distributions, there are three different
types of partitions: Primary, Extended, and Logical.
With MBR, any partition that is not explicitly created as an extended or logical partition,
is a primary partition. And, as stated earlier, there can be no more than four primary
partitions.
The screenshot below was taken from
an installation process where four
primary partitions were created. If we
observe closely, we will see that the first
primary partition is sda1 and the last
sda4. Unlike hard drives, partition numbers start from 1, not 0 (zero).
Any space not allocated to the primary partitions is shown as “Free.” But while it may be
free, it is, however, unusable. And that is because as far as the system is concerned, that
free space does not exist.

So if we attempt to create another partition using the free space, the installer will throw
up the type of error message shown in this image. The error message will always say,
“not enough free space,” even when we know that there is space available. And it does
not matter how much that free space is. It will be unusable.

To get around the four primary partitions limit of the MBR partition table, the smart guys
involved came up with the concept of an extended partition. By tagging a partition as an
extended partition, it is then possible to create many more partitions under the extended

www.ckundan.com.np 3

partition. Those partitions are called logical partitions. Theoretically, there is no limit to
the number of logical partitions that we can create. Note: Only one extended partition
may be configured on a single hard drive.
What the concept of extended partition brings to the table is illustrated in the screenshot
below. We can see that there are three primary partitions (sda1, sda2 and sda3). And the
fourth partition is an extended partition, which makes it possible to create more
partitions (sda5, sda6 and sda7 in this example).
Under an extended partition, we can have free space, and that free space will still be
usable. So we do not have to allocate all the available free space to the logical partitions
of an extended partition.
Being able to create logical partitions comes in handy when we have to dual-boot a Linux
distribution with other operating systems like Windows, PC-BSDor even another Linux
distribution, especially if that other operating system has used up three primary
partitions.
In the image below, which was taken while setting up a system to dual-boot Windows 7
and Fedora 15, three Windows 7 partitions already exist on the target hard drive. That
meant there was just one primary partition to play with.
Only by setting up the available free space as an extended partition was it possible to
install the system. What this also shows is that Linux can boot from a logical partition.
www.ckundan.com.np 4

In the last two screenshots, the extended partitions were the last primary partitions
(sda4).
But it does not have to be. In this screenshot, for example, the extended partition is the
second primary partition (sda2), and the first logical partition number is still 5 (sda5).
So whether an extended partition is the last primary partition or not, the logical
partition number always starts with the number 5.
Not all installation programs broadcast the presence of an extended partition. But if we
know what to look for, we can tell if one exists. In the image below, for example, we can
see the partition numbers go from 1, then 5, 6 and 7.
The presence of partition number 5 and above, is the most obvious tell-tale sign of an
extended partition. This image, by the way, was taken while installing Ubuntu.
As stated earlier, GPT, or GUID Partition Table, overcomes two limitations of the MBR
scheme maximum of four primary partitions, and the 2TB limit to partition sizes.

www.ckundan.com.np 5

In the image below, for example, we can see that there are eight partitions, with about
45GB still available. The most important point to note here is that all eight partitions are
primary, as the concept of extended and logical partitions is foreign to GPT.
With GPT, there can always be unallocated space at the end of existing partitions. And
unlike the case with an MBR scheme that has no extended partition, that “unallocated”
space can be used to create new or additional partitions, unless the maximum number of
partitions possible with GPT has been reached.
In the image below, for example, there are six partitions and a small unallocated space
remaining. The unallocated space may be used to create a new partition.
Currently, Chakra is the only Linux distribution that is configured to use GPT by default.
We may read GPT disk partitioning guide for Chakra to see the steps involved.
Fedora 16, which is slated for release in early November 2011, will support GPT. Test
installations of the first beta release show that GPT will be the default in standalone
installations.

www.ckundan.com.np 6

In dual-boot setups, MBR will be used if there is an existing operating system installed
on MBR partitions on the target disk. We may read feature preview of Fedora 16
installer and Fedora 16 KDE and GNOME alpha screenshots for a few screenshots of
GPT partitions in Anaconda, the Fedora system installer.

Advantages of Disk Partitions:


a. Separation of the operating system (OS) and program files from user files. b.

Having a separate area for operating system virtual memory swapping/paging. c.

Keeping frequently used programs and data near each other.

d. Having cache and log files separate from other files. These can change size
dynamically and rapidly,
potentially making a file
system full.

e. Protecting or isolating files,


to make it easier to recover a
corrupted file system or
operating system
installation. If one partition
is corrupted, other file systems may not be affected.

f. Raising overall computer performance on systems where smaller file systems are
more efficient.

g. Partitioning for significantly less than the full size available when disk space is not
needed can reduce the time for diagnostic tools such as check disk to run or for
full image backups to run.

Disadvantages of Disk Partitions:


a. Reduces the total space available for user storage on the disk, as it forces the
operating system to duplicate certain file system administration areas on the disk
for each partition.

b. Reduces overall disk performance on systems where data is accessed regularly


and in parallel on multiple partitions, because it forces the disk's read/write head
to move back and forth on the disk to access data on each partition and to
maintain and update file system administration areas on each partition.

c. Increases disk fragmentation because it lowers the average size of contiguous free
blocks on each partition as compared to a single partition of the same overall size
after the same amount of data has been written to them.

www.ckundan.com.np 7

d. May prevent using the whole disk capacity, because it may break free capacities
apart.

e. Hurts portability and might impose constraints on how entities might be linked
together inside the file system.

f. Moving files across volumes will require actual copying (of bytes), whereas moving
files within a volume generally require only the "meta-data" to be updated.

Command to Manage Linux Disk Partition:


fdisk stands (for “fixed disk or format disk“) is a most commonly used command-line
based disk manipulation utility for a Linux/Unix systems. With the help of fdisk
command we 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, organizing space for
new drives, re-organizing old drives and copying or moving data to new disks. It allows
us to create a maximum of four new primary partitions and number of logical (extended)
partitions, based on the size of the hard disk we have in our system.

1. View all Disk Partitions in Linux:


The following basic command list all existing disk partition on our system. The ‘-l‘
argument stands 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.

2. View Specific Disk Partition in Linux:


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

www.ckundan.com.np 8

3. Check all Available fdisk Commands:


If we 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 us
output similar to below.
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, we will see all available options for
fdisk that we can be used on the /dev/sda device.

4. Print all Partition Table in Linux:


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

www.ckundan.com.np 9

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.

5. How to Delete a
Partition in Linux:
If we would like to delete a specific partition (i.e /dev/sda9) from the specific hard disk
such as /dev/sda. We must be in fdisk command mode to do this.

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 the partition table.
Enter ‘w‘ to write table to disk and exit after making new alterations to the partition
table. The new changes would only take place after the next reboot of the system. This
can be easily understood from the below output.
Warning: Be careful, while performing this step, because using option ‘d‘ will completely
delete the partition from the system and may lose all data on the partition.

www.ckundan.com.np 10

6. How to Create a New Partition in Linux:


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

After entering in command mode, now press “n” command to create a new partition
under /dev/sda with the specific size. This can be demonstrated with the help of
following given output
While creating a new partition, it will ask us two options ‘extended‘ or ‘primary‘
partition creation. Press ‘e‘ for extended partition and ‘p‘ for primary partition. Then it
will ask us to enter the following two inputs.
1. First cylinder number of the partition to be create.
2. Last cylinder number of the partition to be created (Last cylinder, +cylinders or
+size).
We can enter the size of the cylinder by adding “+5000M” in the last cylinder. Here, ‘+‘
means addition and 5000M means the size of the new partition (i.e. 5000MB). Please
keep in mind that after creating a new partition, we should run ‘w‘ command to alter
and save new changes to the partition table and finally reboot our system to verify
newly created partition.

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.

www.ckundan.com.np 11

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 the size of any specific device.

9. How to Fix Partition


Table Order:
If we’ve deleted a logical partition and
again recreated it, we might notice ‘partition
out of order‘ problem or an 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, we
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.
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, we will no longer get error messages.

10. How to Disable Boot Flag (*) of a Partition:


By default, fdisk command shows the boot flag (i.e. ‘*‘) symbol on each partition. If we
want to enable or disable boot flag on a specific partition, do the following steps.

www.ckundan.com.np 12

Press ‘p‘ command to view the current partition table, you see there is a boot flag
(asterisk (*) symbol in orange colour) on /dev/sda1 disk as shown below.
Next enter command ‘a‘ to disable boot flag, then enter partition number ‘1‘ as (i.e.
/dev/sda1) in my case. This will disable boot flag on the partition /dev/sda1. This will
remove the asterisk (*) flag.
Installation of Linux:
Points to Keep in Mind Before Installing
Linux: 1. Make Sure That Computer Can Run Linux:
Our computer must meet the following system requirements:
a. 2 GHz processor
b. 2 gigabytes of RAM (system memory)
c. 5 gigabytes of hard drive space (25 gigabytes recommended)
d. A DVD drive or a USB port to install Linux

www.ckundan.com.np 13

2. Find A Blank DVD Disc Or A Flash Drive:


To install Ubuntu Linux on our computer, we'll first need to create an installer by placing
the Ubuntu ISO file on a disc or flash drive. If we get a DVD, make sure that it is a DVD-R
that has never been used before. We'll need a standard 4.5 gigabyte DVD. If we choose to
use a flash drive, make sure it can hold at least 2 gigabytes of information.

3. Download The Ubuntu Linux ISO File. To-Do


So: a. Go to https://www.ubuntu.com/download/desktop
b. Scroll down and click Download to the right of our preferred version (the latest
release is 17.10, though the latest long-term support release is 16.04.3). c. Scroll
down and click the Not now, take me to the download link. d. Wait for the download
to start or click the download now link.

4. Burn the ISO File Onto


A DVD:
We can also use a flash drive, but we'll need
to format it for either FAT32 (Windows)
or MS-DOS (FAT) (Mac) and then use
UNetBootin, Rufus, Universal USB
Installer (recommended) to make
the flash drive recognizable by our
computer's operating system.

5. Partition
Computer's Hard Drive:
Creating a partition sections off a determined part of our hard drive, allowing that part
to function as a separate hard drive. This is what we'll install Linux onto, so our partition
will need to be at least five gigabytes in size. The Ubuntu support page recommends
at least 25 gigabytes of free space.

6. Make Sure That Our Installer Is Inserted:


Our DVD or flash drive should be inserted into or attached to our computer. Once we're
certain that the installer is connected and we've performed the rest of the steps in this
section, we can proceed to install Ubuntu Linux on our Windows or a Mac computer.

Installation Process:
Step 1:
Insert the Ubuntu cd or flash driver and boot the computer from cd or flash driver. First
of all, we will be prompted to select language English or other languages according to
our preferences.

www.ckundan.com.np 14

Step 2:
Now we will see the
ubuntu menu, we can
choose to try Ubuntu
without installing
option to try Ubuntu
without actually
installing it on our
hard drive. For
installing ubuntu
choose the second
option Install
Ubuntu.
Step 3:
Ubuntu will start now initialize and after a few minutes, we can see the installation
wizard.

www.ckundan.com.np 15

Step 4:
Click Forward and it will check the minimum requirements for running Ubuntu on
our PC. If everything is fine we can see green colored tick marks. We can also select to
download updates while installing and install some third-party software. After selecting
the things we want to click forward.
Step 5:
Now we can choose either erase and use entire disk option or specify partitions
manually option. We can choose the 1st option if we just want Linux to exist in our
system. Else select the second option. Now it will display the free space available for our
pc.
www.ckundan.com.np 16

Select free space and click on Add option to create a new partition and choose partition
type as primary, size around 70% of the free space available or choose anything like
10,000 or 20,000mb, use as ext3 journaling file system and select mount point as /.
Now again select free space from the table and click add option. Now select size to be
around 300mb, use as ext3 journaling file system and select mount point as /boot.
www.ckundan.com.np 17

Now again select free space from the table and click add option. Now select size to be
around twice the size of our ram that is around 1000 MB if our ram size is 512mb and
select use as swap area and click ok.
Step 6:
Click Install now button and then the wizard will ask us a location. Select our location
and click forward.

www.ckundan.com.np 18
Step 7:
While we are selecting these options wizard will continue to copy files. Now select the
desired keyboard layout and click forward.
Step 8:
Now fill in the details. Fill name, computer name, choose a username and create a
password and click forward and let Ubuntu copy all the essential files.

www.ckundan.com.np 19

Step 9:
After all, files have
been copied and
installed Ubuntu will
display a message
saying that
installation complete
and click on the
restart button to
restart the computer. Remove the cd from the cd drive or pen drive.

Step 10:
After restarting pc wait for the Ubuntu to load and then it will display the login screen.
Choose the user and enter the password and click login.

www.ckundan.com.np 20

Troubleshooting of Installation:
1.CD-ROM Reliability:
Sometimes, especially with older CD-ROM drives, the installer may fail to boot from a CD
ROM. The installer may also even after booting successfully from CD-ROM fail to
recognize the CD-ROM or return errors while reading from it during the installation.
There are many different possible causes of these problems. Here is the only list of some
common issues and provide general suggestions on how to deal with them. The rest is up
to us.

Two Very Simple Things to Try First:


a. If the CD-ROM does not boot, check
that it was inserted correctly and
that it is not dirty.
b. If the installer fails to recognize a
CD-ROM, try just running the
option Detect and mount CD-ROM a
second time. Some DMA related issues with very old CD-ROM drives are known
to be resolved in this way.
If this does not work, then try the suggestions in the subsections below. Most, but not all,
suggestions discussed there are valid for both CD-ROM and DVD, but we'll use the term
CD-ROM for simplicity.
If we cannot get the installation working from CD-ROM, try one of the other available
installation methods.

Common Issues:
a. Some older CD-ROM drives do not support reading from discs that were burned at
high speeds using a modern CD writer.

b. Some very old CD-ROM drives do not work correctly if “direct memory access”
(DMA) is enabled for them.

How To Investigate And Maybe Solve


Issues: If the CD-ROM fails to boot, try the suggestions listed
below:
a. Check BIOS actually supports booting from CD-ROM (only an issue for very old
systems) and that CD booting is enabled in the BIOS.

b. If download an ISO image, check that the md5sum of that the image matches the
one listed for the image in the MD5SUMS file that should be present in the same
location as where WE downloaded the image from.

www.ckundan.com.np 21

Next, check that the md5sum of the burned CD-ROM matches as well. The following
command should work. It uses the size of the image to read the correct number of bytes
from the CD-ROM.
If, after the installer has been booted successfully, the CD-ROM is not detected,
sometimes simply trying again may solve the problem. If we have more than one
CD-ROM drive, try changing the CD-ROM to the other drive.
If that does not work or if the CD-ROM is recognized but there are errors when reading
from it, try the suggestions listed below. Some basic knowledge of Linux is required for
this.
a. To execute any of the commands, we should first switch to the second virtual
console (VT2) and activate the shell there.

b. Switch to VT4 or view the contents of /var/log/syslog (use nano as editor) to


check for any specific error messages. After that, also check the output of dmesg.

c. Check in the output of dmesg if our CD-ROM drive was recognized. We should see
something like (the lines do not necessarily have to be consecutive):
If we don't see something like that, chances are the controller our CD-ROM is connected
to was not recognized or maybe not supported at all. If we know what driver is needed
for the controller, we can try loading it manually using modprobe.
Check that there is a device node for our CD-ROM drive under /dev/. In the example
above, this would be /dev/hdc. There should also be a /dev/cdrom.
Use the mount command to check if the CD-ROM is already mounted; if not, try
mounting it manually:

www.ckundan.com.np 22

Check if there are any error messages after that command.


“1” in the first column after using_dma means it is enabled. If it is, then tries disabling it:
a. Make sure that we are in the directory for the device that corresponds to our CD
ROM drive.

b. If there are any problems during the installation, try checking the integrity of the

CD-ROM using the option near the bottom of the installer's main menu. This
option can also be used as a general test if the CD-ROM can be read reliably.
2.Boot Configuration:
If we have problems and the kernel hangs during the boot process, doesn't recognize
peripherals we actually have, or drives are not recognized properly, the first thing to
check is the boot parameters. In some cases, malfunctions can be caused by missing
device firmware.

3.Software Speech Synthesis:


If software speech synthesis does not work, there is most probably an issue with our
soundboard, usually because either the driver for it is not included in the installer or
because it has unusual mixer level names which are set to mute by default.
We should thus submit a bug report which includes the output of the following
commands, run on the same machine from a Linux system which is known to have sound
working (e.g., a live CD).
a. dmesg
b. lspci
c. lsmod
d. amixer

www.ckundan.com.np 23

4.Common 32-bit PC Installation Problems:


There are some common installation problems that can be solved or avoided bypassing
certain boot parameters to the installer.
If our screen begins to show a weird picture while the kernel boots, e.g. pure white, pure
black or colored pixel garbage, our system may contain a problematic video card which
does not switch to the frame buffer mode properly. Then we can use the boot parameter
fb=false to disable the frame buffer console. Only a reduced set of languages will be
available during the installation due to limited console features.

5.System Freeze during the PCMCIA


Configuration Phase:
Some very old laptop models produced by
Dell are known to crash when PCMCIA
device detection tries to access some
hardware addresses. Other laptops may
display similar problems.
If we experience such a problem and we
don't need PCMCIA support during the
installation, we can disable PCMCIA using
the

hw-detect/start_pcmcia=false boot parameter. We can then configure PCMCIA after


the installation is completed and exclude the resource range causing the problems.
Alternatively, we can boot the installer in expert mode. We will then be asked to enter
the resource range options our hardware needs.
For example, if we have one of the Dell laptops mentioned above, we should enter
exclude port 0x800-0x8ff here. There is also a list of some common resource range
options in the System resource settings section of the PCMCIA HOWTO. Note that we
have to omit the commas if any when we enter this value in the installer.

6.Interpreting the Kernel Startup Messages:


During the boot sequence, we may see many messages in the form can't find something,
or something, not present, can't initialize something, or even this driver release
depends on something.
Most of these messages are harmless. We see them because the kernel for the
installation system is built to run on computers with many different peripheral devices.
Obviously, no one computer will have every possible peripheral device, so the operating
system may emit a few complaints while it looks for peripherals we don't own.
We may also see the system pause for a while. This happens when it is waiting for a
device to respond, and that device is not present on our system. If we find the time it
takes to boot the system unacceptably long, we can create a custom kernel later.

www.ckundan.com.np 24

7.Reporting Installation Problems:


If we get through the initial boot phase but cannot complete the install, the menu option
save debug logs may be helpful. It lets us store system error logs and configuration
information from the installer to a floppy, or download them using a web browser. This
information may provide clues as to what went wrong and how to fix it. If we are
submitting a bug report, we may want to attach this information to the bug report.
Other pertinent installation messages may be found in /var/log/ during the installation,
and /var/log/installer/ after the computer has been booted into the installed system.

8.Submitting Installation Reports:


If we still have problems, we can submit an installation report. We also encourage
installation reports to be sent even if the
installation is successful, so that we
can get as much information as
possible on the largest number of
hardware configurations.
Note that our installation report will
be published in the Debian Bug Tracking
System (BTS) and forwarded to a public
mailing list. Make sure that we use an
e-mail address that we do not mind being
made public.
If we have a working Ubuntu system, the
easiest way to send an installation report
is to install the installation-report
and reportbug packages (aptitude
install installation report reportbug), configure reportbug, and run the command
reportbug installation-reports.
Alternatively we can use this template when filling out installation reports, and send the
report to<[email protected]>.

www.ckundan.com.np 25
In the bug report, describe what the problem is, including the last visible kernel
messages in the event of a kernel hang. Describe the steps that we did which brought
the system into the problem state.

www.ckundan.com.np 26
Unit IV: System Administration - Linux

Root Login:
The "root" account on a Linux computer is the account with full privileges. Root access is
often necessary for performing commands in Linux, especially commands that affect
system files.
Because root is so powerful, it's recommended to only request root access when
necessary, as opposed to logging in as the root user. This can help prevent accidental
damage to important system files.

1.Gaining Root
Access in the
Terminal:

Open The Terminal:


If the terminal is not already open, open it.
Many distributions allow us to
open it by pressing Ctrl + Alt + T.

Type su - and press Enter:


This will attempt to log us in as "superuser." We can actually use this command to log in
as any user on the machine, but when left blank it will attempt to log in as root.

Enter The Root Password When Prompted:


After typing su - and pressing ​ Enter, we'll be prompted for the root password. If we get
an "authentication error" message, our root account is likely locked. See the next section
for instructions on unlocking it.
www.ckundan.com.np 1

Check The Command Prompt:


When we are logged in as root, the
command prompt should end with #
instead of $.

Enter The Commands That Require Root Access:


Once we've used su - to log in as root, we can run any commands that require root
access. The su command is preserved until the end of the session, so we don't need to
keep re entering the root password every time we need to run a command.

www.ckundan.com.np 2

Consider using sudo instead of su -sudo ("superuser do") is a command that lets us run
other commands as root temporarily. This is the best way for most users to run root
commands, as the root environment is not maintained, and the user doesn't need to
know the root password. Instead, the user will enter their own user password for
temporary root access.
a. Type sudo command and press ​ Enter (e.g. sudoifconfig). When prompted for the
password, enter user password, not the root password.

b. sudo is the preferred method for distributions like Ubuntu, where it will work
even when the root account is locked.

c. This command is limited to users with administrator privileges. Users can be


added or removed from /etc/sudoers.
2.Unlocking the Root Account (Ubuntu):
Ubuntu (and several other distributions) locks the root account so that the average user
can't access it. This is done because root access is rarely necessary when using the sudo
command. Unlocking the root account will allow us to log in as root.

Open The Terminal:


If we're in the desktop environment, we can press Ctrl+Alt+T to start the terminal.

Type sudo passwd root and press Enter:


When prompted for a password, enter the user password.

www.ckundan.com.np 3
Set A New Password:
We'll be prompted to create a new password and enter it twice. Once a password has
been set, the root account will be active.

Lock The Root Account Again:


If we want to lock the root account, enter the following command to remove the
password and lock root: sudopasswd -dl root
www.ckundan.com.np 4

3.Logging In As Root:
Consider Using Other Methods For Gaining Temporary
Root Access:
Logging in as root is not recommended for regular use, as it is very easy to perform
commands that will render our system inoperable, and it also poses a security risk,
especially if we are running an SSH server on our machine.
Only log in as root when performing emergency repairs, such as dealing with disk
failures or restoring locked accounts.
a. Using sudo or su instead of logging in as root will help prevent unintended damage
while logged in as root. Using these commands gives the user a chance to think
about the command before severe damage is done.

b. Some

distributions, such as Ubuntu, leave the root account locked until we manually
unlock it. Not only does this prevent users from unknowingly doing too much
damage using the root account, but it also secures the system from potential
hackers, as the root account is typically targeted first. With a locked root account,
hackers aren't able to gain access with it.

Enter root As the User When Logging into Linux:


If the root account is unlocked and we know the password, we can log in as root when
we're prompted to log in with a user account. Enter root as the user when prompted to
log in. If we need root access to perform a command, use the method in the previous
section.

Enter The Root Password As The User Password:


After entering root as the username, enter the root password when prompted. In many
cases, the root password may be "password." If we don't know the root password or have

www.ckundan.com.np 5

forgotten it, see the next section for instructions on resetting it. In Ubuntu, the root
account is locked and cannot be used until it has been unlocked.
Avoid Running Complex Programs While Logged In As
Root:
There's a chance that the program we intend to run will harm our system when it has
root access. It's highly recommended that we use sudo or su to run programs instead of
logging in as root.
4.Resetting The Root Or Admin Password:
Reset the Root Password If It Has Been
Forgotten:
If we've forgotten the root password and our user password, we'll need to boot into
recovery mode to change them. If we know our user password and need to change the

www.ckundan.com.np 6

root password, just type sudopasswd root, enter user password, then create a new root
password.

Reboot Computer and Hold Left Shift after the BIOS


Screen:
This will open the GRUB menu. The timing on this can be tricky, so we may have to try
multiple times.

Select the First (Recovery Mode) Entry on the


List: This will load recovery mode for our current distribution.
www.ckundan.com.np 7

Select The Root Option From The Menu That


Appears: This will start the terminal with us logged in as the root account.
Remount The Drive With Write Permissions:
When we boot into recovery mode, we will typically only have read permissions. Enter
the following command to enable write access: mount -rw -o remount /
Create New Password for Any Account We're Locked Out
Of:
Once we're logged in as root and have changed the access permissions, we can create a
new password for any account: Type passwd accountName and press ​ Enter. If we need
to change the root password, type passwd root. Enter the new password twice when
prompted.

www.ckundan.com.np 8

Reboot Computer After Resetting Passwords:


Once we're finished resetting passwords, we can reboot and use our computer as
normal. Our new passwords will take effect immediately.

Superuser (sudo):
There are two ways to run administrative applications in Linux. We can either switch to
the superuser (root) with the su command, or we can take advantage of sudo. How we
do this will depend upon which distribution we use.
Some distributions enable the root user (such as Fedora, Red Hat, OpenSUSE), while
some do not (such as Ubuntu and Debian). There are pros and cons to each.
Sudo stands for either "substitute user do" or "superuser do" (depending upon how we
want to look at it). What sudo does is incredibly important and crucial to many Linux
distributions.
Effectively, sudo allows a user to run a program as another user (most often the root
user). There are many things sudo is the best way to achieve "best practice security" on
Linux. There are some, however, that feel quite the opposite.

www.ckundan.com.np 9

Regardless of where we stand, and what distribution we are currently using, there will
come a time when we will have to take advantage of sudo. Whether we will need to
simply use sudo or we will have to configure sudo or we will want to know the ins and
outs of this powerful tool.

History of sudo:
Sudo found its beginnings in 1980 at the department of computer science SUNY/Buffalo
(created by Bob Coggeshall and Cliff Spencer). Since its first inception, sudo has been re
iterated numerous time (adding new features and changing developers).
At one point, around 1994, sudo was being developed by Todd Miller at the Colorado
University in Boulder, CO and an unofficial "fork" of sudo was released called "CU sudo".
This "fork" added support for more distributions as well as numerous bug fixes.
This "CU" prefix was finally dropped in
1999 and what was "CU sudo" is now the
version of sudo we use today. The
original sudo has not had a release since
1991. So the "fork" won and is still
developed by Todd Miller. Now that we
have had a bit of a history lesson, let's
take a look and see how sudo is used.

Difference Between
sudo and su:
If we are accustomed to a more traditional
Linux setup, then we are used to use the su
command to gain root privileges. We can even issue the command su - to effectively log
in as the root (root's home becomes our home).
With these types of distributions, we can also log in as the root user. Too many think this
is a bad idea. NEVER log in as the root user. If we are using a distribution that relies on su
and allows root user login, login as our standard user and su to the root user.
Now with sudo-based distributions we will most likely notice that we cannot log in as a
root user. In fact, in distributions such as Ubuntu, the root user account has been
"disabled." We cannot log in as root and we cannot suto become the root user.
All we can do is issue commands with the help of sudo to gain administrative privileges.
Usage:
Using sudo, in its most basic form, is simple. Say we have to run the dpkg to install a
piece of software. If, as our standard user, we just issue the command dpkg
-isoftware.deb we will receive an error warning us that the user does not have proper
permissions to execute the command.
That is because standard users, by default, cannot install applications on a Linux
machine. To successfully install an application on a Linux machine, we have to have
superuser

www.ckundan.com.np 10

You might also like