Linux Assignment - 4

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Q: 1

Ans:

Linux Boot Sequence:


An operating system (OS) is the low-level software that manages resources, controls peripherals, and
provides basic services to other software. In Linux, there are 6 distinct stages in the typical booting
process.

1. BIOS

BIOS stands for Basic Input/Output System. In simple terms, the BIOS loads and executes the Master
Boot Record (MBR) boot loader.

When you first turn on your computer, the BIOS first performs some integrity checks of the HDD or SSD.

Then, the BIOS searches for, loads, and executes the boot loader program, which can be found in the
Master Boot Record (MBR). The MBR is sometimes on a USB stick or CD-ROM such as with a live
installation of Linux.

Once the boot loader program is detected, it's then loaded into memory and the BIOS gives control of
the system to it.

2. MBR

MBR stands for Master Boot Record, and is responsible for loading and executing the GRUB boot loader.

The MBR is located in the 1st sector of the bootable disk, which is typically /dev/hda, or /dev/sda,
depending on your hardware. The MBR also contains information about GRUB, or LILO in very old
systems.

3. GRUB

Sometimes called GNU GRUB, which is short for GNU GRand Unified Bootloader, is the typical boot
loader for most modern Linux systems.

The GRUB splash screen is often the first thing you see when you boot your computer. It has a simple
menu where you can select some options. If you have multiple kernel images installed, you can use your
keyboard to select the one you want your system to boot with. By default, the latest kernel image is
selected.

The splash screen will wait a few seconds for you to select and option. If you don't, it will load the
default kernel image.
In many systems you can find the GRUB configuration file at /boot/grub/grub.conf or /etc/grub.conf.
Here's an example of a simple grub.conf file:

#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
initrd /boot/initrd-2.6.18-194.el5PAE.img
4. Kernel

The kernel is often referred to as the core of any operating system, Linux included. It has complete
control over everything in your system.

In this stage of the boot process, the kernel that was selected by GRUB first mounts the root file system
that's specified in the grub.conf file. Then it executes the /sbin/init program, which is always the first
program to be executed. You can confirm this with its process id (PID), which should always be 1.

The kernel then establishes a temporary root file system using Initial RAM Disk (initrd) until the real file
system is mounted.

5. Init

At this point, your system executes runlevel programs. At one point it would look for an init file, usually
found at /etc/inittab to decide the Linux run level.

Modern Linux systems use systemd to choose a run level instead. According to TecMint, these are the
available run levels:

Run level 0 is matched by poweroff.target (and runlevel0.target is a symbolic link to poweroff.target).

Run level 1 is matched by rescue.target (and runlevel1.target is a symbolic link to rescue.target).

Run level 3 is emulated by multi-user.target (and runlevel3.target is a symbolic link to multi-user.target).

Run level 5 is emulated by graphical.target (and runlevel5.target is a symbolic link to graphical.target).

Run level 6 is emulated by reboot.target (and runlevel6.target is a symbolic link to reboot.target).


Emergency is matched by emergency.target.

systemd will then begin executing runlevel programs.

6. Runlevel programs

Depending on which Linux distribution you have installed, you may be able to see different services
getting started. For example, you might catch starting sendmail …. OK.

These are known as runlevel programs, and are executed from different directories depending on your
run level. Each of the 6 runlevels described above has its own directory:

 Run level 0 – /etc/rc0.d/


 Run level 1 – /etc/rc1.d/
 Run level 2  – /etc/rc2.d/
 Run level 3  – /etc/rc3.d/
 Run level 4 – /etc/rc4.d/
 Run level 5 – /etc/rc5.d/
 Run level 6 – /etc/rc6.d/

Note that the exact location of these directories varies from distribution to distribution.

If you look in the different run level directories, you'll find programs that start with either an "S" or "K"
for startup and kill, respectively. Startup programs are executed during system startup, and kill programs
during shutdown.

Q: 2

Ans:

Installing GRUB
For information on where GRUB should be installed on PC BIOS platforms, see BIOS installation.

In order to install GRUB under a UNIX-like OS (such as GNU), invoke the program grub-
install (see Invoking grub-install) as the superuser (root).

The usage is basically very simple. You only need to specify one argument to the program, namely,
where to install the boot loader. The argument has to be either a device file (like ‘/dev/hda’). For
example, under Linux the following will install GRUB into the MBR of the first IDE disk:

# grub-install /dev/sda
Likewise, under GNU/Hurd, this has the same effect:

# grub-install /dev/hd0
But all the above examples assume that GRUB should put images under the /boot directory. If you want
GRUB to put images under a directory other than /boot, you need to specify the option --boot-directory.
The typical usage is that you create a GRUB boot floppy with a filesystem. Here is an example:

