April 15, 2024

Part-4: Basic 10 Linux Interview Questions and Answers

In this article, we’ve included 4th set of 10 basic Linux Interview Questions and detailed answers that will help candidates prepare for the Linux interview.

These Linux interview questions and answers will be useful for both freshers and experienced users.

Q.1) How does the Linux boot process work on the (Sys V) init system?

It is very important for a Linux administrator to understand the Linux system boot process to troubleshoot boot problems.

In this session, we will show you an overview of the Linux boot process with a flowchart diagram for a better explanation.

In Linux, the traditional init (aka SysV init boot system) system booting process consists of 6 distinct stages.

  • BIOS performs some system integrity checks when you press the power button of the machine. Once done, BIOS determines bootable device and executes the MBR boot loader.
  • MBR read information about GRUB or LILO and executes the GRUB boot loader.
  • GRUB bootloader loads the 'vmlinuz' kernel image and extracts the contents of 'initrd' image.
  • The kernel loads driver modules from initrd image and executes the '/sbin/init' program.
  • Init detects the default initlevel from the '/etc/inittab' file and load the associated runlevel programs. Usually the system default run level would be 3 or 5.
  • Runlevel executes all associated program from one of the following directories.
    • Run level 0 – /etc/rc.d/rc0.d/
    • Run level 1 – /etc/rc.d/rc1.d/
    • Run level 2 – /etc/rc.d/rc2.d/
    • Run level 3 – /etc/rc.d/rc3.d/
    • Run level 4 – /etc/rc.d/rc4.d/
    • Run level 5 – /etc/rc.d/rc5.d/
    • Run level 6 – /etc/rc.d/rc6.d/

Q.2) How does the Linux boot process work on the systemd system?

The following flowchart diagram shows how the boot process happens in systemd system.

The systemd system booting process consists of 5 distinct stages as shown below.

  • POST is executed by the BIOS or UEFI for system integrity testing.Once done, it determines bootable device and executes the MBR boot loader.
  • MBR read information about GRUB 2 and executes the GRUB 2 boot loader.
  • GRUB 2 bootloader loads the 'vmlinuz' kernel image and extracts the contents of 'initramfs' image.
  • The kernel loads driver modules from initramfs image and start the system’s first process, 'systemd'.
  • The systemd reads the '/etc/systemd/system/default.target' file and execute the associated programs.

Q.3) What is Runlevel and how many runlevels are in Linux?

A runlevel is one of the mode that a Unix-based operating system runs in.

The “/etc/inittab” file contains the default runlevel information for the SysVinit system, which is used to boot the Linux system into the specific runlevel.

Once the specified runlevel is identified, it starts all other associated applications in the background according to the run level.

There are 7 different run levels in the Linux system for different purposes (run level 0-6). The details are given below.

Run LevelShort Description
0, haltHalt System (To shut down the system)
1, S, singleSingle user mode
2Basic multi user mode without NFS
3Full Multi User with Network (text based)
4Experimental (No User or Unused)
5Multi user mode with Graphical User Interface
6, rebootTo Reboot a System

How do I check my current runlevel?

You can check your current runlevel in Linux using the “runlevel” command.

sudo runlevel

N 5
  • N – It’s short for “none”, meaning the system has never been on any other runlevel previously.
  • 5 – This shows that our system is currently in runlevel 5.

Q.4) What are Target Units in Linux?

Systemd has a concept of targets, which serves a purpose like runlevels, but operates slightly differently. Each target is named instead of numbers and is intended to serve a specific purpose.

The “/etc/systemd/system/default.target” file contains the default target information for the systemd system, which is used to boot the system into the corresponding target.

Once the specified target is identified, it starts all other processes and applications in the background according to the target.

Below is the available target for Linux (there are seven targets from zero to six). The details are given below.

Target UnitsShort Description
runlevel0.target, poweroff.target, systemctl haltHalt System (Shut down and power off)
runlevel1.target, rescue.targetSingle User Mode
runlevel[234].target, multi-user.targetFull Multi User with Network (text based)
runlevel5.target, graphical.targetMulti user mode with Graphical User Interface
runlevel6.target, reboot.target, systemctl rebootShut down and reboot the system

How do I check my current target in systemd system?

To check current runlevel of systemd system, run:

systemctl get-default

graphical.target

Q.5) What is Linux System Manager and How to Identify it?

System Manager is the first process started by the kernel during system boot.

It holds the process ID (PID) of 1. It will continue to run in the background until the system is shut down.

Below are three system administrators that are widely used in Linux.

  • System V (Sys V): System V (Sys V) is one of the first and traditional init system for Unix like operating system.
  • Upstart: Upstart is an event-based replacement for the /sbin/init daemon.
  • systemd: systemd is a new init system and system manager that has been adapted by most Linux distributions instead traditional SysVinit systems.

You can easily identify the system manager by running ps command on your system.

ps -p1 | grep "init\|upstart\|systemd"

   1 ?        00:18:09 systemd

