Month: October 2021

Why doesn’t the kill command kill the process?

The kill command is used to stop a process, the command syntax is:

sudo kill PROCESS-ID

Related article: What are the differences and how to use the kill, pkill and killall commands

You may run into a situation when using kill does not kill the process.

You can get the process ID knowing the name of the executable file with the command:

ps -e | grep 'NAME'

The same command can be used to check if the process is still running.

Related article: How to use ps command to monitor Linux processes

The kill command is usually sufficient to kill most processes. But it may be that some process does not react to ‘kill’ command at all, even if you run it with sudo.

The name of the “kill” command continues to mislead many, many users (including myself at the beginning). It is assumed that when you say “kill X” it means exactly “stop (kill) the process X”. But in reality, this is far from the case. The kill command just sends one of the signals to the process.

If kill is called without any parameters, it sends signal number 15 (SIGTERM). This signal can be ignored by the process. This signal notifies a process to put its things in order, and then the process itself exits correctly. This is a good way.

You can also “send” signal number 9 (SIGKILL), which the process cannot ignore. The process doesn't even recognize it, because the kernel ends the process, not the process itself. This is an evil way.

Processes can ignore some signals. If you send a SIGKILL, it will not be able to ignore it and will not perform preparatory actions to complete, such as saving data or cleaning up.

Try:

kill -9 PROCESS-ID

If you suspend a process with CTRL-z, it will ignore most of the signals while it is suspended (that is, until you fg or bg on the process).

Also note that in some very specific circumstances a process can be in a zombie/non-functional state that even SIGKILL cannot kill the process. In this case, you will need to find the parent process and kill the parent process.

Some say kill -9 <PID> always works. It's a delusion. There are situations where even kill -9 does not kill the process. For example, when the process is in state D (continuous sleep). The process enters this state every time it waits for I/O (usually not very long). So, if a process is waiting for I/O (for example, on a faulty hard disk) and it is not properly programmed (with a timeout), then you simply cannot kill the process. Whatever you do. You can simply try to make the file available to keep the process going.

What are the differences and how to use the kill, pkill and killall commands

How to shutdown a process by process id

Each of the kill, pkill and killall commands are used to stop processes in Linux. In “How to use ps command to monitor Linux processes”, we looked at a number of ways to identify processes, including name, command, user, and terminal. We also looked at ways to identify processes by their dynamic attributes such as CPU and memory usage.

One way or another, we can define the processes that are running. Knowing their process ID, we can (if needed) stop any of these processes with the kill command. If we wanted to kill process 898, we would use this format:

sudo kill 898

Please be aware that in some cases the process will not terminate and will not display any errors or warnings. In fact, this command is a “recommendation”, it “asks” the process to exit. See the article “Why doesn't the kill command kill the process?” for details.

How to disable a process knowing its name

The pkill command allows you to kill processes by name. Make sure you define the correct process! This command will end the top process.

sudo pkill top

How to stop multiple processes by name

If you have multiple copies of a process running, or the process spawned multiple child processes (as Google Chrome can do), how can you shutdown them all? It's just as easy. We are using the killall command.

We have two instances of top running:

ps -e | grep top

We can terminate both of them with this command:

sudo killall top

This time no response means no problem, that is, both of these processes have been stopped.

Before killing the process

Make sure it's the one you want and make sure it doesn't cause any problems. In particular, it is worth checking this with the ps command running with the -H and --forest options to make sure there are no important child processes that you forgot about. See “How to use ps command to monitor Linux processes” for details.

ps -f --forest -C sshd

See also: Why doesn't the kill command kill the process?

How to use ps command to monitor Linux processes

The ‘ps’ (processes status) command is a built-in Unix/Linux utility for viewing information regarding the selection of running processes on the system: it reads this information from virtual files in the /proc file system. It is one of the essential system administration utilities, especially in the context of process monitoring, to help you understand what is happening on a Linux system.

ps has many options for manipulating the output, but you will find a small number of them practically useful for daily use.

The ps utility displays a snapshot of the processes on your Linux machine. You will be able to find processes by name, user or even terminal with as much detail as you need. This article has prepared many examples of using ps.

Linux process control

The heart of all Linux and Unix-like operating systems is the kernel. Among its many responsibilities is the allocation of system resources such as RAM and CPU time. They must be executed in real time so that all running processes get their fair share according to the priority of each task.

Sometimes tasks can be locked, or get stuck, or stop responding for other reasons. Or they can continue to run, but gobble up too much processor time or RAM, or behave in some similar antisocial manner. Sometimes tasks need to be killed to keep the system running smoothly. Of course, the first step is to identify the problematic process.

