Why can some commands be executed when the /usr directory is not visible?

Asked 2 years ago, Updated 2 years ago, 76 views

Event

1. Create LV in rhel 7.5 environment
2.Create a file system on the LV
3.Create mount point/usr9
4.Mount LV to /usr9 (Mistake command)
positive) mount/dev/vg/lvol1/usr9
Wrong) mount/dev/vg/lvol1/usr

Impact

Unable to execute command under /usr.Most commands are linked under /usr.

Workaround

·Verified that pwd and echo can be executed.
·Forced kernel panic execution reboot
echo>/proc/sysrq-trigger

顧客 Due to the customer environment, VM restart is not possible immediately, and the kernel panic is reached by desperate measures.

What to check

I would like to know why the echo command and others could be executed in the above situations.

After a reboot recovery, we investigated the command path and found that it was referenced under /usr.

Busybox has not been introduced yet.

command-line rhel

2022-09-30 12:08

2 Answers

Cause

Shells such as bash and zsh have built-in commands.It was also found in Bourne Shell, the base of bash.The built-in commands do not refer to /usr/bin and are available even if /usr is no longer available.(If the shell is moving)

embedded commands

A list of built-in commands can be found using the help command.
You can also use the type command to determine whether it is built-in or external.

$type cd
cd is a shell built-in function.

$ type man
man is /usr/bin/man

$ help
GNU bash, version 5.0.17(1)-release(x86_64-pc-linux-gnu)
These shell commands are internally defined.Type `help' to see the list.
US>Enter `help name' to provide a more detailed description of the function called `name'.

~ (abbreviated below)

Reason for Existence

There are several reasons why it is a built-in command.Accelerate, or even if you can't execute it without a built-in command in the first place
(For example, the cd command... because external commands will revert after execution.)


2022-09-30 12:08

There are other examples besides shell built-in commands.

When /usr is full, I would like to put it in single user mode and replace the /usr mounting destination. Of course, /usr does not exist in the middle of replacing the /usr mounting destination.You can still use the commands in /bin or /sbin under the root partition.

I mean, the various commands stored in /bin and /sbin are made with static links to work without /usr (at least in commercial UNIX)

Most field-built binaries are ./configure to use the following shared libraries, so you need to have /usr to install them, so you should not use /usr/local or /opt to overwrite /bin.


2022-09-30 12:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.