Q.6) What is Single User Mode and how to boot into single user mode in Linux?

Single user mode, also referred to as maintenance mode, allows a super user to recover/repair the system from problems that cannot be resolved in a multi-user environment or system boots, but does not function properly or you cannot log in to it.

It uses ‘runlevel 1’ in the SysVinit system whereas ‘runlevel1.target’ or rescue.target in systemd system.

It only enable few services and minimal functionality to repair the system. This method is most useful if you want to run fsck to fix corrupted file systems or reset a forgotten root password or change the “/etc/fstab” file.

Q.6.1) How to boot into Single User Mode on systemd system

  • When the GRUB2 menu screen appear, select the kernel that you want to edit and press the ‘e’ key to edit further.
  • Add the ‘rd.break’ at the end of the ‘linux16’ line and then enter.
  • Finally press ‘Ctrl+x’ to boot the system with emergency target.

Q.6.2) How to boot into Single User Mode on Sys V init system

  • When the GRUB menu screen appear, select the kernel that you want to edit and press the ‘e’ key to edit further.
  • Add the ‘single’ at the end of the ‘kernel’ line and then enter.
  • Finally press ‘Ctrl+x’ to boot the system with emergency target.

Q.7) What is Emergency Mode (Target) and how to boot into emergency mode in Linux?

You can boot the system with emergency mode to repair your system when the system cannot enter rescue mode. This provides a very minimal environment for the user.

In emergency mode, the system mounts the root file system for read-only purposes and does not attempt to load any other local file systems. Also, it does not activate network interfaces and only starts some essential services.

How to boot into Emergency mode (target)

  • When the GRUB2 menu screen appear, select the kernel that you want to edit and press the ‘e’ key to edit further.
  • Add the ‘systemd.unit=emergency.target’ at the end of the ‘linux16’ line.
  • Finally press ‘Ctrl+x’ to boot the system with emergency target.

Q.8) What is Rescue Mode (Target) and how to boot into rescue mode in Linux?

If your system unable to complete a regular booting process due to an issue, you can boot the system into rescue (single-user) mode for further troubleshooting.

In rescue mode, the system tries to mount all local file systems and start only few important system services, but it does not activate network interfaces or allow more users to log into the system at the same time.

Make a note: The rescue mode of the installation program differs from the rescue mode (equivalent to single-user mode) and the emergency mode, which are provided as part of the systemd system and service manager.

Booting into Rescue mode (target)

It can be done in two methods:

Method-1:

You can boot the system directly into rescue mode from the GRUB2 menu because you have the option for that.

Method-2:

  • When the GRUB2 menu screen appear, select the kernel that you want to edit and press the ‘e’ key to edit further.
  • Add the ‘systemd.unit=rescue.target’ at the end of the ‘linux16’ line.
  • Finally press ‘Ctrl+x’ to boot the system with emergency target.

Q.9) How to boot a system into rescue mode using LIVE ISO DVD in Linux?

You need to boot your Linux system into rescue mode using the installation DVD or ISO to repair the corrupted '/boot' partition.

This mode can be used to perform a wide variety of troubleshooting.

  • Boot up your system from Live ISO image.
  • In the boot menu, select the ‘Troubleshooting’ option and press enter.
  • In the next screen, select the ‘Rescue a CentOS Linux system’ option and press enter.
  • In the next screen, input '1' and then press enter to continue.
  • Now, press ‘Enter’ to obtain a shell.

Finally, run the below command to gain your root environment.

chroot /mnt/sysimage

Q.10) What’s SELinux?

SELinux (stands for Security Enhanced Linux) is a security feature of the Linux kernel that add additional security layer to the Linux system.

It implements mandatory access control (MAC) that allows users and administrators more control over discretionary access control (DAC).

SELinux defines access control policies for applications, processes, sockets, and files that dictate them what they can or can’t be accessed, which protects the system from malicious or flawed applications that can damage or destroy the system.

When enabled, SELinux can run in one of two modes:

  • enforcing
  • permissive

Execute one of the following commands to check in which mode SELinux is running.

getenforce
or
sestatus

The ‘getenforce’ command returns the SELinux status such as Enforcing, Permissive, or Disabled whereas the ‘sestatus’ command returns the SELinux status and the SELinux policy being used.

  • Enforcing: It enforces the SELinux policy and denies access based on SELinux policy rules.
  • Permissive: In permissive mode, SELinux policy is not enforced and does not deny any actions but only logs AVC messages.
  • Disabled: Allow all operations and doesn’t log any events.

To permanently change the SELINUX mode from one to another, you must modify the mode value in the following SELinux configuration file.

sudo vi /etc/selinux/config

Conclusion

In this guide, we’ve included the most frequently asked 4th set of 10 basic Linux Interview Questions and detailed answers for your reference purpose and we hope it will be very useful.

If you have any questions or feedback, feel free to comment below.

Leave a Reply

%d bloggers like this: