202.1 Customizing system startup (weight: 3)

Tech Tutorial: 202.1 Customizing System Startup #

Introduction #

In this tutorial, we will delve into customizing the system startup process on Linux-based systems. Understanding and being able to customize the startup process is crucial for system administrators to ensure that their systems are configured precisely for their needs, whether for security, performance, or special functionalities.

We will cover key utilities and commands used to manage system services, check service statuses, and customize service behavior during boot.

Key Knowledge Areas: #

  • Understanding the boot process and its components
  • Managing system services
  • Enabling and disabling services
  • Checking service status

Utilities: #

  • systemctl
  • chkconfig
  • service
  • update-rc.d

Step-by-Step Guide #

1. Understanding the Boot Process #

Before diving into commands and utilities, it’s essential to understand the boot process. Linux boot process stages include:

  • BIOS/UEFI stage
  • Bootloader stage (GRUB)
  • Kernel loading
  • Init process (SysVinit, Upstart, or systemd)

Most modern Linux distributions use systemd as their init system, which brings us to our first utility.

2. Using systemctl #

systemctl is the central management tool for controlling the systemd system and service manager.

Start a Service #

To start a service immediately:

sudo systemctl start apache2.service

Enable a Service at Boot #

To enable a service to start on boot:

sudo systemctl enable apache2.service

This creates a symbolic link from the system’s copy of the service file (usually in /etc/systemd/system/ or /lib/systemd/system/) to the location systemd reads at startup.

Disable a Service at Boot #

To prevent a service from starting on boot:

sudo systemctl disable apache2.service

Check Status of a Service #

To check the status of a service:

sudo systemctl status apache2.service

3. Using chkconfig #

For systems using legacy SysVinit, chkconfig is used for managing system services.

List Service Status #

To list all services and their boot settings:

chkconfig --list

Enable a Service #

To enable a service at runtime levels 2, 3, and 5:

sudo chkconfig apache2 on

Disable a Service #

To disable a service:

sudo chkconfig apache2 off

4. Using service #

The service command is used in SysVinit systems to run a System V init script.

Start a Service #

To start a service:

sudo service apache2 start

Stop a Service #

To stop a service:

sudo service apache2 stop

Restart a Service #

To restart a service:

sudo service apache2 restart

5. Using update-rc.d #

update-rc.d is another tool for managing SysVinit scripts in Debian-based systems.

Enable a Service #

To enable a service:

sudo update-rc.d apache2 enable

Disable a Service #

To disable a service:

sudo update-rc.d apache2 disable

Conclusion #

Understanding and mastering service management commands and tools is essential for any Linux system administrator. Whether you’re using a modern system with systemd or maintaining older systems with SysVinit, the ability to control what services start at boot and how they behave is a powerful tool in your arsenal.

Remember, the exact commands may vary slightly based on your Linux distribution and the init system it uses, so always refer to your distribution’s documentation for the most accurate information.