But perhaps you have no problem with tasks or performance at all. Perhaps you're just curious about what processes are running on your computer and would like to look under the hood of the Linux operating system. The ps command meets both of these requirements. It gives you a snapshot of what is happening inside your computer “right now”.

ps is flexible enough to provide you with exactly the information you need, in exactly the format you like. In fact, ps has a lot of options. The options described here will suit most common needs. If you want to take a deeper look at the ps command, familiarizing yourself with the ps command in this article and examples of using ps will make the man page easier for you.

Program for showing processes in Linux

The easiest way to use ps is to run it without parameters:

ps

ps will show the list of processes in the given terminal.

There are four columns in the output:

  • PID: process identification number.
  • TTY: The name of the console the user is signed in to.
  • TIME: The amount of CPU time that the process consumed.
  • CMD: the name of the command that started the process

How to see all processes in Linux

Adding the -e (select all processes) option will make ps list the processes that were started by all users, not just the user running the ps command. Since this will be a long list, you can add the less command.

ps -e | less

Scrollable list of processes in less command:

There are many more process records now, but we see the same four columns as before. A question mark (?) In the TTY column means that the process was not started from a terminal window.

Displaying the hierarchy of processes (process tree in Linux)

If you see what processes other processes have started, sometimes it can help you figure out a problem or identify a specific process. For this we use the -H option.

ps -eH | less

Indentation indicates which processes are the parents of which other processes.

To add some clarity, we can ask ps to add some ASCII lines and draw a tree-like hierarchy. This can be done with the --forest option.

ps -e --forest | less

This makes it easier to keep track of which processes are the parents of other processes.

How to print a tree of a specific process

You can get the process tree of only the program you need as follows (replace “sshd” with the process you are interested in):

ps -f --forest -C sshd

Or like this:

ps -ef --forest | grep -v grep | grep sshd

The -C option will be discussed later in this article.

Filtering ps output by specific lines (by command name, for example)

You can pipe the output from ps through grep and find the process entries you want along any lines. Here we are looking for entries matching the search term “firefox”:

ps -e | grep firefox

In this case, the output is a single record for the process of interest. Of course, if we were running multiple instances of Firefox, there would be more than one item in the list.

More columns in ps output

To add additional columns to the output, use the -f (full format) option.

ps -ef | less

An additional set of columns is included in the ps output.

The following new columns have been added:

  • UID: User ID of the owner of this process.
  • PPID: Parent Process ID.
  • C: The number of children the process has.
  • STIME: Start time. The time when the process was started.

Using the -F (extra full format) option, we can get even more columns:

ps -eF | less

If you have a small terminal window, the columns we get this time require scrolling to the side to show them all. Pressing the Right Arrow key (→) shifts the display to the left.

The following columns have now been added:

  • SZ: The size of the RAM pages of the process image.
  • RSS: Resident Set Size. It is not the swapped physical memory used by the process.
  • PSR: The processor to which the process is assigned.

Do I need to put a hyphen in front of ps options

In some examples, you may see ps used with non-hyphen options or with long GNU-style options. For compatibility, ps supports all three formats. Non-hyphenated options are BSD style and the meaning of hyphenated and non-hyphenated options can be different!

An example of showing processes in BSD format:

ps au
# OR
ps axu

In this command, the meaning of the options is as follows:

  • u – user oriented format
  • a – removes the restriction “only own processes”
  • x – removes the restriction “only processes with a terminal”

Simply put, if you use “a” and “x” together, then all processes will be shown.

Be careful not to forget to hyphenate if you are using UNIX options, since ps will try to interpret it differently if it is ambiguous. In this manual, except for the example shown above, UNIX options are used everywhere.

Search for processes by process ID

Once you have found the process ID for the process you are interested in, you can use it with the ps command to display detailed information about that process. To do this, use the -p parameter after which specify a number – the process ID:

ps -p 3403

More than one process ID can be specified, separated by commas or spaces.

Search for processes by command name

The -C COMMAND option allows you to search for a process using the command name. That is, the name of the command that started the process. This is slightly different from a command line, which can include path names and parameters or options.

ps -F -C soffice.bin

Only information about the process started by the specified command is displayed:

There can be several processes if many instances of this command are running:

ps -F -C bash

How to see the flows of a process

To list all threads in a process, use the -H flag. The -L option will display the LWP (light weight process) column as well as the NLWP (number of light weight process) column.

ps -fL -C httpd

How to see the processes of a specific user

