0% found this document useful (0 votes)
92 views11 pages

End Term Question Paper Linux For Devices 2022-11 SAP Solution

This document provides information about a Linux course including the course title, code, examination details, examiner name, and model answers for the exam. It lists 11 topics that will be covered in the exam, including free and open-source Linux, the graphical user interface, encryption, customization, updates, and multi-user access. Each topic is described in 1-3 paragraphs. The document also provides 4 sample exam questions, including using NFS file sharing, writing a script to ask about favorite operating systems, and using find commands to locate files belonging to a specific user.

Uploaded by

Keshav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views11 pages

End Term Question Paper Linux For Devices 2022-11 SAP Solution

This document provides information about a Linux course including the course title, code, examination details, examiner name, and model answers for the exam. It lists 11 topics that will be covered in the exam, including free and open-source Linux, the graphical user interface, encryption, customization, updates, and multi-user access. Each topic is described in 1-3 paragraphs. The document also provides 4 sample exam questions, including using NFS file sharing, writing a script to ask about favorite operating systems, and using find commands to locate files belonging to a specific user.

Uploaded by

Keshav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Course Title: Linux for Devices Course Code: CSE438

Examination: End Semester Nov-Dec 2022

Programme: B.Tec.

Name of the Examiner: Dr. Ashok kumar Yadav(307891)

Sr. Model Answers Distribution


No. of Marks
Section A
1 1. Free and Open-Source 5+1 marks
Linux is completely free of cost, and expenses are never a
hindrance to using it as an operating system.

Linux is open-source. This means that modification of code,


analysis of codes, redistribution of codes, or selling copies of
the enhanced codes can be done by anyone in the world
provided they come under the same license where the license
also costs no charge.

Linux operating system is released under the GNU(General


Public Licence) and is now one of the largest open-source
projects worldwide.

2. Extremely Flexible
Linux has incorporated itself into embedded products like
watches, digital equipment and supercomputing servers.

There are no prerequisites for installing an entire Linux suit. It


allows a user to install only the components that are required by
the user.

3. Lightweight Infrastructure
Linux consumes lesser storage space, and its installation
requires around 4GB to 8GB of disk space.

Memory footprint or the amount of memory (RAM) used by the


software while running is also less and it is compatible with all
kinds of file formats like text files, audio files, video files,
graphic formats, etc.

4. Graphical User Interface (GUI)


Even though Linux works on using the command line interface
but it can be converted to be used like windows having a
Graphical user interface. This is done mostly by installing
packages. The most common way of having a GUI on the
Linux environment is to log in to Ubuntu server and install its
desktop environment.
5. End-to-end encryption
Linux allows end-to-end encryption while accessing data thus
storing public keys in the server. All data is password protected
and provides authentication to users. It also allows many
security features and provides file permissions, a secure shell,
etc.
1. Free and Open-Source
Linux is completely free of cost, and expenses are never a
hindrance to using it as an operating system.

Linux is open-source. This means that modification of code,


analysis of codes, redistribution of codes, or selling copies of
the enhanced codes can be done by anyone in the world
provided they come under the same license where the license
also costs no charge.

Linux operating system is released under the GNU(General


Public Licence) and is now one of the largest open-source
projects worldwide.

2. Extremely Flexible
Linux has incorporated itself into embedded products like
watches, digital equipment and supercomputing servers.

There are no prerequisites for installing an entire Linux suit. It


allows a user to install only the components that are required by
the user.

3. Lightweight Infrastructure
Linux consumes lesser storage space, and its installation
requires around 4GB to 8GB of disk space.

Memory footprint or the amount of memory (RAM) used by the


software while running is also less and it is compatible with all
kinds of file formats like text files, audio files, video files,
graphic formats, etc.

4. Graphical User Interface (GUI)


Even though Linux works on using the command line interface
but it can be converted to be used like windows having a
Graphical user interface. This is done mostly by installing
packages. The most common way of having a GUI on the
Linux environment is to log in to Ubuntu server and install its
desktop environment.

