<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Akshay</title>
    <description>The latest articles on Forem by Akshay (@akshay_khoje).</description>
    <link>https://forem.com/akshay_khoje</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1230389%2Fd06ceb4a-b443-4700-aa46-766d0a780cdc.jpg</url>
      <title>Forem: Akshay</title>
      <link>https://forem.com/akshay_khoje</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/akshay_khoje"/>
    <language>en</language>
    <item>
      <title>Systemd vs sysVinit - Initializing the system</title>
      <dc:creator>Akshay</dc:creator>
      <pubDate>Wed, 20 Dec 2023 07:02:57 +0000</pubDate>
      <link>https://forem.com/akshay_khoje/systemd-vs-sysvinit-initializing-the-system-5h71</link>
      <guid>https://forem.com/akshay_khoje/systemd-vs-sysvinit-initializing-the-system-5h71</guid>
      <description>&lt;p&gt;Motivation behind this post - my first post &lt;a href="https://dev.to/akshay_khoje/system-has-not-been-booted-with-systemd-as-init-system-pid-1-5e1d"&gt;here&lt;/a&gt;. In this post I'll try to explain the system initializer in linux and the difference between &lt;code&gt;sysVinit&lt;/code&gt; and &lt;code&gt;systemd&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  ESSENTIAL BACKGROUND
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is the &lt;code&gt;init&lt;/code&gt; process?
&lt;/h2&gt;

&lt;p&gt;To answer this, we need to look a little bit at the booting process.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Boot sequence&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The boot process is everything that happens from the time you press the power button until you are presented with a login screen. It generally follows this sequence:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

1. BIOS/UEFI locates and executes the bootloader (or UEFI can load a kernel directly).
2. Bootloader(e.g. GRUB2 loads the desired kernel into memory).
3. Kernel starts the init process (pid = 1).
4. init process manages overall system initialization : systemd( or sysVinit, upstart, etc).
5. Then the display manager takes over the control (the login screen).



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;This post focuses on point #4 of the boot sequence.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;em&gt;init process&lt;/em&gt;&lt;/strong&gt; essentially means loading all the services and daemons required by the user after login, to be loaded into the RAM and get the system up and ready.&lt;/p&gt;

&lt;p&gt;Now, various system initializers are available - systemd, sysVinit, upstart, openRC, etc. In modern systems - &lt;code&gt;systemd&lt;/code&gt; is the &lt;strong&gt;default system initializer&lt;/strong&gt;, however some distros like MXLinux still prefer sysVinit (an older guy in the game).&lt;/p&gt;

&lt;h3&gt;
  
  
  What does systemd do?
&lt;/h3&gt;

&lt;p&gt;The systemd is an &lt;u&gt;&lt;strong&gt;init and service manager&lt;/strong&gt;&lt;/u&gt;. It is the &lt;code&gt;first user-level process&lt;/code&gt; that runs until the PC is shutdown. It's process ID id 1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5tlqpaeiapyw780k6a07.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5tlqpaeiapyw780k6a07.png" alt="pid of systemd is 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It does the following tasks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Once kernel starts the init process, systemd handles all the later stages of the boot process.&lt;/li&gt;
&lt;li&gt;It configures the environment by loading all the services and daemons needed to login the user.&lt;/li&gt;
&lt;li&gt;It allows managing services, devices, sockets, mount points, swap areas, etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Few notes about systemd:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Starts all services parallely.&lt;/li&gt;
&lt;li&gt;Can start daemons without restarting the running service.&lt;/li&gt;
&lt;li&gt;It is the universal parent of all processes.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  What is sysVinit?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;sysVinit&lt;/strong&gt; was initially created for UNIX systems, it later got adapted in Linux. Till RHEL5, RedHat used this as its default system initializer. Thereafter, they switched to systemd.&lt;/p&gt;

&lt;p&gt;Few notes about sysVinit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It loaded services in kind of a synchronous fashion as against parallel in systemd.&lt;/li&gt;
&lt;li&gt;A next service can be loaded only after the current one being loaded is timed out.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;One final question beginners might have is...&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is systemctl and how is it related to systemd?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;systemctl&lt;/code&gt; is a command line utility to manage services, get the status of services. &lt;br&gt;
&lt;code&gt;systemd&lt;/code&gt; on the other hand is a daemon which keeps running in the background until the machine is shut down. &lt;code&gt;systemctl&lt;/code&gt; is simply an interface to access the services provided by systemd.&lt;/p&gt;