# mke2fs /dev/fd0
# mount -t ext2 /dev/fd0 /mnt
# mkdir /mnt/boot
# grub-install --boot-directory=/mnt/boot /dev/fd0
# umount /mnt
Some BIOSes have a bug of exposing the first partition of a USB drive as a floppy instead of exposing the
USB drive as a hard disk (they call it “USB-FDD” boot). In such cases, you need to install like this:

# losetup /dev/loop0 /dev/sdb1


# mount /dev/loop0 /mnt/usb
# grub-install --boot-directory=/mnt/usb/bugbios --force --allow-floppy
/dev/loop0
This install doesn’t conflict with standard install as long as they are in separate directories.

On EFI systems for fixed disk install you have to mount EFI System Partition. If you mount it
at /boot/efi then you don’t need any special arguments:

# grub-install
Otherwise you need to specify where your EFI System partition is mounted:

# grub-install --efi-directory=/mnt/efi
For removable installs you have to use --removable and specify both --boot-directory and --efi-directory:

# grub-install --efi-directory=/mnt/usb --boot-directory=/mnt/usb/boot --


removable

Q: 3

Ans:

Yum Repository Using Linux ISO Image:


The system must have sufficient storage space to host a full Oracle Linux Media Pack DVD image
(approximately 3.5 GB for Oracle Linux Release 6 Update 3).
To create a local yum repository (for example, if a system does not have Internet access):

On a system with Internet access, download a full Oracle Linux DVD image from the Oracle Software
Delivery Cloud at https://edelivery.oracle.com/linux onto removable storage (such as a USB memory
stick). For example, V33411-01.iso contains the Oracle Linux Release 6 Update 3 Media Pack for x86 (64
bit).

Note

You can verify that the ISO was copied correctly by comparing its checksum with the digest value that is
listed on edelivery.oracle.com, for example:

# sha1sum V33411-01.iso
7daae91cc0437f6a98a4359ad9706d678a9f19de V33411-01.iso
Transfer the removable storage to the system on which you want to create a local yum repository, and
copy the DVD image to a directory in a local file system.

# cp /media/USB_stick/V33411-01.iso /ISOs
Create a suitable mount point, for example /var/OSimage/OL6.3_x86_64, and mount the DVD image on
it.

# mkdir -p /var/OSimage/OL6.3_x86_64
# mount -o loop,ro /ISOs/V33411-01.iso /var/OSimage/OL6.3_x86_64
Note

Include the read-only mount option (ro) to avoid changing the contents of the ISO by mistake.

Create an entry in /etc/fstab so that the system always mounts the DVD image after a reboot.

/ISOs/V33411-01.iso /var/OSimage/OL6.3_x86_64 iso9660 loop,ro 0 0


Disable all existing yum repositories.

In the /etc/yum.repos.d directory, edit any existing repository files and disable all entries by
setting enabled=0. If you have the yum-utils package installed, as described in Section 2.3.4, “Using Yum
Utilities to Manage Configuration”, you can disable all repositories by running:

# yum-config-manager --disable \*
Create the following entries in a new repository file (for example, /etc/yum.repos.d/OL63.repo).

[OL63]
name=Oracle Linux 6.3 x86_64
baseurl=file:///var/OSimage/OL6.3_x86_64
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY
gpgcheck=1
enabled=1
Clean up the yum cache.
# yum clean all
Test that you can use yum to access the repository.

# yum repolist
Loaded plugins: refresh-packagekit, security
...
repo id repo name status
OL63 Oracle Linux 6.3 x86_64 25,459
repolist: 25,459

Q: 4

Ans:

Run Levels in Linux:

A run level is a state of init and the whole system that defines what system services are operating. Run
levels are identified by numbers. Some system administrators use run levels to define which subsystems
are working, e.g., whether X is running, whether the network is operational, and so on.

 Whenever a LINUX system boots, firstly the init process is started which is actually responsible
for running other start scripts which mainly involves initialization of you hardware, bringing up
the network, starting the graphical interface.
 Now, the init first finds the default runlevel of the system so that it could run the start scripts
corresponding to the default run level.
 A runlevel can simply be thought of as the state your system enters like if a system is in a single-
user mode it will have a runlevel 1 while if the system is in a multi-user mode it will have
a runlevel 5.
 A runlevel in other words can be defined as a preset single digit integer for defining the
operating state of your LINUX or UNIX-based operating system. Each runlevel designates a
different system configuration and allows access to different combination of processes.

The important thing to note here is that there are differences in the runlevels according to the operating
system. The standard LINUX kernel supports these seven different runlevels :

 0 – System halt i.e the system can be safely powered off with no activity.


 1 – Single user mode.
 2 – Multiple user mode with no NFS(network file system).
 3 – Multiple user mode under the command line interface and not under the graphical user
