RHCSA Series: Process Management in RHEL 7: Boot, Shutdown, and Everything in Between – Part 5 ================================================================================ We will start this article with an overall and brief revision of what happens since the moment you press the Power button to turn on your RHEL 7 server until you are presented with the login screen in a command line interface. ![RHEL 7 Boot Process](http://www.tecmint.com/wp-content/uploads/2015/03/RHEL-7-Boot-Process.png) Linux Boot Process **Please note that:** 1. the same basic principles apply, with perhaps minor modifications, to other Linux distributions as well, and 2. the following description is not intended to represent an exhaustive explanation of the boot process, but only the fundamentals. ### Linux Boot Process ### 1. The POST (Power On Self Test) initializes and performs hardware checks. 2. When the POST finishes, the system control is passed to the first stage boot loader, which is stored on either the boot sector of one of the hard disks (for older systems using BIOS and MBR), or a dedicated (U)EFI partition. 3. The first stage boot loader then loads the second stage boot loader, most usually GRUB (GRand Unified Boot Loader), which resides inside /boot, which in turn loads the kernel and the initial RAM–based file system (also known as initramfs, which contains programs and binary files that perform the necessary actions needed to ultimately mount the actual root filesystem). 4. We are presented with a splash screen that allows us to choose an operating system and kernel to boot: ![RHEL 7 Boot Screen](http://www.tecmint.com/wp-content/uploads/2015/03/RHEL-7-Boot-Screen.png) Boot Menu Screen 5. The kernel sets up the hardware attached to the system and once the root filesystem has been mounted, launches process with PID 1, which in turn will initialize other processes and present us with a login prompt. Note: That if we wish to do so at a later time, we can examine the specifics of this process using the [dmesg command][1] and filtering its output using the tools that we have explained in previous articles of this series. ![Login Screen and Process PID](http://www.tecmint.com/wp-content/uploads/2015/03/Login-Screen-Process-PID.png) Login Screen and Process PID In the example above, we used the well-known ps command to display a list of current processes whose parent process (or in other words, the process that started them) is systemd (the system and service manager that most modern Linux distributions have switched to) during system startup: # ps -o ppid,pid,uname,comm --ppid=1 Remember that the -o flag (short for –format) allows you to present the output of ps in a customized format to suit your needs using the keywords specified in the STANDARD FORMAT SPECIFIERS section in man ps. Another case in which you will want to define the output of ps instead of going with the default is when you need to find processes that are causing a significant CPU and / or memory load, and sort them accordingly: # ps aux --sort=+pcpu # Sort by %CPU (ascending) # ps aux --sort=-pcpu # Sort by %CPU (descending) # ps aux --sort=+pmem # Sort by %MEM (ascending) # ps aux --sort=-pmem # Sort by %MEM (descending) # ps aux --sort=+pcpu,-pmem # Combine sort by %CPU (ascending) and %MEM (descending) ![http://www.tecmint.com/wp-content/uploads/2015/03/ps-command-output.png](http://www.tecmint.com/wp-content/uploads/2015/03/ps-command-output.png) Customize ps Command Output ### An Introduction to SystemD ### Few decisions in the Linux world have caused more controversies than the adoption of systemd by major Linux distributions. Systemd’s advocates name as its main advantages the following facts: Read Also: [The Story Behind ‘init’ and ‘systemd’][2] 1. Systemd allows more processing to be done in parallel during system startup (as opposed to older SysVinit, which always tends to be slower because it starts processes one by one, checks if one depends on another, and then waits for daemons to launch so more services can start), and 2. It works as a dynamic resource management in a running system. Thus, services are started when needed (to avoid consuming system resources if they are not being used) instead of being launched without a valid reason during boot. 3. Backwards compatibility with SysVinit scripts. Systemd is controlled by the systemctl utility. If you come from a SysVinit background, chances are you will be familiar with: - the service tool, which -in those older systems- was used to manage SysVinit scripts, and - the chkconfig utility, which served the purpose of updating and querying runlevel information for system services. - shutdown, which you must have used several times to either restart or halt a running system. The following table shows the similarities between the use of these legacy tools and systemctl: 注:表格
Legacy tool | Systemctl equivalent | Description |
service name start | systemctl start name | Start name (where name is a service) |
service name stop | systemctl stop name | Stop name |
service name condrestart | systemctl try-restart name | Restarts name (if it’s already running) |
service name restart | systemctl restart name | Restarts name |
service name reload | systemctl reload name | Reloads the configuration for name |
service name status | systemctl status name | Displays the current status of name |
service –status-all | systemctl | Displays the status of all current services |
chkconfig name on | systemctl enable name | Enable name to run on startup as specified in the unit file (the file to which the symlink points). The process of enabling or disabling a service to start automatically on boot consists in adding or removing symbolic links inside the /etc/systemd/system directory. |
chkconfig name off | systemctl disable name | Disables name to run on startup as specified in the unit file (the file to which the symlink points) |
chkconfig –list name | systemctl is-enabled name | Verify whether name (a specific service) is currently enabled |
chkconfig –list | systemctl –type=service | Displays all services and tells whether they are enabled or disabled |
shutdown -h now | systemctl poweroff | Power-off the machine (halt) |
shutdown -r now | systemctl reboot | Reboot the system |