To see the processes owned by a specific user, use the -u USERNAME LIST option:

ps -u mial

Processes belonging to the mial user account are displayed.

How to list all processes started by root user

This is a special case of showing the processes of a certain user.

The command below allows you to view each process running with root privileges (a valid and effective identifier) in user format.

ps -U root -u root

Viewing group processes

If you want to list all processes belonging to a specific group (real group ID (RGID) or name), enter:

ps -fG www-data
#OR
ps -fG 33

To list all processes belonging to the effective group (or session) name, enter.

ps -fg www-data

Listing processes by terminal

To see the processes associated with a TTY, use the -t SPECIFY TTY option. When used without a TTY number, the -t option reports the processes associated with the current terminal window.

ps -t 1

All listed processes are associated with pts/1.

Selecting columns to display

With the -o FORMAT option, you can choose which columns you want to include in the ps output. Columns must be specified by name. From the ps manual:

man ps

you'll find a long list of column names in the “STANDARD FORMAT SPECIFIERS” section.

In the following example, we display the CPU time consumed by the process (pcpu), the processor's memory consumption (pmem) and the command that ran it along with the options (args):

ps -e -o pcpu,pmem,args | less

Note that the -o option does not add columns to the default set, but only displays the indicated fields.

Sorting output by columns

You can sort the output using the --sort option. Let's sort the output by the CPU column:

ps -e -o pcpu,pmem,args --sort -pcpu | less

The hyphen “-” means sorting from highest to lowest.

To see the ten most resource-intensive processes, pipe the output through the head command:

ps -e -o pcpu,args,args --sort -pcpu | head -10

We get a sorted, truncated list.

If we add more columns to display, we can sort by more columns.

Without a hyphen or with a “+” sign, sorting is performed from smallest to largest.

Let's add the pmem column to the sort:

ps -e -o pcpu,pmem,args --sort -pcpu,pmem

Sorting is still performed by pcpu value, but if these values are the same for some records, then pmem sort is performed for these values.

Let's make the output a little more useful and add a process id (pid) column so we can see the process number of each process in our listing.

ps -e -o pid,pcpu,pmem,args --sort -pcpu,pmem | head -10

We can now identify the processes.

All possible ps fields

To see all possible ps fields, run this command:

ps L

You can use these fields with the -o option.

Custom ps output examples

The command below allows you to see the PID, PPID, username and command of the process.

ps -eo pid,ppid,user,cmd

Below is another example of a custom output format showing the file system group, nice value, start time, and elapsed time of the process.

ps -p 1154 -o pid,ppid,fgroup,ni,lstart,etime

How to find the name of a process by PID

To find the name of a process using its PID.

ps -p 1154 -o comm=

Show parent and child processes

To select a specific process by its name, use the -C flag, this will also display all of its child processes.

ps -C sshd

To find all PIDs of all process instances, which is useful when writing scripts that need to read the PIDs from the stdin.

ps -C httpd -o pid=

How to shutdown a process by process id

We've covered a number of ways to identify processes, including name, command, user, and terminal. We also looked at ways to identify processes by their dynamic attributes such as CPU and memory usage.

One way or another, we can define the processes that are running. Knowing their process ID, we can (if needed) stop any of these processes with the kill command. If we wanted to kill process 898, we would use this format:

sudo kill 898

See also: What are the differences and how to use the kill, pkill and killall commands

Please be aware that in some cases the process will not terminate and will not display any errors or warnings. In fact, this command is a “recommendation”, it “asks” the process to exit. See the article “Why doesn't the kill command kill the process?” for details.

How to disable a process knowing its name

The pkill command allows you to kill processes by name. Make sure you define the correct process! This command will end the top process.

sudo pkill top

How to stop multiple processes by name

If you have multiple copies of a process running, or the process spawned multiple child processes (as Google Chrome can do), how can you shutdown them all? It's just as easy. We are using the killall command.

We have two instances of top running:

ps -e | grep top

We can terminate both of them with this command:

sudo killall top

Usually no response means no problem, that is, both of these processes have been stopped.

Before killing the process

Make sure it's the one you want and make sure it doesn't cause any problems. In particular, it is worth checking with the -H and --forest options to make sure there are no important child processes that you forgot about.

Troubleshooting Linux system performance

If your system is not working properly, for example, if it is unusually slow, you can troubleshoot some system problems as follows.

To find all the processes consuming the most memory and CPU in Linux:

ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

OR

ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head

Displaying security information

You can show the security context (specifically for SELinux) as follows:

ps -eM

OR

ps --context

