Understanding Ubuntu’s Event-Driven System Architecture

Linux, as we know, is a kernel and not a complete operating system, and it ships with a variety of distributions, such as Debian, Fedora, and Ubuntu, among others.

Ubuntu, developed by Mark Shuttleworth, is one of the most popular and widely used distributions worldwide. Being open-source and free, Ubuntu has frequent updates and annual releases, with contributions from thousands of developers who work on its development.

But how does Ubuntu function internally? What processes and events drive its operations, and why are they significant? This article provides an in-depth understanding of the internals of Ubuntu, making it accessible even for beginners.

Ubuntu System Layout

At the heart of Ubuntu’s operations lies a robust system of processes that drive its core functionalities, such as power management, boot-up, and system crash handling. Every system service in Ubuntu is treated as a process, and each process has configuration files located in the /etc/init/ directory.

These configuration files define events that trigger the start and stop of processes, making Ubuntu an event-driven system.

The central figure in Ubuntu’s event-driven system is the init process (process ID 1). This is the first process that runs when the system starts up and continues to run until the system shuts down.

It has the crucial role of managing the start-up and shutdown events and acts as the parent of all other processes. It ensures the system runs smoothly from boot-up to shutdown.

The Transition from Upstart to systemd

Ubuntu previously used Upstart, an event-driven init system, which was last updated to version 1.13.2 in September 2014. However, Upstart was discontinued and has not seen any updates since then.

Ubuntu transitioned away from Upstart with the release of version 15.04 (Vivid Vervet) in April 2014, replacing it with systemd as the default init system.

Systemd is a more advanced init system that manages processes and services differently than Upstart, providing more flexibility, parallelization, and better control over services.

Systemd also simplifies boot management and service supervision, making it the standard init system for most modern Linux distributions, including Ubuntu.

Understanding the Boot Process in Ubuntu (Systemd)

When the system boots up, init is the first process that is triggered. This process then starts other processes in a hierarchical manner. In a typical Ubuntu system with systemd, the boot sequence follows a series of steps and events that trigger the starting of services.

Here’s a breakdown of the boot hierarchy:

  • Init (PID 1): The first process to start during boot. It sets up the environment for the rest of the system and triggers events.
  • systemd: After init, systemd becomes the primary init process, which is responsible for launching all other system services (called units). These units are defined in unit files located in /etc/systemd/system and /lib/systemd/system.
  • Bootstrapping Services: systemd begins the process of bootstrapping services. It starts basic services such as mounting filesystems, loading kernel modules, setting up network connections, and more.
  • Filesystem Mounting: Services like mountall are responsible for mounting local and remote filesystems during the boot process. systemd handles the event generation that tells other services when it’s safe to proceed.
  • Display Manager: Once the basic system services are set up, the display manager (like gdm or lightdm) starts, allowing users to log in to the system.
  • User Session Initialization: After login, a user session is initiated, which involves loading environment settings, launching a graphical user interface, and starting user-specific processes.

Key systemd Targets and Events

  • Default Target: The default.target is the final state that the system reaches once boot is complete, which is usually set to graphical.target, which starts the user interface.
  • Multi-User Target: This target is used for starting non-graphical multi-user environments, typically set to multi-user.target.
  • Rescue Target: For situations requiring minimal system operation, rescue.target provides a single-user mode for repairing system issues.

Process and Event Management

In Ubuntu, each system service or process is associated with events. For example, systemd and other service managers use unit files that specify the start and stop conditions for services. These conditions define when a process should be triggered based on system events (e.g., when the system starts or when a certain file is mounted).

There are two types of processes in Ubuntu’s event-driven model:

  • Short-lived processes (Work-and-die jobs): These processes execute and then terminate after completing their tasks. Examples include mounting filesystems or loading kernel modules.
  • Long-lived processes (Stay-and-work jobs): These processes persist throughout the system’s uptime, managing essential services like networking, logging, and user sessions.

Services or units are triggered by events and are defined by unit files, and these unit files specify the events that cause a service to start and stop.

Each process or service that systemd manages is defined as a unit, and units can be of various types, such as:

  • Service units (.service), which define services that systemd manages.
  • Socket units (.socket), which define communication endpoints.
  • Target units (.target), which define a grouping of services for a specific purpose or stage in the boot process.

systemd Process Hierarchy

With the adoption of systemd, processes in Ubuntu are organized hierarchically, with each service depending on the other to function properly. The systemd service manager takes care of creating and managing these dependencies through unit files, which define the order of service start-ups.

The hierarchy can be visualized as follows:

Systemd (PID 1) -> Essential Services (e.g., mounting, kernel modules) -> Display Manager -> User Session

Key Services and Events in the Boot Process

  • hostname: Sets the system’s hostname, which is configured in /etc/hostname.
  • kmod: Loads kernel modules as defined in /etc/modules.
  • mountall: Mounts all local and remote filesystems, including /proc and /sys.
  • plymouth: Displays the splash screen during the boot process, providing visual feedback to the user.

Other key processes are started as needed during boot, such as dbus (for inter-process communication), network-manager (for network configuration), and udev (for device management).

Conclusion

Ubuntu’s boot process has evolved significantly over the years. While earlier versions relied on Upstart, modern Ubuntu versions (since 15.04) use systemd as the default init system.

systemd offers numerous improvements, including better parallelization, simplified service management, and greater flexibility. Understanding how systemd works in Ubuntu is crucial for anyone who wants to understand the internal workings of the operating system, manage services, or troubleshoot boot-related issues.

By grasping the key concepts of systemd’s units, targets, and events, you can gain a much deeper understanding of how Ubuntu operates during boot-up and beyond.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Gunjit Khera
Currently a Computer Science student and a geek when it comes to Operating System and its concepts. Have 1+ years of experience in Linux and currently doing a research on its internals along with developing applications for Linux on python and C.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

6 Comments

Leave a Reply
  1. Good coverage.
    Should that not be “Low Down” rather than “Lay Down” ?
    I feel that the “phantom boot” nature of ureadahead deserves a mention, it is a startup strategy rather than a persistent feature, so it may be out of discussion scope.
    init deserves a nice tree graphic to illustrate.

    Reply
    • no its lay down as it shows how the system is laid down i.e. comprising of init process and all…

      And yes, you are right ureadahead should be there as it reads the files required for boot in advance of their use in the page cache. It starts when the mountall is just about to start and stops after all the old style sysvinit jobs are run..

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.