0% found this document useful (0 votes)
166 views59 pages

Learning UNIX.: 2.0 Main Features of UNIX

The document provides an overview of the main features and structure of UNIX operating systems. It discusses how UNIX allows for multi-user access, multi-tasking of programs, and uses a hierarchical directory structure. It also outlines the three main components of the UNIX operating system - the kernel, shell, and utilities. Finally, it describes how UNIX handles user processes, running programs in the background, and security rights for files.

Uploaded by

Venkat Reddy A
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views59 pages

Learning UNIX.: 2.0 Main Features of UNIX

The document provides an overview of the main features and structure of UNIX operating systems. It discusses how UNIX allows for multi-user access, multi-tasking of programs, and uses a hierarchical directory structure. It also outlines the three main components of the UNIX operating system - the kernel, shell, and utilities. Finally, it describes how UNIX handles user processes, running programs in the background, and security rights for files.

Uploaded by

Venkat Reddy A
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 59

Learning UNIX.

Part 1: Overview/1
http://uva.ulb.ac.be/cit_courseware/unix/onlinet.htm

http://www.nextstep4it.com/qa/linux/systemadmin/index3.html

2.0 Main Features of UNIX


This section contains a brief overview of the main features of UNIX. At the time UNIX was
introduced, some of these features set the UNIX operating system apart from other systems
available at that time. Today, many of these features are common place.

 multi-user
more than one user can use the machine at a time
supported via terminals (serial or network connection)
 multi-tasking, more than one program can be run at a time
 hierarchical directory structure, to support the organisation and maintenance of files
 portability
only the kernel ( <10%) written in assembler. This meant the operating system could be
easily converted to run on different hardware
 tools for program development, a wide range of support tools (debuggers, compilers)

 3.0 The UNIX Operating System


This section outlines the basic structure of the UNIX operating system, as a division of three
parts.

 kernel
schedules programs
manages data/file access and storage
enforces security mechanisms
performs all hardware access
 shell
presents each user with a prompt
interprets commands types by a user
executes user commands
supports a custom environment for each user
 utilities
file management (rm, cat, ls, rmdir, mkdir)
user management (passwd, chmod, chgrp)
process management (kill, ps)
printing (lp, troff, pr)
program development tools
 

4.0 Multi-User Operating Systems


A multi-user operating system allows more than one user to share the
same computer system at the same time.

It does this by time-slicing the computer processor at regular intervals


between the various users.

The switching between user programs is done by part of the kernel. To switch from one program
to another requires,

 a regular timed interrupt event


 saving the interrupted programs state and data
 restoring the next programs state and data
 running that program till the next timed interrupt occurs

The timed event is usually about 1 to 10 milliseconds apart. It is generated by a real-time clock.

4.1 Handling Programs


Each computer has a maximum amount of memory (RAM) that is installed in the computer.
Some of this memory is required by the operating system. The remainder is available to user
programs.

The more memory that can be provided in total the better. Where there is insufficient main
memory to run a users program, some other users program residing in main memory must be
written out to the disk unit to create some free memory space.

This process is called swapping. When the system becomes overloaded (where there are more
users than the system can handle), the operating system spends most of its time shuttling users
programs between main memory and the disk unit, and users response time degrades. This is
called disk thrashing and is overcome by installing more main memory.

4.2 Processes
Each program running on a UNIX system is called a process. When a user types a command,
UNIX constructs a Process Control Block (PCB) for the process that process. Each process has a
PCB that holds its priority, the process state, register information and additional details.
UNIX provides a set of utilities for managing processes.

ps list processes
kill kill a process
& run a process in the background

If the system administrator found that a particular user was performing an operation that was
consuming too much computing time or dominating a system resource such as a printer, they
could use the ps command to identify the offending users process and then use the kill command
to terminate that process.

Each program is assigned a priority level. Higher priority tasks (like reading and writing to the
disk) are performed more regularly. User programs may have their priority adjusted dynamically,
upwards or downwards, depending upon their activity and available system resources.

Multi-tasking systems support foreground and background tasks. A foreground task is one that
the user interacts directly with using the keyboard and screen. A background task is one that runs
in the background (it does not have access to the screen or keyboard). Background tasks are
usually used for printing.

4.2.1 Running Programs In The Background

 lets the user carry on with more important tasks


 examples are printing and formatting documents
 the ampersand symbol (&) is appended to the command
 the shell assigns a process number (pid) to the command
 background jobs can be deleted using the kill command

4.3 When a user logs on


When the UNIX system starts up, it also starts a system process (getty) which monitors the state
of each terminal input line. When getty detects a user has turned their terminal on, it presents the
logon prompt and once the password is validated, the UNIX system associates the shell program
(/bin/sh) with that terminal.
Each user is presented with a shell. This is a
program which displays the users prompt,
handles user input and displays output on the
terminal.

The shell program provides a mechanism for


customising each users setup requirements, and
storing this information for re-use (in the file
.profile).

The user interacts with /bin/sh, which interprets


each command typed. Internal commands are
handled within the shell (set, unset), external
commands are invoked as programs (ls, grep,
sort, ps).

There are a number of different command line shells (user interfaces).

 Bourne (sh)
 Korn (krn)
 C shell (csh)
 Bash (an improved Bourne shell with history and aliases)

The shell is often called a command line shel, since it presents a single prompt for the user. The
user types a command, the shell invokes that command, then presents the prompt again when the
command has finished. This is done on a line by line basis, hence the term 'command line'.

Recent enhancements turn the command line interface into a graphical one (X, MOTIF,
OPENVIEW), where programs are represented as objects or icons on a screen. By use of a
mouse these icons are selected and run. This is similar to operating systems like Windows or
OS/2.

5.0 Unix Command Syntax


This section outlines the standard format for all UNIX commands.

Commands are short two or three character names, and


accept additional options that control their actions.

 all commands have a similar format


 commands are generally two or three characters long
 commands are case sensitive (use lowercase)
 options always preceed filenames
 options are prefixed using a - symbol
 the man command can be used to display the correct syntax

6.0 The UNIX File System


This section discusses UNIX files and directories. The file system refers to the way in which
UNIX implements files and directories. In UNIX, a file system has the following features,

 hierarchical structure (support for directories)


 files are expandable (may grow as required)
 files are treated as byte streams (can contain any characters)
 security rights are associated with files and directories (read/write/execute privledge for
owner/group/others)
 files may be shared (concurrent access)
 hardware devices are treated just like files

6.1 What is a file?


A file is a collection of information, which can be data, an application, documents; in fact, under
UNIX, a file can contain anything. When a file is created, UNIX assigns the file a unique internal
number (called an inode).

6.2 What is a file Link?


A file link is a directory entry which points to an original file somewhere else. A link is made to
an existing file using the ln command. This creates a directory entry which points to the existing
file (it does not make a copy of the existing file). This allows more than one reference to an
exisiting file.

For instance, a person can give another access to a file and let them create a link to it. In this way
they both can access and work with the same file, ensuring that the information they enter into
the file is up-to-date. Only the original owner of the file may delete the file.

6.3 What are the security rights associated with files and directories?
UNIX provides three sets of security rights for each file and directory entry. These sets are for
the owner, the group to the owner belongs, and any other users on the system.
Each user belongs to a group (only one at a time). Group membership facilitates the sharing of
common files. A user can change their membership to another group by using the newgrp
command.

The security rights are

 read (read, display, copy the file contents)


 write (modify and append to the file contents)
 execute (run the file as a program)

The security bits are grouped as a series of three bits


for each of the owner, group and other access rights.

The group to which the file belongs is changed using


the chgrp command.

The owner of the file is changed using the chown


command.

Security rights for a file or directory are modified by


using the chmod utility.

6.4 Listing files

