Saturday, August 25, 2012

Interview Questions and Answers - Linux Administrator

1.  How do u force a user to change password on next login in linux?

 

A.  chage -d 0 "User"



2.What command can be used to findout server architechure (x86 or x64) apart from 

    uname?

 

A. arch

 

3. How do u findout the users who are NOT logged in for more than 30 days? which file u 

    will check?

 

A. last , lastlog,   /var/log/wtmp

 

4. whats is called 1.5 stage in boot process of linux?

 

A. Which contains extra code to allow cylinders above 1024, or LBA type drives, to be read. The  

    1.5 boot loader is stored (if needed) in the MBR or the boot partition.The great thing about  

    GRUB is that it includes knowledge of Linux file systems. Instead of using raw sectors on the 

    disk, as LILO does, GRUB can load a Linux kernel from an ext2 or ext3 file system. It does this 

    by making the two-stage boot loader into a three-stage boot loader. Stage 1 (MBR) boots a 

    stage 1.5 boot loader that understands the particular file system containing the Linux kernel 

    image. Examples include reiserfs_stage1_5 (to load from a Reiser journaling file system) or  

   e2fs_stage1_5 (to load from an ext2 or ext3 file system). When the stage 1.5 boot loader is   

    loaded and running, the stage 2 boot loader can be loaded."

 

    So Basically,

 

    Stage 1 Boot loader is MBR

 

    Stage 2 Boot loader is GRUB

 

    Stage 1.5 Boot loader is e2fs_stage1_5 

    (Basically this module will load the knowledge of Filesystem to Grub to read the kernel)

 

5. When u try to create a file, u got a error that "No space available". But actually space  

     available on volume? How do u resolve this issue?

 

A. Try this df -i   list inode information instead of block usage [Perhaps are you out of inodes on 

    this file system.], To "rectify it", remove unwanted files or move them somewhere else.]

 

 

How do you find out hardware errors inside Linux?

How do you find out hardware errors inside Linux?

  • dmesg
  • /var/log/messages
  • dmidecode –t system 
  • IML (Integrated Management Logs) - An iLO console feature
  • hpacucli - To check RAID array status
  • use grep or less commands on

o    /var/log/messages and /var/log/warn

o    /var/log/debug

o    /var/log/kern.log

o    /var/log/mcelog

 

What is the major difference between ext2 and ext3 file systems?

What is the major difference between ext2 and ext3 file systems?

The main difference between ext2 and ext3 is, ext3 allows journaling. (Journaling is a type of log file, which tracks all the file system changes. so that you can recover in case of filesystem crash)

 

How do you extend a LV? For example, How do you expand /var file system with additional 2GB space?

How do you extend a LV? For example, How do you expand /var file system with additional 2GB space?

  • Check which logical volume (LV) holds the  /var file system using df –h
  • Now, find out this particular LV belongs to which VG using lvdisplay <lv_name>
  • Check the free space available in that Volume Group (VG) using vgdisplay <vgname>. Look for "Free PE / Space" line in the ouput.
  • If the free space available in VG, now you can expand the LV using lvextend –L +2G <lv_name>. Now, Logical Volume has been expanded. Now we have to expand the file system using resize2fs /var. All these can be done in online without unmounting the filesystems.

 

Explain Linux Booting Process?

Explain Linux Booting Process?

·       When the computer is switched on, it automatically invokes BIOS [a ROM chip embedded in the motherboard].

·       The BIOS will start the processor and perform a POST [power on self test] to check whether the connected device are ready to use and are working properly.

·       Once the POST is completes BIOS will check for the booting device. The boot sector is always the first sector of the hard disk and BIOS will load the MBR into the memory. MBR holds the boot loader of the OS.

·       From here the boot loader takes the control of the booting process.

·       GRUB is the boot loader for Linux. 

·       Depending on the boot option selected the kernel is loaded first.

·       After kernel is loaded the kernel will take the control of the booting process

·       Initrd will be loaded which contains drivers to detect hardware (Initialization of RAM Disk)

·       Then it will initialize all the hardware including I/O processors etc.

·       Kernel then mounts the root partition as read-only

·       INIT is loaded as the first process.

·       INIT will mount the root partition and other partitions as read/write and checks for file system errors.

·       Sets the System Clock, hostname etc..

·       Based on the Runlevel, it will load the services and runs the startup scripts which are located in /etc/rcX.d/ (Network, cups, nfs, SSH etc.)

·       Finally it runs the rc.local script.

·       Now the login prompt will appear.

 

Thursday, August 23, 2012

Linux General questions.

 

1. To which operating system is GNU/Linux compatible?

a. Windows

b. Unix

c. it\'s a system on it\'s own

d. don\'t know

 

2. What is the origin of GNU/Linux?

a. 1984 by Richard Stallman

