Linux Chapter 6
Linux Chapter 6
1. BIOS
3. GRUB
GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system, you can
choose which one to be executed.
GRUB displays a splash screen, waits for few seconds, if you don’t
enter anything, it loads the default kernel image as specified in the
grub configuration file.
GRUB has the knowledge of the filesystem (the older Linux loader
LILO didn’t understand filesystem).
So, in simple terms GRUB just loads and executes Kernel and
initrd images.
4. Kernel
Mounts the root file system as specified in the “root=” in grub.conf
Kernel executes the /sbin/init program
Since init was the 1st program to be executed by Linux Kernel, it
has the process id (PID) of 1.
initrd stands for Initial RAM Disk.
6. Runlevel programs
When the Linux system is booting up, you might see various
services getting started. For example, it might say “starting
sendmail …. OK”.
Those are the runlevel programs, executed fromthe run level
directory as defined by your run level.
Depending on default init level setting, the system will execute the
programs from one of the following directories.
o Run level 0 – /etc/rc.d/rc0.d/
Runlevels:
• A runlevel is the operating state of a Linux operating system.
Runlevel 2 Boots the system into a multi-user mode with text based
console login capability. This runlevel does not, however,
start the network.
Runlevel 6 Reboots the system. Another runlevel that you are unlikely
to want as your default.
System Administration
The job involves the management of the entire system, ranging from
maintaining security, performing backups and disk management, to
providing a reliable service to all users.
This task is usually entrusted to a single person, the system administrator,
also sometimes known as the super user.
He has vast powers, having access to everything.
The success and stability of any UNIX installation depends, on the
effectiveness of the system administrator’s
System administration in UNIX is quite demanding, and requires from the
administrator an in depth knowledge of the different components of the
system.
Most routine system administration functions can be handled by a special
menu-driven software sysadm (SVR4), scoadmin (Sea UNIX), control-panel
(Red Hat Linux) and yaSt (SuSE Linux).
The UNIX system provides a special login name for the exclusive use of the
system administrator's , it is called root.
This account doesn't need to be separately created, but comes with every
system.
It also has a password, and like other user-ids, the administrator is expected
to enter it before he logs in.
The prompt of root is #, unlike the $ used by all other users. Once you log in
to root, you are placed in the root (the top-most) directory (/root in Linux).
Most super user commands are resident in /etc (/sbin and /usr/sbin in SCO
UnixWare and Linux), the reason why his PATH list is different from other
users:
Since the super user is always moving around in the file system, it is
possible that he might inadvertently execute programs and shell scripts of
other users.
That's why the PATH for a super user doesn't include the current directory
Many of the standard scripts supplied with UNIX systems for system
administration work (especially the scripts related to booting) rely on the
Bourne shell for execution.
As an administrator, you should not use the Korn shell, and definitely not the
C shell, as your login shell.
Linux uses bash for system administrative activities also.
Any user can acquire super user status with the su command if she knows
the root password.
For example, the user local (with the home directory /home/local) can also
use become a super user:
If you have not specified a user name su will try to acquire the root’s
privilege.
$ su – manoj
password : ***********
$
Now you got the privilege of the user manoj.
$ exit
$
Now you have returned back to the privilege of the original user
# su – manoj
$
Since you are using su as root it will not ask for the password of the new
user.
Administration Privileges
The super user has enormous powers, and, any command invoked by him
has a greater chance of success than those issued by others.
There are several commands that are reserved for his exclusive use; no
other user will be able to execute them at all.
There are some more commands that behave differently when executed by
him .
The authority of the administrator is mainly derived from his power to
change the attributes of any file, and the power to initiate or kill any process.
No file can ever be secure from him; he can delete any file with rm even if it
is write-protected.
The restriction on ownership (file or process) simply doesn't apply to him.
That is why the administrator has to use these powers with the utmost
caution.
Note that the system doesn't prompt for the old password when you invoke
this command as a super user.
You should also make sure that knowledge of this password is kept closely
guarded.
However, you must remember it yourself because if you forget it, then the
entire UNIX system may have to be reloaded
A system administrator can never function properly unless he has access to
every user's directory.
If he has reason to believe that an unauthorized person has acquired
knowledge of a user's password, then he should change the password of the
user immediately.
Since he is not the custodian of everybody's password, UNIX allows him a
certain privilege of changing anybody's password without knowing it:
Once again, the old password is not prompted for, only the new one has to
be entered twice.
Note: When the super user uses the passwd command to change a user's
password, he doesn't have to enter the old password to be able to change it.
Maintaining Security
When you create a new file, Linux assigns the file permissions of the new
file using your default UID and GID.
To allow others access to the file, you need to either change the security
permissions for the everyone security group or assign the file a different if all
group that contains other users.
If you want to create and share documents among several people, there are
three additional bits of the information that Linux stores for each file and
directory like SUID, SGID, Sticky Bit.
These are are some other special permission apart from the normal file
permissions read, write and execute which we set with chmod and chown
commands.
SUID Example
$ chmod u+s testfile.txt OR $ chmod 4750 testfile.txt
In above example, 4 indicates SUID bitset, 7 for full permissions for owner,
5 for write and execute permissions for group and no permissions for others
SGID Example
$ chmod g+s <file / Directory > OR $ chmod 2750 <file / Directory >
Here, in 2750, 2 indicates SGID bitset, 7 for full permissions for owner, 5
for write and execute permissions for group and no permission for others
Sticky Bit Example
$ chmod o+t /opt/ftp-data OR $chmod 1757 /opt/ftp-data
In above example, 1 indicates Sticky Bit Set, 7 for full permissions for
owner, 5 for read and execute permissions for group and full permissions
for others
Users and Groups
The control of users and groups exists at the core of Red Hat Linux system
administration.
Users can be either people or logical users (accounts that exist for
applications so that they can perform specific tasks).
Both types of users have a Unique User ID and Group ID.
Groups are logical expressions of organization.
Groups form the foundation of tying users together and giving them
permissions to read, write, or execute a given file .
Proper management of users and groups, as well as assigning and revoking
permissions, is one of the most important tasks of a system administrator.
Types of Users:
• In a multiuser OS environment, there are multiple users who log into the
system to carry out their tasks. The users in multiuser OS environment
can be categorized as-
End users-
• These work on various utilities or applications installed on the system.
• These utilities can be single line utilities, shell scripts and C/C++
programs.
• The End users of the system are not involved in system maintenance
task.
Power users-
• The power users of the system carry out all the activities of an end user
and are also responsible for
• maintaining printer queues,
• backing up files on regular basis and
• performing house keeping tasks like cleaning up unwanted files.
System Administrators-
• System administrators have complete control over the manner in which
the OS is set up on the machine and all the applications installed on the
system.
• They are also responsible for maintaining the hardware devicesattached
to the system.
Managing users and groups is tedious, but Red Hat Linux provides a few
tools and conventions to make users and groups easier to manage.
While you can use useradd to create a new user from the shell prompt, a
popular way to manage users and groups is through
# redhat-config-users
useradd command
From time to time, you have to add new users to the system.
You have to associate each user with a group, and decide the permissions
that have to be set for both the user and her group.
Adding a user involves setting of the following parameters, most of them in
/etc/passwd:
A user identification number (UID) and username
A group identification number (GID) and group name
The home directory
The login shell
The mailbox
The password
If the user is to be placed in a new group, an entry for the group has to be
created in /etc/group.
A user always has one primary group, and may also have one or more
secondary groups.
This file contains all the named groups of file system.
The useradd command can be used to create user accounts. The
command format is given below:
useradd [-u UID][-g GID] [-G group1,group2…] [-c comment]
[-s shell] [-d home] [-e expire_date] [-f n] –m <username>
-u UID User identification no. If not specified the next available
user ID will be taken as the UID
-g GID To specify the primary group ID for the user
-G group1 To specify the supplementary groups where the user
Should have the membership
-c To specify the comment.
-s To specify the default shell of the user. If not specified /bin/bash
will be taken as the default shell.
-d To specify the path for the home directory. If not specified home
directory will be created as /home/<username>
-e To specify the date of expiry of the user account in YYYY-MM-DD
format.
-f n Disable the account n days after the account password expires.
-m To create the home directory if it does not exists.
<username> Name of the useraccount.
usermod Command
usermod [-u UID] [-g GID] [-G grop1,group2…] [-c comment] [-s shell] [-d
home] [-e expire_date] -l -L -U –m <username>.
groupdel groupname
The id command
This command can be used to get the information about the uid, gid and
supplementary group Ids and group names of a user account. If you
invoke this command without any argument it will give details about
the current user.
# id
uid=0(root) gid=0(root) groups=0(root), 1(bin), 2(daemon), 3(sys), ……
# id meera
For getting the uid and gid information of a different user you can give
the user name as an argument to id command as above.
Using Graphical tools
On the GNOME desktop, go to the Main Menu Button (on the Panel)
--> Programs --> System -->
User Manager.
On the KDE desktop, go to the Main Menu Button (on the Panel) -->
Red Hat --> System -->
User Manager.
Operation
Booting and shutting down a system are some of the functions you
have to perform daily as an administrator.
Unlike DOS, a UNIX system can't be brought up by simply switching
on the machine, but rather by issuing a series of commands in
sequence, or responding to some prompts.
A separate series of steps also needs to be followed before the
machine is brought to a standstill.
Booting / Startup
Before the system is brought up, you have to first turn on power to the
peripherals that are immediately required.
This is necessary because, when the kernel is loaded, the device
drivers for those peripherals that are powered and connected, can be
loaded too.
After these external devices are switched on, the computer itself can
be turned on.
The machine then goes through a complex series of processes that
may take up to a few minutes to complete the boot cycle.
The exact sequence of the steps followed will depend both on the
hardware and software used.
The first major event is the loading of the kernel into memory.
The kernel then starts Spawning further processes, the most
important of which is init. This process always has the PID 1.
It, in turn, spawns further processes some of which monitor all the
terminal lines.
Eventually, init becomes the parent of all shells
UNIX system can be set up in a number of modes (called run levels)
that are controlled by init.
Options
been brought down, with the choice as to which left up to the system.
-H : Requests that the system be halted after it has been brought down.
-P : Requests that the system be powered off after it has been brought
down.
sudo shutdown
shutdown -P
sudo shutdown -c
IP Address Configuration
eth0is the Linux name of the first network interface that is shown by
the boot messages or the dmesg output.
If the machine is a gateway, then the second interface name could be
eth1.
You can think of it like any normal database. You can query these
tables in following two ways:
Listing the entire table.
The single domain configurations are the most widely used in most
situations. Fig. 5.4 illustrates the single domain, single server
configuration.
In Fig. 5.4, the single server, master-1, responds to all queries from NIS
clients (client-1, client-2, and client-3) and is the sole source of
information for the domain, named admin.
2. A single domain with a master server, one or more slave servers, and one
or more clients:
Fig. 5.5 illustrates the same domain but includes a slave server, slave-1.
In this case, client-1 and client-2 continue to query the master server, but
client-3 communicates with the slave server when performing NIS queries.
In Fig. 5.5, client-3 has not specifically been configured to communicate
with the slave server. Rather, it sends out NIS broadcast messages for a
given domain and accepts replies from any server authoritative for that
domain the server that "wins" is the server that replies first.
3. Multiple domains, each with its own master server, no slave servers, and
one or more clients:
At large sites or in complicated networks, you might find it necessary to
have multiple NIS domains hence Fig. 5.6 and 5.7 illustrate such
configurations.
Fig. 5.6 shows two domains, admin and devel, each with its own master
server, master-admin and master-devel. Clients in the admin domain (client-
1, client-2, and client-3) communicate only with the master-admin server,
and clients in the devel domain (client-4, client-5, and client-6) communicate
only with master-devel.
4. Multiple domains, each with its own master server, one or more slave
servers and one or more clients:
Fig. 5.7 illustrates the same setup as Fig. 5.6, except that each domain
has a slave server, slave-admin and slave-devel, and some of the clients in
each domain communicate with the slave servers rather than with the
master.
As in the single server example, any given client will communicate with
the server for its domain that responds the fastest to a broadcast query.
A property configured NIS Setup involves configuring at least one NIS
Server and one or more NIS Clients.
NFS stands for Network File System, a file system developed by Sun
Microsystems, Inc..NFS allows a system to share directories and files
with others over a network.
By using NFS, users and programs can access files on remote systems
almost as if they were local files.
For example, if you were using a computer linked to a second computer
via NFS, you could access files on the second computer as if they
resided in a directory on the first computer.
The possible uses of NFS are quite varied. For example, many sites store
users' home directories on a central server and use NFS to mount the
home directory when users log in or boot their systems.
Of course, In this case, the exported directories must. be mounted
/home/username on the local (client) systems, but the export itself can
be stored anywhere on the NPS server, say, /exports/users/username.
Another common scheme is to export public data or project-specific files
from an NFS server and to enable clients to mount these remote file
systems anywhere they see fit on the local system.
SAMBA
SAMBA is a collection of different applications with when used together let a
Linux server perform network actions like file serving,
authentication/authorization, name resolution and print services.
Linux Samba Server is one of the powerful servers that helps you to share
files and printers with Windows-based and other operating systems.
Samba is based on the common client/server protocol of Server Message
Block (SMB) /Common Internet File System (CIFS).
SMB is a file sharing protocol that was invented by IBM and has been
around since the mid-eighties. Since it's a protocol, (an agreed upon way of
communicating between systems).
SAMBA allows for a Linux server to act as a Domain Controller. By doing so,
user credentials on the Windows domain can be used instead of needing to
be recreated and then manually kept in sync on the Linux server.
Using client software that also supports SMB/CIFS (for example, most
Microsoft Windows products).
An end user sends a series of client requests to the SAMBA server on
another computer in order to open that computer's files, access a shared
printer, or access other resources.
The SAMBA server on the other computer responds to each client request,
either granting or denying access to its shared files and resources.
This means you can use a Linux server to provide file sharing, printing, and
other services to other non-native Linux clients such as Microsoft Windows
using SAMBA.
SAMBA as a DC:
This option allows you to keep all your logins and passwords on the
Linux system, while all your Windows boxes authenticate with SAMBA.
Custom Script:
You can create scripts for maintaining logins and passwords.
This can be done using a cross-platform scripting language like Python.
Using df
• The easiest way to see how much free disk space is available on a
system is to use the df command.
• Linux produces a different output; df there shows the percentage disk
utilization also
• E.g.:
• $df
File 1k-blocks Used Available Use% Mounted on
system
/dev/sda3 8428196 4282228 3717836 54% /
/dev/sda1 124427 18815 99188 16% /boot
/dev/sda4 8428196 3801644 4198420 48% /home
none 644600 0 644600 0% /dev/shm
• As we can see,
• df lists every mounted system
• provides information such as device size (under the 1k-blocks
column), as well as the space used and still available.
However, the easiest thing to do is to simply scan the Use% column for any
numbers nearing 100%.
du - report disk space in use
• du reports the amount of disk space in use for the files or directories you
specify.
• Syntax
du [options] [directory or file]
• Common Options
• -a display disk usage for each file, not just subdirectories
• -s display a summary total only
• -k report in kilobytes (SVR4)
Examples
• #du /home/sales/
4244 /home/sales/fans
6777 /home/sales/tvs
3229 /home/sales/ovens
The path list (I) indicates that the search should start from the root directory.
Each file in the list is then matched against the selection criteria (-name afi edt.
buf), which always consists of an expression in the form -operator argument. If
the expression matches the file (i.e., the file has the name afiedt.buf), then the
file is selected. The third section specifies the action (-print) to be taken on the
file, in this case, a simple display on the terminal. All find operators start with a -,
and the path list can never contain oneJ
-name is not the only operator used in framing the selection criteria; there
are many others (Table 17.1). s
The actual list is much longer, and takes into account practically every file
attribute.
• The dd command allows you to copy from raw devices, such as disks and
tapes, specifying the input and output block sizes.
• dd was originally known as the disk-to-disk copy program. With dd you
can also convert between different formats, for example, EBCDIC to
ASCII, or swap byte order, etc.
• Syntax
dd[if=input_device] [of=output_device] [Operand=value]
Common Options
• if=input_device the input file or device
• of=output_device the output file or device
• If the input or output devices are not specified they default to standard
input and standard output, respectively.
In Linux, the mdadm utility makes it easy to create and manage software RAID
arrays. If mdadm utility is not installed then use following command:
# sudo apt install madam
Use the following command to check the number of disk on your Linux system:
# lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT
If you have two disks then you can configure RAID 0 and RAID 1. In the below
case there are three disk names as (sda, sdb, sdc)
This is a mandatory step before logically removing the device from the array,
and later physically pulling it out from the machine in that order (if you miss
one of these steps you may end up causing actual damage to the device):
Telnet
Backup Strategies
Syntax
• cpio {-i} [options] [pattern...] [ _ archive]
• cpio {-o} [options] _ name-list [ _ archive]
• cpio {-p} [options] dest-dir _ name-list
cpio copies files between archives and directories.
E.g.:
• # ls | cpio –ov > /dev/fd0
• This copies the files in current directory to 1.44 MB floppy
• # cpio –iv < /dev/fd0
• This command restores the files from backup.
• Unless specifically stated otherwise, options are applicable in all operating
modes.
Then you have the name of the file you want to create (linux_notes.tar) and
the files you want to backup (notes*.txt).