{"id":255788,"date":"2021-05-21T19:00:00","date_gmt":"2021-05-21T16:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-linux-runlevels-affect-running-services-cloudsavvy-it\/"},"modified":"2021-05-21T19:00:00","modified_gmt":"2021-05-21T16:00:00","slug":"how-linux-runlevels-affect-running-services-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-linux-runlevels-affect-running-services-cloudsavvy-it\/","title":{"rendered":"#How Linux Runlevels Affect Running Services \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2e310081521\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2e310081521\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-linux-runlevels-affect-running-services-cloudsavvy-it\/#Standard_Runlevels\" >Standard Runlevels<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-linux-runlevels-affect-running-services-cloudsavvy-it\/#Runlevels_and_Startup_Services\" >Runlevels and Startup Services<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-linux-runlevels-affect-running-services-cloudsavvy-it\/#Inspecting_Your_Systems_Runlevel\" >Inspecting Your System\u2019s Runlevel<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-linux-runlevels-affect-running-services-cloudsavvy-it\/#Switching_Between_Runlevels\" >Switching Between Runlevels<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-linux-runlevels-affect-running-services-cloudsavvy-it\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How Linux Runlevels Affect Running Services \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<figure style=\"width: 2464px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage wp-image-11404 size-full\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/05\/5c016313.png?width=1200&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"power button\" width=\"2464\" height=\"1386\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\"><span class=\"type:primaryImage imagecredit\"><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.shutterstock.com\/image-photo\/power-button-sign-symbol-abstract-night-728316739\">Shutterstock\/Allexxandar<\/a><\/span><\/figcaption><\/figure>\n<p>Linux runlevels distinguish between system operating states. Switching runlevel will change the services which are running. You can customise runlevels so each level starts with a specific set of services.<\/p>\n<h2 id=\"standard-runlevels\"><span class=\"ez-toc-section\" id=\"Standard_Runlevels\"><\/span>Standard Runlevels<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Linux kernel defines seven standard runlevels. Individual operating system distributions may customise these runlevels or add additional ones. Users are also free to create and modify runlevels.<\/p>\n<ul>\n<li><strong>Runlevel 0<\/strong> \u2013 No activity, equivalent to shutdown. The system is ready for a physical loss of power.<\/li>\n<li><strong>Runlevel 1<\/strong> \u2013 Running in single-user (rescue) mode.<\/li>\n<li><strong>Runlevel 2<\/strong> \u2013 Running in multi-user mode without networking and graphics.<\/li>\n<li><strong>Runlevel 3<\/strong> \u2013 Multi-user mode with the addition of networking support.<\/li>\n<li><strong>Runlevel 4<\/strong> \u2013 Left for users\/distributions to define.<\/li>\n<li><strong>Runlevel 5<\/strong> \u2013 Multiple user mode with a graphical user interface.<\/li>\n<li><strong>Runlevel 6<\/strong> \u2013 System reboot mode.<\/li>\n<\/ul>\n<p>Most Linux systems will boot into Runlevel 5. This is the runlevel you\u2019re probably most familiar with. The broadest range of services are available, including a display server and full networking stack. If you\u2019re on a headless server without a display stack, you might be in Runlevel 3.<\/p>\n<p>Some single-user systems will start in Runlevel 1.. You\u2019ll also encounter this runlevel if you use a recovery mode to rescue your system. This lets you obtain shell access without logging in as a regular user.<\/p>\n<p>Runlevels 2, 3 and 4 can vary across distribution. Some distributions will create a clear distinction between each runlevel; in others, all three may have the same effect. <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">General<\/a>ly, you can expect any of these three to give you a single-user text shell with networking available.<\/p>\n<p>Your system can only be in one runlevel at a time. A single runlevel will be selected after boot. You won\u2019t transition been runlevels unless you explicitly initiate a change. Usually, the only runlevel transitions that occur are from levels 1-5 into level 0 or 6, when your system shuts down or reboots.<\/p>\n<p>Higher runlevels indicate increasing levels of available functionality. This convention is followed by all distributions. A low runlevel usually means that only a subset of the system\u2019s services are running.<\/p>\n<h2 id=\"runlevels-and-startup-services\"><span class=\"ez-toc-section\" id=\"Runlevels_and_Startup_Services\"><\/span>Runlevels and Startup Services<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Startup services are coupled to runlevels. Linux traditionally adds startup services to runlevels. When your system enters a runlevel, all the services associated with that level will be started.<\/p>\n<p>The way in which services are actually handled depends on the service manager you\u2019re using. Individual distributions ship with different service managers. The original service manager, <code>init<\/code>, defines its services within <code>\/etc\/init.d<\/code>. <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">Script<\/a>s created here get symlinked into <code>\/etc\/rc<\/code> where they\u2019re sorted by runlevel:<\/p>\n<ul>\n<li><code>\/etc\/rc0.d<\/code> \u2013 Scripts placed in here are executed by runlevel 0\u2026<\/li>\n<li><code>\/etc\/rc1.d<\/code> \u2013 Scripts for runlevel 1\u2026<\/li>\n<li><code>\/etc\/rc2.d<\/code> \u2013 \u2026etc.<\/li>\n<\/ul>\n<p>To add new startup services, create or edit a script in <code>\/etc\/init.d<\/code>:<\/p>\n<pre>ms:345:respawn:\/usr\/bin\/service_executable<\/pre>\n<p>Next, use <code>chkconfig<\/code> to enable the service:<\/p>\n<pre>sudo chkconfig service_executable on<\/pre>\n<p>The <code>345:respawn<\/code> in the script line instructs <code>init<\/code> to run <code>service_executable<\/code> when the system enters runlevels 3, 4 or 5.<\/p>\n<p>Many newer distributions have replaced <code>init<\/code> with more modern alternatives. These can provide a higher-level abstraction over runlevels and the init system.<\/p>\n<p>The majority of Linux distributions, including Debian, Ubuntu, CentOS, Arch and Red Hat, now use <code>systemd<\/code>. This doesn\u2019t reference runlevels directly; instead, they\u2019re converted to \u201ctargets\u201d which are identified by name. While Linux can only be in one runlevel at a time, <code>systemd<\/code> supports multiple concurrently active targets. The mapping between runlevels and targets is only approximate; it\u2019s <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.man7.org\/linux\/man-pages\/man8\/runlevel.8.html\">provided for<\/a> compatibility purposes.<\/p>\n<p>The special <code>default<\/code> target defines what the system will boot into. The <code>default<\/code> target is usually linked to the <code>multi-user<\/code> target \u2013 equivalent to a runlevel of 2 or higher.<br \/>Each target\u2019s services are stored in a \u201cwants\u201d directory. This will contain <code>.service<\/code> files. These are also symbolic links that point back to service definitions in <code>\/usr\/lib\/systemd\/system<\/code>.<\/p>\n<pre>ls -l \/etc\/systemd\/system\/multi-user.target.wants\/*.service<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11104\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/05\/ba35c584.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1541\" height=\"533\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><br \/>This allows service definitions to be created once and shared with multiple \u201ctargets\u201d. When Linux boots, <code>systemd<\/code> will select the target indicated by the runlevel. The services wanted by that target will then be loaded up. <code>systemd<\/code> supports service dependencies, so individual services can be made to wait on other services before they start.<\/p>\n<h2 id=\"inspecting-your-systems-runlevel\"><span class=\"ez-toc-section\" id=\"Inspecting_Your_Systems_Runlevel\"><\/span>Inspecting Your System\u2019s Runlevel<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can find out your system\u2019s runlevel using the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.man7.org\/linux\/man-pages\/man8\/runlevel.8.html\"><code>runlevel<\/code> command<\/a>. This will print two characters to the terminal. They show your system\u2019s previous and current runlevels.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11108\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/05\/34cdd048.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"315\" height=\"71\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p><code>N 5<\/code> is a typical output for a desktop Linux system. The <code>5<\/code> indicates you\u2019re in a multi-user graphical session with networking available. <code>N<\/code> means the previous runlevel couldn\u2019t be determined, usually because the system was shutdown.<\/p>\n<p>On some systems, you may be able to get the current and previous runlevels using the <code>$RUNLEVEL<\/code> and <code>$PREVLEVEL<\/code> environment variables. If these variables are set, the <code>runlevel<\/code> command simply emits their values.<\/p>\n<p>You can also inspect your current runlevel using the <code>who<\/code> command. Run <code>who -r<\/code> to see the runlevel number and the time at which the runlevel was entered.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11105\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/05\/ec3a33fe.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"559\" height=\"77\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 id=\"switching-between-runlevels\"><span class=\"ez-toc-section\" id=\"Switching_Between_Runlevels\"><\/span>Switching Between Runlevels<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can switch between runlevels using the <code>telinit<\/code> command. This lets you manually trigger different modes, such as single-user mode or rescue mode.<\/p>\n<p>Running <code>telinit 0<\/code> will shutdown your machine; <code>telinit 6<\/code> should initiate a reboot. Using <code>telinit<\/code> with runlevels 1 \u2013 5 will activate the corresponding operating mode. If you\u2019re currently in text-only mode, <code>telinit 5<\/code> will try to enable the display server and enter graphical mode.<\/p>\n<p>When using <code>systemd<\/code>, the <code>systemctl isolate<\/code> command lets you activate a different \u201ctarget\u201d. All running services will be stopped; services associated with the new target then get started up.<\/p>\n<p>Here\u2019s how to activate the <code>multi-user<\/code> target:<\/p>\n<pre>sudo systemctl isolate multi-user.target<\/pre>\n<p>If you want to make a permanent change to the runlevel, use the <code>systemctl set-default<\/code> command:<\/p>\n<pre>sudo systemctl set-default multi-user.target<\/pre>\n<p>Now the <code>multi-user<\/code> target will be selected whenever your system reboots.<\/p>\n<h2 id=\"summary\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Linux runlevels describe different states within the operating system. Each runlevel layers additional functionality in the form of extra running services.<\/p>\n<p>Low runlevels are commonly used for recovery modes and text-only operation. A desktop Linux system with a graphical environment will usually be in runlevel <code>5<\/code>. You should check your distribution\u2019s documentation for a detailed description of available runlevels, as implementations can vary.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/11101\/how-linux-runlevels-affect-running-services\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How Linux Runlevels Affect Running Services \u2013 CloudSavvy IT&#8221; Shutterstock\/Allexxandar Linux runlevels distinguish between system operating states. Switching runlevel will change the services which are running. You can customise runlevels so each level starts with a specific set of services. Standard Runlevels The Linux kernel defines seven standard runlevels. Individual operating system distributions may customise&#8230;<\/p>\n","protected":false},"author":1,"featured_media":255789,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/05\/5c016313.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-255788","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/255788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=255788"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/255788\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/255789"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=255788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=255788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=255788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}