Files are listed using the ls command.

This picture shows the security rights associated with


the file, as well as the owner (joe), the group that the
owner belongs to, the size of the file and other
information.
6.5 Wild Card Characters
Wild card characters are used when working with a number of files at once.

 used to match characters in filenames


 the asterisk * matches any sequence of zero or more
characters
 the question mark ? matches exactly one character

6.6 Mountable File Systems


All UNIX systems have at least one permanent non-removable hard disk system. The root
directory and the directories below it are stored on this disk. Its structure is known as the root file
system.

If an additional hard disk is added,


UNIX creates a separate new filesystem
on this disk. Before it can be used, it
must be attached to the root file system.
This is called mounting an additional
filesystem.

An empty directory on the root file system is selected as the mount point, and using the UNIX
mount command, the new file system will appear under this directory.

6.7 UNIX Standard Devices


There are THREE standard devices supported by the UNIX
shell, stdin, stdout and stderr. Each program that runs has
allocated to it a stdin, stdout and stderr device.

 these devices may be redirected to another device or file


 standard output (stdout) is associated with the users terminal display
 standard input (stdin) is associated with the users terminal keyboard
 standard error (stderr) is associated with the users terminal display

When a program is executed, it has associated


with it each of three standard UNIX devices.

6.8 Device Redirection

The input or output devices associated with a


program may be redirected to another device.

For example, a program that normally reads from stdin (the keyboard) can be redirected to read
from a file.
In a similar manner, a program that
normally writes to stdout (the screen) can
redirect its output to a file or printer. In this
example, the ls command redirects stdout to
files.

 the standard devices may be redirected to a device or file


 other devices can be printers, terminals
 devices appear as files in the /dev subdirectory
 the symbol > changes the standard output device, creating a new file
 the symbol < changes the standard input device
 >> redirects stdout, appending to an existing file

6.8.1 Shell Device Redirection


It is also possible to redirect any device using the file descriptor number assigned to that device.

By default, the c compiler sends the error output to the screen.


To redirect the error output to a file, it is necessary to use the
file descriptor.

 stdin has a file descriptor of 0


 stdout has a file descriptor of 1
 stderr has a file descriptor of 2

6.9 Pipes
Sometimes, the use of intermediatary files is undesirable. Consider an example where you are
required to generate a report, but this involves a number of steps. First you have to concatenate
all the log files. The next step after that is strip out comments, and then to sort the information.
Once it is sorted, the results must be printed.
A typical approach is to do each operation as a separate step, writing the results to a file that then
becomes an input to the next step.

Pipelining allows you to connect two programs


together so that the output of one program becomes
the input to the next program.

 allow commands to be combined in a sequential order


 connects stdout of one program to the stdin of the next program
 the symbol | (vertical bar) represents a pipe
 any number of commands can be connected in sequence, forming a pipeline
 all programs in a pipeline execute at the same time
 complex operations are easily perfomed by piping commands

7.0 Shell Scripts


To automate many routine tasks, a system administrator will create a file that contains the
commands to be executed. This is known as a shell script file.

This is an example of a shell script file.

It is a file called testlogin that accepts a


username and then tests to see if that user is
logged on.

Shell scripts

 contain command sequences


 have execute permission (using chmod)
 simplify repetitious command sequences
 are run by the shell as if it has been typed at the terminal
 

7.1 Create A Shell Script


Shell scripts must be in ASCII text format, and can be created using a simple editor such as vi.

This example uses the cat command (and redirect


output) to create the script file that echos the current
date when executed.

7.2 Set 'execute' And Run A Shell Script


Once an administrator creates a shell script, its rights must be changed to executable before it can
be run.

The administrator used the chmod command to alter


permission settings for files.

Once the script file has execute rights, the shell script is
run by typing its name.

7.3 Shell Variables

When working with shell scripts, it is often


desirable to use variables. These can be either
user-defined or in-built variables that the shell
supports.

 the shell supports internal variables


 application and user defined variables are also supported
 the set command displays all currently defined shell variables
 variables are used to find programs (path) or set terminal types

 
7.4 Defining Shell Variables

Shell variables are created by assigning a string


(sequence of characters) to a variable name.
Variables can also contain valid UNIX
commands.

To access the value of a shell variable, the


variable is prefixed with the $ symbol.

7.5 Shell Programming Language

Commands can be combined in shell scripts using a mini


programming language supported by the shell.

Support for repetitive tasks (for and while statements) and conditions (if and select statements)
allow system administrators to write scripts that are reasonably powerful.

 simple statements which when combined, create powerful scripts


 support for conditional execution and conditional repetition
 command substitution (the output of a command can be fed back into the script for
execution)
 support for shell variables

7.6 Shell Arguments and Quotes


When using arguments to shell scripts or variables, the system administrator must be careful to
ensure that the resultant action is valid. Arguments are often interpreted by the shell in a manner
that is unintentional.
This is due to the shell applying certain rules
about special characters, so system
administrators should exercise care when
using these in arguments to scripts and
variables.

 the shell supports pattern matching and recognition


 the asterisk (*) symbol matches all strings
 the question mark (?) symbol matches a single character
 the special symbols < > * ? [ ] have special meaning
 to use special symbols, they are enclosed in single or double quotes, else the shell will try