interface.
 4 – User-definable.
 5 – Multiple user mode under GUI (graphical user interface) and this is the standard runlevel for
most of the LINUX based systems.
 6 – Reboot which is used to restart the system.

By default most of the LINUX based system boots to runlevel 3 or runlevel 5.


In addition to the standard runlevels, users can modify the preset runlevels or even create new ones
according to the requirement. Runlevels 2 and 4 are used for user defined runlevels and runlevel 0 and 6
are used for halting and rebooting the system.

Obviously the start scripts for each run level will be different performing different tasks. These start
scripts corresponding to each run level can be found in special files present under rc sub directories.
At /etc/rc.d directory there will be either a set of files named rc.0, rc.1, rc.2, rc.3, rc.4, rc.5 and rc.6, or a
set of directories named rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d and rc6.d.
For example, run level 1 will have its start script either in file /etc/rc.d/rc.1 or any files in the directory
/etc/rc.d/rc1.d.

Q: 5

Ans:

Adduser and Addgroup:

adduser and addgroup add users and groups to the system according to command line options


and configuration information in /etc/adduser.conf. They are friendlier front ends to the low-level tools
like useradd, groupadd and usermod programs, by choosing policy-conformant UID and GID values,
creating a home directory with skeletal configuration, running a custom script, and other features.

There are five major ways to use adduser and addgroup can run in one of five modes:

Add a normal user


If called with one non-option argument and without the --system or --group options, adduser adds a
normal user.

adduser chooses the first available UID from the range specified for normal users in the configuration
file. The UID can b overridden with the --uid option.

The range specified in the configuration file may be overridden with the --firstuid and --lastuid options.

By default, each user in a GNU/Linux system is given a corresponding group with the same name. User
groups allow group writable directories to be easily maintained by placing the appropriate users in the
new group, setting the set-group-ID bit in the directory, and ensuring that all users use a umask of 002. If
this option is turned off by setting USERGROUPS to no, all users' GIDs are set to USERS_GID. Users'
primary groups can also be overridden from the command line with the --gid or --ingroup options to set
the group by id or name, respectively. Also, users can be added to one or more groups defined
in adduser.conf either by setting ADD_EXTRA_GROUPS to 1 in adduser.conf, or by passing --
add_extra_groups on the command line.

adduser creates a home directory subject to DHOME, GROUPHOMES, and LETTERHOMES. The home
directory can be overridden from the command line with the --home option, and the shell with the --
shell option. The home directory's set-group-ID bit is set if USERGROUPS is yes so that any files created
in the user's home directory have the correct group.

adduser will copy files from SKEL into the home directory and prompt for finger (gecos) information and
a password. The gecos may also be set with the --gecos option. With the --disabled-login option, the
account is created but will be disabled until a password is set. The --disabled-password option will not
set a password, but login is still possible (for example with SSH RSA keys). To set up an encrypted home
directory for the new user, add the --encrypt-home option.

If the file /usr/local/sbin/adduser.local exists, it will be executed after the user account is set up to do


any local setup. The arguments passed to adduser.local are: "username uid gid home-directory".

The environment variable VERBOSE is set according to the following rules:

 if --quiet is specified
 if neither --quiet nor --debug is specified
 if --debug is specified

(The same applies to the variable DEBUG, but DEBUG is deprecated and will be removed in a later
version of adduser).

Add a system user


If called with one non-option argument and the --system option, adduser adds a system user. If a user
with the same name already exists in the system uid range (or, if the uid is specified, if a user with that
uid already exists), adduser will exit with a warning. This warning can be suppressed by adding "--quiet".

adduser chooses the first available UID from the range specified for system users in the configuration
file (FIRST_SYSTEM_UID and LAST_SYSTEM_UID). If you want to have a specific UID, you can specify it
using the --uid option.

By default, system users are placed in the "nogroup" group. To place the new system user in an already
existing group, use the --gid or --ingroup options. To place the new system user in a new group with the
same ID, use the --group option.

A home directory is created by the same rules as for normal users. The new system user has the
shell /bin/false (unless overridden with the --shell option), and have logins disabled. Skeletal
configuration files are not copied.
Add a user group
If adduser is called with the --group option and without the --system option, or addgroup is called, a user
group is added.

A GID will be chosen from the range specified for system GIDS in the configuration file
(FIRST_GID, LAST_GID). To override that mechanism, you can give the GID using the --gid option.

The group is created with no users.

Add a system group


If addgroup is called with the --system option, a system group is added.

A GID will be chosen from the range specified for system GIDS in the configuration file
(FIRST_SYSTEM_GID, LAST_SYSTEM_GID). To override that mechanism, you can give the GID using the --
gid option.

The group is created with no users.

Add an existing user to an existing group


If you run adduser with two non-option arguments, it adds existing user user to group group, if it exists.

Q: 6