You can also display security information in a user-defined format with this command:

ps -eo euser,ruser,suser,fuser,f,comm,label

Monitor your processes in real time with the watch utility

Finally, because ps displays static information, you can use the watch utility to continuously update the screen information and monitor processes in real time with repeated output. In this example, the information will be updated every second. Specify your own ps command to suit your purpose.

watch -n 1 'ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head'

See also:

How to install the Active Directory PowerShell module on Windows Server, Windows 11 and Windows 10

The Active Directory Module for Windows PowerShell is one of the main tools for domain administration, managing objects in Active Directory, and getting various information about AD computers, users, groups, etc. Any Windows administrator should know how to use AD as a graphical snap-in (usually These are ADUC – Active Directory Users & Computers) and RSAT-AD-PowerShell cmdlets for performing day-to-day Active Directory administration tasks. In this article, we'll take a look at how to install the Active Directory PowerShell module on Windows.

How to install Powershell Active Directory Module on Windows Server

On Windows Server 2016, 2019 and 2022, you can install AD Module for PowerShell from Server Manager: Add Roles and Features → Features → Remote Server Administration Tools → Role Administration Tools → AD DS and AD LDS Tools → Active Directory module for Windows PowerShell.

If you have already installed the Active Directory Domain Services role, this means that the Active Directory Powershell module is already activated and no additional action is required.

See also: Active Directory comprehensive guide, from installation and configuration to security auditing. Part 4: Install Active Directory Domain Services in Windows Server 2022

You can also install the module from the PowerShell console using the command:

Install-WindowsFeature -Name "RSAT-AD-PowerShell" -IncludeAllSubFeature

How to Install Active Directory PowerShell Module on Windows 11 and Windows 10 in command line

You can install the RSAT-AD-PowerShell module not only on Windows Server, but also on your workstations.

On Windows 11 or Windows 10, run this PowerShell command to install the Active Directory module:

Add-WindowsCapability -online -Name "Rsat.ActiveDirectory.DS-LDS.Tools"

The previous command must be executed in the command line with administrator rights.

Related article: PowerShell with administrator rights: how to run and verify

How to install Active Directory PowerShell module in Windows 11 in a GUI

To install the Active Directory PowerShell module in Windows 11 using a GUI, open “Settings” by pressing Win+i and select the “Apps” tab, then go to “Optional Features”.

Now select “View features” under “Add an optional feature”.

To install the Active Directory Remote Administration Tools, search for “RSAT: Active Directory Domain Services and Lightweight Directory Services Tools”, check the box and click “Next”,

then click “Install”.

Note: if, when searching for a particular component, you cannot find it, then, probably, this component is already installed.

To verify this, in the search bar under “Installed features” enter the name of the component you are looking for.

Also, remember that English and localized versions of Windows have different names for these components!

How to Install Active Directory PowerShell Module on Windows 10 in using a GUI

To install the Active Directory PowerShell module in the GUI, press Win+x, then select “Apps and Features” from the menu that opens.

Next, select “Optional Features”.

Now select “Add a feature”.

To install the Active Directory Remote Administration Tools, select “RSAT: Active Directory Domain Services and Lightweight Directory Services Tools” and click the “Install” button.

PowerShell with administrator rights: how to run and verify

How to run PowerShell as an administrator

Some commands and cmdlets require elevated privileges. Examples of actions that require administrator rights are service management (install, start, stop, uninstall) and package management (add and remove package providers, install and remove packages).

For example, the following cmdlet tries to add a new package provider:

Install-PackageProvider chocolatey

It will throw the following error:

Install-PackageProvider: Administrator rights are required to install packages in ''. Log on to the computer with an account that has Administrator rights, and then try again, or install in 'C:\Users\MiAl\AppData\Local\PackageManagement\ProviderAssemblies' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).

To fix this error, you need to run PowerShell as an administrator.

How to run PowerShell as an administrator on Windows

Let's consider several ways.

1. Launch PowerShell with administrator rights via the Power user menu

Press Win+x and in the menu that opens, select “Windows Terminal (Admin)”:

If you have two versions of PowerShell installed on your OS (PowerShell 5 preinstalled with Windows, and PowerShell 7 installed manually), this will open PowerShell 5.

2. Run PowerShell as an administrator from the Start menu

To open PowerShell 7 as an administrator, click the Start menu and search for “PowerShell” or “PowerShell 7”, select “Run as Administrator”:

3. How to run Windows Terminal with administrator rights in Windows

By default, Windows Terminal uses PowerShell, so if you run Terminal with administrator rights, then Terminal will also be with elevated rights.