5. End-to-end encryption
Linux allows end-to-end encryption while accessing data thus
storing public keys in the server. All data is password protected
and provides authentication to users. It also allows many
security features and provides file permissions, a secure shell,
etc.
6. Portable Environment
Linux works on any kind of environment and doesn't depend on
the device being high-ended or low-ended. A large number of
users can simultaneously use it anytime, any place, and on
multiple devices. It supports all kinds of hardware to work on.

Multiple distributions or enterprises are also supported by


Linux.

Linux has its own repository for software that can be used to
install the required packages.

7. Shell/ Command-line Interface


The Linux command line interpreter is known as Shell that
provides an interface between the user and kernel which then
executes programs known as commands.

Hence, Linux uses Command-line interface to carry out the


execution of tasks which is comparatively more efficient to
execute and takes lesser time. It also takes lesser space in the
memory,

8. Customized keyboard
Linux is available in all languages which makes it acceptable
worldwide. That is why language can be changed from the
keyboard according to the requirements and preferences.

Users can also build their own customized layout for


keyboards.

9. Frequent New Updates


Linux operating system provides a wide range of accessible
software updates that can be deployed and used according to
requirements.

They update more frequently thus giving users an option to


choose the updates and install them as per their need.

10. Hierarchical File System


Linux comes with a well-defined file structure where user files
are arranged in a definite directory structure. According to the
type of files, the directories are categorised as Binary
directories, configuration directories, Data directories, memory
directories, Usr(Unix System Resources), var(variable
directory) and non standard directories.

11. Multi-user and Multi-programming


Linux allows multiple users to access the system resources at
the same time and allows multiple applications to run at the
same time.

The primary difference between Linux and many other popular


contemporary operating systems is that the Linux kernel and
other components are free and open-source software. Linux is
not the only such operating system, although it is by far the
most widely used.
2 An NFS file server provides an easy way to share large amounts 6 Marks
of data among the users and computers in an organization. An
administrator of a Linux system that is configured to share its
filesystems using NFS has to perform the following tasks to set
up NFS:
Set up the network
Start the NFS service.
Choose what to share from the server
Set up security on the server
Mount the filesystem on the client

From a client Linux system, you can use the showmount


command to see what shared
directories are available from a selected computer. For example:
$ /usr/sbin/showmount -e server.example.com

To create a directory called /var/remote and temporarily mount the


/var/mystuff directory from the NFS server (named nfsserver in this
example) on that mount point, type the following as root user from the NFS
client:
# mkdir /var/remote
# mount -t nfs nfsserver:/var/mystuff /var/remote

The first command (mkdir) creates the mount point directory.


(/mnt is a common place to put temporarily mounted disks and
NFS filesystems.) The mount command identifies the remote
computer and shared filesystem, separated by a colon
(nfsserver:/var/mystuff), and the local mount point directory
/var/remote.
To ensure that the NFS mount occurred, type mount -t nfs. This
command lists all mounted NFS filesystems.
3 To create the required script, do the following: Using any text editor, create a 6 marks
script called $HOME/bin/myos and make the script executable:
$ chmod 755 $HOME/bin/myos
■ The script could contain the following:
#!/bin/bash
# myos
read -p "What is your favorite operating system, Mac, Windows or
Linux? "
opsys
if [ $opsys = Mac ] ; then
echo "Mac is nice, but not tough enough for me."
elif [ $opsys = Windows ] ; then
echo "I used Windows once. What is that blue screen for?"
elif [ $opsys = Linux ] ; then
echo "Great Choice!"
else
echo "Is $opsys an operating system?"
fi