to execute them as commands or use them as parameters to commands
 within double quotes, the symbols $ \ ` " retain their special meaning. To use these
characters inside a double quoted string, preceed these symbols with a backslash (\)
symbol

8.0 Networking
This section deals with some of features and commands associated with networking or accessing
other UNIX systems.

UNIX systems are usually interconnected using TCP/IP (transmission control protocol, Internet
protocol). This is a protocol mechanism that is widely used by large networks world-wide to
interconnect computers of different types.

A protocol is a set of rules that governs how computers talk to each other. TCP/IP is a widely
used and very popular protocol. With TCP/IP, different computer systems can reliably exchange
data on an interconnected network. It also provides a consistent set of application programming
interfaces (API's) to support application development.

8.1 Network File Systems (NFS)


This allows you to manipulate files on a remote TCP/IP host as if they reside on your local
machine. NFS supports a hierarchical file structure (refer mountable file systems). Using NFS, a
system administrator can mount a directory structure that resides on another computer into the
directory structory of the local computer.

 
8.2 Remote Execution (rexec)
This allows you to execute a command on another host and receive the results on your local
machine. This means you can take advantage of better processing power or unavailable software
which your local machine does not have.

A host machine, username, password and the command to execute are passed to the host
machine. If the authenification succeeds, the command is executed, and responses returned to
your local machine.

8.3 Remote Shell (rsh)


This allows you to execute a command on another host. Unlike rexec, it neither requires or
allows you to provide a password. You must have a user account on the host server however.

8.4 File Transfer Protocol (ftp)


This allows you to transfer files between your host and another host machine. A shell is provided
which enables you to

 change directories on the host or local machine


 display directories and files
 change the file transfer mode (binary or text)
 execute commands
 delete or rename files
 open and close connections to a host

8.5 Terminal Emulation (telnet)


This allows you to logon to a host using terminal emulation. You can execute commands on the
host and run application software.

8.6 Domain Name Servers


This is a hierarchical naming system for identifying host computers on networks or the Internet.
Each host name is comprised of domain labels separated by periods. If your machine is
connected to the Internet, you assign local domain name host names only, and your higher level
domain name is assigned to you.

For example, the domain name assigned to CIT is,

cit.ac.nz
and contains the higher level domain names of ac (academic) and nz (New Zealand). Examples
of the host computers at CIT are called news, ice, and www. Their host names in the domain are

news.cit.ac.nz
ice.cit.ac.nz
www.cit.ac.nz

Users are also assigned names. Consider the user joe, who has an account on the host machine
ice. The domain name for this user is,

[email protected]

When you send email or access resources on other computers, the domain names need to be
resolved in order that a connection is made to the correct computer. One host computer in the
network acts as a name resolver (domain name server), which resolves domain names to
computers. For example, if you want to ftp to the local host ice, your computer sends a request to
the designated name domain server, which if it knows about the host ice, will send back the
computer TCP/IP address, which your computer then uses to initiate a connection request.

The name domain server uses a special file called hosts to resolve host names and their TCP/IP
addresses.

8.7 Simple Network Management Protocol (snmp)


This provides a means for managing a network environment. Each host, router or gateway
running SNMP can be interrogated for information related to the network.

Examples of information are,

 names
 packets transmitted and received
 errors
 routing information

8.8 Boot Protocol (bootp)


This service allows a local computer to get its Internet address (TCP/IP configuration details)
from a designated bootp server. The bootp server has a list of network card addresses for each
computer and the TCP/IP addresses to use for those computers stored in a file (/etc/bootptab).
When it receives a request from a computer, it looks at this file for a match and responds with the
assigned TCP/IP address.

 
8.9 Network Services
To provide services such as ftp, telnet and WWW servers, they are enabled on the host computer
by running the appropriate software, called a system daemon process. For example, to configure
a computer as an ftp server requires the installation, configuration and running of the ftpd
process (most system processes end in d, which means daemon).

If the daemon process is not started, the service is not available on that host computer. In other
words, you cannot ftp into a host which is not running the ftp daemon service.

When a UNIX host starts up, it usually runs an inetd service, which reads the file /etc/inetd.conf
which contains a list of the networking services for the host to run. A system administrator
would edit this file and include the various services that are required to run when the system
starts.

8.10 Sockets
Sockets are an end to end numbered connection between two UNIX machines communicating
via TCP/IP. Standard packages are assigned special socket numbers (telnet is port 23). The
socket numbers for various protocols and services are found in /etc/services.

A programming socket interface provides calls for opening, reading, writing and closing a socket
to another host machine. In this way, the programmer need not be concerned with the underlying
protocol associated with the socket interface.

8.11 Networking Commands


Below is a discussion of some of the more common networking commands.

8.11.1 arp (address resolution protocol)


This command displays and modifies the Internet to physical hardware address translation tables.
As computers establish connections to other computers (via telnet, ftp or other means), the
details of these are kept locally in a buffer store called the arp cache. The system administrator
can view this cache and modify its contents using the arp command.

$ arp
Address HWtype HWaddress Flags Mask Iface
lewis-fe00sw-dit.cit.ac ether 00:30:19:77:83:00 C eth0
flame.cit.ac.nz ether 00:C0:4F:CF:99:C2 C eth0
$

 
8.11.2 netstat (network status)
This command displays the network status of the local host. It provides information about the
TCP connections, packet statistics, memory buffers and socket information.

$ netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 126 luni.cit.ac.nz:telnet flame.cit.ac.nz:1756 ESTABLISHED
tcp 0 0 luni.cit.ac.nz:telnet dhcp-78-8.cit.ac.n:1100 ESTABLISHED
tcp 0 0 luni.cit.ac.nz:telnet dhcp-78-3.cit.ac.n:1130 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] STREAM 830794 /dev/log
unix 2 [ ] STREAM CONNECTED 830793
unix 1 [ ] STREAM 830746
unix 2 [ ] STREAM 830697 /dev/log
unix 2 [ ] STREAM CONNECTED 830696
unix 2 [ ] STREAM 830680 /dev/log
unix 2 [ ] STREAM CONNECTED 830679
$

8.11.3 ping
This command sends an echo request to a host. It is a diagnostic tool for testing whether a host
can be found. When the request reaches the host, it is sent back to the originator.

$ ping flame
PING flame.cit.ac.nz (156.59.20.75): 56 data bytes
64 bytes from 156.59.20.75: icmp_seq=0 ttl=128 time=0.8 ms
64 bytes from 156.59.20.75: icmp_seq=1 ttl=128 time=0.8 ms
64 bytes from 156.59.20.75: icmp_seq=2 ttl=128 time=0.8 ms
--- flame.cit.ac.nz ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.8/0.8/0.8 ms
$

8.11.4 route
This command manually manipulates the network routing tables which are used to connect to
other hosts.

Example

route add net 129.34.10.0 129.34.20.1 1


; add a new network 129.34.10.0 accessible via the gateway
;129.34.20.1 and there is one metric hop to this destination

 
8.11.5 nslookup
This command is used to query a domain name server and return information about a designated
host.

$ nslookup
Default Server: araiahi.cit.ac.nzAddress: 156.59.65.10
> flame
Server: araiahi.cit.ac.nz
Address: 156.59.65.10
Name: flame.cit.ac.nz
Address: 156.59.20.75
> exit
$

8.11.6 traceroute
This command is similar to ping, but traces the path (or route) that data travels across the
network to a specific host computer.

$ traceroute www
traceroute to tukutuku.cit.ac.nz (156.59.65.16), 30 hops max, 40 byte packets
1 route64.cit.ac.nz (156.59.64.1) 1.87 ms 1.737 ms 1.727 ms
2 tukutuku.cit.ac.nz (156.59.65.16) 2.815 ms 2.862 ms 3.101 ms
$

8.12 Some networking files


The following files are associated with networking and are generally found in the /etc
subdirectory.

/etc/bootptab Used by bootpd


/etc/gateways Used by routed and identifies the accessible gateway machines.
/etc/hosts Used by clients and servers to resolve host names if a name server is unavailable.
/etc.inetd.conf Used by inetd to start services when computer boots
/etc/ftpusers Used by ftpd to restrict or block specific users accessing ftp
/etc/resolv.conf Used by clients and servers to provide a domain name and name server address.

Objective
The objectives of this module is to

 introduce you to system administration tasks


 write shell scripts
 process text files and generate reports (program in awk)
 use system tools and utilities
 develop programs based on sockets and process communication

1.0 System Administrators


A system administrator is responsible for the day to day running of the computer. This involves
the following activities

 Creation, modification and deletion of user accounts


 Generate daily reports from log files
 Monitor system activity and perform auditing
 Ensure sufficient dish space exists and ensure file system integrity is maintained
 Install, configure and remove software packages as required
 Perform daily maintenance tasks, monitoring mail, print and other applications
 Start and shutdown the system
 Perform backups
 Install, mount and configure peripheral devices such as terminals and disk drives

A system administrator has unrestricted access, thus can delete any file (including system files
that are part of UNIX), and execute any program.

For the most part, a system administrator can automate some activities to reduce the amount of
work they are required to do, but other tasks, such as resetting user passwords and unlocking
terminals or user accounts require the administrator to log on to the computer system using the
administrator account (root).

1.1 How do you log on as an administrator?


There are two ways that you can log on as a system administrator. If you are already logged on
as a user, you can use the su (substitute user) utility to assume the administrator identity.

$ su
Password ######
#_

When you are logged in as a system administrator, the system prompt changes to #.

The other way you can log on as a system administrator is to use the special administrator
account, named root.

Login: root
Password ######
#_

1.2 What is so special about the system administrator account?


When you are logged in as root, the UNIX system gives you unrestricted access to every file and
directory. This means can delete, rename, copy or move any file, including vital system files
required for UNIX to function correctly. If a file is accidentally erased, there is no way to
undelete the file other than to restore it from tape backup, or failing this, reinstalling the
operating system.

2.0 The /etc directory and system administrators


This directory contains important system files, user and group account information, and special
scripts that configure the system. Some of these are shown below and will be discussed later in
greater detail.

/etc/adduser.conf Specifies default configuration for creating user accounts


/etc/bootptab Holds computer names and IP addresses for remote booting workstations
/etc/crontab List of jobs to be executed
/etc/fstab List of filesystems to mount when UNIX boots
/etc/group List of groups
/etc/inittab Lists the processes that are started when UNIX boots
/etc/passwd The password file, usernames, passwords, group membership, shell
/etc/motd Message of the day
/etc/mtab List of currently mounted filesystems

2.1 Other /etc files


Use the man command to identify the functions of the following files.

/etc/ftpusers  
/etc/printcap  
/etc/resolv.conf  

3.0 Setting up user accounts


A system administrator is responsible for creating, modifying and deleting user accounts. When
a user account is created, an entry is made in the /etc/passwd file. When a group account is
created, an entry is made in the /etc/group file.
 

3.1 /etc/passwd
This plain text file holds information about users, such as their logon name and home directory.
Each user has a separate line of information (a record) in the /etc/passwd file. Each field of the
user record is separated by colons. The following table illustrates the purpose of each field of a
user record.

logon_name:encrypted_password:userid:groupid:user_name:home_directory:shell

brownbr:jwrt#4de:1154:101:Brian Brown:/user/brownbr:/bin/sh

Each user must have a unique ID and belong to a group that is defined in the /etc/group file.

3.2 adduser
Most UNIX systems provide a tool to allow creation of user accounts. The program adduser is
one such example.

When a system administrator runs adduser, they specify a number of options on the command
line. In the following example, adduser will create a new user called bloggsjo and make them a
member of the bc group (this group has already been defined in the /etc/group file).

# adduser --ingroup bc bloggsjo

Example of adding a user using adduser

luni:/etc# adduser --ingroup bc bloggsjo


Adding user bloggsjo...
Adding new user bloggsjo (1161) with group bc.
Creating home directory /user/bloggsjo.
Copying files from /etc/skel
Changing password for bloggsjo
Enter the new password (minimum of 5, maximum of 8 characters)
Please use a combination of upper and lower case letters and numbers.
New password: ****
Re-enter new password: ****
Password changed.
Changing the user information for bloggsjo
Enter the new value, or press return for the default

Full Name []: Joe Bloggs


Room Number []:
Work Phone []:
Home Phone []:
Other []:

Is the information correct? [y/n] y


luni:/etc#

What file does adduser reference to obtain default configuration details when creating a user
account?

_______________________________________________

When a user is created using adduser, a number of default settings are used. These have been
specified in the configuration file identified above.

What is the default group that adduser places a new user into (hint: look at the contents of the
configuration file)?

_______________________________________________

What is the path of the home directory that adduser creates for a newuser (hint: look at the
contents of the configuration file)?

_______________________________________________

When a user is created using adduser, a new entry is made in the /etc/passwd file for that user.
In addition, a home directory is created for the user and confiuration files copied into their new
home directory. Directory permissions are also applied so the user can access their home
directory and other files.

What is the location (directory) that adduser references to copy the configuration files (such
as .profile) to the users new home directory (hint: man adduser)?

_______________________________________________

The purpose of having master configuration files is so that the system administrator can
configure these (using vi editor) appropriately and not have to worry about copying them to each
new users home directory, or whether they are configured correctly.
 

3.3 Creating a user account


To create a user account the following needs to be done,

1. Create an entry in /etc/passwd for the user


2. Create a home directory for the user that matches the location in the users record in
/etc/passwd
3. Copy the configuration files (such as .profile) to the users home directory
4. Change the security bits associated with the files and the users home directory using chown
and chmod

Of course, the simpler way is to use adduser to create the user account (see also useradd).

3.4 Setting up a users environment


Once a system administrator has created a user account by adding a record to /etc/passwd, that
record will specify the default shell and home directory for the user.

After applying the correct security permissions to the users home directory, the default
configuration files such as .profile are copied into the users home directory. This ensures that
when they log on to UNIX, their shell is configured correctly.

3.5 Changing a users password


To change a users password, the system administrator can use the passwd command. In the
following example, the system administrator changes the password for the user bloggsjo.

luni:/etc# passwd bloggsjo


Changing password for bloggsjo
Enter the new password (minimum of 5, maximum of 8 characters)
Please use a combination of upper and lower case letters and numbers.
New password:
Re-enter new password:
Password changed.
luni:/etc#

System administrators are often required to change a users password, due to users forgetting their
password. An alternative method is to edit the /etc/passwd file and remove the characters for the
password field. This allows the user to logon with an empty password, and once logged on, they
can themselves run the passwd command and assign themselves a password.

 
3.6 Deleting a user account
To retire a user account involves removing their account record from /etc/passwd and deleting
their home directory (see also userdel).

3.7 Setting up a new group


UNIX allows members of a group to share files. This is achieved through group permissions and
group memberships (a user can only belong to one group at a time).

To make a new group requires adding a record to the /etc/group file, assigning the group a
unique ID.

The alternative is to use the adduser command to create a new group.

What command would a system administrator type to create a new group account called dipbc
(hint: man adduser)

_______________________________________________

(See also groupadd).

3.8 Locking a user account


A system administrator may want to lock a users account (disable) temporarily. Perhaps the user
is going on leave, or has been doing unpermitted tasks.

The system administrator can use the passwd command to lock a user account.

What command would a system administrator type to disable the user account bloggsjo (hint:
man passwd)

_______________________________________________

3.9 Unlocking a user account


When the user account is needed again, the system administrator can re-eanble the user account
using the passwd command.

What command would a system administrator type to enable the user account bloggsjo (hint:
man passwd)

_______________________________________________
 

3.10 Changing the group to which a user belongs


A user can only be a member of one group at a time. There are occasions where a user may
require access to a different group. Perhaps this to due to the user now working on a project with
others, and files need to be shared by members of the this group.

The usermod command lets a system administrator change the group that a user belongs to.

3.11 Changing the ownership of files


The following three commands are used by system administrators to modify file permissions.
This may be necessary when a user moves into a new group, or files are made available to a new
group (necessitating a change of ownership and group membership).

chgrp change the group ownership of files


chmod change the access permissions of files
chown change the user and group ownership of files

3.12 Summary
Handling users can be a large part of a system administrators job on UNIX.

A user cannot remember their password. Name two ways in which a system administrator can
change the users password?

_______________________________________________

What actions are required in order for a system administrator to delete a user account?

_______________________________________________

_______________________________________________

_______________________________________________

An exisiting user (who is a member of the group sales) is assigned to a new group called dev.
The user has a number of existing files that they created earlier, yet other members in the group
dev cannot access them. What command should be used to correct this problem?

_______________________________________________

 
4.0 Mounting and Un-mounting file systems
System administrators are often required to mount and unmount file systems. Sometimes a hard
disk may need to be added to the system. On another ocassion, a CD-ROM may need to be
mounted so it can be used by a particular application (such as a WWW server).

The files and commands associated with these activities are

/etc/fstab List of filesystems to mount when UNIX boots


/etc/mtab List of currently mounted filesystems
mount Mount a filesystem
umount Unmount a filesystem

When UNIX boots, it mounts the hard disk as the root file system, and if specified, additional
partitions as other file systems, such as /users and also a swap file system.

Each partition and disk unit (such as hard drive, floppy disk and CD-ROM) appears as a device
(either block or character) in the /dev subdirectory. The following table shows some of the
devices listed in the /dev subdirectory (obtained using ls -la /dev).

lrwxrwxrwx 1 root root 8 Dec 18 02:07 cdrom -> /dev/hdc


brw-rw---- 1 root floppy 2,96 Feb 23 1999 fd0u1760
brw-rw---- 1 root disk 3, 0 Feb 23 1999 hda
brw-rw---- 1 root disk 3, 1 Feb 23 1999 hda1
brw-rw---- 1 root disk 3, 5 Feb 23 1999 hda5

In the above table, /dev/hda is the entire hard disk, with /dev/hda1 the first partition (where the
root file system is located on this system) and /dev/hda5 the second partition (where user
directories have been located on this system).

Type the command mount to view the current mounted filesystems. Complete the following
table listing the mounted devices and mount points (directories).

/dev/hda1 /type
   
   
   

If a particular device requires to be mounted all the time, the details are placed in /etc/fstab. To
list the mounted devices on the system, type mount or view the /etc/mtab file.

4.1 Example of mounting the CD-ROM device, /dev/hdc


Consider the case where a web server has been installed on the UNIX system (apache is a free
web server). The root directory for the web server files was specified as /www and holds the web
site. A training provider has been hired to deliver a two-day workshop. The workshop will
require access to a training CD-ROM that contains HTML files. The system administrator has
been asked to make the files available via the web server.

One method would be to copy the CD-ROM files into a directory under /www, such as
/www/train. This would involve creating the /www/train subdirectory (mkdir /www/train), then
mounting the CD-ROM (mount /dev/hdc /cdrom) and then copying all the files into
/www/train.

The alternative is to mount the CD-ROM as the /www/train subdirectory (mount /dev/hdc
/www/train). The system administrator first creates the empty directory /www/train and then
mounts the CD-ROM. This avoids the necessity to copy the files.

5.0 Backing up files


Another activity that system administrators are responsible for is to backup system and user files.
This ensures that accidently deleted information can be restored at a later date, as well as
protecting against sudden catastrophic failures such as a hard disk crash (when the hard disk
crashes, all files can no longer be accessed).

A system administrator must therefore be familiar with backup programs, and implement a
backup strategy that ensures system and user files are regularly backed up. Typically, the backup
of these files would be automated at run at regular intervals with little or no intervention from the
system administrator. They would typically be run late at night or early morning when few
people are using the computer (running it during the day may slow the system down and affect
performance to users). However, one daily task would be to check the log files to ensure there
was no problem encountered backing up files.

5.1 cpio
A typical program is cpio which provides the ability to read and write files to or from a cpio
archive file.

cpio --create -O archivename


cpio --extract -I archivename

cpio has three operating modes. Use the man command to fill in the following table,
describing each of the three operating modes for cpio.

copy-out mode  
copy-in mode  
copy-pass mode  
Some of the available options for cpio are

-o Create an archive, run in copy-out mode


-i Extract files from an archive, run in copy-in mode
Append to an existing archive. Only works in copy-out mode. The archive must
-A
be a disk file specified with the -O or -F (--file) option
-d Create leading directories where needed.
-I archive Archive filename to use instead of standard input
-O archive Archive filename to use instead of standard output

5.1.1 cpio exercise


In this exercise you will use cpio to create an archive, delete the orginal files, then use cpio to
restore the files.

5.1.1.1 Create the files to be archived


To do this exercise will require a number of files to work with. To create the files to use in this
exercise, type the following commands,

$ cd $HOME
$ mkdir test
$ cd test
$ man cpio > text1
$ man tar > text2
$ cd $HOME
$

You now have two files in the test subdirectory that will be used in this exercise.

5.1.1.2 Run cpio to archive the files


cpio can accept a list of files either from standard input or from a file. Type the following
command

$ cpio -o -Otestcpio

cpio is now waiting for a list of filenames to archive. Type the following

test/text1
test/text2
ctrl-d (Note: this means press ctrl-d key combination)
 

How many blocks were written by cpio?

_______________________________________________

What is the size of the file testcpio?

_______________________________________________

You now have an archive file testcpio that contains the two files /test/text1 and test/text2. This
can be verified using the ls command.

5.1.1.3 Delete the original files and subdirectory


In this part of the exercise you will delete the orginal files. Type the following commands to
delete the original files and the test subdirectory.

$ cd $HOME
$ cd test
$ rm text1
$ rm text2
$ cd $HOME
$ rmdir test
$

The original files have now been erased. The test subdirectory has also been deleted. This can be
verified using the ls command.

5.1.1.4 Restore the orginal files from the archive


In this part of the exercise, you will extract the files from the archive and restore them to the
original location. cpio will also need to create the subdirectory when the files are restored.

Type the following commands to restore the files to their original location.

$ cd $HOME
$ cpio -i -Itestcpio
$

What was the messages printed by cpio?


_______________________________________________

_______________________________________________

_______________________________________________

Do a listing of the files and directories to determine whether the files were restored. Why
do you think cpio printed these messages?

_______________________________________________

_______________________________________________

Type the following commands to restore the files to their original location.

$ cd $HOME
$ cpio -i -Itestcpio -d
$

What was the message printed by cpio?

_______________________________________________

Do a listing of the files in the test subdirectory. Enter the file sizes below.

text1 _______________________________________________

text2 _______________________________________________

Type the following commands to delete the files used in the cpio exercise.

$ cd $HOME
$ cd test
$ rm text1
$ rm text2
$ cd $HOME
$ rmdir test
$ rm testcpio
$

In this cpio exercise, you archived some files, deleted the original files, and later restored those
files from the archive. These are typical system administrator functions. However, a system
administrator would probably use a tape device rather than a file, and would also automate the
archiving of the files so they regularly occurred. In the next section you will learn about tar,
another archiving program.
 

5.2 tar
Another program used to read and write files associated with an archive is tar. Some of the
available options are

-A Append files to an archive


-c Create a new archive
-f Name of archive
-P Keep absolute paths of files
-t List the files in an archive
-v Verbose mode
-x Extract files from an archive
-z Compress/decompress files using gzip

Some examples of tar are

tar -xvf test.tar extract the files from test.tar


tar -xvzf test.tar.gz extract the files from gzipped test.tar.gz
tar -cvf test.tar test/ archive contents of folder test to test.tar

5.2.1 tar exercise


To do this exercise will require a number of files to work with. To create the files to use in this
exercise, type the following commands,

$ cd $HOME
$ mkdir test
$ cd test
$ man cpio > text1
$ man tar > text2
$ cd $HOME
$

You now have two files in the test subdirectory that will be used in this exercise.

5.2.1.1 Run tar to archive the files


Type the following command

$ tar -cvf test1.tar test/


You now have an archive file test1.tar that contains the two files /test/text1 and test/text2. This
can be verified using the ls command.

What is the size of the file test1.tar?

_______________________________________________

5.2.1.2 Create a compressed archive file


In this exercise you will create a new archive, but this time compress the files. Type the
following command

$ tar -zcvf test2.tar.gz test/

You now have an archive file test2.tar.gz that contains the two files /test/text1 and test/text2. This
can be verified using the ls command.

What is the size of the file test2.tar.gz?

_______________________________________________

What conclusions do you draw from files produced by exercises 5.2.1.1 and 5.2.1.2?

_______________________________________________

5.2.1.3 Delete the original files and subdirectory


In this part of the exercise you will delete the orginal files. Type the following commands to
delete the original files and the test subdirectory.

$ cd $HOME
$ cd test
$ rm text1
$ rm text2
$ cd $HOME
$ rmdir test
$

The original files have now been erased. The test subdirectory has also been deleted. This can be
verified using the ls command.

 
5.2.1.4 Restore the orginal files from the archive
In this part of the exercise, you will extract the files from the archive and restore them to the
original location. tar will also need to create the subdirectory when the files are restored.

Type the following commands to restore the files to their original location.

$ cd $HOME
$ tar -zxvf test2.tar.gz
$

Do a listing of the files in the test subdirectory. Enter the file sizes below.

text1 _______________________________________________

text2 _______________________________________________

Type the following commands to delete the files used in the tar exercise.

$ cd $HOME
$ cd test
$ rm text1
$ rm text2
$ cd $HOME
$ rmdir test
$ rm test.tar
$ rm test2.tar.gz
$

In this tar exercise, you archived some files, deleted the original files, and later restored those
files from the archive. These are typical system administrator functions.

6.0 Running programs at scheduled times


Some system administrative tasks suit themselves to being run at regular times. This could be
tasks such as removing temporary files, generating reports, moving or printing audit logs, or
running a tape backup device to save all the system and user files to tape.

6.1 cron
This program is started automatically (from the file /etc/init.d/cron) when the system enters
multi-user mode. cron searches for crontab files in /var/spool/cron/crontabs and if found, loads
them into memory ready for execution. Any crontab files are updated or removed using the
crontab command.
cron also reads /etc/crontab and the files in /etc/cron.d. Every minute, cron is activated and
examines all stored crontab files, checking each command to see if it should be run in the current
minute.

If a command is executed, the output is sent to the owner of the crontab file.

Programs can be scheduled to run daily (/etc/cron.daily), weekly (/etc/cron.weekly)or monthly


(/etc/cron.monthly). Finer control, such as every hour, or minute is also possible.

6.2 crontab
This command can also be used by users (if permitted) so they can run programs at scheduled
times.

crontab is the command used to install, edit, list and remove crontab files . Each user can have
their own crontab file (list of programs to execute).

/etc/cron.allow specifies users allowed to use crontab


/etc/cron.deny specifies users denied access to crontab

crontab accepts the following options

-l List the current crontab


-r Remove the current crontab
-e Create or edit the crontab file

Examples of crontab

crontab -l List the current crontab for the user


crontab -e Edit (or create a new one if there is none) the crontab
crontab -r Remove the current crontab

A user creates a new crontab by using the -e option. Once the editor is quit (by saving the file
and exiting), the new crontab is automatically installed.

6.3 crontab file format


The format for the crontab file is as follows

minute hour dayofmonth month dayofweek command

An example is
5 * * * * who >> /etc/users.list

The asterisk means all occurrences (in the above example, all hours, all days, all months). The
minutes is set to 5 in the above example. This means at 5 minutes past the hour the command
will be executed (it does not mean every five minutes).

6.4 crontab exercise


This exercise assumes that users are allowed to run crontab. Please follow the steps in sequence
as they are inter-related.

6.4.1 Establish your terminal ID


Type the following command to identify your terminal number

$ tty

The system will respond with a /dev/ttyp number. Record this in the space below.

_______________________________________________

6.4.2 Type the following commands to create a crontab file.

$ cd $HOME
$ crontab -e

After a brief message that a crontab file does not exist, the sytem will load the editor and create a
new file.

6.4.3 Enter the following line so that the command executes every minute. Change the
/dev/ttyp number to match that you recorded above in step 6.4.1

* * * * * date > /dev/ttyp1

6.4.4 Press the ESC key. Save the file by typing the following command.

:wq

6.4.5 You should now be at the UNIX shell prompt. To verify that you have a crontab file, type
the following command.

$ crontab -l

6.4.6 What was the message printed when you typed the above command?
_______________________________________________

6.4.7 Wait at least two minutes. The crontab should be executed twice during this time.

6.4.8 What was printed on the screen during this time? Enter the messages printed in the
space below.

_______________________________________________

_______________________________________________

_______________________________________________

6.4.9 Type the following command to remove the crontab file

$ crontab -r

6.4.10 Type the following command.

$ crontab -l

6.4.11 What was the message printed when you typed the above command?

_______________________________________________

7.0 User information


On occasions, a system administrator might want to communicate with a specific user, or all
users on the computer, or determine what programs users are running on the computer system.
For example, the administrator might want to shutdown the computer so a new disk can be
installed. Thus, the administrator would need to inform all users that this was about to take place
and they needed to save their files and log out.

7.1 who
The who command prints the following information for each user currently logged on,

loginname terminalline logintime remotehostnameorXdisplay

Example

$ who
fitiseto ttyp1 Mar 9 13:25 (dhcp-78-168.cit.ac.nz)
oreganma ttyp2 Mar 9 13:31 (dhcp-78-25.cit.ac.nz)
ulaleiu ttyp3 Mar 9 12:09 (dhcp-79-75.cit.ac.nz)
brownbr ttyp6 Mar 9 13:32 (flame.cit.ac.nz)
$

7.1.1 What is the command option you would use to display only the login names and the
number of users logged on (work out the correct command and test it to verify that it
works)?

_______________________________________________

7.2 w
The w command displays the users that are logged on and what they are doing. The following
entries are displayed for each user:

login name, the tty name, the remote host, login time, idle time, JCPU, PCPU,
and the command line of their current process.

Example

$ w
1:37pm up 28 days, 4:24, 10 users, load average: 0.10, 0.09, 0.03
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
oreganma ttyp0 dhcp-78-25.cit.a 1:09pm 7:02 4.09s 2.44s vi newfile
fitiseto ttyp1 dhcp-78-168.cit. 1:25pm 6.00s 3.11s 1.16s vi newfile
brownbr ttyp6 flame.cit.ac.nz 1:32pm 2.00s 3.49s 1.48s w
$

7.2.1 Use the man command for w to complete the following table

Abbreviation Meaning
JCPU  
PCPU  

7.3 writeall (wall)


The wall command displays the contents of a file or, by default, its standard input, on the
terminals of all currently logged in users. When used by a system administrator, it overrides the
user settings of those that have chosen to deny messages (using msg) or are using a program
which automatically denies messages.

An example (do not type this)

$ wall
Hello there. This is the system administrator.
Please logout. The system is being shutdown in 5 minutes.
ctrl-d
$

7.4 /etc/motd
The message of the day is held in the /etc/motd file. The contents of /etc/motd are displayed after
a successful login. A system administrator can place any message in this file and can thus advise
users of upcoming events etc when they log on. This is easier than using email and uses less disk
space.

8.0 Other system activities


System administrators are responsible for looking after the file systems, hard disks, printers and
shutting down the system.

8.1 fdisk
This command lets a system administrator view or edit table partition of a hard disk drive. Disk
drives are normally divided into one or more logical disks called partitions.

/dev/hd[a-h] for IDE disks


/dev/sd[a-p] for SCSI disks

A partition is a device name followed by a partition number. The partition is a device name
followed by a partition number. For example, /dev/hda1 is the first partition on the first IDE hard
disk in the system.

All unix systems require a separate partition that is used as a swap area (this is used to implement
virtual memory and the operating system swaps processes out of main memory to this swap
area). The size of the swap partition depends upon a number of factors, such as available
memory, amount of disk space available and the number of users.

The LINIX computer used for these exercises has been configured with a 200MB swap partition
size (the system uses a 4GB disk and supports approximately 40 simultaneous users with 64MB
RAM).

What is the command that will list the partition tables?

_______________________________________________

 
8.2 fsck
fsck is used to check (or repair) a filesystem. As files are created, renamed, moved, deleted or
aborted, corruption of the filesystem can take place. There may be an entry for a file that really
doesn’t exist (the space for the file is marked as free).

System administrators regularly use fsck to check the filesystems to ensure that there are no file
problems.

fsck cannot be run on a filesystem that is mounted. When a UNIX system is shutdown correctly,
the filesystem is marked with a special flag. On bootup, the state of this flag is checked. If the
system was simply turned off or crashed, the startup sequence thus detects that the system was
not shutdown correctly, so automatically runs fsck at startup before the filesystems are mounted.

8.3 mkfs
When a new disk is added to a UNIX system, it is partitioned using fdisk. Once the desired
partitions are created, a filesystem must be created on the partitions so that files can be stored.

mkfs is the command used to create UNIX filesystems. The following example creates a new
UNIX filesystem on the first partition of the hard drive.

$ mkfs /dev/hda1

8.4 df and du
Another task a system administrator performs is to maintain the file system, by using df to report
the number of free blocks, and du to report the number of blocks used in a directory. In a typical
system, at least 15% free space is requarded as a minimum.

8.5 shutdown
When it becomes necessary to shutdown the computer system, the system administrator should
use the correct command to ensure that the system is shutdown in the correct sequence. The
following command

$ shutdown -g0

shuts down the computer without delay.

What would be the command to shutdown the computer in 10 minutes and display the
message "Please logoff now" to all users, automatically reboot after shutdown and force
the system to run fsck on reboot?
_______________________________________________

8.6 init
This command, used only by the system itself and system administrators, changes the runlevel of
the system. The runlevel is a mode of operation, such as single user or multiuser mode.

The init command accepts the following arguments

S Single user mode, used for maintenance


0-6 Runlevel to boot into
0 = halt the system
1 = single user mode
2 = multiuser mode
6 = reboot the system
-b Emergency, boot directly into a single user shell without running any other startup scripts

An example (do not type this command)

$ init 1

Type the following command

$ init

What was the message printed?

_______________________________________________

8.7 runlevel
runlevel displays the current and previous system runlevel (by reading the file /var/run/utmp)
separated by a single space. If there was no previous system runlevel, the letter N is printed.

Type the following command

$ runlevel

What was the message printed?

_______________________________________________

 
 

This now compeletes these exercises in system administrator commands. This exercise is an
introduction and thus does not cover all aspects of system administration. It is designed to get
you started.

Linux - File System format supported

EXT2 - Extended 2

EXT3 - Extended 2 + Journal

JFS - Journal file system

Resier - Advanced Journal

LVM - Logical Volume manager

VFAT - FAT 16 / 32

NTFS

System Initialization & Services


1.     Describe the boot process.

Ans.

BIOS Initialization

         Detection of peripherals

         Boot device selection

         Read & execution of first sector of the boot device

Boot Loader execution

Kernel Initialization

         init process starts and enters desired run level by executing
                     /etc/rc.d/rc.sysinit

                     /etc/rc.d/rc

                     /etc/rc.d/rcX.d/   (Where X is the run level specific digit)

                     /etc/rc.d/rc.local

                     X Display Manager

2.      What is the function of /etc/rc.d/rc.sysinit?

Ans.

This file includes the tasks:

         Sets kernel parameters in /etc/sysctl.conf

         Sets the system clock

         Keymaps loading

         Enables swap partition

         Sets hostname

         Root filesystem check and mount

         Add RAID devices

         Disk quota enable

         Check and mount other filesystems

         Cleans up stale locks and PID files

3.      What is the function of /etc/rc.d/rc?.d?

Ans.
               Run level specific script directories

4.      What is the function of /etc/rc.d/rc.local?

Ans.

This script is run each time the system enters a run level.

It is the common place for the custom modification.

It is a convenient place to start processes that need to be running.

5.      What does the /etc/inittab contains?

Ans.

This file contains:

         Initial run level

         System initialization scripts

         Run level specific script directories

         Trap certain key sequences

         UPS power fail and restore scripts

         Spawn gettys on virtual console

         Initialize X window system in run level 5

6.      What is the Linux default run level?

Ans. Linux default run level is 3


7.      Describe the various run levels?

Ans.

         0                  Halt

         1, S              Single user mode      

         2              Multi user mode without support of NFS

         3                  Multi user mode with NFS support (GUI not

                                 supported)

         4          >       User definable, but duplicate of run level 3 by default

         5                  X11 (Includes NFS support)

         6                  Reboot

8.      Describe the various tools used to control the system services?

Ans.

ntsysv

redhat-config-services

chkconfig

service

9.      What are the various commands used for system  shutdown/reboot?

Ans.

shutdown -h now (Halt after shutdown)

shutdown -r  now (Reboot after shutdown)


halt

poweroff

init 0

reboot

init 6

10.   What does the /etc/sysctl.conf file contains?

11.   What is the path of the grub.conf file?

Ans. /boot/grub/grub.conf

12.   How to reinstall the GRUB boot loader?

Ans. 

Reboot the system in rescue mode.

After system is up run the commands:

         # Chroot /mnt/sysimage

         # /sbin/grub-install   /dev/had

13.   Where to examine the kernel messages?

Ans.  In /var/log/dmesg file.

14.   Which is the first process started in Linux and What is its process ID?

Ans.  init process and its PID is 1.


Kernel Modules
1.       What is the advantage of modular kernel approach in Linux?

Ans.

Most components of the Linux kernel can be compiled as dynamically loadable


modules. This increases the functionality of the kernel without increasing the
size of the kernel loaded at boot time.

2.         Where does the kernel modules reside?

      Ans.     In /lib/modules/

3.         Specify the commands used to control the modules?

      Ans.              lsmod           >          lists the modules currently reside in the kernel

insmod         >          inserts module (Also used modprob)

rmmod         >          unloads module

depmod        >          module dependency database is generates

4.        What is the advantage of modprob over insmod?

Ans.
modprob is used to load the kernel modules with three improvements over
insmod:

            It will load any underlying modules required by a given module.

            It will consult /etc/modules.conf for default module parameters.

            It can try a list of modules, and when it loads a module successfully, it will
cease trying others in the list.

      5.         Which thread is responsible for executing the modprob as needed?

      Ans.     kmod.

      6.         In which file modules are configured?

      Ans.    /etc/modules.conf

      7.         How to see the module information?

      Ans.     By the command:

                        #  modinfo  -p 

8.         What is Initial RAM Disk (initrd)? What is its function?

Ans.

An initrd is a compressed image of a filesystem, which contains modules that


may be necessary prior to kernel mounting the root filesystem.

      9.         Which command is used to create the initrd?

      Ans.     mkinitrd


Hardware Browsing & System Monitoring
1.      How to check the system hardware?

Ans.

   Any of the following methods can be used:

            /var/log/dmesg

            /proc filesystem

            /etc/sysconf/hwconf

            /usr/share/hwdata/

            hwbrowser

2.      How to check PCI / ISA devise information?

Ans.

    /proc/bus/pci/

    /sbin/lspci

    /proc/isapnp/

3.      How to get info of hotswappable devices?

Ans.
    /etc/hotplug

    /sbin/hotplug

    /proc/bus/

4.      How to get info of USB devices?

Ans.    /sbin/lsusb

    /sbin/usbmodules

    /dev/usb

5.      How to get PCMCIA bus information?

Ans.

    /sbin/cardmgr

    /etc/pcmcia/

    /proc/bus/pccard

    /sbin/cardctl

6.      What are the various tools used for system monitoring?

Ans.

    top & gnome-system-monitor         >          Display snapshot of processes.

    vmstat >          virtual memory status

    iostat               >          Recourse usage including I/O statistics

    free                 >          Summery of system memory usage

 
7.      What are the various tools used for process control?

Ans.

    kill                  >          sends system signal to a process

    renice             >          Change priority of a process

1.         Name the Linux specific partition types?

Ans.

            0x82                     >          Linux swap

            0x83                     >          Linux

            0x8e                      >          Linux LVM

            0xfd                      >          Linux RAID auto

            0x5                        >          Extended

            0xf                         >          Windows partition

2.         How many partitions are supported by Linux?

Ans.

            The maximum number of partitions supported by Linux kernel is:

            63 for IDE drives

            15 for SCSI drives

3.         Why partitions required?

Ans.
Separate partitions improve performance by keeping data together which
reduces the disk head seek.

4.         What are the tools used to create or manage partitions?

Ans.

            fdisk

            sfdisk

            parted (GNU) - An advanced partition manipulation tool (create, copy,

                              resize etc.)

5.         What is the function of partprobe?

Ans.

            Reinitializes the kernel's in memory copy of the partition table.

6.         How to create a filesystem?

Ans.

            The mkfs command is used to create the filesystem.

            mkfs.ext2 / mkfs.ext3     >          To create ext2/ext3 filesystem

            mkfs.minix                       >          minix filesystem

            mkfs.msdos                      >          MS-DOS filesystem


7.         What is the difference between ext2 and ext3 filesystem?

Ans.

            ext3 filesystem supports journaling, where as ext2 does not.

8.         What is journaling?

Ans.

           

9.         What are the journaling modes supported by ext3 filesystem?

Ans.

            Ordered                >          Journals only metadata (This is the default)

            Journaled              >          Journals data as well as metadata

            Writeback            >          Journal updates are not atomic, but this gives

                                                      better performance.

10.       How to convert an ext2 filesystem to ext3?

Ans.

            Change the /etc/fstab to specify ext3 for desired filesystem(s)

            Create the ext3 journal on the ext2 filesystem(s) as:

            # tune2fs  -j 

            If the kernel needs to have access to the ext3 module at boot time, create  a
new initial ramdisk as:
            # mkinitrd  /boot/initrd-.img

11.       How to connect a file system to a Linux box?

Ans.

            Mount command is used.

12.      How to find currently mounted and available filesystems?

Ans.

Use mount command without arguments.

13.      Which filesystem is referred by mount when displaying mounted & available
filesystems?

Ans.

When mount command is invoked without any arguments it referes to the


/etc/mtab filesystem.

14.      How to disconnect a filesystem from a Linux box?

Ans.

            The umount command is used.


15.      Which command is used to display information about the processes using a
filesystem?

Ans.

           The fuser command is used.

16.      How to display who/what is acting on a filesystem?

Ans.

           # fuser  -v  mnt_point

17.      How to kill all actions on a filesystem?

Ans.

                 # fuser  -km  mnt_point

18.      How to view all the mounted and unmounted partitions?

Ans.     Use the fdisk -l command to view all the mounted and unmounted

             filesystems available on your system.

           

19.      How to view only the mounted filesystems?

Ans.

Use the df -k command, which shows only mounted filesystems but has the big
advantage of giving you the mount points too.

20.      What is the function of e2label command?

Ans.
With the help of e2label command a filesystem label can be written into the
superblock of ext2/ext3 filesystem.

Eg:-           #e2label  /dev/hda3  datadisk3

Will create a label of datadisk3 on the filesystem on partition /dev/hda3.

21.      How to display the label for a device (/dev/hdb2)?

Ans.

            # e2lable  /dev/hdb2

22.      What is the function of /etc/fstab?

Ans.

This file is referenced each time the system boots to create the desired
filesystem hierarchy.

23.      What are the fields /etc/fstab containd?

Ans.

            The /etc/fstab fields are:

                  Device                        >          Special device/filesystem

                                                                   label dev to mount

                  Mount_Point             >          The path used to access the

                                                                   filesystem
                  fs_type                       >          The filesystem type

                  Options                       >          List of Options (each is

                                                                   separated by a comma)

                  Dump frequency        >          Level 0 dump freq (0 = never

                                                                  dump, 1 = daily &

                                                                  2 = every other day)

                  fsck Order                  >         0 = ignore, 1 = first (root

                                                                  should have this value),

                                                                  2 to 9 = 2nd, 3rd and so on.

                                                                  NFS & CD-ROM s should                             


be ignored (i.e., value 0).

24.      How to list the ext2/ext3 filesystem attributes?

Ans.    lsattr  command displays file attributes

25.      How to change the ext2/ext3 filesystem attributes?

      Ans.   chattr command changes the file attributes.

Filesystem Management 2
26.    What is swap space?
Ans.  Swap space is supplement to system RAM.

27.    How to set up swap partition?


Ans.  Steps involved in setting up swap partition.
         Create a partition using a partitioning program (fdisk/sfdisk/parted)
         Set partition id type to 0x82.
         Create the signature on the partition using the mkswap command
         # mkswap  -v1  /dev/hdb3
        Add an entry for the swap in /etc/fstab file as:
        /dev/hdb3   swap   swap   defaults    0   0
        Activate the swap partition using
        # swapon -a
        Check the swap partition status using
        # swapon  -s

28.    How to create a swap file?


Ans.  Create a file as
         # dd  if=/dev/zero  of=swapfile   bs=512  count=N
         (Where N is the file size in KB)
         Run the mkswap to create signature
         Activate the swap file with swapon command (OR) initialize it in the startup
         script /etc/rc.d/rc.local

29.    Why fsck used?


Ans.  fsck (filesystem check) is used to maintain filesystem consistency.

30.    When the system runs the fsck and which script invokes it?
Ans.  When the system boots,  the rc.sysinit script runs the fsck on any filesystems
         marked for checking in /etc/fstab file. If any of these filesystems are markes as  
         dirty or have data in the journal, fsck will attempt to repair them. If it succeeds,
         the filesystems will be mounted and boot process continues, else rc.sysinit will 
         run sulogin and will report that fsck needs to be run manually.

31.    What is e2fsck command?


Ans.  fsck is a front end tool for e2fsck.

32.    What is journaling?


33.    Types of journals and their function?
Ans.  Ordered          :    This is the default and journal only meta-data
         Journaled        :    Journals data and meta-data
         Writeback       :    Journal updates are not atomic.

34.    Differentiate ext2 and ext3 file systems?


Ans.  ext3 filesystem supports journaling concept where ext2 does not.

35.    What is the function of tune2fs command?


Ans.  This is used to modify the filesystem attributes (Like converting ext2 to ext3).

36.    What is the function of dump2fs command?


Ans.  Provides a dump of file system information to standard out (Console). Can be
         redirected to a file.

37.    What is the function of debugfs command?


Ans.  This utility is used to to examine and debug an ext2 filesystem. This can also be
         used to manually verify the inode integrity and an aid to recover data.

38.    What is the function of resize2fs command?


Ans.  This can be used to change the size of an ext2 or ext3 filesystem.

Regularly Monitoring and capturing system log files.

2) Regularly Monitoring and capturing data of server CPU , memory usage

3) Regularly monitoring Filesytems space.

4) Regularly monitoring capturing Network usage.

5) Writing automated scripts to handle routine user and sysadmin tasks.

6) Users Management and Support

7) Taking backup of Important filesystems.

8) Maitaining documentation for system paramters and disk layout.

9) updating with new technologies

 /var/log/dmesg - Check hardware.


 /var/log/messages - Check Linux message log.
 /var/log/syslog - Check Linux system log.

Reconfigure Linux installation


The second Linux installation troubleshooting is to re-configure Linux installation. If you need to
re-configure your software or hardware, check this list:

 pkgtool - Software package maintenance tool. Install, remove or view packages.


 fdisk or cfdisk - Partitioning.
 /boot/grub/grub.conf - GRUB boot loader.
 /etc/lilo.conf - LiLo boot loader.
 netconfig - Networking (ethernet and tcp/ip)
 timeconfig - Time zone
 adduser - User accounts
 xorgsetup - Reconfigure X window system
 xorgconfig - Reconfigure mouse, keyboard, x window.

Linux important scripts location


Below are Slackware Linux important scripts location. If you are using different Linux
distribution, you can find the script with find, whereis and locate commands.

Configuration and startup scripts

 /etc/inittab - run level setting script


 /etc/rc.d - startup script

General purpose Linux network configuration scripts

 /etc/hosts - store hostname and IP address


 /etc/inetd.conf - execution information for on demand system services
 /etc/resolv.conf - contains DNS server addresses
 /etc/services - contains names and ports of network services
 /etc/nsswitch.conf - Sequences that the Linux system looks for the network services

You might also like