Remember that the terminal is not included in the standard set of Windows 10 programs and must be installed from the Microsoft Store. In Windows 11, this program is installed by default.

Go to the start menu and start typing “Terminal”:

If you do not see the “Run as administrator” item, then click the arrow to expand the entire list:

Click on “Run as administrator”.

4. How to run PowerShell as an administrator in the command line

If you already have a PowerShell console open with standard user rights, then directly from it you can start a new elevated PowerShell process:

Start-Process PowerShell -Verb RunAs

This command will launch PowerShell 5 or PowerShell 6, whichever is the default on your system. To run the latest version that you manually installed, i.e. PowerShell 7, run the command:

Start-Process pwsh -Verb RunAs

5. How to run PowerShell as an administrator on Linux

To run PowerShell as administrator on Linux, run the command with sudo:

sudo pwsh

How do I check if a PowerShell script or PowerShell terminal is running as administrator

If you need to run a PowerShell script as an administrator, you can check if the current process has powershell.exe or pwsh.exe elevated permissions right in your PS code.

In addition, sometimes you need to determine whether the terminal is running with elevated privileges or with the rights of a regular user.

How to determine if PowerShell terminal is running with administrator rights

First of all, pay attention to the command line prompt:

A PowerShell window opens with the current working directory in C:\windows\system32 and, accordingly, there is the following command line prompt:

PS C:\windows\system32>

If the PowerShell process has normal rights, then the user's folder is opened as the current working directory:

PS C:\Users\MiAl>

Things get more complicated if PowerShell is used through the Windows Terminal. Take a look at this screenshot, one of these terminals is open as an administrator, and the other as a regular user – they are no different.

It was a test of attentiveness – the name of the window with administrator rights contains the word “Administrator”.

When you need to find out if a given shell has administrator rights, run the following two commands in sequence:

$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

PowerShell console with administrator privileges will print True, console with normal privileges will print False:

By the way, the same method can be used in scripts as well.

How to check in a PowerShell script that it is running as administrator

The following PowerShell code can be used to test if the current script is running in “Run as Administrator” mode:

Write-Host "Checking elevated rights..."
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
	Write-Warning "Insufficient permissions for the script. Open PowerShell console as administrator and rerun this script."
	Break
}
else {
	Write-Host "The code is run as administrator - script can continue..." -ForegroundColor Green
}

Save the PowerShell code in check_process_elevation.ps1 and run it in the console without admin rights:

C:\PS\check_process_elevation.ps1

As you can see, a message appeared that you do not have administrator rights, so the PowerShell script was stopped.

Now run the script in an elevated PowerShell session. As you can see, the script detected that this PowerShell session is running as administrator.

Alternatively, you can request administrator rights directly from a PowerShell script. To do this, instead of the line:

	Write-Warning "Insufficient permissions for the script. Open PowerShell console as administrator and rerun this script."
	Break

use the following code:

Start-Process Powershell -ArgumentList $PSCommandPath -Verb RunAs

When you run the script without administrator rights, it will rerun in a new elevated PowerShell session and you will see a UAC elevation prompt. If you accept it, your PS1 script will run as administrator. (The path to the current PowerShell script file is passed using the $PSCommandPath environment variable.)

In PowerShell 4.0 or newer, it's even easier to check if your script is running as an administrator. To do this, use the -RunAsAdministrator directive.

#requires -version 4.0
#requires -RunAsAdministrator
Write-Host "PowerShell is running as administrator" -ForegroundColor Green

If the script does not run under administrator, the following error will appear:

C:\PS\check_process_elevation.ps1: The script 'check_process_elevation.ps1' cannot be run because it contains a "#requires" statement for running as Administrator. The current PowerShell session is not running as Administrator. Start PowerShell by using the Run as Administrator option, and then try running the script again.

If you run the script on a PowerShell v2 machine, you receive the following error message:

Cannot process the “#requires” statement at line 2 because it is not in the correct format.
The “#requires” statement must be in one of the following formats:
“#requires -shellid <shellID>”
“#requires -version <major.minor>”
“#requires -pssnapin <psSnapInName> [-version ]”

To manage Active Directory, you may need a different task: check if the current user has domain administrator rights from a PowerShell script. Use the following code:

If(([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Domain Admins"))
{
	# the user who ran this script has Domain Admins rights
}
Else
{
	# no Domain Admins rights
}

Error “Cannot open access to console, the root account is locked” (SOLVED)

After a sudden power outage, unsuccessful update or adding a new disk to /etc/fstab, you may face the problem that your system does not boot, or rather, boots into the console or into a black screen. Sometimes the problem is compounded by the fact that the system administrator cannot even get into the emergency console. Let's see how to solve the following error:

You are in emergency mode. After logging in, type 'journalctl -xb' to view system logs, 'systemctl reboot'
'systemctl default' or "exit" to boot into default mode.

Cannot open access to console, the root account is locked.

See sulogin(8) man page for more details.

Press Enter to continue.

Reloading system manager configuration

After pressing Enter, everything can be repeated.

This message states that the system booted in emergency mode. In fact, this is not so bad – sometimes a system administrator can deliberately boot into emergency mode to restore the OS.

The real problem is that the root account is locked (this is indicated by the message “Cannot open access to console, the root account is locked”) and you cannot get into the console to start solving problems.

The situation becomes stalemate – the system will not let you go anywhere except in the root console, and it will not let you in the root console either, since this user is locked…

How to unlock the root user in emergency mode

Nevertheless, there is a way out of this situation. Start by booting into single user mode – this is the same mode used to reset the Linux password. Below is a generalized instruction, if something does not work out for you, then separate instructions for different distributions for booting into single-user mode can be found here.

Stop the booting by holding down the SHIFT key while starting the computer, you will see:

Press the “e” key and you will proceed to editing the boot settings:

Find the line starting with “linux”.

Go to the end of this line, insert a space, and add:

single init=/bin/bash

It should look something like this (the kernel number may differ):

When everything is ready, press Ctrl+x or F10 to continue the booting with the set options.

You will see a shell prompt, also note that we are logged in as root i.e. we have elevated privileges, including the use of the passwd command:

Command

passwd

will set the password for the root user.

If the passwd command fails:

passwd: Authentication token manipulation error
passwd: password unchanged

the filesystem is most likely mounted read-only. To verify this, enter the command:

mount

The “ro” indicate that the filesystem is mounted read-only and therefore the changes made cannot be saved. Remount the file system:

mount -rw -o remount /

After that, the password change should be successful.

Remove the password lock for the root user:

passwd -u root

If the root user is locked, then this may not be enough. Check which shell is set for root:

less /etc/passwd

If “/usr/sbin/nologin” is specified as the shell for root, run one of the following commands.

  • To assign a Bash shell to the root user:
sudo usermod -s /usr/bin/bash root
  • To assign a ZSH shell to the root user:
sudo usermod -s /usr/bin/zsh root

See also: How to change the login shell in Linux. chsh instruction

To exit, type:

sync
umount /

To turn off your computer run:

poweroff -f

Or restart your computer with the command:

reboot -f

If after the reboot you see “Give root password for maintenance”, then this means that the first stage of recovery was successful – we activated the root user and can now start restoring the system.

How to recover a computer in emergency mode

Now we have the opportunity to restore the system. If you have no idea what exactly caused the error, then run the command

journalctl -xb

and try to find the cause of the problem there.

Checking disks for errors

If you think the error is caused by hard disk problems, then use the following commands to check the partitions:

umount /dev/sda2
fsck -y /dev/sda2

Partition number and disk name may differ from “sda2”, to find out the exact name, use the command

fdisk -l

or

mount

Failed update

If the system does not boot due to an interrupted update, then try the following commands:

apt install -f -y
dpkg --configure -a

If you think that the problem was caused by an unsuccessful update of a specific package, then use a command like this:

dpkg-reconfigure PACKAGE

This command will reconfigure an already installed package.

For example, the following command will re-configure the Linux kernel:

dpkg-reconfigure linux-image-`uname -r`

System does not boot due to incorrect entry in /etc/fstab

In the event of an unsuccessful mount (this can happen if you made an incorrect entry in the /etc/fstab file, the system will not be able to boot, it will go into emergency mode and the following message will be displayed:

You are in emergency mode. After logging in, type "journalctl -xb" to view system logs, "systemctl reboot" to reboot, "systemctl default" or "exit" to boot into default mode.
Give root password for maintenance
(or press Control-D to continue):

To fix the problem, enter the root password and open the /etc/fstab file for editing:

nano /etc/fstab

Comment out or delete the problematic line. Save the file (Ctrl+o), close it (Ctrl+x) and reboot:

reboot

Do I need to restart the server after updating the Linux kernel (SOLVED)

Unlike Windows, in which a program must not be running to update this program, in Linux you can update running programs without any problems – this will not lead to any errors. In Linux, you can delete files in use (including executables) and while they are in use, they will be kept in the cache, and when the system stops using them, they will be truly deleted. That is, when updating a running program, the new version of the file will be used after you close and reopen this program.

Updating the Linux kernel is no exception – you can update the kernel on a running system and continue using it.

This raises the question, is a system reboot actually required after a Linux kernel update? This issue is especially relevant for web servers that become unavailable during the reboot period. It also matters when using caching (Varnish or NGINX), since the cache is usually stored in RAM and is lost on reboot, resulting in the need to refill the web page cache.

So is it necessary to restart the computer after updating the Linux kernel?

In short, yes, absolutely. For the system to start using the new kernel, the computer (server) needs to be rebooted.

After updating the kernel, you can continue to use the server without rebooting, but besides the fact that the benefits of the new kernel have not taken effect, there are a few more things to keep in mind.

1. Avoid subsequent package updates until reboot

Since the kernel header packages (linux-headers, kernel-headers) are updated along with the kernel, there may be a problem with building modules using dkms (Dynamic Kernel Modules System). A situation arises when an old kernel is used, for which the kernel header files (linux-headers) may have already been deleted, so the system cannot build the dkms modules normally.

And even if the kernel headers are saved and it was possible to build the kernel modules for the outdated kernel, then immediately after the reboot these modules will conflict with the new kernel and will not work due to the difference between the versions of the current kernel and the kernel for which they were built.

2. dkms modules may not work until kernel update

When updating the kernel, all kernel modules that use dkms are rebuilt. Examples of packages that use dkms kernel modules are Wi-Fi adapter drivers, VirtualBox guest additions, other drivers, and kernel modules.

So, new kernel modules are rebuilt when the kernel is updated, but cannot be used while the old kernel is in use. That is, in order for them to work, a reboot is required. In this case, old kernel modules in some distributions are immediately removed.

3. Unexpected reboot can lead to unexpected results

Remember that your system has not been tested with a new kernel. Therefore, if the server is restarted without your attention, then in case of problems, you will not be able to respond to them quickly.

How not to reboot Linux after a kernel update

1. Kexec

Kexec is a system call that enables you to load and boot into another kernel from the currently running kernel. This is useful for kernel developers or other people who need to reboot very quickly without waiting for the whole BIOS boot process to finish. Note that kexec may not work correctly for you due to devices not fully re-initializing when using this method, however this is rarely the case.

In short, Kexec is a reboot of the computer with skipping the hardware part (what you see starting from the start of the BIOS).

2. Does the Linux 4.0 kernel no longer require a computer restart?

In the Linux 4.0 changelog, it is said that starting with this version, a kernel reboot is no longer required. But either it doesn't or doesn't work out of the box. At a minimum, this requires additional steps to be implemented.

Summary

Rebooting the computer after updating the Linux kernel is required. It may be postponed, but in fact it is better to postpone the kernel update than to postpone reboot after the update.

As an option to reduce downtime due to reboots, you can reduce the number of updates by taking them only to fix vulnerabilities.

Full-text search in MS Word files and archives in Linux

Unlike Windows, where “Full-text search for documents in a folder” is possible, Linux “out of the box” does not support full-text search in office formats. This search and indexing of office documents can be implemented using recoll package, but it requires configuration. In addition, recoll relies on pre-indexing documents, which causes problems when working with removable media: the removable media had to be re-indexed every time it was plugged.

Now, starting with Double Commander version 1.0.0 beta, which added the ability to search for texts in office XML documents, this problem has been resolved.

See also: Free analogue of Total Commander

Double Commander supports many archives out of the box, but if you want to get support for any archives that exist, check out the article “How to add the plugin to Double Commander to support all types of archives” (it's not difficult).

So, to perform a full-text search on office files, in Double Commander go to the folder with documents and click the “Search” icon, you can also use the Alt+F7 keyboard shortcut to open the search window.

In the window that opens, check the box “Find text in file” and enter the text you want to find. Be sure to check the “Office XML” checkbox. To limit your search to specific files, you can enter parts of the name in the “File mask” field. When everything is ready, press the “Start” button.

After completing the search, you will see a tab with results, which will list all files containing the search phrase. To go to the required file, double-click on its name.

Hint: if you want to familiarize yourself with several files in the search results, then after performing the first search and opening the first file, you do not need to restart the search – open this panel and immediately go to the “Results” tab – the results found during the last search are stored there…

To search through archives, when specifying search terms, additionally check the “Search in archives” box.

Now full-text search in office files will be performed even for documents placed in archives. The search results will show the names of the archives and the names of the files in those archives that contain the search text.

Full-text search in office files (Word) and archives – now it’s easy!

In the article “Full-text search for documents in a folder” we examined a way to search the contents of many office documents, including the exact match of the phrase. The considered method allows you to find the required file containing the required string without installing additional programs. But the method proposed in that note has disadvantages:

  • search is slow, especially if you search in a folder containing a lot (hundreds) of documents
  • Windows Explorer is used for searching, which is not very convenient by itself and requires additional configuration
  • search through archives is possible, but the set of supported formats is very limited
  • to search for a literal match of a string, you need to remember a complex construction (I am still opening this article to find the desired sequence of characters)

In general, the proposed method is better than nothing, but it is not very convenient.

In this article, I will show you a new way that allows you to search through Word files and all other office files supported by programs from MS Office (in the correct language, in any office XML files).

We need Double Commander. If you are not familiar with this program yet, read the article “Free analogue of Total Commander”, I have no doubt you will love this file manager!

Double Commander supports many archives out of the box, but if you want to get support for any archives that exist, check out the article “How to add the plugin to Double Commander to support all types of archives” (it's not difficult).

So, to perform a full-text search on office files, in Double Commander go to the folder with documents and click the “Search” icon, you can also use the Alt+F7 keyboard shortcut to open the search window.

In the window that opens, check the box “Find text in file” and enter the text you want to find. Be sure to check the “Office XML” checkbox. To limit your search to specific files, you can enter parts of the name in the “File mask” field. When everything is ready, press the “Start” button.

After completing the search, you will see a tab with results, which will list all files containing the search phrase. To go to the required file, double-click on its name.

Hint: if you want to familiarize yourself with several files in the search results, then after performing the first search and opening the first file, you do not need to restart the search – open this panel and immediately go to the “Results” tab – the results found during the last search are stored there…

To search through archives, when specifying search terms, additionally check the “Search in archives” box.

Now full-text search in office files will be performed even for documents placed in archives. The search results will show the names of the archives and the names of the files in those archives that contain the search text.

Full-text search for documents in a folder

What if you need to find a specific document among tens or hundreds?

If you know the name of the document, then searching is quite simple – many programs, including the standard Windows Explorer, can search by file name.

To find a file by name, open Windows Explorer (file manager), navigate to the folder where you want to search, and in the Search box, enter the file name or part of the name to find all files that match it:

Full text folder search

But what if we want to find a file by its contents? For example, we know the surname that is mentioned in the document.

If you are looking among text documents, then many programs can help you, for example, Total Commander and Double Commander can search by the contents of text files.

But if these are office documents, then things get more complicated, since .docx, .doc and other office formats are quite complex containers.

Fortunately, the most common Windows Explorer can do full-text search in all MS Office formats.

To search the contents of office documents, go to the folder where the files you want to search are located. In the Search box, enter your search word or phrase. Click on “Search options” and in the drop-down menu click “File contents”:

As a result, if there are many files, then the search will take much longer than the search by file names. But now you can find documents by words that are contained in the text of office files.

How to search by files in ZIP archives

If files are packed in ZIP archives, then by default they are not searched even if search by file contents is enabled.

To enable searching for ZIP archives, enter a search word, in the Search box, enter your search word or phrase. Click on “Search options” and in the drop-down menu click “Zipped (compressed) folders”:

These options are permanent and persist even after you close Explorer and restart your computer. If you usually search by filename (rather than content) and the search has become too slow for you, then disable these options in the same order as shown to enable them.

How to search by exact match. How to search by phrase

By default, documents containing any of the search words will be shown. In this case, spaces, periods and other punctuation marks are the separators between words. For this reason, it is impossible to find an exact phrase that consists of several words or includes periods and other symbols.

Putting the phrase in quotation marks will not change anything – documents containing at least one word will still be shown.

In Windows 10

Nevertheless, there is a solution, for this you need to use the construction ~="FIND IT"

To make it clearer, let's say we need to find documents containing the exact phrase “Exa.ct Phr.ase”, then we need to enter in the search bar:

~="Exa.ct Phr.ase"

In Windows 11

In Windows 11, the ~="FIND IT" construct still works to find an exact match. But the indexing of files greatly affects the search. For example, when indexing was enabled, the following features were observed:

  • the ~="FIND IT" construct didn't work
  • to search for an exact match of a phrase, it was enough to put it in double quotes
  • search through archives did not work, although it was enabled

After disabling indexing of a folder, the search operation became similar to that in Windows 10. That is, if you do not know if indexing of the folder in which you are searching is enabled, then try both methods described in this article and see which one works.

Loading...
X