4 Run the following command to find all fi les under the /home directory that 6 marks
belong to aset. If you did the exercises in order, notice that after you deleted
the user with the highest user ID and group ID, those numbers were assigned to
aset. As a result, any files left on the system by auup now belong to aset.
(For this reason, you should remove or change ownership of files left behind
when you delete a user.)
# find /home -user aset -ls
262184 4 drwx------ 4 aset aset 4096 Jan 25 08:00 /home/auup
262193 4 -rw-r--r-- 1 aset aset 176 Jan 27 2011 /home/auup
/.bash_profile
262189 4 -rw-r--r-- 1 aset aset 18 Jan 27 2011
/home/auup/.bash_logout
262194 0 -rw-rw-r-- 1 aset testing 0 Jan 25 07:59
/home/auup/file.txt
262188 4 -rw-r--r-- 1 aset aset 124 Jan 27 2011
/home/auup/.bashrc
262197 4 drwx------ 4 aset aset 4096 Jan 25 08:27
/home/maryjones
262207 4 -rw-r--r-- 1 aset aset 176 Jan 27 2011 /home/maryjones
/.bash_profile
262202 4 -rw-r--r-- 1 aset aset 18 Jan 27 2011 /home/maryjones
/.bash_logout
262206 628 -rw-r--r-- 1 aset aset 640999 Jan 25 08:27
/home/maryjones/
services
262201 4 -rw-r--r-- 1 aset aset 124 Jan 27 2011
/home/maryjones/.bashrc

$HOME — All users store information in their home directories


that directs how their login accounts behave. Many configuration
files are directly in each user’s user’s home directory (such as
/home/aset) and begin with a dot (.), so they don’t appear in a
user’s directory when you use a standard ls command (you need
to type ls -a to see them). Likewise, dot files and directories
won’t show up in most file manager windows by default. There
are dot files that define the behavior of each user’s shell, the
desktop look-and-feel, and options used with your text editor.
There are even files such as those in each user’s $HOME/.ssh
5 One of the first things your driver will need to do when setting 6 mark
up a char device is to obtain one or more device numbers to work s
with. The necessary function for this task is
register_chrdev_region, which is declared in <linux/fs.h>:
int register_chrdev_region(dev_t first, unsigned int count,
char *name);
Here, first is the beginning device number of the range you
would like to allocate. The minor number portion of first is often
0, but there is no requirement to that effect. count is the total
number of contiguous device numbers you are requesting. Note
that, if count is large, the range you request could spill over to
the next major number; but everything will still work properly as
long as the number range you request is available. Finally, name
is the name of the device that should be associated with this
number range; it will appear in /proc/devices and sysfs. As with
most kernel functions, the return value from
register_chrdev_region will be 0 if the allocation was
successfully performed. In case of error, a negative error code
will be returned, and you will not have access to the requested
region. register_chrdev_region works well if you know ahead of
time exactly which device numbers you want. Often, however,
you will not know which major numbers your device will use;
there is a constant effort within the Linux kernel development
community to move over to the use of dynamicly-allocated
device numbers. The kernel will happily allocate a major number
for you on the fly, but you must request this allocation by using
a different function:
int alloc_chrdev_region(dev_t *dev, unsigned int firstminor,
unsigned int count, char *name);
With this function, dev is an output-only parameter that will, on
successful completion, hold the first number in your allocated
range. First minor should be the requested first minor number to
use; it is usually 0. The count and name parameters work like
those given to request_chrdev_region. Regardless of how you
allocate your device numbers, you should free them when they
are no longer in use. Device numbers are freed with:
void unregister_chrdev_region(dev_t first, unsigned int count);
The usual place to call unregister_chrdev_region would be in
your module’s cleanup function.
6(a) Find command 5 marks

Locate command

Which command

whereis command

find options path_list selection_criteria action

find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...]


[expression]

The options controls the treatment of the symbolic links,


debugging options, and optimization method.

The path defines the starting directory or directories from where


find will start searching the files.

The expression attribute is made up of options, search


patterns, and actions separated by operators.

[-H] option: Do not follow symbolic links, except while processing


the command line arguments. When find examines or prints
information about files, the information used shall be taken from
the properties of the symbolic link itself. The only exception to
this behaviour is when a file specified on the command line is a
symbolic link, and the link can be resolved.

[-L] option: Follow symbolic links. When find examines or