b. 1987 by Andrew Tannenbaum

c. 1991 by Linus Torvalds

d. don\'t know

 

3. What has Linus Torvalds developed?

a. he developed the whole system

b. he developed the kernel of the system

c. he is only the coordinator

d. don\'t know

 

4. What is the mascott of Linux?

a. a penguin

b. a gnu

c. a window

d. don\'t know

 

5. On what kind of mashines is GNU/Linux running?

a. on mainframes

b. on PCs

c. on a lot of different machines

d. don\'t know

 

6. Does the system have a graphical user environments?

a. No, there is only the text-console

b. yes, the environment is called KDE

c. yes, there are a lot of environments

d. don\'t know

 

7. In which programming language is most of GNU/Linux written?

a. Pascal

b. C

c. C++

d. C#

e. LISP

f. don\'t know

 

8. Which of these programming languages do not exist for GNU/Linux?

a. Fortran, Lisp, Pascal, Modula-2, ADA

b. Java, JavaScript

c. Visual Basic, Visual C, Visual Java

d. don\'t know

 

9. Which kernel was created in the GNU project?

a. BSD

b. HURD

c. Linux

d. don\'t know

 

10. The Linux kernel was invented by

a. Linus Pauling

b. Linus Torvalds

c. Linus Thorwalds

d. Linus Van Pelt

 

11. Which of the following is not a Linux distro?

a. Debian

b. Yellow Devil

c. Yellow Dog

d. Devil-Linux

 

12. What is a Linux ISO?

a. An Independent System Organizer for compiling Linux apps

b. A particular isolated section of Linux code

c. A downloadable file containing a CD-ROM disc image of Linux

d. An Incredibly Stupid Operator of Linux

 

13. What animal represents Linux?

a. Bob the Mandrake

b. Tux the Penguin

c. George the Wombat

d. Bill the evil bat of greed

 

14. What is GNU/Linux?

a. The official name of the complete Linux OS according to Richard Stallman

b. A combination of a free software kernel with Linux apps

c. A fancy way of identifying new distros

d. A distro of Linux meant for wildebeests

 

15. Which of the following is not a Linux GUI?

a. Xfree86

b. KDE

c. Motif

d. Gnome

 

Linux Firefox X11: Turn On 3D View Button

Mozilla Firefox version 11.x+ has support for 3D view. It is a WebGL based website visualization tool that highlights page structure. You can see relationship between your code and the page output by stacking elements as they are nested in the DOM and lets you see elements that are hidden or off the page. You can zoom in and out, rotate and pan the view to see the page from any angle that is helpful to you. In this blog post I will explain how to enable 3D view on X11. Please note that the 3D view is not for your daily browsing needs. It is useful for finding out bugs such as nesting issues or even XSS vulnerabilities. Personally, I use 3D view as a tool to understand divs, spans, and other elements on the page.

Requirements

You need to 3d accelerator graphics card such as NVIDIA, ATI/AMD and Intel cards with WebGL support - a JavaScript API for rendering interactive 3D graphics and 2D graphics. However, not all cards are supported.

How do I enable 3D view under X11?

You need to turn on inspector.
Right-click page > Select inspect element (Q)

Fig.01: Turning on the 3D view

You will see bar at the bottom with a "3D View" button as follows:

Fig.02: 3D view button at the bottom

How do I rotate and view pages in 3D?

  1. You can use mouse wheel to zoom in/out.
  2. Mouse button to select element.
  3. Hold mouse button move left / right / up / down.

Keyboard functions

  1. Zoom in/out : + / -
  2. Rotate left/right : a / d
  3. Rotate up/down : w / s
  4. Pan left/right : /
  5. Pan up/down : /
  6. Reset zoom level : 0
  7. Focus on selected node : f
  8. Reset view : r
  9. Hide current node : x

Sample outputs:

Fig.03: 3D view in action (click to enlarge)

 

YUM ....Server side configuration:

YUM Configuration

Server side configuration:

Step 1:

Install createrepo.rpm from the DVD for creating repository.

#rpm -ivh createrepo.rpm (Install the dependencies first, if any [eg:deltarpm, python-deltarpm])

#rpm -ivh vsftpd.rpm (for FTP server)

 

Step 2:

Copy all rpms form the DVD and past over the hard disk share them up in NFS.

#createrepo /path-to-rpms

eg:#createrepo /var/ftp/pub

It will take several minutes that depends upon the number of rpms that you have copied from the DVD specified and the configuration of yourmachine.

 

Step 3: 

#service vsftpd restart

Touch the following file with the contents specified.

#vim /etc/yum.repos.d/somename.repo

[base]

name=friendly name

baseurl=ftp://192.168.0.254/pub/  (Give the ipaddress of the YUM server) 

enabled=1

gpgcheck=0

 

Step 4: 

