Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Linux

troubleshooting
apt
apt is a command-line utility for installing, updating,
removing, and otherwise managing deb packages on
Ubuntu, Debian, and related Linux distributions. It
combines the most frequently used commands from the
apt-get and apt-cache tools with different default values
of some options.
apt is designed for interactive use. Prefer using apt-get
and apt-cache in your shell scripts as they are backward
compatible between the different versions and have
more options and features.
apt -f install

apt install --fix-broken

apt install --fix-missing

apt remove --purge package_name

apt autoremove

apt clean ... etc


dnf/yum
The DNF command (Dandified yum) is the next-
generation version of the traditional YUM package
manager for RedHat based systems. It is the default
package manager for Fedora 22, CentOS8, and RHEL8.
It is intended to be a replacement for YUM. It does
Package Management using RPM and libsolv. The DNF
package manager is efficient on performance, memory
consumption and dependency resolution issues.DNF
handles package, dependency crisis in much better and
differently.
dnf repolist /dnf repolist all Repository list
dnf help/dnf help search Help about DNF
List of Installed and AvailablePackages
dnf list/dnf list available/dnf list installed
Clean up your system using DNF
dnf clean all/dnf autoremove
Group operations using DNF
dnf grouplist/dnf groupinstall group_name/dnf
groupremove group_name
Update Check and Updating your system
dnf check-update/dnf list updates/dnf update/dnf update
package_name
dpkg --configure -a
dpkg is the main package management program in Debian
and Debian based System. It is used to install, build, remove,
and manage packages. Aptitude is the primary front-end to
dpkg.
To view and list all the installed packages, use the “-l” option
along with the command.
The ‘r‘ option will only remove the package and not
configuration files.
Content of a particular package, use the “-c” option, along with
the file name
Using “-s” option with package name, will display whether an
deb package installed or not.
-L To list location of files to be installed to your system from
package-name.
systemd-analyze
systemd-analyze may be used to determine
system boot-up performance statistics and
retrieve other state and tracing information
from the system and service manager, and
to verify the correctness of unit files. It is
also used to access special functions useful
for advanced system manager debugging.
systemd-analyze
To get an overview of the system boot-up
time

systemd-analyze blame
To view a list of all running units, sorted by
the time they took to initialize (highest time
on top)
systemd-analyze dump
This command outputs a (usually very long) human-
readable serialization of the complete server state. Its
format is subject to change without notice and should
not be parsed by applications.

The outputs from systemd-analyze are not only


interesting but also make it possible to see at a
glance why the boot process is taking so long.
Services that slow down the boot process can thus be
identified directly where lengthy troubleshooting or
analysis might otherwise be necessary.
sysctl
The /sbin/sysctl command is used to view, set, and
automate kernel settings in the /proc/sys/ directory.
This is the same information seen if each of the files
were viewed individually. The only difference is the
file location.

Each time the system boots, the init program runs


the /etc/rc.d/rc.sysinit script. This script contains a
command to execute sysctl using /etc/sysctl.conf to
determine the values passed to the kernel. Any
values added to /etc/sysctl.conf therefore take effect
each time the system boots.
systemctl
Systemctl is a Linux command-line utility used
to control and manage systemd and services.
You can think of Systemctl as a control
interface for Systemd init service, allowing you
to communicate with systemd and perform
operations. Systemctl is a successor of Init.

systemctl reboot, poweroff, get-default, rescue


There are many ways to display the status of
services. In some cases, admins may wish to
see information about all services, while, in
other situations, they may only be interested in
managing a single specific service. Either way,
systemctl can help.
systemctl list-units --type=service
List services by status
To list services by status, type the following:
systemctl list-units --type=service --state=active
systemctl list-units --failed
Prevent service from starting
A stopped, or disabled, service can still be
started if another service calls it. To prevent a
service from starting in any case, use the mask
subcommand. This links the service
configuration to the /dev/null file.

# systemctl mask {servicename}


Confirm active status
The systemctl command confirms the
current and startup status of specific
services by using the command below, as
well as the is-enabled command:

# systemctl is-active {servicename}


Today's administrators manage more on-premises
and cloud-hosted Linux systems than ever.
Service management and monitoring are critical to
ensuring the satisfactory delivery of resources to
consumers. The systemctl command is one of the
most useful tools available.
Become familiar with the many subcommands,
and watch your Linux administration productivity
skyrocket.
vmstat
Virtual memory statistics reporter, also known as
vmstat , is a Linux command-line tool that reports
various bits of system information. Things like
memory, paging, processes, IO, CPU, and disk
scheduling are all included in the array of information
provided.
mpstat
Mpstat is used to monitor CPU utilization on your system.
It will be more useful if your system has multiple
processors. The first processors will be signed as CPU 0.
The second one will be signed CPU 1 and so on.
The mpstat command writes to standard output activities
for each available processor, processor 0 being the first
one. Global average activities among all processors are
also reported. The mpstat command can be used both on
SMP and UP machines, but in the latter, only global
average activities will be printed. If no activity has been
selected, then the default report is the CPU utilization
report
pidstat
The pidstat command is used for monitoring
individual tasks currently being managed by the
Linux kernel. It writes to standard output activities
for every task selected with option -p or for every
task managed by the Linux kernel if option -p ALL
has been used.
iostat
To evaluate the performance of I/O devices, their
efficiency with respect to time is calculated. In Linux,
we use the iostat command to find out its usage of
CPU and other connected Input/Output devices with
respect to time. On the basis of these reports, the
configurations of the I/O devices can be changed to
optimize the load on the CPU.
The iostat command is helpful in monitoring the CPU
and other I/O devices connected to it.
lsof
lsof command stands for List Of Open File. This
command provides a list of files that are opened.
Basically, it gives the information to find out the files
which are opened by which process. With one go it
lists out all open files in output console.
Journalctl
Linux-based systems provide multiple tools that help
record and analyze system logs. Just like the
“systemd”, which is a powerful tool used to collect logs
from the sources in a binary format and allows the
user to get the logs using command-line.

The “Journald” is a system program from the systemd


tool that collects data from multiple logs in a binary
format. It works the same way as syslog but gives a
more efficient way to manage logs.
dmesg
dmesg command also called as “driver message” or
“display message” is used to examine the kernel ring
buffer and print the message buffer of kernel. The
output of this command contains the messages
produced by the device drivers.
/var/log/
Linux has a special directory for storing logs called /var/log
This directory contains logs from the OS itself, services,
and various applications running on the system.
From a security perspective, there are 5 groups of files
which are essential. Many other files are generated and
will be important for system administration and
troubleshooting.
Contains global system messages, including the
messages that are logged during system startup. There
are several things that are logged in /var/log/messages
including mail, cron, daemon, kern, auth, etc.

You might also like