prints information about files, the information used shall be
taken from the properties of the file to which the link points,
not from the link itself (unless it is a broken symbolic link or
find is unable to examine the file to which the link points)

[-P] option: Never follow symbolic links. This is the default


behaviour. When find examines or prints information about a file,
and the file is a symbolic link, the information used shall be taken
from the properties of the symbolic link itself.
[-D debugopts] option: Print diagnostic information; this can be
helpful to diagnose problems with why find is not doing what you
want. The list of debug options should be comma separated.

[-Olevel] option: Enables query optimization. The find


program reorders tests to speed up execution while preserving
the overall effect

Locate command: find files by name

locate [OPTION]... PATTERN...

Example locate -b '\NAME’: To search for a file named exactly


NAME (not *NAME*). \ is a globing character, this disables the
implicit replacement of NAME by *NAME*.

The which command tells you the directory that contains the
command

It searching the directories of PATH in sequence, and abandons its


search just after it locates a file

The locate command is faster than the find command because


it uses a previously built database, whereas the find command
searches in the real system, through all the actual directories
and files. The locate command returns a list of all path names
containing the specified group of characters

The “which” command returns the absolute path of the executable


that is called when a command is issued.

This is useful in finding the location of an executable for creating a


shortcut to the program on the desktop, on a panel, or other place in
the desktop manager.

The whereis command is used to find out where the binary,


source, and man page files for a command are located

A Linux distribution that is intended to support factory automation 5 marks


(b).
is called Open Industrial Linux (OpenIL), and it's promising true
industrial-grade security based on trusted computing, hardened
software, cryptographic operations and end-to-end security. The
fact that factory managers and industrial equipment manufacturers
are turning to Linux is not surprising considering its operational
stability, professional approach to system security, and its obvious
low cost of ownership. The importance of the security and
reliability of manufacturing security to the well-being of any
industrial nation is clear from the focus that DHS places on this
sector.
OpenIL features includes the following:
Xenomai — a real-time framework for Linux
XML and NETCONF network configuration utilities
Precision time synchronization using gPTP
Ethernet drivers for time-sensitive networking
Support for edge computing services
Deterministic Network
Time Sensitive Networking
Flexibility
Stability
Security and reliability
Easier evaluation
Better support
Possible savings
Section B
7 Containers 5+5 marks

A container is a runnable instance of an image. You can create,


start, stop, move, or delete a container using the Docker API or
CLI. You can connect a container to one or more networks,
attach storage to it, or even create a new image based on its
current state.

By default, a container is relatively well isolated from other


containers and its host machine. You can control how isolated a
container’s network, storage, or other underlying subsystems
are from other containers or from the host machine.

A container is defined by its image as well as any configuration


options you provide to it when you create or start it. When a
container is removed, any changes to its state that are not stored
in persistent storage disappear.

Example docker run command

The following command runs an ubuntu container, attaches


interactively to your local command-line session, and runs
/bin/bash.

docker run -i -t ubuntu /bin/bash

When you run this command, the following happens (assuming


you are using the default registry configuration):

If you do not have the ubuntu image locally, Docker pulls it


from your configured registry, as though you had run docker
pull ubuntu manually.

Docker creates a new container, as though you had run a docker


container create command manually.
Docker allocates a read-write filesystem to the container, as its
final layer. This allows a running container to create or modify
files and directories in its local filesystem.

Docker creates a network interface to connect the container to


the default network, since you did not specify any networking
options. This includes assigning an IP address to the container.
By default, containers can connect to external networks using
the host machine’s network connection.

Docker starts the container and executes /bin/bash. Because the


container is running interactively and attached to your terminal
(due to the -i and -t flags), you can provide input using your
keyboard while the output is logged to your terminal.

When you type exit to terminate the /bin/bash command, the


container stops but is not removed. You can start it again or
remove it.

Images

An image is a read-only template with instructions for creating


a Docker container. Often, an image is based on another image,
with some additional customization. For example, you may
build an image which is based on the ubuntu image, but installs
the Apache web server and your application, as well as the
configuration details needed to make your application run.

You might create your own images or you might only use those
created by others and published in a registry. To build your own
image, you create a Dockerfile with a simple syntax for
defining the steps needed to create the image and run it. Each
instruction in a Dockerfile creates a layer in the image. When
you change the Dockerfile and rebuild the image, only those
layers which have changed are rebuilt. This is part of what
makes images so lightweight, small, and fast, when compared
to other virtualization technologies.
8(a) To add a 100MB Linux partition, 200MB swap partition, and 500MB LVM 5 marks
partition to the USB flash drive, type the following:
# fdisk -cu /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-15667199, default 2048): <ENTER>
Last sector, +sectors or +size{K,M,G} (default 15667199):
+100M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First sector (616448-8342527, default 616448): <ENTER>
Last sector, +sectors or +size{K,M,G} (default 15667199):
+200M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First sector (616448-15667199, default 616448): <ENTER>
Using default value 616448
Last sector, +sectors or +size{K,M,G} (default 15667199):
+500M
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap /
Solaris)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): w
# partprobe /dev/sdb
# grep sdb /proc/partitions
8 16 7833600 sdb
8 17 102400 sdb1
8 18 204800 sdb2
8 19 512000 sdb3

(b). To determine what init daemon sshd is using on your Linux server, be 5 marks
aware that the init daemon that sshd uses is not solely dependent upon
which init daemon the server is currently using. Several services may not
yet be ported over to new init daemons. Therefore, try out both the newer
init daemon and the classic SysVinit commands.
■ For the Upstart init daemon, a positive result, shown here, means the
sshd has been converted to Upstart:
# initctl status ssh
ssh start/running, process 2390
■ Forsystemd, a positive result, shown here, means the sshd has been
converted to systemd:
# systemctl status sshd.service
sshd.service - OpenSSH server daemon
Loaded: loaded (/lib/systemd/system/sshd.service;
enabled)
Active: active (running) since Mon, 30 Apr 2015 12:35:20...
■ Ifyou don’t see positive results for the preceding tests, try the following
command for the SysVinit init daemon. A positive result here, along
with negative results for the preceding tests, means sshd is still using the
SysVinit daemon.
# service ssh status
sshd (pid 2390) is running...

Section C
9 (a) To list all processes running on the system and sort those processes by the 3 marks
name of the user running each process, type the following:
$ ps -ef --sort=user | less

To start the gedit process from your desktop and use the System Monitor
window to kill that process, do the following:
$ gedit &
Next, select Applications->System Tools->System Monitor. Find the gedit
process on the Processes tab (you can sort alphabetically to make it easier by
clicking on the Process Name heading). Right-click the gedit command and
then select either End Process or Kill Process, and the gedit window on your
screen should disappear
(b) To determine the largest directory structures under /usr/share, sort them 1.5+1.5
from largest to smallest, and list the top 10 of those directories in terms of size marks
using the du command, type the following:
$ du -s /usr/share/* | sort -rn | head
458320 /usr/share/locale
129400 /usr/share/doc
124116 /usr/share/icons
80524 /usr/share/gnome

To show the space that is used and available from all the filesystems currently
attached to the local system, but exclude any tmpfs or devtmpfs
filesystems by using the df command, type the following:
$ df -h -x tmpfs -x devtmpfs
Filesystem Size Used Avail Use% Mounted on
/deev/sda4 20G 4.2G 16G 22% /
(c) Answer: 10 marks
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
% make
make[1]: Entering directory `/usr/src/linux-2.6.10'
CC [M] /home/ldd3/src/misc-modules/hello.o
Building modules, stage 2.
MODPOST
CC /home/ldd3/src/misc-modules/hello.mod.o
LD [M] /home/ldd3/src/misc-modules/hello.ko
make[1]: Leaving directory `/usr/src/linux-2.6.10'
% su
root# insmod ./hello.ko

You might also like