&lt;p&gt;Finally, if you found this topic interesting, I had highly recommend you to check out this &lt;a href="https://www.reddit.com/r/linuxadmin/comments/zl2m9v/systemd_vs_sysvinit/" rel="noopener noreferrer"&gt;reddit discussion&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you find any mistakes, feel free to comment. Also, if you want to add any points, the comment section is all yours.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>systems</category>
      <category>operatingsystem</category>
      <category>booting</category>
    </item>
    <item>
      <title>ERROR : "System has not been booted with systemd as init system (PID 1). Can't operate."</title>
      <dc:creator>Akshay</dc:creator>
      <pubDate>Tue, 19 Dec 2023 18:57:23 +0000</pubDate>
      <link>https://forem.com/akshay_khoje/system-has-not-been-booted-with-systemd-as-init-system-pid-1-5e1d</link>
      <guid>https://forem.com/akshay_khoje/system-has-not-been-booted-with-systemd-as-init-system-pid-1-5e1d</guid>
      <description>&lt;p&gt;I encountered this error when I was setting up docker on my recently installed MXLinux machine.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;This fix is likely to work on Debian-based distros.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The command was simply to check if docker service is up or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl status docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It gave me the following error:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tFZRo4Si--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpkfdu47bwougl9agrvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tFZRo4Si--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpkfdu47bwougl9agrvg.png" alt="Error message" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OR Is it really an error that needs fixing?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Try this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service docker status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://dev.to/akshay_khoje/systemd-vs-sysvinit-initializing-the-system-5h71"&gt;Explain this to me&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Temporary fix
&lt;/h2&gt;

&lt;p&gt;I figured out a way to fix this temporarily by editing the grub command line arguments by adding the parameter &lt;br&gt;
&lt;code&gt;init=/lib/systemd/systemd&lt;/code&gt; besides &lt;code&gt;splash quite&lt;/code&gt;. You can locate this on a line starting with the &lt;code&gt;linux&lt;/code&gt; keyword. However, this turns out to be a &lt;strong&gt;temporary fix&lt;/strong&gt;. So at every reboot, I needed to repeat this procedure of adding this &lt;strong&gt;init&lt;/strong&gt; parameter to the grub edit menu.&lt;/p&gt;
&lt;h2&gt;
  
  
  Permanent fix
&lt;/h2&gt;

&lt;p&gt;A little bit of time into fixing this and I learnt that those parameters are actually referenced from the /etc/default/grub file. This file is essentially a key-value pair required to generate the desired configuration during the booting process.&lt;/p&gt;

&lt;p&gt;From the /etc/default/grub file, the key(variable) of our attention is &lt;code&gt;GRUB_CMDLINE_LINUX_DEFAULT&lt;/code&gt;. This variable is passed to the kernel at boot-time. The famous &lt;code&gt;quiet splash&lt;/code&gt; attributes to disable the log messages and enabling the splash screen are values to this variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A7B5yGcJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cx32etw5h48jqs95ruv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A7B5yGcJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cx32etw5h48jqs95ruv.png" alt="/etc/default/grub file before changes" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we simply have to add the required library that will load the systemd process at every boot by default. Thus, we add a new attribute i.e. the path to the systemd file to the above mentioned variable as follows. &lt;em&gt;Assuming &lt;code&gt;quiet splash&lt;/code&gt; already exist there&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GRUB_CMDLINE_LINUX_DEFAULT="splash quiet init=/lib/systemd/systemd"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y4wR8px0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxbjw1728vuh6nc4p3ev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y4wR8px0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxbjw1728vuh6nc4p3ev.png" alt="/etc/default/grub file after changes" width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The final step is to reboot the system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo reboot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try the systemctl command again:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KIv3XP9a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lngly4v2kttbevv40q08.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KIv3XP9a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lngly4v2kttbevv40q08.png" alt="Post reboot it works" width="800" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See, it works on my machine ;)&lt;/p&gt;

</description>
      <category>devops</category>
      <category>community</category>
      <category>opensource</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