Ans:

Kernel:
Kernel is central component of an operating system that manages operations of computer and
hardware. It basically manages operations of memory and CPU time. It is core component of an
operating system. Kernel acts as a bridge between applications and data processing performed at
hardware level using inter-process communication and system calls.

Types of Kernel :
1. Monolithic Kernel  –
It is one of types of kernel where all operating system services operate in kernel space. It has
dependencies between systems components. It has huge lines of code which is complex.
Example :
Unix, Linux, Open VMS, XTS-400 etc.

 Advantage :
It has good performance.
 Disadvantage :
It has dependencies between system component and lines of code in millions.
2. Micro Kernel –
It is kernel types which has minimalist approach. It has virtual memory and thread scheduling. It is more
stable with less services in kernel space. It puts rest in user space .
Example :

Mach, L4, AmigaOS, Minix, K42 etc.

 Advantage :
It is more stable.
 Disadvantage :
There are lots of system calls and context switches.
3. Hybrid Kernel –
It is the combination of both monolithic kernel and mircrokernel. It has speed and design of monolithic
kernel and modularity and stability of microkernel.
Example :

Windows NT, Netware, BeOS etc.

 Advantage :
It combines both monolithic kernel and microkernel.
 Disadvantage :
It is still similar to monolithic kernel.
4. Exo Kernel –
It is the type of kernel which follows end-to-end principle. It has fewest hardware abstractions as
possible. It allocates physical resources to applications.
Example :
Nemesis, ExOS etc.

 Advantage :
It has fewest hardware abstractions.
 Disadvantage :
There is more work for application developers.
5. Nano Kernel –
It is the type of kernel that offers hardware abstraction but without system services. Micro Kernel also
does not have system services therefore the Micro Kernel and Nano Kernel have become analogous.
Example :
EROS etc.

 Advantage :
It offers hardware abstractions without system services.
 Disadvantage :
It is quite same as Micro kernel hence it is less used.
Q: 7

Ans:

Linux Networking Commands:


Every computer is connected to some other computer through a network whether internally or
externally to exchange some information. This network can be small as some computers connected in
your home or office, or can be large or complicated as in large University or the entire Internet.

Maintaining a system's network is a task of System/Network administrator. Their task includes network
configuration and troubleshooting.

Here is a list of Networking and Troubleshooting commands:

ifconfig Display and manipulate route and network interfaces.

ip It is a replacement of ifconfig command.

traceroute Network troubleshooting utility.

tracepath Similar to traceroute but doesn't require root privileges.

ping To check connectivity between two nodes.

netstat Display connection information.

ss It is a replacement of netstat.

dig Query DNS related information.

nslookup Find DNS related query.

route Shows and manipulate IP routing table.

host Performs DNS lookups.


arp View or add contents of the kernel's ARP table.

iwconfig Used to configure wireless network interface.

hostname To identify a network name.

curl or wget To download a file from internet.

mtr Combines ping and tracepath into a single command.

whois Will tell you about the website's whois.

ifplugstatus Tells whether a cable is plugged in or not.

Q: 8

Ans:

Architecture of Linux OS
To know whether your system is 32-bit or 64-bit, type the command "uname -m" and press "Enter". This
displays only the machine hardware name. It shows if your system is running 32-bit (i686 or i386) or 64-
bit(x86_64).

The Linux operating system's architecture mainly contains some of the components: the Kernel, System
Library, Hardware layer, System, and Shell utility.

1. Kernel:- The kernel is one of the core section of an operating system. It is responsible for each of
the major actions of the Linux OS. This operating system contains distinct types of modules and
cooperates with underlying hardware directly. The kernel facilitates required abstraction for hiding
details of low-level hardware or application programs to the system. There are some of the important
kernel types which are mentioned below:
 Monolithic Kernel
 Micro kernels
 Exo kernels
 Hybrid kernels
2. System Libraries:- These libraries can be specified as some special functions. These are applied
for implementing the operating system's functionality and don't need code access rights of the modules
of kernel.
3. System Utility Programs:- It is responsible for doing specialized level and individual activities .
4. Hardware layer:- Linux operating system contains a hardware layer that consists of several
peripheral devices like CPU, HDD, and RAM.
5. Shell:- It is an interface among the kernel and user. It can afford the services of kernel. It can take
commands through the user and runs the functions of the kernel. The shell is available in distinct types
of OSes. These operating systems are categorized into two different types, which are the  graphical
shells and command-line shells.
The graphical line shells facilitate the graphical user interface, while the command line shells facilitate
the command line interface. Thus, both of these shells implement operations. However, the graphical
user interface shells work slower as compared to the command-line interface shells.

There are a few types of these shells which are categorized as follows:

 Korn shell
 Bourne shell
 C shell
 POSIX shell

You might also like