Linux Interview Questions
what is load average ?
Number of jobs in run queue are waiting for disk IO averaged over 1, 5 and 15 mins.
mpstat -P ALL 1 (produces all CPU's utilization for every 1 second)
while true; do true; done
debug cpu performance issue
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
How to get a UUID of san devices from file?
ll /dev/disk/by-uuid/
how to block particular lun using multipath.conf file
Edit /etc/multipath/multipath.conf file and add your device in blacklist section
blacklist {
wwid 26353900f02796769
devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
devnode "^hd[a-z]"
}
How to scan scsi and fc devices for new disks?
FC :
# echo "1" > /sys/class/fc_host/host0/issue_lip
# echo "1" > /sys/class/fc_host/host1/issue_lip
SCSI
# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan
to get the list of fc adapters : ls /sys/class/fc_host
to get the wwn number :
cat /sys/class/fc_host/host0/node_name
to get the port number
cat /sys/class/fc_host/host0/port_name0x10000000c9538d83
cat /sys/class/fc_host/host1/port_name0x10000000c9538dac
scan the newly added lun
echo "1" > /sys/class/fc_host/host0/issue_lip
echo "- - -" > /sys/class/scsi_host/host0/scan
----------------------------------------------------------------------------------------------------------
tool you use to check the system performance?
# top
# sar
# vmstat
# iostat
-----------------------------------------------------------------------------------------------------------
------------------------------
zombie process :
------------------------------
poorly written parent process might not call the wait () function when the child process is created.
SIGCHLD signal will be ignored or another application is affecting this process.
# top (to check the no of zombies)
# ps aux | egrep "Z|defunct"
# ps -o ppid= -p 7641
# ps -e | grep 7636
-------------------------------------------------------------------------------------------------------------
File descriptors :
--------------------
File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr).
at first, 2>1 may look like a good way to redirect stderr to stdout.
However, it will actually be interpreted as "redirect stderr to a file named 1".
& indicates that what follows and precedes is a file descriptor and not a filename. So the construct becomes: 2>&1.
Consider >& as redirect merger operator.
--------------------------------------------------------------------------------------------------------------
sed command
---------------------
To extract lines one to four, we type this command:
sed -n '6,9p' coleridge.txt
We can use the -e (expression) option to make multiple selections. With two expressions, we can select two verses, like so:
sed -n -e '1,4p' -e '31,34p' coleridge.txt
occurrences of “day” to “week,” and give the mariner and albatross more time to bond:
sed -n 's/day/week/p' coleridge.txt
We have to add a “g” at the end of the expression, as shown below, to perform a global search so all matches in each line are processed:
sed -n 's/day/week/gp' coleridge.txt
We type the following, adding an i to the command at the end of the expression to indicate case-insensitivity:
sed -n 's/day/week/gip' coleridge.txt
We can achieve the same result if we use a semicolon (;) to separate the two expressions, like so:
sed -n 's/motion/flutter/gip;s/ocean/gutter/gip' coleridge.txt - two substitutes in single command.
sed -e '/swap/s/^/#/' - inserts # at the beginning of the line after matching the pattern.
------------------------------------------------------------------------------------------------------------------------
CPU Softlockup and hardlockup :
----------------
A soft lockup is the symptom of a task or kernel thread using and not releasing a CPU for a longer period of time than allowed.
A hard lockup is when a CPU has interrupts disabled for a long time, which might block important communication between processes or hardware.
The default hard lockup threshold is 30 second on RHEL5/6 and 10 seconds on RHEL7.
---------------------------------------------------------------------------------------------------------------------------
lvreduce:
-Umount the filesystem using umount command,
-use resize2fs command , e.g resiz2fs /dev/mapper/myvg-mylv 10G
-Now use the lvreduce command , e.g lvreduce -L 10G /dev/mapper/myvg-mylv
-----------------------------------------------------------------------------------------------------------
grub config file explained :
GRUB2 configuration file /boot/grub2/grub.cfg
Do not edit this file directly.
Use the grub2-mkconfig command to generate grub.cfg
This command uses the template scripts in /etc/grub.d and menu-configuration settings taken from /etc/default/grub
The /etc/grub2.cfg file is a symbolic link to /boot/grub2/grub.cfg
/etc/default/grub File :
# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
If changes are made to any of these parameters, you need to run grub2-mkconfig to re-generate the /boot/grub2/grub.cfg file.
# grub2-mkconfig –o /boot/grub2/grub.cfg
-------------------------------------------------------------------------------------------------------------------------
Rescue mode :
-------------------
Rescue mode : Three ways
1) There is a GRUB2 menu option when you boot up the system which can be selected to directly boot into rescue mode.
2)During bootup, when the GRUB2 menu shows up, press the e key for edit.
Add the following parameter at the end of the linux16 line:
systemd.unit=rescue.target
Press Ctrl+x to boot the system with the parameter.
To switch to Emergency target, simply run following command as root:
3) By booting the system from an installation boot CD-ROM.
- By booting the system from other installation boot media, such as USB flash devices or .iso files for a virtual machine.
Troubleshooting ---> Rescue a Linux machine
press 1 to continue.
chroot /mnt/sysimage
Bootup into Emergency mode(target) :
Emergency mode provides the most minimal environment possible and allows you to
repair your system even in situations when the system is unable to enter rescue mode.
In emergency mode, the system mounts the root file system as read-only,
does not attempt to mount any other local file systems, does not activate network interfaces.
1. During bootup, when the GRUB2 menu shows up, press the e key for edit.
Boot up screen grub2
2. Add the following parameter at the end of the linux16 line :
systemd.unit=emergency.target
Press Ctrl+x to boot the system with the parameter.
-------------------------------------------------------------------------------------------------------------------------
Re-install grub :
boot into rescue mode.
change root directory using cmd # chroot /mnt/sysimage
grub-install /dev/sda (majority of the scenarios, grub is installed on /dev/sda which is a boot device)
(you can check grub.conf to verify for the boot device from /dev/grub2/grub.conf file
grep boot=/dev /dev/grub2/grub.conf file.)
execute exit command twice to reboot.
-------------------------------------------------------------------------------------------------------------------------
rpmdb corrupted what would you do ?
There are a number of factors that can lead to the RPM database corruption, such as incomplete previous transactions,
installation of certain third-party software, removing specific packages, and many others.
backing up your current RPM database before proceeding (you might need it in the future), using the following commands.
# mkdir /backups/
# tar -zcvf /backups/rpmdb-$(date +"%d%m%Y").tar.gz /var/lib/rpm
# rm -f /var/lib/rpm/__db*
# /usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages
In case the above operation fails, meaning you still encounter errors, then you should dump and load a new database. Also verify the integrity of the freshly loaded Packages file as follows.
# cd /var/lib/rpm/
# mv Packages Packages.back
# /usr/lib/rpm/rpmdb_dump Packages.back | /usr/lib/rpm/rpmdb_load Packages
# rpm -qa
rebuild the RPM database using the following command
# rpm -vv --rebuilddb
-----------------------------------------------------------------------------------------------
/etc/resolv.conf entries getting erased what would you do ?
set peerdns=no in /etc/sysconfig/network-scripts/ifcfg-eth0 and stop the NetworkManager service.
------------------------------------------------------------------------------------------------
no nfs mounts in the server, df -h command getting hang what would you do ?
/etc/mtab file should be symbolic link to /proc/self/mounts.
Create the symbolic link again using ln -s.
You can even reinstall util-linux package as /etc/mtab is provided by it.
It will restore the link and permissions.
-------------------------------------------------------------------------------------------------
In db system, disk utilization is full but there are less number of files in the partition what would you do
how do you kill the files (cont from the above scenario)
lsof | egrep "deleted|COMMAND"
As it is a db system, we can not kill the process.
We need to truncate the file size (de-allocate the space used by that file)
echo > /proc/pid/fd/fd_number
eg:
$ file /proc/25575/fd/33
/proc/25575/fd/33: broken symbolic link to `/oradata/DATAPRE/file.dbf (deleted)'
$ echo > /proc/25575/fd/33
------------------------------------------------------------------------------------------------------
what is dracut ?
The tool named dracut is used to create a Linux boot image (initramfs) by copying tools and files from an installed system
and combining it with the Dracut framework, which is usually found in /usr/lib/dracut/modules.
How to resolve kernel panic error ?
This happens mostly because of initramfs.img file missing or corrupted
1.Boot the system in rescue mode
2.Log in using the root account
3.Navigate to /boot
4. See if initramfs.img file is available (If it is available, it must be corrupted
5.find kernel version (uname -r)
6.mkinitrd initramfs-kernel_version.img kernel_version
7.Boot the machine
-------------------------------------------------------------------------------------------------------
disk IO utilization is high, how do you trace and troubleshoot ?
Using iostat command we can trace on which experiencing the high IO
using lsblk we can trace the exact partition.
using ps -ef and lsof we can trace which files are in usage.
----------------------------------------------------------------------------------------------------------
Pre-req to check before performing the vmotion :
The hosts must be licensed for vMotion.
The hosts must be running ESXi 5.1 or later.
The hosts must meet the networking requirement for vMotion. See vSphere vMotion Networking Requirements.
The virtual machines must be properly configured for vMotion. See Virtual Machine Conditions and Limitations for vMotion
Virtual machine disks must be in persistent mode or be raw device mappings (RDMs). See Storage vMotion Requirements and Limitations.
The destination host must have access to the destination storage.
When you move a virtual machine with RDMs and do not convert those RDMs to VMDKs, the destination host must have access to the RDM LUNs.
Consider the limits for simultaneous migrations when you perform a vMotion migration without shared storage. This type of vMotion counts against the limits for both vMotion and Storage vMotion, so it consumes both a network resource and 16 datastore resources.
----------------------------------------------------------------------------------------------------------
how do you enter into rescue mode ?
1) boot into rescue mode from installation DVD/ISO
boot with iso -- select troubleshooting -- rescue a centos linux system -- continue -- chroot /mnt/sysimage
2) There is a GRUB2 menu option when you boot up the system which can be selected to directly boot into rescue mode.
3) Edit the grub menu and append the following to linux16 line systemd.unit=rescue.target
4) systemctl rescue (it directly switches to rescue mode)
----------------------------------------------------------------------------------------------------------\
How all the users are able to change their respective passwords ?
The "/usr/bin/passwd" file is owned by user "root" and has the SETUID bit set. The process executes "/usr/bin/passwd" with effective user ID 0 (root) and so can change the contents of "/etc/shadow".
----------------------------------------------------------------------------------------------------------\
Can we reduce the size of xfs filesystem ? if yes, how ?
using xfs_reduce we can reduce. we need xfsdump to take backup of the partition before reducing.
incase if its a LVM
yum install xfsdump -y
xfsdump -f /tmp/<partition_name.dmp> /data (backup the data)
umount /<partition>
lvreduce -L 400M /dev/vg00/lv00
mkfs.xfs -f /dev/vg00/lv00
mount /dev/vg00/lv00 /data
xfsrestore -f /tmp/<partition_name> /data
ls -l /<partition_name>
In some cases, the following workarounds may be acceptable:
Use some backup/restore solution, such as xfsdump and xfsrestore. This may be useful especially if the filesystem is mostly empty.
-----------------------------------------------------------------------------------------------------------
how do you repair the xfs filesystem ?
# xfs_repair /mount/point
# xfs_repair /dev/mapper/vg_test-lv_test
# xfs_check /dev/mapper/vg_test-lv_test (check for filesystem problems, but not fix any problems)
xfs_repair -n” command to do a dry run for xfs_repair.
---------------------------------------------------------------------------------------------------------------
how do you edit the grub in Linux explain procedure ?
1) boot into rescue mode from installation DVD/ISO
boot with iso -- select troubleshooting -- rescue a centos linux system -- continue -- chroot /mnt/sysimage
2) There is a GRUB2 menu option when you boot up the system which can be selected to directly boot into rescue mode.
3) Edit the grub menu and append the following to linux16 line systemd.unit=rescue.target
4) systemctl rescue (it directly switches to rescue mode)
---------------------------------------------------------------------------------------------------------------
How many ways are there to boot system into rescue mode ?
explained above
---------------------------------------------------------------------------------------------------------------
How do you activate the deactivated LVM ?
To deactivate the logical volume/ volume group
lvchange -an /dev/vg_name/lv_name
vgchange -an vg_name
to activate
lvchange -ay /dev/vg_name/lv_name
vgchange -ay vg_name
-----------------------------------------------------------------------------------------------------------------
/bin/mount file got deleted, after reboot now no mounts are getting mounted because of mount command not found, how do you restore ?
Anyway, we are going to fix the issue and make /bin's contents as close as is possible to where it was. The only difference would be some symbolic links which we will fix too.
boot the system into rescue mode
we can get a list of packages which have installed files in /bin using:
dpkg --search /bin | cut -f1 -d: | tr ',' '\n'
dpkg --listfiles PACKAGE-NAME | grep "^/bin/" # or awk '$0 ~ "^/bin/ (we can also use this to list files under /bin)
we simply create a list of all packages that are necessary to us, then download them and extract them to /bin with something like:
xargs apt download < list-packages
dpkg-deb -x PACKAGE .
mv ./bin/* /bin
we can make use of this script to restore multiple files
https://github.com/ravexina/restore-bin.git
-----------------------------------------------------------------------------------------------------------------
Using ping command how do we come to know it is windows or Linux machine ?
TTL value for Linux/Unix is 64, and TTL value for Windows is 128.
-----------------------------------------------------------------------------------------------------------------
ping uses which protocol ?
UDP
-----------------------------------------------------------------------------------------------------------------
boot procedure of linux role of explain initramfs in it ?
https://www.thegeekdiary.com/centos-rhel-7-booting-process/
-----------------------------------------------------------------------------------------------------------------
I want to boot the server into previous kernel, how do you do it and explain the ways ?
https://www.thegeekdiary.com/centos-rhel-7-change-default-kernel-boot-with-old-kernel/
-----------------------------------------------------------------------------------------------------------------
what is semaphore in Linux ?
a semaphore is a variable or abstract data type used to control access to a common resource by multiple threads and avoid critical section problems in a concurrent system such as a multitasking operating system.
Advantages of Semaphores
There is no resource wastage because of busy waiting in semaphores as processor time is not wasted unnecessarily to check if a condition is fulfilled to allow a process to access the critical section. Semaphores are implemented in the machine independent code of the microkernel.
----------------------------------------------------------------------------------------------------------------
what is a process and thread ?
A process is a program under execution
Processes require more time for context switching as they are more heavy.
A thread is a lightweight process that can be managed independently by a scheduler.
Threads require less time for context switching as they are lighter than processes.
-----------------------------------------------------------------------------------------------------------------
Introduction
"Good Morning Scott, and thank you for the opportunity to speak with you today.
My name is Gopi Krishna, and I have almost 14 years of extensive experience in Infrastructure Management.
During this time of my career, I've specialized in Redhat Linux Administration, Bash Scriptin, Ansible, Redhat Satellite servers, KVM, VMware Vsphere.
Key Highlights
In my Current role at Tech Mahindra,
I am leading a team of 14 members to provide tech solutions and project implementations strategies, for that we received many customer appreciations.
My contributions have often centered on problem-solving, team collaboration, and delivering projects even under tight schedules too.
Passion and Growth
I always try to work in such a way that create impactful user experiences, streamline operations, or mentor rising talent.
I’m always eager to learn and adapt to newer technologies, which has allowed me to cope up with the newer requirements of deployments.
Alignment with the Role
I’m particularly interested in this role because I have expertise and experience in almost most of the JD.
My background in Linux, Ansible, Bash Scripting, Vsphere aligns well with the requirements.
I’m confident that I can bring value by Providing complete end to end support to the team in which I am going to support.
Closing
I look forward to discussing how my skills and experiences can contribute to your team.
Thank you again for considering my application."
############################################################################################################################################
what does touch /.autorelabel do
The command touch /.autorelabel is used to instruct SELinux (Security-Enhanced Linux) to perform a filesystem relabeling on the next reboot. Here's a detailed explanation:
What Does Relabeling Mean?
SELinux enforces security policies based on labels (or contexts) associated with every file, directory, and process on the system.
These labels define the type of access a process has to a resource.
If the labels are missing, incorrect, or corrupted (e.g., after restoring a backup, modifying files, or disabling/re-enabling SELinux), relabeling is required.
Purpose of /.autorelabel
Triggers a Full Relabeling:
The touch /.autorelabel command creates an empty file named .autorelabel in the root (/) directory.
On the next reboot, the systemd and SELinux services detect this file and initiate a full relabeling of the filesystem.
When Is It Needed?
After enabling SELinux on a system where it was previously disabled.
After recovering or restoring the root filesystem from a backup.
When file contexts are corrupted or mismatched.
What Happens During Relabeling?
The restorecon command (or a similar SELinux utility) systematically resets the SELinux labels for all files and directories based on the policy definitions.
The process can take time depending on the size of the filesystem.
How to Use It
Create the .autorelabel file:
touch /.autorelabel
Reboot the system:
reboot
On reboot, SELinux relabels the filesystem.
You'll see messages on the console indicating the relabeling process.
After the relabeling is complete, the system automatically removes the .autorelabel file and reboots again.
Implications of Relabeling
Performance Impact:
Relabeling can take a long time on systems with large filesystems, especially if many files are present.
Required for Proper Functionality:
Without correct labels, SELinux might block legitimate processes or services due to label mismatches.
Example Scenario: Enabling SELinux
If SELinux was disabled (e.g., selinux=0 or permissive mode), and you re-enable it:
Enable SELinux in /etc/selinux/config:
SELINUX=enforcing
Create the .autorelabel file:
touch /.autorelabel
Reboot the system:
reboot
SELinux relabels the entire filesystem during the boot process.
Troubleshooting
If relabeling fails or you need a manual relabel:
restorecon -R /path/to/directory
This command relabels only the specified directory and its contents.
############################################################################################################################################
Q) selinux is disabled and i have done the password reset of root on rhel 8 server. is it necessary to create /.autorelabel file for successful root password reset ?
No, it is not necessary to create the /.autorelabel file for a successful root password reset if SELinux is disabled. Here's why:
Why SELinux Relabeling Is Not Needed in This Case
SELinux Disabled:
If SELinux is disabled (SELINUX=disabled in /etc/selinux/config), it does not enforce policies or require any file labeling. The /.autorelabel mechanism is relevant only when SELinux is enabled or in enforcing/permissive mode.
Password Reset:
When you reset the root password, the only requirement is that the changes are saved to /etc/shadow and /etc/passwd files. This operation is unrelated to SELinux labels unless SELinux is enforcing.
When /.autorelabel Might Be Necessary
If SELinux is enabled (in enforcing or permissive mode), and you reset the root password from a recovery environment (e.g., using rd.break), SELinux may block authentication if the file labels of /etc/shadow or /etc/passwd become incorrect.
In such a scenario, you would:
Reset the password.
Create the /.autorelabel file.
Reboot the system to ensure SELinux relabels the filesystem, allowing the changes to work correctly.
How to Confirm SELinux Status
Before deciding to use /.autorelabel, check the SELinux status:
View the SELinux configuration file:
cat /etc/selinux/config
Look for the SELINUX= line:
disabled: SELinux is completely off, and relabeling is unnecessary.
permissive or enforcing: SELinux is active, and relabeling might be needed.
Check the runtime status (if the system is running):
sestatus
Summary
If SELinux is disabled, you do not need to create /.autorelabel for a successful root password reset. If SELinux is enabled, relabeling ensures the system applies the correct labels to avoid potential authentication issues.
############################################################################################################################################
Understanding and modifying kernel boot parameters (e.g., rd.break, quiet, ro).
How they affect the boot process.
Kernel Boot Parameters: Understanding and Modifying
Kernel boot parameters are instructions passed to the Linux kernel by the bootloader (GRUB2 in RHEL 9) during boot.
They control kernel behavior, influence the initialization process, and help troubleshoot boot issues.
How to Modify Kernel Parameters
Temporary Change (at Boot Time):
During the GRUB boot menu:
Highlight the desired boot entry.
Press e to edit the boot parameters.
Locate the line starting with linux (or linux16 for BIOS systems).
Append or modify kernel parameters at the end of this line.
Press Ctrl+X or F10 to boot with the modified parameters.
Permanent Change:
Modify /etc/default/grub:
sudo vim /etc/default/grub
Add or edit the GRUB_CMDLINE_LINUX line:
GRUB_CMDLINE_LINUX="quiet rd.break"
Regenerate the GRUB configuration:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg # BIOS systems
sudo grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg # UEFI systems
Common Kernel Parameters and Their Effects
Here are some commonly used kernel parameters and their impact on the boot process:
1. rd.break (Rescue Breakpoint)
Purpose:
Breaks into the initramfs shell before mounting the root filesystem.
Usage:
Ideal for recovery tasks like resetting the root password or repairing the root filesystem.
Example Workflow:
Add rd.break to the kernel line and boot.
You'll get a prompt like:
dracut:/#
From here, you can:
Access the real root filesystem (/sysroot).
Modify files or run recovery commands.
Exit with exit to continue booting.
2. quiet
Purpose:
Suppresses most kernel messages during boot, showing only critical messages.
Effect:
Provides a cleaner boot experience.
Default in RHEL 9:
RHEL 9 typically includes quiet by default in GRUB_CMDLINE_LINUX.
3. ro and rw
Purpose:
Controls whether the root filesystem is mounted as read-only (ro) or read-write (rw) at boot.
Use Cases:
ro: Default. The filesystem is mounted read-only for consistency and is remounted as read-write later in the boot process by systemd.
rw: Used for debugging or custom setups where early read-write access is required.
4. emergency and single
Purpose:
Boots the system into minimal modes for troubleshooting.
Differences:
emergency: Boots directly into a shell without starting any services.
single: Boots into single-user mode with minimal services started.
5. selinux=0
Purpose:
Disables SELinux entirely.
Effect:
Turns off SELinux enforcement and auditing, useful for debugging SELinux-related issues.
6. nosplash
Purpose:
Disables graphical boot splash screens (e.g., Plymouth).
Effect:
Displays all kernel messages during boot, useful for debugging.
7. nomodeset
Purpose:
Disables kernel mode setting for graphics hardware.
Use Cases:
Resolves display issues (e.g., blank screen or distorted graphics) during boot.
8. rd.driver.blacklist=<module>
Purpose:
Prevents specific kernel modules (drivers) from loading.
Example:
Blacklist the Nouveau driver:
rd.driver.blacklist=nouveau
9. console=<device>
Purpose:
Specifies where kernel messages should be sent (e.g., a serial console or TTY).
Example:
Redirect messages to a serial console:
console=ttyS0
10. ipv6.disable=1
Purpose:
Disables IPv6 support.
Effect:
Prevents the kernel from initializing IPv6 networking.
#################################################################################################################################################
RHEL 9 boot procedure in detail
The boot process in RHEL 9 (or any Linux system using systemd) involves several distinct stages,
starting from the firmware and ending with a fully operational system.
Here’s a detailed breakdown of each step:
1. Firmware Initialization (BIOS/UEFI)
BIOS (Legacy Systems):
The Basic Input/Output System initializes the hardware (CPU, memory, and devices).
It looks for the bootloader on the first bootable device (e.g., hard disk, SSD, USB).
UEFI (Modern Systems):
The Unified Extensible Firmware Interface provides advanced initialization features, including support for larger disks and secure boot.
UEFI systems use a boot manager to locate and execute the bootloader file (usually located in the EFI System Partition).
2. Bootloader Execution (GRUB2)
Role of GRUB2 (GNU GRUB):
GRUB2 is the default bootloader in RHEL 9.
It presents the boot menu, allowing the user to select a kernel or boot into a rescue mode.
GRUB2 Configuration:
The main configuration file is located at /boot/grub2/grub.cfg (BIOS systems) or /boot/efi/EFI/redhat/grub.cfg (UEFI systems).
GRUB reads its configuration and loads the selected Linux kernel and initramfs (initial RAM filesystem) into memory.
3. Kernel Initialization
Loading the Kernel:
The kernel file (e.g., /boot/vmlinuz-*) is loaded into memory by GRUB.
Passing Control to the Kernel:
GRUB hands control to the kernel, along with any boot parameters specified in the GRUB configuration.
Kernel Responsibilities:
Initializes hardware using device drivers.
Mounts the initramfs as a temporary root filesystem.
4. Initial RAM Filesystem (initramfs)
What is initramfs?
A temporary root filesystem used by the kernel to load necessary drivers and mount the real root filesystem.
Located in /boot/initramfs-<version>.img.
Tasks Performed by initramfs:
Detects and loads modules needed to mount the real root filesystem (e.g., for RAID, LVM, or specific storage devices).
Executes systemd (the init process) from the temporary root.
5. systemd Initialization
Role of systemd:
systemd replaces traditional init systems and manages all subsequent system startup tasks.
systemd Responsibilities:
Reads the default target (similar to runlevel) from /etc/systemd/system/default.target.
Parses unit files (e.g., service, mount, socket files) from /usr/lib/systemd/system/ and /etc/systemd/system/.
Starts units based on dependencies.
6. Root Filesystem Mounting
systemd mounts the real root filesystem, replacing the temporary initramfs.
The real root is mounted in read-only mode initially, then remounted as read-write.
7. Target Activation
Default Target:
RHEL 9 typically defaults to graphical.target (multi-user mode with a graphical interface) or multi-user.target (non-graphical, multi-user mode).
Unit Activation:
systemd starts all required units for the default target, including services, sockets, and timers.
Examples of important services:
sshd.service: Enables SSH access.
network.service or NetworkManager.service: Configures networking.
getty@tty1.service: Provides a login prompt on the terminal.
8. Login Prompt or Display Manager
CLI Login:
If booting to multi-user.target, the system presents a console login prompt.
Graphical Login:
If booting to graphical.target, the display manager (e.g., GDM) starts, providing a graphical login screen.
Detailed Commands for Troubleshooting Each Step
Inspect GRUB Boot Menu:
Edit kernel parameters at boot by pressing e in the GRUB menu.
Check GRUB Configuration:
cat /boot/grub2/grub.cfg
View Kernel Logs:
Use dmesg to inspect kernel messages:
dmesg | less
Verify systemd Targets:
Check the current target:
systemctl get-default
Switch to a different target:
systemctl isolate multi-user.target
Debug initramfs:
Rebuild the initramfs if corrupted:
dracut --force
Check systemd Logs:
View boot logs with journalctl:
journalctl -b
Diagram of RHEL 9 Boot Process
[BIOS/UEFI] --> [GRUB2 Bootloader] --> [Kernel Loading] --> [initramfs] --> [systemd] --> [Target Reached] --> [Login]
This covers the boot procedure in detail. Would you like more on any specific stage, such as kernel parameters, systemd units, or troubleshooting techniques?
#############################################################################################################################################################
Q I HAVE modified /etc/default/grub file how to rebuild it
After modifying /etc/default/grub, you need to regenerate the GRUB configuration file for the changes to take effect. Here's how to do it on a RHEL-based system:
Steps to Rebuild GRUB Configuration
Verify Your Changes: Ensure your changes in /etc/default/grub are correct:
cat /etc/default/grub
Regenerate GRUB Configuration: The command depends on whether your system uses BIOS or UEFI:
For BIOS Systems:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
For UEFI Systems:
sudo grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
Confirm the GRUB File Was Updated: After running the command, check the timestamp or contents of the generated GRUB configuration:
ls -l /boot/grub2/grub.cfg # BIOS
ls -l /boot/efi/EFI/redhat/grub.cfg # UEFI
Reboot the System: Reboot to apply the new GRUB configuration:
sudo reboot
Troubleshooting Common Issues
Error: grub2-mkconfig Command Not Found:
Ensure the grub2-tools package is installed:
sudo dnf install grub2-tools
GRUB Doesn't Reflect Changes:
Double-check the GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT entries in /etc/default/grub.
Regenerate the GRUB configuration again.
For Advanced Users: If you're using custom bootloader paths or configurations, adjust the command accordingly.
###################################################################################################################3
What are environment variables ?
Types of Environment Variables
System-Wide Environment Variables:
Defined globally for all users.
Set in system-wide configuration files like /etc/environment or /etc/profile.
User-Specific Environment Variables:
Defined for individual users.
Typically set in shell configuration files such as:
~/.bashrc
~/.bash_profile
~/.profile
Session Environment Variables:
Set temporarily for the duration of a session or a specific shell instance.
Defined using the export command in a terminal.
Common Environment Variables
PATH:
Defines directories where the system searches for executable files.
Example:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
HOME:
Specifies the user's home directory.
Example:
echo $HOME
/home/username
USER:
Represents the currently logged-in user.
Example:
echo $USER
username
SHELL:
Indicates the user's default shell.
Example:
echo $SHELL
/bin/bash
LANG:
Specifies the system language and locale settings.
Example:
echo $LANG
en_US.UTF-8
EDITOR:
Specifies the default text editor.
Example:
echo $EDITOR
/usr/bin/vim
LOGNAME:
The name of the logged-in user.
Example:
echo $LOGNAME
username
PWD:
Displays the current working directory.
Example:
echo $PWD
/home/username
LD_LIBRARY_PATH:
Specifies directories where shared libraries are searched for.
Example:
echo $LD_LIBRARY_PATH
/usr/local/lib
TEMP or TMP:
Directory used for storing temporary files.
Example:
echo $TEMP
/tmp
Viewing and Managing Environment Variables
View All Environment Variables:
printenv
or
env
View a Specific Variable:
echo $VARIABLE_NAME
Set a Variable (Session Only):
VARIABLE_NAME=value
export VARIABLE_NAME
Set a Variable (Permanent):
Add the export statement to ~/.bashrc or ~/.bash_profile:
echo 'export VARIABLE_NAME=value' >> ~/.bashrc
source ~/.bashrc
Unset a Variable:
unset VARIABLE_NAME
System-Wide Environment Variables
Edit System-Wide Variables:
Modify /etc/environment or /etc/profile for global changes.
Example:
sudo vim /etc/environment
Add:
VARIABLE_NAME=value
#################################################################################################################################################
Comments
Post a Comment