Use the yum server in the same machine because server is the first client of the same service most of the times the following command is used for install gcc compiler

#yum install gcc

 

Client side configuration:

Touch the following file with the contents specified.

#vim /etc/yum.repos.d/somename.repo

[base]

name=friendly name

baseurl=ftp://192.168.0.254/pub/  (Give the ipaddress of the YUM server) 

enabled=1

gpgcheck=0

 

#yum install gcc (just for an example)

 

Tuesday, August 21, 2012

Linux Booting Procedure

Linux Booting Procedure

 

How Linux boot?

System startup

How computer startup?

¡    Booting is a bootstrapping process that starts operating systems when the user turns on a computer system

¡    A boot sequence is the set of operations the computer performs when it is switched on that load an operating system

Booting sequence

      Tern on

      CPU jump to address of BIOS (0xFFFF0)

      BIOS runs POST (Power-On Self Test)

      Find bootale devices

      Loads and execute boot sector form MBR

      Load OS

BIOS (Basic Input/Output System)

¡    BIOS refers to the software code run by a computer when first powered on

¡    The primary function of BIOS is code program embedded on a chip that recognises and controls various devices that make up the computer.

Boot loader

MBR (Master Boot Record)

¡    OS is booted from a hard disk, where the Master Boot Record (MBR) contains the primary boot loader

¡    The MBR is a 512-byte sector, located in the first sector on the disk (sector 1 of cylinder 0, head 0)

¡    After the MBR is loaded into RAM, the BIOS yields control to it.

 

 

MBR (Master Boot Record)

MBR (Master Boot Record)

¡    The first 446 bytes are the primary boot loader, which contains both executable code and error message text

¡    The next sixty-four bytes are the partition table, which contains a record for each of four partitions

¡    The MBR ends with two bytes that are defined as the magic number (0xAA55). The magic number serves as a validation check of the MBR

Extracting the MBR

¡    To see the contents of MBR, use this command:

¡    # dd if=/dev/hda of=mbr.bin bs=512 count=1

¡    # od -xa mbr.bin

**The dd command, which needs to be run from root, reads the first 512 bytes from /dev/hda (the first Integrated Drive Electronics, or IDE drive) and writes them to the mbr.bin file.

**The od command prints the binary file in hex and ASCII formats.

Boot loader

¡    Boot loader could be more aptly called the kernel loader. The task at this stage is to load the Linux kernel

¡    Optional, initial RAM disk

¡    GRUB and LILO are the most popular Linux boot loader.

Other boot loader (Several OS)

¡    bootman

¡    GRUB

¡    LILO

¡    NTLDR

¡    XOSL

¡    BootX

¡    loadlin

¡    Gujin

¡    Boot Camp

¡    Syslinux

¡    GAG

 

GRUB: GRand Unified Bootloader

¡    GRUB is an operating system independant boot loader

¡    A multiboot software packet from GNU

¡    Flexible command line interface

¡    File system access

¡    Support multiple executable format

¡    Support diskless system

¡    Download OS from network

¡    Etc.

 

GRUB boot process

      The BIOS finds a bootable device (hard disk) and transfers control to the master boot record

      The MBR contains GRUB stage 1. Given the small size of the MBR, Stage 1 just load the next stage of GRUB

      GRUB Stage 1.5 is located in the first 30 kilobytes of hard disk immediately following the MBR. Stage 1.5 loads Stage 2.

      GRUB Stage 2 receives control, and displays to the user the GRUB boot menu (where the user can manually specify the boot parameters).

      GRUB loads the user-selected (or default) kernel into memory and passes control on to the kernel.

Example GRUB config file

LILO: LInux LOader

¡    Not depend on a specific file system

¡    Can boot from harddisk and floppy

¡    Up to 16 different images

¡    Must change LILO when kernel image file or config file is changed

Kernel

Kernel image

¡    The kernel is the central part in most computer operating systems because of its task, which is the management of the system's resources and the communication between hardware and software components

¡    Kernel is always store on memory until computer is tern off

¡    Kernel image is not  an executable kernel, but a compress kernel image

¡    zImage  size less than 512 KB

¡    bzImage size greater than 512 KB

Task of kernel

¡    Process management

¡    Memory management

¡    Device management

¡    System call

 

Major functions flow for Linux kernel boot

Init process

¡    The first thing the kernel does is to execute init program

¡    Init is the root/parent of all processes executing on Linux

¡    The first processes that init starts is a script /etc/rc.d/rc.sysinit

¡    Based on the appropriate run-level, scripts are executed to start various processes to run the system and make it functional

 

The Linux Init Processes

¡    The init process is identified by process id "1

¡    Init is responsible for starting system processes as defined in the /etc/inittab file

¡    Init typically will start multiple instances of "getty" which waits for console logins which spawn one's user shell process

¡    Upon shutdown, init controls the sequence and processes for shutdown

Process ID

Description

0

The Scheduler

1

The init process

2

kflushd

3

kupdate

4

kpiod

5

kswapd

6

mdrecoveryd

System processes

 

Inittab file

¡    The inittab file describes which processes are started at bootup and during normal operation

l   /etc/init.d/boot

l   /etc/init.d/rc

¡    The computer will be booted to the runlevel as defined by the initdefault directive in the /etc/inittab file

l   id:5:initdefault:

 

Runlevels

¡    A runlevel is a software configuration of the system which allows only a selected group of processes to exist

¡    The processes spawned by init for each of these runlevels are defined in the /etc/inittab file

¡    Init can be in one of eight runlevels: 0-6

 

Runlevels

Runlevel

Scripts Directory
(Red Hat/Fedora Core)

State

0

/etc/rc.d/rc0.d/

shutdown/halt system

1

/etc/rc.d/rc1.d/

Single user mode

2

/etc/rc.d/rc2.d/

Multiuser with no network services exported

3

/etc/rc.d/rc3.d/

Default text/console only start. Full multiuser

4

/etc/rc.d/rc4.d/

Reserved for local use. Also X-windows (Slackware/BSD)

5

/etc/rc.d/rc5.d/

XDM X-windows GUI mode (Redhat/System V)

6

/etc/rc.d/rc6.d/

Reboot

s or S

Single user/Maintenance mode (Slackware)

M

Multiuser mode (Slackware)

 

rc#.d files

¡    rc#.d files are the scripts for a given run level that run during boot and shutdown

¡    The scripts are found in the directory /etc/rc.d/rc#.d/ where the symbol # represents the run level

init.d

¡    Deamon is a background process

¡    init.d is a directory that admin can start/stop individual demons by changing on it

l   /etc/rc.d/init.d/ (Red Hat/Fedora )

l   /etc/init.d/ (S.u.s.e.)

l   /etc/init.d/ (Debian)

 

Start/stop deamon

¡    Admin can issuing the command and either the start, stop, status, restart or reload option

¡    i.e. to stop the web server:

l   cd /etc/rc.d/init.d/

l   (or /etc/init.d/ for S.u.s.e. and Debian)

l   httpd stop

 

Linux files structure

Linux files structure

FSSTND : (Filesystem standard)

¡    All directories are grouped under the root entry "/"

¡    root - The home directory for the root user

¡    home - Contains the user's home directories along with directories for services

l   ftp

l   HTTP

l   samba

 

FSSTND : (Filesystem standard)

¡    bin - Commands needed during booting up that might be needed by normal users

¡    sbin - Like bin but commands are not intended for normal users. Commands run by LINUX.

¡    proc - This filesystem is not on a disk. It is a virtual filesystem that exists in the kernels imagination which is memory

l   1 - A directory with info about process number 1. Each process has a directory below proc.

FSSTND : (Filesystem standard)

¡    usr - Contains all commands, libraries, man pages, games and static files for normal operation.

l   bin - Almost all user commands. some commands are in /bin or /usr/local/bin.

l   sbin - System admin commands not needed on the root filesystem. e.g., most server programs.

l   include - Header files for the C programming language. Should be below /user/lib for consistency.

l   lib - Unchanging data files for programs and subsystems

l   local - The place for locally installed software and other files.

l   man - Manual pages

l   info - Info documents

l   doc - Documentation

l   tmp

l   X11R6 - The X windows system files. There is a directory similar to usr below this directory.

l   X386 - Like X11R6 but for X11 release 5

FSSTND : (Filesystem standard)

¡    boot - Files used by the bootstrap loader, LILO. Kernel images are often kept here.

¡    lib - Shared libraries needed by the programs on the root filesystem

¡    modules - Loadable kernel modules, especially those needed to boot the system after disasters.

¡    dev - Device files

¡    etc - Configuration files specific to the machine.

¡    skel - When a home directory is created it is initialized with files from this directory

¡    sysconfig - Files that configure the linux system for devices.

 

FSSTND : (Filesystem standard)

¡    var - Contains files that change for mail, news, printers log files, man pages, temp files

l   file

l   lib - Files that change while the system is running normally

l   local - Variable data for programs installed in /usr/local.

l   lock - Lock files. Used by a program to indicate it is using a particular device or file

l   log - Log files from programs such as login and syslog which logs all logins and logouts.

l   run - Files that contain information about the system that is valid until the system is next booted

l   spool - Directories for mail, printer spools, news and other spooled work.

l   tmp - Temporary files that are large or need to exist for longer than they should in /tmp.

l   catman - A cache for man pages that are formatted on demand

 

FSSTND : (Filesystem standard)

¡    mnt - Mount points for temporary mounts by the system administrator.

¡    tmp - Temporary files. Programs running after bootup should use /var/tmp