<?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>DEV Community: Ethan Rodrigo</title>
    <description>The latest articles on DEV Community by Ethan Rodrigo (@ethanrodrigo).</description>
    <link>https://dev.to/ethanrodrigo</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%2F786319%2F4d72ede7-e819-47d4-a62b-28f16521c055.jpg</url>
      <title>DEV Community: Ethan Rodrigo</title>
      <link>https://dev.to/ethanrodrigo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ethanrodrigo"/>
    <language>en</language>
    <item>
      <title>Jetpack Compose 101; Setup the Environment</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Sat, 04 Feb 2023 17:57:20 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/jetpack-compose-101-setup-the-environment-51f5</link>
      <guid>https://dev.to/ethanrodrigo/jetpack-compose-101-setup-the-environment-51f5</guid>
      <description>&lt;p&gt;Welcome to the second installment of the Android Development series! In our previous article, a brief overview of the Jetpack framework and Jetpack Compose was provided. In case you missed it, be sure to catch up by reading it &lt;a href="https://ethanrodrigo.hashnode.dev/jetpack-compose-a-modern-ui-toolkit" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It's time to get hands-on and set up the environment for Jetpack Compose. So, grab a coffee, fire up your laptop, and let's dive in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffluentincoffee.b-cdn.net%2Fwp-content%2Fuploads%2F2022%2F05%2Fbut-first-coffee.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffluentincoffee.b-cdn.net%2Fwp-content%2Fuploads%2F2022%2F05%2Fbut-first-coffee.png" alt="75 Funny Coffee Memes To Brighten Up Your Day" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE&lt;/em&gt;: This article series assumes that you have an understanding of native android development fundamentals. This series is here to take your skills to the next level. The main focus in this series is solely on the Jetpack framework and its capabilities.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setup the Environment
&lt;/h1&gt;

&lt;p&gt;Open up the Android Studio(you can download it from &lt;a href="https://developer.android.com/studio/install" rel="noopener noreferrer"&gt;here&lt;/a&gt;). If this is your first time, you can see something as follows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fhjuo3tvovshslikaq82v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fhjuo3tvovshslikaq82v.png" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now click the box&lt;code&gt;New Project&lt;/code&gt; on the top left side.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F1xmw9z7rs0ztbxl4wlx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F1xmw9z7rs0ztbxl4wlx5.png" width="141" height="57"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the following dialog, select &lt;code&gt;Phone and Tablet&lt;/code&gt;(often it's selected by default), then &lt;code&gt;Empty Compose Activity&lt;/code&gt; from the right side. Finally, click on &lt;code&gt;Next&lt;/code&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fsrkpz57e9xyyjr6oh442.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fsrkpz57e9xyyjr6oh442.png" width="800" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next dialog box, give your app a &lt;code&gt;Name&lt;/code&gt;. I name it as &lt;code&gt;My First Compose Application&lt;/code&gt;(I know that's too long).&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Package name&lt;/code&gt; is a unique identifier for your app on a device. Let it be the default. Also, consider changing the &lt;code&gt;Minimum SDK&lt;/code&gt;, which is the minimum android version that your app can be installed on.&lt;/p&gt;

&lt;p&gt;Keep the default values for the other settings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fjqh63onev1iwrz6h12j5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjqh63onev1iwrz6h12j5.png" width="800" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give it some time to create and initialize an environment for you. Your internet connection speed affects the initialization process as Android Studio downloads some packages from the internet.&lt;/p&gt;

&lt;p&gt;Then you'll have something as follows&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8q15ft5cl5hgjitpneip.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8q15ft5cl5hgjitpneip.png" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  A quick glimpse at Android Studio
&lt;/h1&gt;

&lt;p&gt;As mentioned earlier in the post, this series focuses more on the &lt;code&gt;Jetpack&lt;/code&gt; framework, and assumes you have some experience with android development and Android Studio. The following tools will aid us in our journey of learning Jetpack Compose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design View
&lt;/h2&gt;

&lt;p&gt;On the left side, you will find three panels labeled Code, &lt;em&gt;Design&lt;/em&gt;, and &lt;em&gt;Split&lt;/em&gt;. The &lt;em&gt;Code&lt;/em&gt; panel displays the code that you are currently working on, the &lt;em&gt;Design&lt;/em&gt; panel shows the visual representation of the UI in a composable function, and the &lt;em&gt;Split&lt;/em&gt; panel combines both in a single panel.&lt;/p&gt;

&lt;p&gt;Click on the &lt;em&gt;Split&lt;/em&gt; box and you will see the UI from the function called &lt;code&gt;Greeting&lt;/code&gt;. If you see nothing, just click on the &lt;code&gt;build and refresh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ffeldkl9fjk1i87f6mle3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ffeldkl9fjk1i87f6mle3.png" width="800" height="577"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is only for testing the UI. To ensure the proper functioning of the app, you will also need to test it using an emulator in Android Studio. The emulator allows you to run and test your app in a virtual environment that mimics a real device.&lt;/p&gt;

&lt;h2&gt;
  
  
  Emulator
&lt;/h2&gt;

&lt;p&gt;You can run your app with the little green play button on the top. Additionally, the green hammer on the left side is to build the project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fjtdo0p9oir4xd04juj4y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjtdo0p9oir4xd04juj4y.png" width="369" height="68"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't worry if you have no emulator selected as in the above screenshot. You can always create a device by going to the &lt;code&gt;Device Manager&lt;/code&gt; on the left side.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fscz34wcuaeev43dtmc8i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fscz34wcuaeev43dtmc8i.png" width="239" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And use &lt;code&gt;Create device&lt;/code&gt; to create a new android device.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fcco10m5avk0z96enfpj7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fcco10m5avk0z96enfpj7.png" width="490" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There you can download an iso image of the latest android version and then select the ram, CPU, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F4kc0mt9h25tqdvksgv5x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F4kc0mt9h25tqdvksgv5x.png" width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Run on your phone
&lt;/h2&gt;

&lt;p&gt;If your hardware is outdated and cannot run an emulator, consider testing the app on your android phone instead. You can use &lt;code&gt;Pair Devices Using Wi-Fi&lt;/code&gt; option located below the selected emulator. Keep in mind that this option needs both of your devices(laptop and phone) connected to the same network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fm72t2gngoy2qyl63mfec.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fm72t2gngoy2qyl63mfec.png" width="325" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will be prompted with something as follows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fkueci5mb0bvc294uewzs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fkueci5mb0bvc294uewzs.png" width="613" height="635"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To connect your phone using this option, go to the &lt;code&gt;Developer option&lt;/code&gt;(check the documentation on &lt;a href="https://developer.android.com/studio/debug/dev-options#enable" rel="noopener noreferrer"&gt;how&lt;/a&gt;) in your phone and select &lt;code&gt;Wireless debugging&lt;/code&gt;. Then choose &lt;code&gt;Pair using QR code&lt;/code&gt;. This will open your camera and you can use it to scan the QR code generated in the window. Then your phone will be connected.&lt;/p&gt;

&lt;p&gt;You can also use &lt;code&gt;Pair using pairing code&lt;/code&gt;. Click on it and choose your device, then select &lt;code&gt;Pair&lt;/code&gt;. Type the pairing code in your phone and you'll be good to go.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F6it0nysffjwztwxlfdg4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F6it0nysffjwztwxlfdg4.png" width="614" height="642"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, this option works only for Android 11 and higher devices only. If your device doesn't have this option as well, you can use &lt;code&gt;USB Debugging&lt;/code&gt;. Read &lt;a href="https://developer.android.com/studio/run/device#setting-up" rel="noopener noreferrer"&gt;the documentation to set it up&lt;/a&gt; on different platforms.&lt;/p&gt;

&lt;h1&gt;
  
  
  Dive into the code
&lt;/h1&gt;

&lt;p&gt;It's coding time...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fqj8dh03rb1i573jkqhqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fqj8dh03rb1i573jkqhqx.png" width="595" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE&lt;/em&gt;: To proceed further you need to have a solid understanding of Kotlin programming language. If you're not familiar with it, take some time and review &lt;a href="https://kotlinlang.org/docs/home.html" rel="noopener noreferrer"&gt;the documentation&lt;/a&gt; and make yourself comfortable with the basics. Other complicated topics can be added on the fly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Composable functions
&lt;/h2&gt;

&lt;p&gt;The traditional way of designing the UI for an android app is &lt;code&gt;XML&lt;/code&gt;. However, Jetpack Compose has thrown away &lt;code&gt;XML&lt;/code&gt;s.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3j68xfefthbvie8jmvtv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3j68xfefthbvie8jmvtv.jpg" width="500" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And embraced &lt;code&gt;Composable&lt;/code&gt; functions. Wait..., what is a composable function?&lt;/p&gt;

&lt;p&gt;Composable functions are where you define your UI. It is just like a usual function in Kotlin but has the &lt;code&gt;@Composable&lt;/code&gt; annotation above the function. Each composable function takes some inputs and returns some UI elements. These UI elements are then combined to form the final UI of the app.&lt;/p&gt;

&lt;p&gt;Remember, Composable functions can be called from another Composable function only. You can't use them inside a usual function.&lt;/p&gt;

&lt;h2&gt;
  
  
  MainActivity.kt
&lt;/h2&gt;

&lt;p&gt;Let's dive into the code in front of us. First, let's break down the &lt;code&gt;class&lt;/code&gt; we have.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyFirstComposeApplicationTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colors.background
                ) {
                    Greeting("Android")
                }
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;MainActivity&lt;/code&gt; class is derived from the base class &lt;code&gt;ComponentActivity&lt;/code&gt;, which is used for activities that use the Compose UI toolkit. The &lt;code&gt;ComponentActivity&lt;/code&gt; class provides a convenient entry point for integrating Compose into an existing Android app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    //...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;MainActivity&lt;/code&gt;, we have an overridden method; &lt;code&gt;onCreate()&lt;/code&gt;. This is the function that is going to call first when the activity is launched. The &lt;code&gt;savedInstanceState: Bundle?&lt;/code&gt; parameter in the function is used to pass in a &lt;a href="https://developer.android.com/reference/android/os/Bundle" rel="noopener noreferrer"&gt;&lt;code&gt;Bundle&lt;/code&gt;&lt;/a&gt; object that contains the state of the activity. This can be used to restore the activity to its previous state after it has been destroyed and recreated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setContent {
    MyFirstComposeApplicationTheme {
    // A surface container using the 'background' color from the theme
    //...
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;setContent&lt;/code&gt; does what its name suggests; sets the content of an activity. This is a Composable function and it takes a single argument; another Composable function, which represents the root of the UI. In this case &lt;code&gt;MyFirstComposeApplicationTheme&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;MyFirstComposeApplicationTheme&lt;/code&gt; is also a composable function that sets the theme for the activity. Note the name originated from the application name. If you click on the function name while pressing the &lt;code&gt;Ctrl&lt;/code&gt;, you may find that function is written on the &lt;code&gt;Theme.kt&lt;/code&gt; file is located in the &lt;code&gt;ui.theme&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5mu79ur5w0asgf5jl9uj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5mu79ur5w0asgf5jl9uj.png" width="441" height="307"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MyFirstComposeApplicationTheme {
                // A surface container using the 'background' color from the theme
    Surface(
        modifier = Modifier.fillMaxSize(),
        color = MaterialTheme.colors.background
    ) {
        Greeting("Android")
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Surface&lt;/code&gt; composable function inside the &lt;code&gt;MyFirstComposeApplicationTheme&lt;/code&gt; is a visual container that can be used to group other composable together and apply a background color and shape to them.&lt;/p&gt;

&lt;p&gt;Note that &lt;code&gt;setContent&lt;/code&gt; is the only mandatory function that we need here. We can call &lt;code&gt;Greeting&lt;/code&gt; inside the &lt;code&gt;setContent&lt;/code&gt; without &lt;code&gt;MyFirstComposeApplicationTheme&lt;/code&gt; and &lt;code&gt;Surface&lt;/code&gt;. It would look like the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Greeting("Android")
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we have a function call to &lt;code&gt;Greeting&lt;/code&gt; and have passed &lt;code&gt;Android&lt;/code&gt; as an argument. &lt;code&gt;Greeting&lt;/code&gt; is a composable function. In the function, we have another function call for &lt;code&gt;Text&lt;/code&gt;, which takes an argument &lt;code&gt;text&lt;/code&gt; and displays it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Composable
fun Greeting(name: String) {
    Text(text = "Hello $name!")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, you can find another annotation &lt;code&gt;Preview&lt;/code&gt;. In Compose, &lt;code&gt;Preview&lt;/code&gt;s are a feature that allows developers to see a live preview of their composable functions directly in the Android Studio editor. This allows developers to see how their UI will look and behave without having to run the whole app on a device or emulator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    MyFirstComposeApplicationTheme {
        Greeting("Android")
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, the background of the preview is transparent, to show the background, you can use &lt;code&gt;showBackground = true&lt;/code&gt; parameter.&lt;/p&gt;

&lt;p&gt;You can have any number of previews you want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fbhbp8m4gt9cfy6epdn06.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fbhbp8m4gt9cfy6epdn06.png" width="800" height="591"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Write your first composable function
&lt;/h1&gt;

&lt;p&gt;With Jetpack Compose, you're now set up to develop apps. You know how to set up an environment for jetpack compose and what's in the Android Studio default. Let's create a composable function and display some text in the preview. If you don't understand the code yet, don't worry. We'll cover it in future lessons.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Composable
fun MyFirstComposableFunction(){
    Text(
        "Hello World!",
        textAlign = TextAlign.Center
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;MyFirstComposableFunction&lt;/code&gt; there is a call for a composable function; &lt;code&gt;Text&lt;/code&gt;, to show some texts. The &lt;code&gt;textAlign&lt;/code&gt; just aligns the text to the center of the screen.&lt;/p&gt;

&lt;p&gt;You can call this from the &lt;code&gt;MyPreview&lt;/code&gt; function that we have created to preview and see what it looks like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Preview(showSystemUi = true)
@Composable
fun MyPreview(){
    MyFirstComposableFunction()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you want to run it in your emulator and see, you can put the function inside the &lt;code&gt;Surface&lt;/code&gt; as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyFirstComposeApplicationTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colors.background
                ) {
                    MyFirstComposableFunction()
                }
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In conclusion, we have learned about setting up the environment for using Jetpack Compose in our Android Development series. Additionally, we explored the MainActivity class and its content, as well as created a Composable function to display some texts.&lt;/p&gt;

&lt;p&gt;I would like to express my gratitude for taking the time to read this article. As we move forward, I will dive deeper into defining the UI with Jetpack Compose. Make sure to subscribe to my newsletter to stay up-to-date.&lt;/p&gt;

&lt;p&gt;If you found this article informative and interesting, let's connect on &lt;a href="https://www.linkedin.com/in/ethan-rodrigo-b8075b259/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://twitter.com/EthanRodrigo8" rel="noopener noreferrer"&gt;&lt;strong&gt;Twitter&lt;/strong&gt;&lt;/a&gt;, and &lt;a href="https://www.instagram.com/ethan.rod6/" rel="noopener noreferrer"&gt;&lt;strong&gt;Instagram&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>fintech</category>
      <category>cryptocurrency</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Jetpack Compose; A Modern UI ToolKit</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Thu, 26 Jan 2023 17:07:18 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/jetpack-compose-a-modern-ui-toolkit-2ai7</link>
      <guid>https://dev.to/ethanrodrigo/jetpack-compose-a-modern-ui-toolkit-2ai7</guid>
      <description>&lt;p&gt;The world of programming changes rapidly and gets better day by day. The frameworks and tools that have been used ten years ago won't be able to fulfill the needs of our apps.&lt;/p&gt;

&lt;p&gt;Today I'm with a new framework for Android development. In this article let's talk about what is &lt;em&gt;Jetpack Compose&lt;/em&gt; and how it helps you to build better android apps. Whether you're a seasoned Android developer or just starting, this article will provide a great introduction to Android Jetpack Compose and its capabilities.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is &lt;em&gt;Jetpack&lt;/em&gt;?
&lt;/h1&gt;

&lt;p&gt;This is what the &lt;a href="https://developer.android.com/jetpack" rel="noopener noreferrer"&gt;Android Developers&lt;/a&gt; say;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Jetpack is a suite of libraries to help developers follow best practices, reduce boilerplate code, and write code that works consistently across Android versions and devices so that developers can focus on the code they care about.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a nutshell, &lt;em&gt;Jetpack&lt;/em&gt; is a collection of libraries that helps you write code with fewer bugs and in less time than traditional methods of developing Android apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Jetpack is made up of components in four categories
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Foundation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This provides libraries for core functionality that is needed in most Android apps, such as the &lt;a href="https://developer.android.com/jetpack/androidx/releases/appcompat" rel="noopener noreferrer"&gt;&lt;code&gt;appCompat&lt;/code&gt;&lt;/a&gt; library, which provides &lt;a href="https://en.wikipedia.org/wiki/Backward_compatibility" rel="noopener noreferrer"&gt;backward compatibility&lt;/a&gt; for newer features on older Android versions, and the &lt;a href="https://developer.android.com/jetpack/androidx/releases/core" rel="noopener noreferrer"&gt;&lt;code&gt;androidx.core&lt;/code&gt;&lt;/a&gt; library, which contains base classes for common Android components.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This component has libraries that help developers to manage the app's architecture, such as &lt;a href="https://developer.android.com/jetpack/androidx/releases/navigation" rel="noopener noreferrer"&gt;&lt;code&gt;navigation&lt;/code&gt;&lt;/a&gt;, which makes it easy to handle navigation between different screens in the app.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Behavior&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Libraries in this component add behaviors to the app, such as notifications, permissions, and sharing. For example, the &lt;a href="https://developer.android.com/reference/androidx/core/app/NotificationCompat" rel="noopener noreferrer"&gt;&lt;code&gt;NotificationCompat&lt;/code&gt;&lt;/a&gt; library makes it easy to create and manage notifications.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;UI&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This component includes libraries for building the app's UI. &lt;em&gt;Jetpack Compose&lt;/em&gt; belongs to this category.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using Android Jetpack, developers can focus on building their app's unique features, while the Jetpack libraries take care of the common tasks, such as handling navigation and managing data. This can help to make the development process faster, more efficient, and more maintainable.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Jetpack Compose?
&lt;/h1&gt;

&lt;p&gt;As previously stated, &lt;em&gt;Jetpack Compose&lt;/em&gt; is a UI library that is part of the Android Jetpack library collection.&lt;/p&gt;

&lt;p&gt;This is what &lt;em&gt;Jetpack Compose&lt;/em&gt; according to the &lt;a href="https://developer.android.com/jetpack/compose" rel="noopener noreferrer"&gt;Android Developers team&lt;/a&gt;;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Jetpack Compose is Android’s recommended modern toolkit for building native UI. It simplifies and accelerates UI development on Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why use Jetpack Compose?
&lt;/h2&gt;

&lt;p&gt;You might be wondering, why to switch from using traditional XML layouts to Android Jetpack Compose. Here are a few reasons why you might consider using Compose for your next project.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reactive programming&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Compose uses a &lt;a href="https://en.wikipedia.org/wiki/Reactive_programming" rel="noopener noreferrer"&gt;reactive programming model&lt;/a&gt;, which updates the UI automatically as the user interacts with the app, making it more dynamic. In contrast, XML is a &lt;a href="https://en.wikipedia.org/wiki/Declarative_programming" rel="noopener noreferrer"&gt;declarative markup language&lt;/a&gt;, which means that the developer needs to explicitly specify the layout of the UI. Further, it does not have built-in support for reactive programming.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Simplicity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Jetpack Compose has a minimalistic and easy-to-read syntax(Compose uses &lt;em&gt;Kotlin&lt;/em&gt;), which makes it simpler and faster for developers to create complex UI elements. In contrast, XML can be verbose and can require a lot of boilerplate code to achieve the same results.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Built-in support for animations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the features that I particularly appreciate in Jetpack Compose is its built-in support for animations. This makes it easy to add dynamic and engaging transitions to your app. However, adding animations in an &lt;em&gt;XML&lt;/em&gt; layout can be more challenging and time-consuming.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Better performance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Jetpack Compose has a better algorithm for layout and rendering, resulting in improved performance compared to XML layouts. It also has built-in support for managing memory and app lifecycle.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Better data management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Jetpack Compose has a built-in mechanism for handling data and state management, making it easy for developers to organize and maintain their code.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Where can I learn Jetpack Compose?
&lt;/h1&gt;

&lt;p&gt;Jetpack Compose is a relatively new toolkit, which means it may have a bit of a learning curve. Yet you can survive as you have the &lt;a href="https://developer.android.com/jetpack/compose/documentation" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Additionally, the Android Developer Team has some helpful tutorials available for learning Jetpack Compose.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.android.com/jetpack/compose/tutorial" rel="noopener noreferrer"&gt;Quick tutorial&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=EOQB8PTLkpY&amp;amp;list=PLWz5rJ2EKKc9Ty3Zl1hvMVUsXfkn93NRk" rel="noopener noreferrer"&gt;YouTube playlist&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/android/compose-samples" rel="noopener noreferrer"&gt;Sample apps&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are two YouTube channels that can help you with Compose. There can be other channels also, but for me, these are the best.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/@AndroidDevelopers" rel="noopener noreferrer"&gt;Android Developers&lt;/a&gt; - The official YouTube channel of Android Developers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/@PhilippLackner" rel="noopener noreferrer"&gt;Philipp Lackner&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/@FlorianWalther" rel="noopener noreferrer"&gt;Florian Walther&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;I am also here to help you!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I hope this article provided a useful introduction to Jetpack Compose and its capabilities as a modern UI toolkit for Android development. As I continue to explore and learn about this technology, I plan to share my findings and insights through a series of articles. Be sure to subscribe to the newsletter of &lt;a href="https://ethanrodrigo.hashnode.dev/" rel="noopener noreferrer"&gt;my blog&lt;/a&gt; to stay up-to-date with my latest posts and join me on my journey to mastering Jetpack Compose. Thank you for reading!&lt;/p&gt;

&lt;p&gt;Additionally, If you find this interesting, let's connect on &lt;a href="https://www.linkedin.com/in/ethan-rodrigo-b8075b259/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://twitter.com/EthanRodrigo8" rel="noopener noreferrer"&gt;&lt;strong&gt;Twitter&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/" rel="noopener noreferrer"&gt;&lt;strong&gt;Instagram&lt;/strong&gt;&lt;/a&gt;, and &lt;a href="https://hashnode.com/@EthanRodrigo" rel="noopener noreferrer"&gt;&lt;strong&gt;Hashnode&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>development</category>
      <category>documentation</category>
      <category>howto</category>
    </item>
    <item>
      <title>Let's Destroy a Linux System</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Mon, 16 Jan 2023 19:17:20 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/lets-destroy-a-linux-system-5hj3</link>
      <guid>https://dev.to/ethanrodrigo/lets-destroy-a-linux-system-5hj3</guid>
      <description>&lt;p&gt;Linux is a powerful and flexible operating system, but with great power comes great responsibility. As a Linux user, it's important to understand the potential dangers of certain commands and how to use them safely. In this blog post, we'll take a closer look at some of the most destructive commands in Linux and how to use them safely.&lt;/p&gt;

&lt;p&gt;So let's dive in and learn how to protect yourself and your system from the destructive power of Linux commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F7soa6k1cug99mvyrijsx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7soa6k1cug99mvyrijsx.png" width="582" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  1. &lt;code&gt;rm&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;rm&lt;/code&gt; command is used to delete files and directories(to find out other ways of deleting files in Linux, see &lt;a href="https://ethanrodrigo.hashnode.dev/remove-files-in-linux" rel="noopener noreferrer"&gt;this article&lt;/a&gt;), but it can be harmful if not used properly. By default, it does not prompt for confirmation before deleting, which means it's possible to accidentally delete important files or entire directories without realizing it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rm&lt;/code&gt; can be even more hazardous when used with the &lt;code&gt;-r&lt;/code&gt; and &lt;code&gt;-f&lt;/code&gt; flags, which stand for recursive deletion and forceful deletion. These flags are mostly used for the deletion of a directory.&lt;/p&gt;

&lt;p&gt;The most dangerous variation of the &lt;code&gt;rm&lt;/code&gt; is &lt;code&gt;sudo rm -rf / --no-preserve-root&lt;/code&gt;. This command says "Delete everything in the &lt;code&gt;/&lt;/code&gt; directory and do not treat it as a special directory."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fwor9wlrmt79x98afqxnt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fwor9wlrmt79x98afqxnt.png" alt="image.png" width="449" height="74"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Preventing accidental file deletion
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Use of the&lt;/em&gt; &lt;code&gt;-i&lt;/code&gt; &lt;em&gt;and&lt;/em&gt; &lt;code&gt;-I&lt;/code&gt; &lt;em&gt;flags&lt;/em&gt;: You can use &lt;code&gt;-i&lt;/code&gt; to prompt before every removal and &lt;code&gt;-I&lt;/code&gt; for prompt whether to proceed with the entire operation, before removing more than three files or when removing recursively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fttqjl2wbd51pxctri52j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fttqjl2wbd51pxctri52j.png" width="572" height="267"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Use a Trash&lt;/em&gt;: Try out &lt;code&gt;trash-cli&lt;/code&gt; and prevent accidental file deletions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Use a recovery tool&lt;/em&gt;: This article talks more about &lt;a href="https://ethanrodrigo.hashnode.dev/recover-deleted-files-on-linux" rel="noopener noreferrer"&gt;how to recover deleted files in Linux&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  2. &lt;code&gt;:(){:|:&amp;amp;};:&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Looks like some emoticons, right? But these are dangerous. These symbols are called a fork bomb in Linux.&lt;/p&gt;

&lt;p&gt;According to the Wikipedia;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In computing, a &lt;strong&gt;fork bomb&lt;/strong&gt; (also called &lt;strong&gt;rabbit virus&lt;/strong&gt; or &lt;strong&gt;wabbit&lt;/strong&gt;) is a &lt;a href="https://en.wikipedia.org/wiki/Denial-of-service_attack" rel="noopener noreferrer"&gt;denial-of-service attack&lt;/a&gt; wherein a process continually replicates itself to deplete available system resources, slowing down or crashing the system due to &lt;a href="https://en.wikipedia.org/wiki/Starvation_(computer_science)" rel="noopener noreferrer"&gt;resource starvation&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a nutshell, the above command creates a chain of processes.&lt;/p&gt;

&lt;p&gt;If you're a programmer or student who is learning to program you may be familiar with recursion. This command utilizes the destructive power of recursive functions.&lt;/p&gt;

&lt;p&gt;As the above command is a function, here is the breakdown version of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bomb(){ # creates a function
    bomb | bomb &amp;amp; # calling recursively and pipe its result to the background job of itself
}; 
bomb # calling of the function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see. this is a function that calls itself (a recursive function). In the function, the function calls itself and the pipe its result to a background job of itself.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to prevent a fork bomb?
&lt;/h3&gt;

&lt;p&gt;Well, don't run that command. That's it.&lt;/p&gt;

&lt;p&gt;And do the following also,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Limit the maximum number of processes per user&lt;/em&gt;: The &lt;code&gt;ulimit&lt;/code&gt; command can be used to limit the number of processes that can be created by a user and prevent a fork bomb. Give a number to the &lt;code&gt;-u&lt;/code&gt; flag and that will be the new limit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fjalfgj2rkxd2z7iittia.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjalfgj2rkxd2z7iittia.png" width="374" height="133"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Limit the maximum number of open file descriptors per process&lt;/em&gt;: The &lt;code&gt;ulimit&lt;/code&gt; command can also be used here. &lt;code&gt;ulimit -n [number]&lt;/code&gt;, sets a hard limit of [number] file descriptors per process. For example, consider the following. It will restrict a process from opening more than 100 file descriptors at a time. Once a process reaches the limit of 100 file descriptors, the system will not allow it to open any new file descriptors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fkzczbbvwcdscbho73skj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fkzczbbvwcdscbho73skj.png" width="298" height="110"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Monitor system resources usage&lt;/em&gt;: This can be done by using a tool &lt;code&gt;top&lt;/code&gt;, &lt;code&gt;ps&lt;/code&gt;, &lt;a href="https://github.com/htop-dev/htop" rel="noopener noreferrer"&gt;&lt;code&gt;htop&lt;/code&gt;&lt;/a&gt; or &lt;a href="https://github.com/aristocratos/bpytop" rel="noopener noreferrer"&gt;&lt;code&gt;bpytop&lt;/code&gt;&lt;/a&gt;. These tools let you introspect the processes running on a Linux system and the resources they're consuming.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  3. dd
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;dd&lt;/code&gt; command in Linux is used to copy and convert files. Yet, it can also be deadly if not used correctly. The command is a very low-level command that operates on a device level, meaning that it doesn't care about file systems, partitions or any other abstraction layer, it will just write to the device whatever is given to it as input.&lt;/p&gt;

&lt;p&gt;For instance, if you use &lt;code&gt;/dev/random&lt;/code&gt;,&lt;code&gt;/dev/urandom&lt;/code&gt; or &lt;code&gt;/dev/zero&lt;/code&gt; as a value for &lt;code&gt;if&lt;/code&gt; parameter and provide a hard drive as the value for &lt;code&gt;of&lt;/code&gt;, the command will wipe all the data on that hard drive. (It's best to try this out in a virtual machine as a safe experiment.)&lt;/p&gt;

&lt;p&gt;This makes it particularly dangerous because if the wrong device is specified, it can cause irreparable damage to the system, including the loss of important data.&lt;/p&gt;

&lt;p&gt;Another reason why &lt;code&gt;dd&lt;/code&gt; is dangerous is, if you specify only the input and output stream, the command will use up the available space on the system, eventually making the system out of storage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fgkxqaf0hmvzh50cvdxmr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgkxqaf0hmvzh50cvdxmr.png" width="616" height="113"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Safe usage of &lt;code&gt;dd&lt;/code&gt; command
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Always double-check what you're writing&lt;/em&gt;: Make sure that the input and output files are correct.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Use of&lt;/em&gt; &lt;code&gt;bs&lt;/code&gt; &lt;em&gt;and&lt;/em&gt; &lt;code&gt;count&lt;/code&gt; &lt;em&gt;options&lt;/em&gt;: The &lt;code&gt;bs&lt;/code&gt; and &lt;code&gt;count&lt;/code&gt; options allow you to specify the block size and the number of blocks to be copied. By using smaller block sizes and fewer blocks, you can reduce the risk of overwriting important data. For example, here &lt;code&gt;dd&lt;/code&gt; creates a file of 100MB with some random data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5x3kc7jqt5wkruxefq9z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5x3kc7jqt5wkruxefq9z.png" width="553" height="111"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Use&lt;/em&gt; &lt;code&gt;status&lt;/code&gt; &lt;em&gt;option:&lt;/em&gt; By using the &lt;code&gt;status=progress&lt;/code&gt; option, you can see what's going on when you run a certain &lt;code&gt;dd&lt;/code&gt; command.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  4. /dev/null
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;/dev/null&lt;/code&gt; is a special file that discards any data written to it. It's often referred to as the &lt;em&gt;null device&lt;/em&gt; or the &lt;em&gt;bit bucket&lt;/em&gt;. This is not a physical device, but a virtual file located in the &lt;code&gt;/dev&lt;/code&gt; directory. It acts as a placeholder for unwanted input or output.&lt;/p&gt;

&lt;p&gt;In this example, I'm finding a file named &lt;code&gt;2022-12-03&lt;/code&gt;. However, as the command looks into the root(&lt;code&gt;/&lt;/code&gt;) directory, there are several &lt;code&gt;Permission denied&lt;/code&gt; errors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5jklo5bho3621y4i181w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5jklo5bho3621y4i181w.png" width="616" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And sometimes, it's not going to fix even if we use &lt;code&gt;sudo&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fm70ctd537w6f4cbxeguu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fm70ctd537w6f4cbxeguu.png" width="388" height="67"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To eliminate these errors, we can redirect them to the &lt;code&gt;/dev/null&lt;/code&gt; device.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fargc1zm48e4a705r7vr8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fargc1zm48e4a705r7vr8.png" width="382" height="36"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, What makes /dev/null potentially so harmful? Well, it's the redirection. If you redirect the output of an important command, such as getting an API key, to &lt;code&gt;/dev/null&lt;/code&gt;, it would be lost forever.&lt;/p&gt;

&lt;h1&gt;
  
  
  5. chmod
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;chmod&lt;/code&gt; command in Linux is used to change the permissions on files and directories.&lt;/p&gt;

&lt;p&gt;One way &lt;code&gt;chmod&lt;/code&gt; can be destructive is by inadvertently removing the execute permission from a file that is required to run the system can cause issues. A shell script needs permission to be executed, and if that permission is removed from a script used during booting, the system can be halted. Similarly, adding executable permissions to an unknown file can also be malicious.&lt;/p&gt;

&lt;p&gt;In the following example, we have a bash script named, &lt;code&gt;hello.sh&lt;/code&gt;. It shows how to add and remove the executable permissions of a file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fga6wvl7e240g9ht6re1s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fga6wvl7e240g9ht6re1s.png" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another way &lt;code&gt;chmod&lt;/code&gt; can be destructive is, by granting too much access to a file or directory. This could allow malicious users or programs to access sensitive information or perform harmful actions.&lt;/p&gt;

&lt;p&gt;For example, consider the following screenshot that shows the permissions of a file. It has granted read permission to everyone, and write permission only to the user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fzvrq8sckwq4es7dy4w76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fzvrq8sckwq4es7dy4w76.png" width="642" height="65"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But if we give read, write, and execute permissions to everyone, that would be a major security vulnerability.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fzy03bd0gjlin1q1polj4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fzy03bd0gjlin1q1polj4.png" width="668" height="97"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Therefore &lt;code&gt;chmod 777&lt;/code&gt; can be considered one of the most destructive commands in Linux.&lt;/p&gt;

&lt;h3&gt;
  
  
  Preventing data loss with &lt;code&gt;chmod&lt;/code&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;_Be careful with wildcard characters (\_, ?, etc.):* You can use wildcards with &lt;code&gt;chmod&lt;/code&gt; command, as it can match multiple files and unintentionally change their permissions. However, let's say you run this command for changing the files in a dir called &lt;code&gt;Dir0&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; chmod 755 Dir0/*
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This looks fine until you realize you have given the same permission for the files and subdirectories as well.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Check the permission before changing:&lt;/em&gt; Check the current permissions of the file or directory using the "ls -l" command to avoid changing them in a way that can cause problems.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fldn6naqks9wykydqrcr9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fldn6naqks9wykydqrcr9.png" width="570" height="199"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Be careful with&lt;/em&gt; &lt;code&gt;-R&lt;/code&gt; &lt;em&gt;flag:&lt;/em&gt; This allows you to change the permissions of a file or directory recursively, which means all the files and directories inside it will also have their permissions changed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fisefvwhodowqh6x1f840.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fisefvwhodowqh6x1f840.png" width="574" height="736"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  A bonus tip for preventing data loss
&lt;/h1&gt;

&lt;p&gt;Well, this is an advice for the system admins, HAVE REGULAR BACKUPS. And also make sure to verify the backups.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fk1kdz8oietf54s4949gu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fk1kdz8oietf54s4949gu.jpg" alt="🔰RB ASHISH (rbashish) ☁️ on Twitter: " width="600" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Thank you for reading! If you haven't subscribed to the newsletter, DO IT IMMEDIATELY! Then you would find my latest article in your inbox. If you find this interesting, let's connect on &lt;a href="https://www.linkedin.com/in/ethan-rodrigo-b8075b259/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, &lt;a href="https://twitter.com/EthanRodrigo8" rel="noopener noreferrer"&gt;&lt;strong&gt;Twitter&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/" rel="noopener noreferrer"&gt;&lt;strong&gt;Instagram&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://dev.to/ethanrodrigo"&gt;&lt;/a&gt;&lt;strong&gt;&lt;a href="http://dev.to"&gt;dev.to&lt;/a&gt;&lt;/strong&gt; and &lt;a href="https://hashnode.com/@EthanRodrigo" rel="noopener noreferrer"&gt;&lt;strong&gt;Hashnode&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now go and execute &lt;code&gt;sudo rm -rf / --no-preserve-root&lt;/code&gt; and make tux happy. Until next time...&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Let's Play with the Linux Kernel</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Thu, 08 Dec 2022 17:03:39 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/lets-play-with-the-linux-kernel-2dm8</link>
      <guid>https://dev.to/ethanrodrigo/lets-play-with-the-linux-kernel-2dm8</guid>
      <description>&lt;p&gt;``In a world full of computers, there are hundreds of implementations of the same tool. When it comes to Linux, as it is an open-source project thousand of tools has been made just to do one thing.&lt;/p&gt;

&lt;p&gt;Today the topic is the kernel. A mandatory concept of computers. In this article let me introduce what a kernel is and what kind of kernels you can use in Linux. Also, we will play with the kernel.&lt;/p&gt;

&lt;p&gt;NOTE: Before you proceed further read my &lt;a href="https://ethanrodrigo.hashnode.dev/what-is-a-kernel" rel="noopener noreferrer"&gt;last article&lt;/a&gt; about an introduction to kernel and its types.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Linux?
&lt;/h2&gt;

&lt;p&gt;For years there's been a debate on this question. However, this is what &lt;code&gt;GNU&lt;/code&gt; says.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Linux is the kernel: the program in the system that allocates the machine's resources to the other programs that you run.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdvk0xyrla%2Fimage%2Fupload%2Fv1670518016%2Fitsthekernel_a4iip7.avif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdvk0xyrla%2Fimage%2Fupload%2Fv1670518016%2Fitsthekernel_a4iip7.avif" alt="image.avif" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, then what Linux kernel you're currently using? To find that out the &lt;code&gt;uname&lt;/code&gt; command can be used. &lt;code&gt;uname -srm&lt;/code&gt; The following is my daily driver.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ff4t03omrhjz4xels5wbu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ff4t03omrhjz4xels5wbu.png" alt="image.png" width="255" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternatives to the Linux kernel
&lt;/h2&gt;

&lt;p&gt;As I mentioned at the beginning of the article, there are numerous implementations of the same concept. In terms of kernel, there are an untold number of kernels. The following four are the officially supported kernels.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Stable
&lt;/h3&gt;

&lt;p&gt;As the name suggests this kernel is stable. It is regularly being updated and new patches are released often. Most Linux users use the stable kernel.&lt;/p&gt;

&lt;p&gt;You can install it with the package manager; &lt;code&gt;pacman -S linux&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.kernel.org/" rel="noopener noreferrer"&gt;Here&lt;/a&gt; is the directory tree in case u need it.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Zen
&lt;/h3&gt;

&lt;p&gt;This can be introduced as the best kernel for the day-to-day system. It is included features that are not included in the mainline(stable) Linux kernel. Zen kernel also supports the latest hardware. If you use Linux as your daily driver, giving Zen kernel a try is worth it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pacman -S linux-zen&lt;/code&gt; would install this kernel on your system.&lt;/p&gt;

&lt;p&gt;Find the source &lt;a href="https://github.com/zen-kernel/zen-kernel" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Longterm
&lt;/h3&gt;

&lt;p&gt;The Long Term Support or LTS kernel can be considered more stable than the conventional Linux kernel. However, this Kernel is lack of latest features of the Linux kernel.&lt;/p&gt;

&lt;p&gt;In the package manager, it's named as &lt;code&gt;linux-lts&lt;/code&gt;. You can install it as follows &lt;code&gt;pacman -S linux-lts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The source code for LTS kernel also resides at &lt;a href="https://www.kernel.org/" rel="noopener noreferrer"&gt;https://www.kernel.org/&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Hardened
&lt;/h3&gt;

&lt;p&gt;A kernel that is focused on security. This has hardening patches and security-oriented configurations for the kernel. Yet, this is very hard to use as it doesn't allow you to run executables.&lt;/p&gt;

&lt;p&gt;To install hardened kernel use &lt;code&gt;pacman -S linux-hardened&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/anthraxx/linux-hardened" rel="noopener noreferrer"&gt;Here&lt;/a&gt; is the source code for the hardened Linux kernel.&lt;/p&gt;

&lt;p&gt;To figure out what kernel you're currently using, try &lt;code&gt;uname -r&lt;/code&gt; command. Following is my daily driver.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F33v49ljpjw86e868q0uc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F33v49ljpjw86e868q0uc.png" width="154" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Install a Kernel
&lt;/h1&gt;

&lt;p&gt;For testing purposes, I use Artix Linux(It's the only lightweight distribution with a fast installation process I could find, besides it's systemd-free). And you can use whatever you want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fiwtsnrq8ipqoco23xd1j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fiwtsnrq8ipqoco23xd1j.png" alt="image.png" width="276" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before doing anything you need to decide what kernel you need. Once you figured it out, you can proceed.&lt;/p&gt;

&lt;p&gt;The kernel can be installed via the package manager. You can also compile the kernel and install it, but I don't want to talk about that here as it's way too complicated.&lt;/p&gt;

&lt;p&gt;Artix also uses &lt;code&gt;pacman&lt;/code&gt;, so...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fwkt1b5n7ia1stvat0nog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fwkt1b5n7ia1stvat0nog.png" alt="image.png" width="407" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you have the kernel installed. However as the &lt;code&gt;grub&lt;/code&gt; (or whatever your bootloader is) need to know that you have a new kernel. Because it's the one who spawns the kernel, right? (more about the boot process can be found &lt;a href="https://ethanrodrigo.hashnode.dev/the-linux-booting-process" rel="noopener noreferrer"&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;To inform grub that we have installed a new kernel, we have to regenerate the grub config file. The following command will do it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo grub-mkconfig -o /boot/grub/grub.cfg&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;See...It's that easy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fyggyf3k5gbbfp33t2hr6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fyggyf3k5gbbfp33t2hr6.png" alt="image.png" width="800" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then reboot the system to get the configuration working.&lt;/p&gt;

&lt;p&gt;Once booted, in the GRUB go to the &lt;code&gt;Advance options&lt;/code&gt; of the welcome menu.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE: I haven't used another boot-manager, therefore can't tell how it works on others. Just google what you want.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Foupw3yslgbjks17q96ur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Foupw3yslgbjks17q96ur.png" alt="image.png" width="800" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There you will find your freshly installed kernel. Press &lt;code&gt;Enter&lt;/code&gt; and start using the system with your new kernel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fml92g4hg09vtv0p66gsz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fml92g4hg09vtv0p66gsz.png" alt="image.png" width="573" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Delete a Kernel
&lt;/h1&gt;

&lt;p&gt;Well running a system without a kernel is far beyond the imagination. Yet, Linux let you do &lt;strong&gt;anything&lt;/strong&gt;. Therefore I would like to teach you how to delete a kernel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5nectuf3pri0hb6avjxs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5nectuf3pri0hb6avjxs.jpg" width="500" height="738"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;You get the kernel from the package manager, So delete it from there first.&lt;/p&gt;

&lt;p&gt;ex: &lt;code&gt;sudo pacman -Rs linux-lts&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fs5qa56jqm3n8qu3xq93k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fs5qa56jqm3n8qu3xq93k.png" alt="image.png" width="543" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Regenerate the grub configuration file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo grub-mkconfig -o /boot/grub/grub.cfg&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F7u0at1bm339vsws74zvd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7u0at1bm339vsws74zvd.png" alt="image.png" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Then reboot&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Thank you for reading! If you haven't subscribed to the newsletter, DO IT IMMEDIATELY! Then you would find my latest article in your inbox. If you have any problems, or doubts reach me on &lt;a href="https://twitter.com/EthanRodrigo8" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt;, &lt;a href="https://dev.to/ethanrodrigo"&gt;dev.to&lt;/a&gt; and &lt;a href="https://hashnode.com/@EthanRodrigo" rel="noopener noreferrer"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now go and execute &lt;code&gt;sudo rm -rf / --no-preserve-root&lt;/code&gt; and make tux happy. Until next time...&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>What is a Kernel?</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Sat, 19 Nov 2022 16:38:05 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/what-is-a-kernel-7a1</link>
      <guid>https://dev.to/ethanrodrigo/what-is-a-kernel-7a1</guid>
      <description>&lt;p&gt;In the world full of computers, there are hundreds of implementations of the same tool. When it comes to Linux, as it is an open source project thousand of tools has been made just to do one thing. &lt;/p&gt;

&lt;p&gt;Today, the topic is kernel. A mandatory concept while talking about computers. In this article let me introduce what really a kernel is and why it is important. Additionally few different types of kernels will be introduced. &lt;/p&gt;

&lt;p&gt;So, why are you waiting? Let's goooooooooo...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5IaXk3ba--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875723/kbvMTDx9V_ouvicx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5IaXk3ba--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875723/kbvMTDx9V_ouvicx.jpg" alt="image.png" width="402" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is a kernel?
&lt;/h1&gt;

&lt;p&gt;Well, first of all, what the heck is a kernel?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0V3myoHe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875739/j1_pu6Eqn_maolnn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0V3myoHe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875739/j1_pu6Eqn_maolnn.jpg" alt="image.png" width="597" height="760"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;According to the wikipedia;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The kernel is a computer program at the core of a computer's operating system and generally has complete control over everything in the system.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a nutshell the kernel is a component of an operating system, but the one in control. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1eAeN7EC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://y.yarn.co/a90638dc-86a5-4ed9-ad18-9b7c0d8bca9c_text.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1eAeN7EC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://y.yarn.co/a90638dc-86a5-4ed9-ad18-9b7c0d8bca9c_text.gif" alt="control.gif" width="400" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the startup the kernel is spawned by the &lt;a href="https://en.wikipedia.org/wiki/Bootloader"&gt;bootloader&lt;/a&gt; (to know how the Linux booting process works read &lt;a href="https://ethanrodrigo.hashnode.dev/the-linux-booting-process"&gt;this article&lt;/a&gt;) into the memory and it lives until you shutdown the system. &lt;/p&gt;

&lt;p&gt;The kernel is loaded into a separate area of memory, called kernel space, protected from application software. It prevents the conflicts with the user space in the memory, which is used by the application software. But things get difference with different kernels. We will look into that later in the article.&lt;/p&gt;

&lt;h4&gt;
  
  
  Difference with an OS
&lt;/h4&gt;

&lt;p&gt;Some gets confused with the OS and the kernel (mainly with Linux). In simple language the kernel interacts with hardware and makes an interface for the OS and other applications, OS on the other hand provides an interface between the user and the hardware.&lt;/p&gt;

&lt;h1&gt;
  
  
  What does kernel do?
&lt;/h1&gt;

&lt;p&gt;Kernel is an important component of an OS. But, what does it really do? why is it so important? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eNeidDpN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875754/tF7JJPMdW_ar1sg2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eNeidDpN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875754/tF7JJPMdW_ar1sg2.jpg" alt="image.png" width="220" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Memory Management
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Random-access_memory"&gt;Random Access Memory or RAM&lt;/a&gt; is one of the most vital devices in a computer. It’s where the instructions and data of the OS and other application are stored for immediate use. Programs load into memory, so does the kernel. &lt;/p&gt;

&lt;p&gt;The RAM is a vital, yet limited device. Therefore it has to be managed. As programs store the data and instructions in the RAM there can be multiple requests for memory. The kernel is what takes these requests and respond. &lt;/p&gt;

&lt;h3&gt;
  
  
  Device Management
&lt;/h3&gt;

&lt;p&gt;A computer uses devices to make it functional and more efficient. After all what's the usage of a computer without devices. Video cards, sound cards, printers, etc. can be few examples for devices we use day to day life. &lt;/p&gt;

&lt;p&gt;Yet, these devices can’t be used if you don’t have device drivers, specifying each device. &lt;a href="https://en.wikipedia.org/wiki/Device_driver"&gt;Device driver&lt;/a&gt; is a computer program that operates a particular devices that is attached to a computer. These drivers are managed by the kernel. &lt;/p&gt;

&lt;p&gt;Devices drivers usually ships with the kernel. If you want, you can add or remove a specific device driver. Again it differs with the kernel type. &lt;/p&gt;

&lt;h3&gt;
  
  
  Input/Output devices
&lt;/h3&gt;

&lt;p&gt;As other devices, IO(Input and Output) devices also has drivers in order to run successfully. While using the computer, different applications request to access IO devices. The kernel allocates these requests and provides a convenient method to use the device. &lt;/p&gt;

&lt;p&gt;These are few functions of a kernel. There are more to this such as &lt;a href="https://en.wikipedia.org/wiki/System_call"&gt;system calls&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Resource_management_(computing)"&gt;resource management&lt;/a&gt;, etc.&lt;/p&gt;

&lt;h1&gt;
  
  
  Types of kernel
&lt;/h1&gt;

&lt;p&gt;As mentioned on the start of this article, there can be hundreds of implementations for the same tool. Therefore we have a number of kernels today. Each of them has their own pros and cons. Let's now see what are some major types of kernels.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;a href="https://en.wikipedia.org/wiki/Monolithic_kernel"&gt;Monolithic kernels&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;In a Monolithic kernel all OS services run along with the main kernel thread and resides in the same memory area. This provides a rich and powerful hardware access. &lt;/p&gt;

&lt;p&gt;A Monolithic kernel has all the operating system core functions and the device drivers. In a nutshell it’s just one single program that contains all the code necessary to perform every kernel-related task. However one bug can crash the whole system.&lt;/p&gt;

&lt;p&gt;The kernel and its components (device drivers, file systems, etc.) are resides in the kernel space. Applications use system calls to communicate with them.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;a href="https://en.wikipedia.org/wiki/Microkernel"&gt;Microkernels&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Microkernels works with set of servers that communicate through a minimal kernel. This leaves a small amount in the kernel space and the rest lies in the user space. &lt;/p&gt;

&lt;p&gt;The kernel, which runs in the kernel space, has a minimal OS services such as memory management, inter-process communication, etc. Other services such as networking, file systems are implemented in user space programs, called servers. &lt;/p&gt;

&lt;p&gt;Servers allow the OS to be modified by simply starting and stopping programs. For example, a machine without a networking support is not started. &lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;a href="https://en.wikipedia.org/wiki/Hybrid_kernel"&gt;Hybrid(modular) kernels&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UQpjs-RN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875767/pkJcCg3ku_f6ic8s.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UQpjs-RN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875767/pkJcCg3ku_f6ic8s.jpg" alt="image.png" width="596" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s just the Microkernel but as an extension that has some Monolothic features. This is made of major advantages from both kernels. &lt;/p&gt;

&lt;p&gt;Hybrid kernel runs some of the services (network stack, filesystem, etc) in the kernel space.&lt;/p&gt;

&lt;p&gt;There are few other design approaches of kernel(&lt;a href="https://en.wikipedia.org/wiki/Nanokernel"&gt;Nanokernels&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Exokernel"&gt;Exokernels&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Multikernel"&gt;Multikernels&lt;/a&gt;). However it would be tedious to talk here.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this article we discussed about what is a kernel and what does it do. Additionally few kernel design approaches are also introduced here.&lt;/p&gt;

&lt;p&gt;In the next article let's play with one of the mostly used kernels, Linux. There I will walk you through how to add and remove kernels into your Linux system. &lt;/p&gt;

&lt;p&gt;If you haven't subscribed to the newsletter, DO IT IMMEDIATELY! Then you would find my latest article on your inbox. Thank you for reading! Now go and execute &lt;code&gt;sudo rm -rf / --no-preserve-root&lt;/code&gt; and make tux happy. Until next time...&lt;/p&gt;

&lt;p&gt;If you find this useful let's connect on &lt;a href="https://twitter.com/EthanRodrigo8"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/"&gt;Instagram&lt;/a&gt;, &lt;a href="https://dev.to/ethanrodrigo"&gt;dev.to&lt;/a&gt; and &lt;a href="https://hashnode.com/@EthanRodrigo"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Recover Deleted Files on Linux</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Wed, 28 Sep 2022 12:16:43 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/recover-deleted-files-on-linux-1lf1</link>
      <guid>https://dev.to/ethanrodrigo/recover-deleted-files-on-linux-1lf1</guid>
      <description>&lt;p&gt;We all are humans and we do make mistakes. Some can be recovered while some can't be. Same way accidentally deleting files can be happened even with an experienced Linux user. Therefore it would be great if the deleted files can be recovered.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE:&lt;/em&gt; The following concept and tactics &lt;em&gt;DO NOT&lt;/em&gt; apply if you've used &lt;code&gt;shred&lt;/code&gt;(or any other data overwriting tool), as it destroys the content of the file rather than deleting.&lt;/p&gt;

&lt;p&gt;Fortunately when a file is deleted it does not get removed right away. It just removes the link between the filename and the file, which makes it inaccessible to read (or write or do whatever by a user). Still, the file content is hidden in the file system. Therefore with the right tool you can access them and recover.&lt;/p&gt;

&lt;p&gt;However the content will get removed from the file system as you create new files in the system, which makes it harder to find the file. Yet, if you have a crashed file system or a hard drive these tools can be used to recover the files.&lt;/p&gt;

&lt;h1&gt;
  
  
  Trash
&lt;/h1&gt;

&lt;p&gt;Most of the Linux distributions provide a trash where you can put your unwanted files and recover them whenever you want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xNE150P3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1664366477554/y25m6o-x2.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xNE150P3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1664366477554/y25m6o-x2.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="509" height="339"&gt;&lt;/a&gt; And for cli users there's &lt;code&gt;trash-cli&lt;/code&gt; which implements the GUI trashcan.&lt;/p&gt;

&lt;h1&gt;
  
  
  TestDisk
&lt;/h1&gt;

&lt;p&gt;However trashcan doesn't work if you've use &lt;code&gt;rm&lt;/code&gt;, &lt;code&gt;unlink&lt;/code&gt;, etc. That's where &lt;code&gt;TestDisk&lt;/code&gt; comes into play.&lt;/p&gt;

&lt;p&gt;Here's what TestDisk is according to the &lt;a href="https://en.wikipedia.org/wiki/TestDisk"&gt;Wikipedia&lt;/a&gt;;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TestDisk is a free and open-source data recovery utility that helps users recover lost partitions or repair corrupted filesystems. TestDisk can collect detailed information about a corrupted drive...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes, it can also be used to recover corrupted partitions, but let's focus on recovering deleted files as for this article.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--smx2MgtB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1664194820340/YjNjXbYE8.jpg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--smx2MgtB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1664194820340/YjNjXbYE8.jpg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="weDontDoThatHere.jpg" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First install TestDisk with a package manager. &lt;code&gt;sudo pacman -S testdisk&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Or get binaries from &lt;a href="https://www.cgsecurity.org/wiki/TestDisk_Download"&gt;here&lt;/a&gt;. Note that TestDisk can be used on Windows and Mac OS also.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recovery
&lt;/h2&gt;

&lt;p&gt;I love cat memes, what about you? I have download some cat memes in a directory. Let me show you some.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KisKma-2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178223972/cgaWgfGe8.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KisKma-2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178223972/cgaWgfGe8.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="deletingCatMemes.png" width="643" height="107"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OOPS! I got deleted everything. What now?&lt;/p&gt;

&lt;p&gt;Fortunately I have TestDisk installed on my system. Therefore I'm going to fire it up.&lt;/p&gt;

&lt;p&gt;Type &lt;code&gt;testdisk&lt;/code&gt; on your terminal and press enter. You will see as below. Create a log file or not, then proceed further. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kv__6bsd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178389438/xesymi8Hj.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kv__6bsd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178389438/xesymi8Hj.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="testdisk0.png" width="628" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may prompt for a password and for that let your cat walk on the keyboard. If TestDisk let you in select a device, if not type the password.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ttjx8gmo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178422373/98Rd0wfBO.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ttjx8gmo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178422373/98Rd0wfBO.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="testDisk1.png" width="639" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, the partition table. Wait... you don't know your partition table? Just use what is selected, TestDisk is smart enough to find it out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8zoUMydx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179060744/TDPleMpYZ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8zoUMydx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179060744/TDPleMpYZ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="testDisk2.png" width="624" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navigate to &lt;code&gt;Advanced&lt;/code&gt;. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---1sKWnVn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178497189/VIxVdfVZL.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---1sKWnVn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178497189/VIxVdfVZL.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="testDisk3.png" width="642" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select your partition type. It would be &lt;code&gt;Linux&lt;/code&gt; most of the time. And then select &lt;code&gt;List&lt;/code&gt; in the list below. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3FRLG972--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178961365/38YsOxUu-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3FRLG972--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178961365/38YsOxUu-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="testDisk4.png" width="687" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you have your directory tree. From there navigate to the dir where the files are deleted. I'm going to search my &lt;code&gt;catMemes&lt;/code&gt; dir which is in the &lt;code&gt;Pictures&lt;/code&gt; dir. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kfBFPxzQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178976294/-RfXPmdQn.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kfBFPxzQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659178976294/-RfXPmdQn.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="testDisk5.png" width="594" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Woah! It's here. Can you see it? This is the whole list I've got deleted. Now as with the instruction below I select everything with &lt;code&gt;a&lt;/code&gt; and copy them to a dir.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--20H6k6iJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179080438/UQEGr5EvR.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--20H6k6iJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179080438/UQEGr5EvR.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="testDiskGotCatMemes.png" width="691" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following will be prompted. From here select what dir you want to put the recovered files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VEHC1BnK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179092414/HuVat0ps4R.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VEHC1BnK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179092414/HuVat0ps4R.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="testDisk6.png" width="559" height="185"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And press &lt;code&gt;C&lt;/code&gt; when the destination is reached and you will have your files copied into that dir.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N8KgRC5x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179102443/bwZROj1Eh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N8KgRC5x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179102443/bwZROj1Eh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="testDiskGotDeleted.png" width="784" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  PhotoRec
&lt;/h1&gt;

&lt;p&gt;Then we have the cousin of TestDisk; PhotoRec. PhotoRec comes with &lt;code&gt;testdisk&lt;/code&gt; package, which means if you have the TestDisk utility you should have &lt;code&gt;photorec&lt;/code&gt; also.&lt;/p&gt;

&lt;p&gt;The only difference between above two is, PhotoRec recovers more files. However the files are not in the original name and lot of unwanted files can be recovered while the process. Therefore if you want to look into a specific file I highly recommend using TestDisk. Still if you have a corrupted or bad hard drive that doesn't let you access files, you can use PhotoRec and recover most of the files.&lt;/p&gt;

&lt;p&gt;Go ahead and fire up the command &lt;code&gt;photorec&lt;/code&gt; and you'll get something as follows. As it suggests, select a disk to recover and then &lt;code&gt;Proceed&lt;/code&gt;. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V2Y4TYfM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581950230/4USUmEa5d.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V2Y4TYfM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581950230/4USUmEa5d.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="photorec0.png" width="638" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now select a partition. If you want to recover the whole disk, select &lt;code&gt;No partition&lt;/code&gt;, the first one. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1PAn6ZW8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581957083/UBnVZFZmM.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1PAn6ZW8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581957083/UBnVZFZmM.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="photorec1.png" width="611" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before selecting a partition, if you go to the &lt;code&gt;File Opt&lt;/code&gt; you will see something like this. Here you can select what file type you want to recover. You can tick a file type with the &lt;code&gt;left&lt;/code&gt; arrow and untick a one with the &lt;code&gt;right&lt;/code&gt; arrow. To exit press &lt;code&gt;Quit&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sgWrJEzo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663582131735/kEL3FGXcP.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sgWrJEzo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663582131735/kEL3FGXcP.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="photorecSelectFileType.png" width="547" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then select the filesystem type of the partion. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sXb5HuWg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663582037946/BLVOOPiW6.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sXb5HuWg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663582037946/BLVOOPiW6.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="photorec2.png" width="613" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you have the directory tree here. Select the directory your files have been stored. Once selected press &lt;code&gt;C&lt;/code&gt; to continue. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0FGPMQcc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581965896/YAdmT0rSd.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0FGPMQcc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581965896/YAdmT0rSd.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="photorec3.png" width="610" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The recovering process has started and you will be able to see the estimated time. If you have a big amount of files then you may have to wait for hours. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dR2l5Vsh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663582211829/mKWKjtvor.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dR2l5Vsh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663582211829/mKWKjtvor.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="photorecSavingProcess.png" width="626" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once completed you'll get the following result. You can access your deleted files within the directory given. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WsjsGmLb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581971040/kff5e5Hw3.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WsjsGmLb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581971040/kff5e5Hw3.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="photorecCompleted.png" width="618" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;PhotoRec&lt;/code&gt; recovers all, whether it is wanted or unwanted. After the recovery you can see a lot of unwelcoming files as below.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UmiYjtAd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581993009/J36Clj87c.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UmiYjtAd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663581993009/J36Clj87c.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="photorecShitting.png" width="724" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Thank you for reading! Now go and execute &lt;code&gt;sudo rm -rf / --no-preserve-root&lt;/code&gt; and make tux happy. Until next time.&lt;/p&gt;

&lt;p&gt;If you find this useful let's connect on &lt;a href="https://twitter.com/EthanRodrigo8"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/"&gt;Instagram&lt;/a&gt;, &lt;a href="https://dev.to/ethanrodrigo"&gt;dev.to&lt;/a&gt; and &lt;a href="https://hashnode.com/@EthanRodrigo"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Setup LVM for a Linux Installation</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Wed, 14 Sep 2022 08:37:15 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/setup-lvm-for-a-linux-installation-3ljn</link>
      <guid>https://dev.to/ethanrodrigo/setup-lvm-for-a-linux-installation-3ljn</guid>
      <description>&lt;p&gt;In Linux there are hundred of ways to get the same work done, and the overwhelming amount of distros makes the number thousand. However it's life saving if we choose the efficient way.&lt;/p&gt;

&lt;p&gt;The process of partitioning a hard drive in Linux is same as other stuff; we have got numerous approaches. Yet, there are more effective methods. The best I've met so far is LVM. LVM allows you to combine partitions, hard drives and use as one single partition (for more about LVM read the &lt;a href="https://ethanrodrigo.hashnode.dev/an-introduction-to-lvm"&gt;LVM introduction article&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;In this article I'll walk you through the setup of LVM for a Linux installation. Before procedure you need to have followings;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; A basic understanding of LVM (get it &lt;a href="https://ethanrodrigo.hashnode.dev/an-introduction-to-lvm"&gt;here&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt; A machine to install Linux on&lt;/li&gt;
&lt;li&gt; A bootable USB stick that has a Linux iso&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To get started, boot your Linux installation...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KR8sgUPW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663141773147/_nBcn2BUJ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KR8sgUPW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1663141773147/_nBcn2BUJ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="630" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Partitioning
&lt;/h1&gt;

&lt;p&gt;Though LVM is an alternative to conventional partition scheme, still we need to partition the hard drive we're going to install the OS on. The reason behind this is, &lt;code&gt;Grub&lt;/code&gt; and some other bootloaders doesn't support on LVM partitions. However other secondary partitions can be added without partitioning into a created Volume Group of LVM.&lt;/p&gt;

&lt;p&gt;Enough talking, let's get into the terminal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FG-fo2-m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1662208842396/Pt6XxN8Hj.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FG-fo2-m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1662208842396/Pt6XxN8Hj.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="430" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But wait, you need to find what kind of &lt;a href="https://en.wikipedia.org/wiki/Firmware"&gt;firmware&lt;/a&gt; you have got. Yes, go and find whether it's &lt;code&gt;BIOS&lt;/code&gt; or &lt;code&gt;UEFI&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What, you don't know how to? Oh! My bad, here's a command. Run it and find out. &lt;code&gt;ls /sys/firmware | grep efi&lt;/code&gt; Only the &lt;code&gt;UEFI&lt;/code&gt; system has got &lt;code&gt;efi&lt;/code&gt; directory inside &lt;code&gt;/sys/firmware&lt;/code&gt;. Therefore if there's no output as follows, yours is &lt;code&gt;BIOS&lt;/code&gt;. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y5GyEflR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659871662635/LHLWUg31w.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y5GyEflR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659871662635/LHLWUg31w.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="379" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok now, choose a hard drive. List all the hard drives on the system with &lt;code&gt;fdisk --list&lt;/code&gt; and select the drive you want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x8W_4snB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953394810/eT3KtizVR.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x8W_4snB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953394810/eT3KtizVR.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="519" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or try &lt;code&gt;lsblk&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zzNVe2cO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659955346607/W2EAzZFFg.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zzNVe2cO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659955346607/W2EAzZFFg.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="477" height="83"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  UEFI partitioning
&lt;/h2&gt;

&lt;h3&gt;
  
  
  UEFI vs EFI
&lt;/h3&gt;

&lt;p&gt;You may have heard &lt;code&gt;UEFI&lt;/code&gt; as well as &lt;code&gt;EFI&lt;/code&gt;. Is it entangling? let me break it down for you. &lt;code&gt;UEFI&lt;/code&gt; is the replacement of BIOS, which is a firmware. &lt;code&gt;EFI&lt;/code&gt; is the storage partition of &lt;code&gt;UEFI&lt;/code&gt;, which contains the bootloader.&lt;/p&gt;

&lt;p&gt;Let's get into partitioning with UEFI now.&lt;/p&gt;

&lt;p&gt;Launch fdisk with your selected hard drive. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qNTRmMyG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953536477/F_2K6MZWL.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qNTRmMyG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953536477/F_2K6MZWL.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="567" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In fdisk run &lt;code&gt;p&lt;/code&gt; command and see if there's any partitions. If you don't have any partitions it would look as follows. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bPGwCAXk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953672846/pZoRxaY0_.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bPGwCAXk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953672846/pZoRxaY0_.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="494" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or else it would list the partitions withing the hard drives &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HfZKkmSp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953717565/8wJmyZoWF.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HfZKkmSp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953717565/8wJmyZoWF.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="519" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you see any partitions there delete them with &lt;code&gt;d&lt;/code&gt; command. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SIgobgZq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953844583/3MwSdnFzN.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SIgobgZq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659953844583/3MwSdnFzN.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="529" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However in case you have stuff in a partitions that you don't want to delete, leave it. Yet, don't create partitions to store different file systems as you do in Windows. We are doing it with LVM here.&lt;/p&gt;

&lt;p&gt;It's time to create the &lt;code&gt;EFI&lt;/code&gt; partition. Follow the next steps in order to achieve it.&lt;/p&gt;

&lt;p&gt;Run command &lt;code&gt;n&lt;/code&gt; to create a new partition. For the &lt;code&gt;Partition type&lt;/code&gt; leave it as default (primary). &lt;code&gt;Partition number&lt;/code&gt; leave the &lt;code&gt;default&lt;/code&gt; number or choose a number within the given range as you wish. &lt;code&gt;First sector&lt;/code&gt;, leave default value. &lt;code&gt;Last sector&lt;/code&gt; is the actual size of the partition, therefore 500MB would be enough for the &lt;code&gt;EFI&lt;/code&gt; partion.&lt;/p&gt;

&lt;p&gt;The partition is labeled as &lt;code&gt;Linux&lt;/code&gt;. But to make it support &lt;code&gt;UEFI&lt;/code&gt; change the type into &lt;code&gt;EFI&lt;/code&gt; with command &lt;code&gt;t&lt;/code&gt; and for the Hex code, provide &lt;code&gt;ef&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BPCNfQQp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659954721082/C65pkKCDg.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BPCNfQQp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659954721082/C65pkKCDg.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="718" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the space left, create a normal partition. The type of the partition should be &lt;code&gt;Linux LVM&lt;/code&gt;, whose Hex code is &lt;code&gt;8e&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2yR91j6j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659954938693/Nwl1GH638.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2yR91j6j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659954938693/Nwl1GH638.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="694" height="504"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly write the changes to the disk and save with the &lt;code&gt;w&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LAlkZVN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659955034312/K24ug7IPb.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LAlkZVN---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659955034312/K24ug7IPb.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="386" height="97"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  BIOS partitioning
&lt;/h2&gt;

&lt;p&gt;Partitioning for &lt;code&gt;BIOS&lt;/code&gt; is really simple and we don't have to create multiple partitions. All we have to do is create a new partition and change its type to &lt;code&gt;Linux LVM&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Following example illustrates how the &lt;code&gt;BIOS&lt;/code&gt; partition is created. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zhsudb9x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659955514817/1Bk5XShl-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zhsudb9x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659955514817/1Bk5XShl-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="707" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting up LVM
&lt;/h1&gt;

&lt;p&gt;Now, it's time to set up LVM on the system. If you remember from my &lt;a href="https://ethanrodrigo.hashnode.dev/an-introduction-to-lvm"&gt;&lt;code&gt;LVM Introduction&lt;/code&gt;&lt;/a&gt; article, we have three main components in LVM.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Physical Volume (PV)&lt;/li&gt;
&lt;li&gt; Volume Group (VG)&lt;/li&gt;
&lt;li&gt; Logical Volume (LV)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;First Physical Volumes are created with the existing hard drive or partitions and then a Volume Group needs to be created and all the Physical Volumes can be added there. Then the VG can be sliced into Logical Volumes and one of them can be used to install the Linux system.&lt;/p&gt;

&lt;p&gt;Let's get into the terminal. Though I use Arch in following examples, it's general to all the other distributions.&lt;/p&gt;

&lt;p&gt;As for the start, create a PV from the partitioned hard drive and put it into a VG. At this moment if you have other hard drives do the same with them as well.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SDqELzaz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660127266821/B_ZxD_9zb.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SDqELzaz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660127266821/B_ZxD_9zb.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="491" height="118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the creation of the LVs comes in. Here you need to decide how many LVs you're going to use and what they are for. You can also leave some space for later usage, means without allocating them into any LV. After all, you just need a &lt;code&gt;/root&lt;/code&gt; partition for Linux to work fine. Still it's a better approach if you create a &lt;code&gt;/home&lt;/code&gt; partition for users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; In the below example I give only 2Gigs to the &lt;code&gt;root&lt;/code&gt; as I'm on a Virtual Machine, but it's better to use 10Gigs. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ouKxhFaE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660128625600/IB9o-Y04m.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ouKxhFaE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660128625600/IB9o-Y04m.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="697" height="143"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we need to load a kernel module for device mapping, &lt;code&gt;dm_mod&lt;/code&gt;. For that execute &lt;code&gt;modprobe dm_mod&lt;/code&gt; command. After that the VG can be activated with &lt;code&gt;vgchange -ay&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oKQ3btNA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660128135084/dEhnPrb-3.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oKQ3btNA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660128135084/dEhnPrb-3.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="485" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! The LVM partitions are now ready to hold a Linux installation.&lt;/p&gt;
&lt;h1&gt;
  
  
  Post setup
&lt;/h1&gt;

&lt;p&gt;Although the LVM setup is now done, there's some stuff left to do. These are general things we should do even we use conventional partition scheme.&lt;/p&gt;

&lt;p&gt;All LVs need to have a file system (or else how can they open and read files?). Choose a file system as you wish and launch &lt;a href="https://man7.org/linux/man-pages/man8/mkfs.8.html"&gt;&lt;code&gt;mkfs&lt;/code&gt;&lt;/a&gt; command with it. The basic syntax of &lt;code&gt;mkfs&lt;/code&gt; is as follows. &lt;code&gt;mkfs.$filesytem /dev/$vgName/$lvName&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$filesystem - the file system you have chosen
$vgName - name of the VG
$lvName - name of the LV
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I like to go with the popular &lt;code&gt;ext4&lt;/code&gt; file system. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7CvFPPAr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660128703884/wzC6JrIjC.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7CvFPPAr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660128703884/wzC6JrIjC.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="703" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, the LVs can be mounted into the system. The &lt;code&gt;root&lt;/code&gt; partition has to mounted into the &lt;code&gt;/mnt&lt;/code&gt; and the &lt;code&gt;home&lt;/code&gt; partition needs to be mounted into the &lt;code&gt;/mnt/home&lt;/code&gt; dir.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TyLxtG23--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660129064199/fAmVMkb0j.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TyLxtG23--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660129064199/fAmVMkb0j.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="526" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Linux Installation
&lt;/h1&gt;

&lt;p&gt;The LVM and the partitions are ready to go for the installation. Here I won't show you the installation as it's just the classical way of the installations. But remember to install the &lt;code&gt;lvm&lt;/code&gt; package as it doesn't come by default.&lt;/p&gt;

&lt;p&gt;If you install the system manually, like in Arch, Gentoo you can now &lt;code&gt;chroot&lt;/code&gt; into the &lt;code&gt;/mnt&lt;/code&gt; and install the system there. And if you use GUI installation, select the root and home(if have created a one) Logical Volumes in the installation process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Also remember to add &lt;code&gt;lvm&lt;/code&gt; into the &lt;code&gt;mkinitcpio&lt;/code&gt; and other initramfs. Yet, this is not required in GUI installations.&lt;/p&gt;

&lt;h1&gt;
  
  
  A script to automate the process
&lt;/h1&gt;

&lt;p&gt;As a programmer it's our responsibility to spend 10 hours on automating 5 minute task.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vKuS-0Hs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660129556184/v6Ok3IrvX.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vKuS-0Hs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1660129556184/v6Ok3IrvX.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="640" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I did the same with above process. You can find it &lt;a href="https://github.com/ethan-rod6/Automations"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can use it on both &lt;code&gt;BIOS&lt;/code&gt; and &lt;code&gt;EFI&lt;/code&gt; systems. Multiple hard drives can also be setup at once and there are more options. Try using &lt;code&gt;-h&lt;/code&gt; flag or analyze the source code. Pull requests are mostly welcomed.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Thank you for reading! Now go and execute &lt;code&gt;sudo rm -rf / --no-preserve-root&lt;/code&gt; and make tux happy. Until next time.&lt;/p&gt;

&lt;p&gt;If you find this useful let's connect on &lt;a href="https://twitter.com/EthanRodrigo8"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/"&gt;Instagram&lt;/a&gt;, &lt;a href="https://dev.to/ethanrodrigo"&gt;dev.to&lt;/a&gt; and &lt;a href="https://hashnode.com/@EthanRodrigo"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>lvm</category>
    </item>
    <item>
      <title>Remove files in Linux</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Tue, 02 Aug 2022 08:40:13 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/remove-files-in-linux-c7i</link>
      <guid>https://dev.to/ethanrodrigo/remove-files-in-linux-c7i</guid>
      <description>&lt;p&gt;Hello folks! An alien here with another Linux blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sb5XLKKo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179869073/ASpYxKMID.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sb5XLKKo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659179869073/ASpYxKMID.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="473" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today let's talk about deleting files. No seriously, It may seem little bit trivial, yet I'm going to dive deep. Will you join with me?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rhdGr6PC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://c.tenor.com/esp-_7TyBHcAAAAM/join-me-chrissy-costanza.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rhdGr6PC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://c.tenor.com/esp-_7TyBHcAAAAM/join-me-chrissy-costanza.gif" alt="img.gif" width="220" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;HEADS-UP:&lt;/em&gt; Following commands are for deleting files from the terminal, means it's not going to store in the trash. Therefore execute them on some unwanted files or just create a &lt;a href="https://en.wikipedia.org/wiki/Virtual_machine"&gt;Virtual Machine&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  rm
&lt;/h1&gt;

&lt;p&gt;Our first command is the great old classic &lt;code&gt;rm&lt;/code&gt;. But did you know there's more to the &lt;code&gt;rm&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;rm&lt;/code&gt; command doesn't let you delete directories (let me call it dirs now on) without specifying. The &lt;code&gt;-d&lt;/code&gt; flag specifies delete empty dirs. Similarly you can use &lt;code&gt;rmdir&lt;/code&gt; command to delete an empty dir(and it's the only use of &lt;code&gt;rmdir&lt;/code&gt;). However to delete a dir that has content needs a specific flag which is &lt;code&gt;-r&lt;/code&gt; or &lt;code&gt;-R&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0jRLjTJZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659284664188/DXdulVzhs.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0jRLjTJZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659284664188/DXdulVzhs.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="470" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not sure about what's being deleted? This can be occur while deleting dirs. You can use &lt;code&gt;-i&lt;/code&gt; flag to prompt before deleting each and every file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--usOkFjVE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659284481365/0o0abfWRb.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--usOkFjVE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659284481365/0o0abfWRb.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes while deleting, specially a file that's belong to the root, can prompt you for a confirmation as you're using &lt;code&gt;-i&lt;/code&gt; flag. It's bothering, isn't it? Just use &lt;code&gt;-f&lt;/code&gt; and it will delete the dir(s)/file(s) without asking. Still remember to use &lt;code&gt;-r&lt;/code&gt; if it's a dir.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iBYJq-nu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659284856931/o6bhAKUce.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iBYJq-nu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659284856931/o6bhAKUce.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="493" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're familiar with my articles you may have seen my conclusion encourages you to run &lt;code&gt;sudo rm -rf /* --no-preserve-root&lt;/code&gt;. It's a really good command that teaches you a lot of things, not only about Linux but also about life, suchlike don't trust bloggers on the internet.&lt;/p&gt;

&lt;p&gt;Well... what does &lt;code&gt;--no-preserve-root&lt;/code&gt; means? It tells the &lt;code&gt;rm&lt;/code&gt; command no to treat the &lt;code&gt;/&lt;/code&gt; (root) dir as a special one and let the &lt;code&gt;rm&lt;/code&gt; deletes what it contains. But if you do not use &lt;code&gt;--no-preserve-root&lt;/code&gt; it's not going to delete the &lt;code&gt;/&lt;/code&gt; as it calls &lt;code&gt;--preserve-root&lt;/code&gt; which is the converse by default. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k_bRL-r---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659336326155/heap7t9NC.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k_bRL-r---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659336326155/heap7t9NC.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="449" height="74"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yet, there's something called &lt;a href="https://man7.org/linux/man-pages/man7/glob.7.html#:~:text=Globbing%20is%20the%20operation%20that,string%2C%20including%20the%20empty%20string."&gt;globbing&lt;/a&gt; in Linux, which prevents &lt;code&gt;--preserve-root&lt;/code&gt; in rm. Frankly you don't have to use &lt;code&gt;--no-preserve-root&lt;/code&gt; if you use globbing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rm -rf /*&lt;/code&gt; means delete all the contents in the &lt;code&gt;/&lt;/code&gt; dir, besides it uses globbing (the &lt;code&gt;*&lt;/code&gt; character). Therefore it doesn't use &lt;code&gt;--preserve-root&lt;/code&gt;, while &lt;code&gt;rm -rf /&lt;/code&gt; means delete the &lt;code&gt;/&lt;/code&gt;, which uses &lt;code&gt;--preserve-root&lt;/code&gt;. Because of that if you do &lt;code&gt;sudo rm -rf /*&lt;/code&gt; you don't have to use &lt;code&gt;--no-preserve-root&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  unlink
&lt;/h1&gt;

&lt;p&gt;Speaking of deleting files in Linux we've also got &lt;code&gt;unlink&lt;/code&gt;. &lt;code&gt;unlink&lt;/code&gt; is not only a command but also a function in C (I know that PHP has that also, yet we don't do that here).&lt;/p&gt;

&lt;p&gt;According to the GNU &lt;a href="https://www.gnu.org/software/libc/manual/html_node/Deleting-Files.html"&gt;man page&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can delete a file with unlink...Deletion actually deletes a file name. If this is the file’s only name, then the file is deleted as well. If the file has other remaining names, it remains accessible under those names.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me explain it. Consider the meaning of the word unlink. Yes, it means removing a link from something that has a link. In Linux you can have multiple names for a single file. The creation of multiple names for a single file is called linking (Here I'm referring to &lt;a href="https://en.wikipedia.org/wiki/Hard_link"&gt;Hard Links&lt;/a&gt;). This doesn't copy the file, it simply makes a new name (an alias) to the file.&lt;/p&gt;

&lt;p&gt;In the following example I create a file in a dir named Test0 and create a link to that file from another dir called Test1. The file &lt;code&gt;here&lt;/code&gt; in the dir &lt;code&gt;Test1&lt;/code&gt; is not really a file, but a link to the file &lt;code&gt;hello&lt;/code&gt; in the dir &lt;code&gt;Test0&lt;/code&gt; &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K-ZhhPyY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658571825590/QVjzmXrcw.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K-ZhhPyY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658571825590/QVjzmXrcw.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="364" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you do &lt;code&gt;unlink&lt;/code&gt; (or even &lt;code&gt;rm&lt;/code&gt;) on a file name which is a link to another file locates elsewhere will be removed, not the file. However if the file doesn't have a link, the file will be deleted, which is equal to the &lt;code&gt;rm&lt;/code&gt; without frills.&lt;/p&gt;

&lt;h1&gt;
  
  
  find
&lt;/h1&gt;

&lt;p&gt;Before seeing deleting files with our next command, &lt;code&gt;find&lt;/code&gt;, let's have a look at what it really is.&lt;/p&gt;

&lt;h2&gt;
  
  
  find command
&lt;/h2&gt;

&lt;p&gt;Here's what &lt;a href="https://en.wikipedia.org/wiki/Find_(Unix)"&gt;find&lt;/a&gt; is according to the Wikipedia;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In Unix-like and some other operating systems, find is a command-line utility that locates files based on some user-specified criteria and either prints the pathname of each matched object or, if another action is requested, performs that action on each matched object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As the name suggest the command &lt;code&gt;find&lt;/code&gt; is used to find a file/dir. Additionally we can perform actions (another commands) on those found file/dirs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find [the path you want to look to into] -options [what to find]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The path - where the find command needs to exactly look into (use &lt;code&gt;.&lt;/code&gt; to refer the current working directory)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What to find - the file/dir name or a regex pattern to get multiple results&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let me give you a brief idea about the &lt;code&gt;find&lt;/code&gt; command with some examples.&lt;/p&gt;

&lt;p&gt;Let's create 100 files that has some random values and name with another random value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SdNqCBHD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658575441390/2p9Y9B73d.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SdNqCBHD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658575441390/2p9Y9B73d.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="661" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if I want to filter the files that has 10 in the name, I can do something as follow&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find . -name "*10*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this time I want only the directories to be filtered,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find . -type d -name "*10*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QByB1P3y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658576310493/bjkpUSzoq.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QByB1P3y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658576310493/bjkpUSzoq.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="721" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More about the &lt;code&gt;find&lt;/code&gt; command can be found &lt;a href="https://man7.org/linux/man-pages/man1/find.1.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  delete with find
&lt;/h2&gt;

&lt;p&gt;As this article is not about finding files, but deleting them, I'm stopping here with what else &lt;code&gt;find&lt;/code&gt; can do. Instead let's see how the &lt;code&gt;find&lt;/code&gt; command can be used to delete files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; It's fine if you're seeking for one file and delete them. But be careful if you're using &lt;code&gt;find&lt;/code&gt; with a regex pattern, as it's going to delete all the filtered files.&lt;/p&gt;

&lt;p&gt;There are three ways to delete with the &lt;code&gt;find&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; with -delete&lt;/p&gt;

&lt;p&gt;Below I delete files and dirs that has 13 in the filename.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Femr-znv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658753684088/aO-ptu1Yh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Femr-znv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658753684088/aO-ptu1Yh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="435" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And order matters. I use &lt;code&gt;-delete&lt;/code&gt; before the file name in the following example, which literally means &lt;code&gt;find files in the current working dir and delete them, then filter the files that has 23 in the name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--94Gsn5GU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658753932212/tfDrJIsOu.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--94Gsn5GU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658753932212/tfDrJIsOu.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="581" height="156"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; with -exec The &lt;code&gt;-exec&lt;/code&gt; flag of the find command is used to execute an action (a command) on the results. Therefore it's followed by another command, which in this case &lt;code&gt;rm&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The syntax for &lt;code&gt;rm&lt;/code&gt; with &lt;code&gt;find&lt;/code&gt;'s &lt;code&gt;-exec&lt;/code&gt; flag as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find [the path] -options [what to find] -exec rm {} \;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;{}&lt;/code&gt; - refers to the current file that is being processed&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;\&lt;/code&gt; - escape character for &lt;code&gt;;&lt;/code&gt;, it also can be quoted with double quotations (";")&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;;&lt;/code&gt; - to indicate the end of the command&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FrTg8UwT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659338129364/yO6mDgICU.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FrTg8UwT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659338129364/yO6mDgICU.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="457" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; with &lt;code&gt;xargs&lt;/code&gt; As for the &lt;a href="https://en.wikipedia.org/wiki/Xargs"&gt;Wikipedia&lt;/a&gt;;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;xargs (short for "eXtended ARGumentS" [1]) is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The command &lt;code&gt;xargs&lt;/code&gt; just takes output from a command and pass it into another as arguments.&lt;/p&gt;

&lt;p&gt;For the deletion with find, we can pipe it with &lt;code&gt;xargs&lt;/code&gt; as following syntax;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find [the path] -options [what to find] | xargs -I {} rm "{}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;-I&lt;/code&gt; - replace &lt;code&gt;{}&lt;/code&gt; with the find's results.&lt;/li&gt;
&lt;li&gt;  rm "{}" - execute &lt;code&gt;rm&lt;/code&gt; on filtered files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k4ejbEty--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659339133471/xm64nsX3l.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k4ejbEty--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1659339133471/xm64nsX3l.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="541" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  shred
&lt;/h2&gt;

&lt;p&gt;Now I give you a bomb. A bomb that can blast your Linux system or make your day even worse than what it is so far.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qYXexkNB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.giphy.com/media/3ohzdDCc4CNx1IBCda/giphy.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qYXexkNB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.giphy.com/media/3ohzdDCc4CNx1IBCda/giphy.webp" alt="bomb.gif" width="480" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This one is for destroying the file, or a hard drive. The &lt;code&gt;shred&lt;/code&gt; command can be used when you need to destroy a file before deleting, so nobody can find what was there.&lt;/p&gt;

&lt;p&gt;Try shredding a file and you will get something as following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Uap_qdAn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658902209498/z2UeQ7ANg.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uap_qdAn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658902209498/z2UeQ7ANg.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="706" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What the &lt;code&gt;shred&lt;/code&gt; command really does is, it overwrites the content of a file. To make it even harder to recover with expensive recovering software, &lt;code&gt;shred&lt;/code&gt; overwrites the file multiple times.&lt;/p&gt;

&lt;p&gt;Not only files but hard drives also can be overwritten by the &lt;code&gt;shred&lt;/code&gt; command. To overwrite a hard drive, just pass the path of the hard drive to the &lt;code&gt;shred&lt;/code&gt; command. For example, execute following in order to overwrite the &lt;code&gt;sda1&lt;/code&gt; partition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;shred /dev/sda1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;According to the man page, &lt;code&gt;shred&lt;/code&gt; overwrites the file three times. To change that you can use &lt;code&gt;-n&lt;/code&gt; flag to repeat the overwriting process for n times. See how &lt;code&gt;shred&lt;/code&gt; without frills works and with the &lt;code&gt;-n&lt;/code&gt; flag. (The flag &lt;code&gt;-v&lt;/code&gt; stands for verbose)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MaQDWTqq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658902959980/0wIoHqxCO.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MaQDWTqq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1658902959980/0wIoHqxCO.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="772" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to the above there, are few more flags, such as &lt;code&gt;-f&lt;/code&gt; to change the permissions to allow writing if necessary. &lt;a href="https://man7.org/linux/man-pages/man1/shred.1.html"&gt;Here&lt;/a&gt; is the man page.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this article we discussed about removing files and dirs from a Linux system. However what if you deleted something accidentally? What if you want something that you didn't want and deleted?. The answer will be in a next article. If you haven't subscribed to the newsletter, DO IT IMMEDIATELY! Then you would find my latest article on your inbox.&lt;/p&gt;

&lt;p&gt;Thank you for reading! Now go and execute &lt;code&gt;sudo rm -rf / --no-preserve-root&lt;/code&gt; and make tux happy. Until next time.&lt;/p&gt;

&lt;p&gt;If you find this useful let's connect on &lt;a href="https://twitter.com/EthanRodrigo8"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/"&gt;Instagram&lt;/a&gt;, &lt;a href="https://dev.to/ethanrodrigo"&gt;dev.to&lt;/a&gt; and &lt;a href="https://hashnode.com/@EthanRodrigo"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>An introduction to LVM</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Wed, 27 Jul 2022 05:53:50 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/an-introduction-to-lvm-323a</link>
      <guid>https://dev.to/ethanrodrigo/an-introduction-to-lvm-323a</guid>
      <description>&lt;p&gt;Hello guys! Your favorite Linux blogger here(Cough... Cough...)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gPFDj79---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1654685232876/JOD0yTRQh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gPFDj79---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1654685232876/JOD0yTRQh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="602" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today I'm here with another interesting Linux tool. This one would help you with partitioning block devices in Linux. The tool is called &lt;code&gt;LVM&lt;/code&gt; and this article would be an introduction for that. Without further delay, let's start.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EEzfs4VZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1654511145078/zLOc3FnYo.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EEzfs4VZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1654511145078/zLOc3FnYo.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="639" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Logical Volume Management
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is Logical Volume Management?
&lt;/h2&gt;

&lt;p&gt;According to the &lt;a href="https://en.wikipedia.org/wiki/Logical_volume_management"&gt;Wikipedia&lt;/a&gt;;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In computer storage, logical volume management or LVM provides a method of allocating space on mass-storage devices that is more flexible than conventional partitioning schemes to store volumes. In particular, a volume manager can concatenate, stripe together or otherwise combine partitions (or block devices in general) into larger virtual partitions that administrators can re-size or move, potentially without interrupting system use&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SAfL5HC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1652176659915/Opp-dq2_r.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SAfL5HC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1652176659915/Opp-dq2_r.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Confused? Don't worry, I've got your back. LVM does nothing but combine all the &lt;a href="https://en.wikipedia.org/wiki/Device_file#BLOCKDEV"&gt;block devices&lt;/a&gt; into one or more virtual partition. Simple af, isn't it?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But how it really works?&lt;/strong&gt; Let me explain it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working of LVM
&lt;/h2&gt;

&lt;p&gt;Before dig into the functioning of the LVM, let's get familiar with few LVM terms.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Physical Volume&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the fundamental part of LVM. A Physical Volume is nothing more than a block device. It is composed with a sequence of small chunks called &lt;em&gt;Physical Extents&lt;/em&gt;(PE). PEs are the smallest storage blocks on a Physical Volume.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Volume Group&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A Volume Group is a container that stores the Physical Volumes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Logical Volume&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A Volume Group can be sliced up into Logical Volumes. This is almost equal to normal partition, except that it sits upon the Volume Group instead of the raw disk. A Logical Volume is formed with small chunks called Logical Extents (LE).&lt;/p&gt;

&lt;p&gt;Now, let's get into the working of LVM&lt;/p&gt;

&lt;p&gt;First the typical hard disks should be converted into Physical Volumes. Then each PEs in those PVs map to LEs, and these LEs are pooled into a Volume Group. At the end the pooled LEs are concatenated into virtual disks called Logical Volumes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vM0wnrqu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653298754997/HbyJyELT5.jpg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vM0wnrqu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653298754997/HbyJyELT5.jpg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="LVMArchitechture.jpg" width="794" height="1123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A typical partitioning scheme slice a raw disks into partitions and then the filesystem can be installed on that device. Apart from that, LVM creates a Physical Volume from the disk and put it into a Volume Group. Then the Logical Volumes, which are almost similar to the conventional partitions are pooled into the Volume Groups.&lt;/p&gt;

&lt;p&gt;Major advantage of using LVM over conventional partitioning scheme is that Logical Volumes can be resized, but partitions can not. Additionally a new hard disk can be added to the Volume group and a slice from that hard disk can be added to a existing Logical Volume.&lt;/p&gt;

&lt;h1&gt;
  
  
  Logical Volume Manager
&lt;/h1&gt;

&lt;p&gt;Here's the Wikipedia's idea;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Logical Volume Manager is a device mapper that uses Logical Volume Management for the Linux kernel.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Simply Logical Volume Manager is the tool that uses Logical Volume Management concept for block device partitioning in Linux.&lt;/p&gt;

&lt;h1&gt;
  
  
  Managing block devices with LVM
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Physical Volume
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Creation
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;pvcreate&lt;/code&gt; is used for creation of physical volumes. It initializes a Physical Volume with a block device and writes a LVM disk label.&lt;/p&gt;

&lt;p&gt;To create a physical volume just add the hard drive (or any other block device) after the &lt;code&gt;pvcreate&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jJTZrE2c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653132345560/0O-lHCN0D.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jJTZrE2c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653132345560/0O-lHCN0D.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="484" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;pvs&lt;/code&gt; command can be used to see how many pvs are there and how much free storage it has.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shrinking
&lt;/h3&gt;

&lt;p&gt;Physical Volumes can be shrink into a desired size. &lt;code&gt;pvresize&lt;/code&gt; command is can be used for this.&lt;/p&gt;

&lt;p&gt;To resize the Physical Volume use &lt;code&gt;pvresize --setphysicalvolumesize [size] [PV]&lt;/code&gt;, where size can be 1G, 100G or any size and PV is the Physical Volume to be resized.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mtv3OrAM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653132616271/nz6HjFjR4.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mtv3OrAM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653132616271/nz6HjFjR4.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="706" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Volume Groups
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Creation
&lt;/h3&gt;

&lt;p&gt;In order to create a Volume Group, &lt;code&gt;vgcreate&lt;/code&gt; command can be used.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;vgcreate&lt;/code&gt; command takes a name for the Volume Group and the Physical Groups that has to be added into the Volume Group as mandatory arguments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T-_VVYcl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653209402720/z0EaVNiWv.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T-_VVYcl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653209402720/z0EaVNiWv.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="354" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The block devices can be also assign to a Volume Group without making it a Physical Volume first. When this happens &lt;code&gt;vgcreate&lt;/code&gt; automatically creates a Physical Volume with that device/s.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BM60LYve--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653209568712/p9dzVzmB-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BM60LYve--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653209568712/p9dzVzmB-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="457" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;vgs&lt;/code&gt; command can be used to display information about volume groups.&lt;/p&gt;

&lt;h3&gt;
  
  
  Renaming of Volume Groups
&lt;/h3&gt;

&lt;p&gt;Once a Volume Group is created, the name can be changed. The command is &lt;code&gt;vgrename&lt;/code&gt; and it takes &lt;code&gt;/dev/oldName&lt;/code&gt; and &lt;code&gt;/dev/newName&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WDEdMdUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653209857972/1Iz7Nh2Pq.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WDEdMdUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653209857972/1Iz7Nh2Pq.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="457" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Addition and removal of Physical Volumes from a Volume Group
&lt;/h3&gt;

&lt;p&gt;To add a new Physical Volume the &lt;code&gt;vgextend&lt;/code&gt; command can be used.&lt;/p&gt;

&lt;p&gt;It's the usual way as the &lt;code&gt;vgcreate&lt;/code&gt; command does. Just supply the Volume Group name and the new Physical Volume.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nP3L3Ems--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653211028118/MzqjXWYMk.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nP3L3Ems--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653211028118/MzqjXWYMk.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="426" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or else a block device can be directly added to a Volume Group as &lt;code&gt;vgcreate&lt;/code&gt; does.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N2gineOJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653210974643/wT8wGLvHi.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N2gineOJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653210974643/wT8wGLvHi.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="419" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command &lt;code&gt;vgreduce&lt;/code&gt; can be used to remove a Physical Volume from the Volume Group.&lt;/p&gt;

&lt;p&gt;Note that &lt;code&gt;vgreduce&lt;/code&gt; is not going to delete any Physical Volumes. It just remove it from the Volume Group.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZO6_Ql96--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653217564536/xy7zXA18G.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZO6_Ql96--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653217564536/xy7zXA18G.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="385" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Caution: Move data on the Physical Volume to another before removing a Physical Volume.&lt;/p&gt;

&lt;p&gt;Use the command &lt;code&gt;pvmove&lt;/code&gt; to move data from a one Physical Volume to another. &lt;code&gt;pvmove&lt;/code&gt; takes the Physical Volume that you need to be emptied.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W-uIewZd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653212865068/zRSB-qRbZ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W-uIewZd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653212865068/zRSB-qRbZ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="475" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Additionally you can provide another Physical Volume where the data would be copied. This means you can also use &lt;code&gt;pvmove&lt;/code&gt; to remove a hard disk and add a new one, if you're using LVM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Logical Volumes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Creation
&lt;/h3&gt;

&lt;p&gt;Creation of Logical Volumes are quiet simple. You guessed it right, the command &lt;code&gt;lvcreate&lt;/code&gt; is the one that is used to create a Logical Volume.&lt;/p&gt;

&lt;p&gt;The command &lt;code&gt;lvcreate&lt;/code&gt; takes the size in two different ways.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;-L&lt;/code&gt; - When the &lt;code&gt;-L&lt;/code&gt; is used the size needs to be given with the Megabytes, Gigabytes, etc. Default is Megabytes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8CJx20TV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653214187272/6z94oMJ7u.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8CJx20TV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653214187272/6z94oMJ7u.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="634" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;-l&lt;/code&gt; - The &lt;code&gt;l&lt;/code&gt; is quiet complicated and cool at the same time. Instead of using Bytes to give the size, &lt;code&gt;l&lt;/code&gt; needs the size in extents.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The common way to provide this is using &lt;code&gt;%&lt;/code&gt; sign. look into &lt;a href="https://linux.die.net/man/8/lvcreate"&gt;this man page&lt;/a&gt; for more info on &lt;code&gt;l&lt;/code&gt; option with &lt;code&gt;%&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is an example of using the 100% of the free storage in the Volume Group.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SiN4z3My--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653214760257/SU5xVxXr-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SiN4z3My--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653214760257/SU5xVxXr-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="642" height="102"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that &lt;code&gt;lvs&lt;/code&gt; command is used to get the info on Logical Volumes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Renaming
&lt;/h3&gt;

&lt;p&gt;For renaming the &lt;code&gt;lvrename&lt;/code&gt; command can be used. It can used in two ways.&lt;/p&gt;

&lt;p&gt;First you can give the &lt;code&gt;old&lt;/code&gt; and &lt;code&gt;new&lt;/code&gt; names with &lt;code&gt;/dev/[vgname]&lt;/code&gt; prefix. Or else just provide the Volume Group name followed by the &lt;code&gt;old&lt;/code&gt; and &lt;code&gt;new&lt;/code&gt; names.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XfwSk8W7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653217484896/5p2azen4r.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XfwSk8W7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653217484896/5p2azen4r.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="657" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Resizing
&lt;/h3&gt;

&lt;p&gt;This is the best part of LVM and this is why you should use it. Yet, resizing of a Logical Volume is risky. If you do it in a wrong manner all the data can be corrupted and sometimes you won't be able to get them back.&lt;/p&gt;

&lt;p&gt;Here's a real experience. It's 22 May as I remember and I finished this article until the preceding paragraph. And I was getting out of storage on root. I had 5Gigs left on the Volume Group. Therefore I did &lt;code&gt;lvextend&lt;/code&gt; and BOOM the file system hadn't resized. Then I ran some commands and got a some kind of a kernel panic, and I realized some files had been deleted and I could not even run &lt;code&gt;pacman&lt;/code&gt; to re-install the kernel. Then what? I re-install the whole OS.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE:&lt;/em&gt; Once the LV is resized without resizing the file system can be restored sometimes. It's the commands that you run for resizing file system that makes the system corrupted.&lt;/p&gt;

&lt;p&gt;WOAH! wait... Don't afraid that much. Let me help you with this. Ironic, huh? Anyway let me show how to do this properly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p-5wjQxL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653215802446/TA5QUiUKs.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p-5wjQxL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653215802446/TA5QUiUKs.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="275" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem here is whenever a Logical Volume is resized, not only the LV is resized, but the filesystem would also be changed. Therefore the filesystem on it also should be resized according to the size of the LV in order to make it work.&lt;/p&gt;

&lt;p&gt;There's two attempts you can try;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; The &lt;code&gt;resize2fs&lt;/code&gt; command&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This command is used to resize the file system. It takes a unmounted device as a compulsory argument.&lt;/p&gt;

&lt;p&gt;If you need to reduce the LV size run the &lt;code&gt;resize2fs&lt;/code&gt; command with the &lt;code&gt;-M&lt;/code&gt; flag, which means &lt;code&gt;Magic&lt;/code&gt;. Just kidding! The &lt;code&gt;-M&lt;/code&gt; flag shrinks the filesystem to the minimum size.&lt;/p&gt;

&lt;p&gt;Then you can use &lt;code&gt;lvresize&lt;/code&gt; for shrinking the LV. After that run &lt;code&gt;resize2fs&lt;/code&gt; without frills.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---YscxZw2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653217421827/2QHcPAjdl.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---YscxZw2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653217421827/2QHcPAjdl.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="666" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If it gives you an error, run &lt;code&gt;e2fsck -fy /dev/[VG_Name]/[LV_Name]&lt;/code&gt;, which is going to fix the file system.&lt;/p&gt;

&lt;p&gt;And If you want to extend the size, you just have to run &lt;code&gt;lvresize&lt;/code&gt; followed by &lt;code&gt;resize2fs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J1mWaCa3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653217385885/AHJOMjU2Z.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J1mWaCa3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653217385885/AHJOMjU2Z.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="669" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;code&gt;resizefs&lt;/code&gt; in one go&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;lvresize&lt;/code&gt; command also have an argument, &lt;code&gt;resizefs&lt;/code&gt;. However it can be used only with ext2, ext3, ext4, ReiserFS and XFS file systems. Anything other than them should use the attempt 1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DLIcOVVy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653218384783/rovHdkQAM.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DLIcOVVy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653218384783/rovHdkQAM.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="667" height="615"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;lvextend&lt;/code&gt; and &lt;code&gt;lvreduce&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;lvextend&lt;/code&gt; and &lt;code&gt;lvreduce&lt;/code&gt; commands are also used for resizing of Logical Volumes. The &lt;code&gt;-l&lt;/code&gt; and &lt;code&gt;-L&lt;/code&gt; are also used here and you can serve extents or size respectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CAUTION:&lt;/strong&gt; Here also remember to use &lt;code&gt;resize2fs&lt;/code&gt; or else you would loose the file system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remove LVs
&lt;/h3&gt;

&lt;p&gt;Be cautious with the removal of LVs also. First make sure you have backed up all your data. Then cheAs this article is not about finding files, but deleting them, let's see the &lt;code&gt;find&lt;/code&gt; command can be used to delete files. ck whether the LV you want to remove is unmounted. If it's not unmount it first.&lt;/p&gt;

&lt;p&gt;The removal process is done with the command &lt;code&gt;lvremove&lt;/code&gt;, which takes &lt;code&gt;VG_Name/LV_Name&lt;/code&gt; as mandatory arguments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6hA2aSAk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653219085381/MA5tdysWk.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6hA2aSAk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1653219085381/MA5tdysWk.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="661" height="193"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this article we have gone through the basics of LVM. We have discussed how LVM works and creation, deletion and other action done with LVs, PVs and VGs.&lt;/p&gt;

&lt;p&gt;In the next article let's see how to partition devices with LVM for installation of Linux. If you haven't subscribed to the newsletter, DO IT IMMEDIATELY! Then you would find my latest article on your inbox.&lt;/p&gt;

&lt;p&gt;Thank you for reading! 😊😊 Now go and execute &lt;code&gt;sudo rm -rf /* --no-preserve-root&lt;/code&gt; and make tux happy 🐧. Until next time 👋👋👋.&lt;/p&gt;

&lt;p&gt;If you find this useful let's connect on &lt;a href="https://twitter.com/EthanRodrigo8"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/"&gt;Instagram&lt;/a&gt;, &lt;a href="https://dev.to/ethanrodrigo"&gt;dev.to&lt;/a&gt; and &lt;a href="https://hashnode.com/@EthanRodrigo"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Analyze Linux Logs</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Mon, 25 Apr 2022 12:21:49 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/analyze-linux-logs-1328</link>
      <guid>https://dev.to/ethanrodrigo/analyze-linux-logs-1328</guid>
      <description>&lt;p&gt;Hello everyone! I'm back after an eternity. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TUnrIGVS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650880370971/KjLWbWit8.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TUnrIGVS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650880370971/KjLWbWit8.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="430" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, let's dive into the topic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bgWMKDMG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650880189599/fMB6ZK1Ci.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bgWMKDMG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650880189599/fMB6ZK1Ci.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="471" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Errors in Linux can be so hard to find sometime, as you can't see lot of issues with GUI. However Linux has few tools for gathering logs, and with that logs you can find what is going on.&lt;/p&gt;

&lt;p&gt;Today I'm here with two tools that is used by Linux for logging. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dmesg&lt;/li&gt;
&lt;li&gt;journalctl (Yeah... You are right, there is a connection with &lt;code&gt;systemd&lt;/code&gt;.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But before we start, please refer to my last posts about systemd, If you want to know what &lt;code&gt;systemd&lt;/code&gt; is and how it works. And get &lt;code&gt;systemd&lt;/code&gt; installed on your system to use &lt;code&gt;journalctl&lt;/code&gt;. You can find them &lt;a href="https://ethanrodrigo.hashnode.dev/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  journalctl
&lt;/h1&gt;

&lt;p&gt;journalctl is used to query the content of systemd journals. &lt;/p&gt;

&lt;h2&gt;
  
  
  journalctl? or journald?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;journald&lt;/code&gt; is the daemon spawned by systemd to collects logs from various log sources. It is also responsible for creation and maintenance of journals that are received from various resources.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--unsCjEGM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650880954502/UbmKAc5sd.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--unsCjEGM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650880954502/UbmKAc5sd.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;journalctl&lt;/code&gt; is the cli-tool that lets you interact with journals created by journald. With &lt;code&gt;journalctl&lt;/code&gt; you can read, monitor and filter logs in real time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the System Time
&lt;/h2&gt;

&lt;p&gt;Let me interrupt for a second. The logs are recorded in UTC or local time, and because of that you need to setup your timezone correctly. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;systemd&lt;/code&gt; suite comes with a handy tool called &lt;code&gt;timedatectl&lt;/code&gt; that can help with this.&lt;/p&gt;

&lt;p&gt;Follow the steps below to set it up.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;timedatectl list-timezones&lt;/code&gt; -- This will list the timezones available on your system. Choose a one.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sudo timedatectl set-timezone [zone]&lt;/code&gt; -- Once you find your timezone, set it up with this command, where &lt;code&gt;zone&lt;/code&gt; is the timezone you have chosen.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;timedatectl status&lt;/code&gt; -- Execute this (or &lt;code&gt;timedatectl&lt;/code&gt; alone) to ensure that your machine is using the correct time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pAvOSvcx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650708253844/-HcotuT0a.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pAvOSvcx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650708253844/-HcotuT0a.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="466" height="135"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  journalctl without frills
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;journalctl&lt;/code&gt;commnad would give the journal logs in chronological order, i.e. they are arranged according to the time. It uses &lt;code&gt;less&lt;/code&gt; underneath which means you can use the same keys to move around the logs as you do with &lt;code&gt;less&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OkhXihqi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1649933127228/ndLGnnnkM.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OkhXihqi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1649933127228/ndLGnnnkM.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yet, if you don’t want to see the logs in a less-like order, you can use &lt;code&gt;--no-pager&lt;/code&gt; flag.Which display the all logs in the terminal. Trust me though, that would be a mess. Therefore use it with &lt;code&gt;grep&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The raw &lt;code&gt;journalctl&lt;/code&gt; command gives you the old logs first. However if you want the recent logs to be displayed first you can use &lt;code&gt;--reverse&lt;/code&gt; or &lt;code&gt;-r&lt;/code&gt; flags to view the logs in reverse order. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9CgzPM0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882006805/e7PcP7Jxs.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9CgzPM0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882006805/e7PcP7Jxs.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  filtering the journal logs?
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;-n&lt;/code&gt; flag to define the number of the logs you want. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JPKDcD2F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650430097702/HbX4yHohY.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JPKDcD2F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650430097702/HbX4yHohY.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  according to a time stamp
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;-f&lt;/code&gt; flag would give you the logs in real time, that is it shows the logs that are currently being written.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jLZ5TCfa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882124342/tG7rrjQ4c.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jLZ5TCfa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882124342/tG7rrjQ4c.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want logs from a specific time period you can use &lt;code&gt;-S&lt;/code&gt; and &lt;code&gt;-U&lt;/code&gt; flags, which indicates time since and until.&lt;/p&gt;

&lt;p&gt;ex: &lt;code&gt;journalctl -S 2022-01-22 -U 2022-01-25&lt;/code&gt; gives you the logs since 22nd of January until 25th.&lt;/p&gt;

&lt;p&gt;The relative time is also allowed in &lt;code&gt;journalctl&lt;/code&gt;. The &lt;code&gt;h&lt;/code&gt;, &lt;code&gt;d&lt;/code&gt;, &lt;code&gt;w&lt;/code&gt; and &lt;code&gt;m&lt;/code&gt; flags specify hours, days, weeks and months respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LYT3tWnv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882340913/VnrKSlU5S.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LYT3tWnv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882340913/VnrKSlU5S.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also define the time with words using &lt;code&gt;yesterday&lt;/code&gt;, &lt;code&gt;today&lt;/code&gt; and &lt;code&gt;tomorrow&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aBD3hRhT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882428154/WYIlHBPOX.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aBD3hRhT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882428154/WYIlHBPOX.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  with data fields
&lt;/h3&gt;

&lt;p&gt;In order to filter the output with data fields use &lt;code&gt;THEFILED=field-you-want&lt;/code&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MTOsT6Dm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650879792418/DGsH3zuzQ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MTOsT6Dm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650879792418/DGsH3zuzQ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll find list of data fields &lt;a href="https://man7.org/linux/man-pages/man7/systemd.journal-fields.7.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want to list out all the values that have been used for a data field you can use &lt;code&gt;-F&lt;/code&gt; flag.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zc_pvfWi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650879852705/IPkQs0pkb.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zc_pvfWi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650879852705/IPkQs0pkb.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="217" height="655"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  change the output format
&lt;/h2&gt;

&lt;p&gt;Because the journal is a binary file, the data need to be translated into plain text. Thus, we can present the output in different output format.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;-o&lt;/code&gt; flag is used define the output format.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dWj7A2Pk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882674028/-KWaKtsz3.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dWj7A2Pk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650882674028/-KWaKtsz3.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following are some output formats you can use, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;short&lt;/li&gt;
&lt;li&gt;verbose&lt;/li&gt;
&lt;li&gt;export&lt;/li&gt;
&lt;li&gt;json&lt;/li&gt;
&lt;li&gt;cat&lt;/li&gt;
&lt;li&gt;with-unit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;PS: you can find a list of formats in the &lt;code&gt;man&lt;/code&gt; page also&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  boot message
&lt;/h2&gt;

&lt;p&gt;If you have got an error relating to the booting process and want to check for that, &lt;code&gt;journalctl&lt;/code&gt; have you hold.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;-b&lt;/code&gt; flag lists out entries related to each boot. &lt;code&gt;-b&lt;/code&gt; without extra filters list the entries of the last boot. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NSi69E82--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650531475264/rvnJJsJpF.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NSi69E82--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650531475264/rvnJJsJpF.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to get logs of a specific boot, the boot ID should be prescribed. It can be retrieved using &lt;code&gt;--list-boots&lt;/code&gt; flag.&lt;br&gt;
The boot ID is the second one as depicted below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dpsX3S3D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706112788/Qio2sgOkw.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dpsX3S3D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706112788/Qio2sgOkw.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="788" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now just add the &lt;code&gt;identifier&lt;/code&gt;, which is the longs number from &lt;code&gt;list-boots&lt;/code&gt; after the &lt;code&gt;-b&lt;/code&gt; to get the logs of a specific boot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h1dGFPd6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706182975/2R6v9l0QL.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h1dGFPd6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706182975/2R6v9l0QL.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  kernel message
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;-k&lt;/code&gt; flag would give you the kernel messages. This is same as using &lt;code&gt;dmesg&lt;/code&gt;.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LNN0cHVs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706474405/8lXgUNStG.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LNN0cHVs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706474405/8lXgUNStG.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  manage storage
&lt;/h2&gt;

&lt;p&gt;The storage that is used by &lt;code&gt;journalctl&lt;/code&gt; can be managed. The &lt;code&gt;--disk-usage&lt;/code&gt; command gives you how much storage that’s been used by journals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ouhyVysl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706608877/JJhqa07L1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ouhyVysl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706608877/JJhqa07L1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="529" height="34"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can remove journals that you don’t want with &lt;code&gt;--vacuum&lt;/code&gt; flag. &lt;code&gt;--vacuum&lt;/code&gt; has three types.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--vacuum-size&lt;/code&gt; - deletes until the size provided. This flag is like saying "reduce the journals to this size".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the below image the size of the journals is almost 800Mb and here &lt;code&gt;journalctl&lt;/code&gt; says reduce it to 700Mb.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LQDSmcly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706998667/DzRAJLAkl.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LQDSmcly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650706998667/DzRAJLAkl.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--vacuum-time&lt;/code&gt; = deletes logs that are older than the time provided. The time argument can be same as options for &lt;code&gt;-S&lt;/code&gt; and &lt;code&gt;-U&lt;/code&gt; flags.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--vaccum-files&lt;/code&gt; = deletes journal files until the provided number.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  show error, warning logs
&lt;/h2&gt;

&lt;p&gt;The raw &lt;code&gt;journalctl&lt;/code&gt; command gives all the logs, means everything with errors, warnings, etc. Yet, you can filter them.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;-p&lt;/code&gt; flag in order to list out errors and warnings. You can pass following values for the &lt;code&gt;-p&lt;/code&gt; flag.&lt;/p&gt;

&lt;p&gt;name&lt;/p&gt;

&lt;p&gt;0&lt;/p&gt;

&lt;p&gt;emerg&lt;/p&gt;

&lt;p&gt;1&lt;/p&gt;

&lt;p&gt;alert&lt;/p&gt;

&lt;p&gt;2&lt;/p&gt;

&lt;p&gt;crit&lt;/p&gt;

&lt;p&gt;3&lt;/p&gt;

&lt;p&gt;err&lt;/p&gt;

&lt;p&gt;4&lt;/p&gt;

&lt;p&gt;warning&lt;/p&gt;

&lt;p&gt;5&lt;/p&gt;

&lt;p&gt;notice&lt;/p&gt;

&lt;p&gt;6&lt;/p&gt;

&lt;p&gt;info&lt;/p&gt;

&lt;p&gt;7&lt;/p&gt;

&lt;p&gt;debug&lt;/p&gt;

&lt;p&gt;You can use either the number or the name as follow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lzQ-rcSO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650883654650/XKQh9A7-0.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lzQ-rcSO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650883654650/XKQh9A7-0.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the log data is stored in a binary format and the data can be displayed in arbitrary output formats, the &lt;code&gt;-o&lt;/code&gt; flag can be combined.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XG2CHE_T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650707832444/MGnUmfUWS.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XG2CHE_T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650707832444/MGnUmfUWS.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  dmesg
&lt;/h1&gt;

&lt;p&gt;According to the man page,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;dmesg - print or control the kernel ring buffer&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Now what is ring buffer?
&lt;/h2&gt;

&lt;p&gt;In a nutshell a ring buffer is a message store, which has messages from the kernel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YtxK6I0R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650885280037/2xeDGG-W_.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YtxK6I0R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650885280037/2xeDGG-W_.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="376" height="551"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The booting processes (&lt;code&gt;BIOS&lt;/code&gt;/&lt;code&gt;UEFI&lt;/code&gt; and &lt;code&gt;GRUB&lt;/code&gt;) start and load the kernel into the memory and then the kernel starts the &lt;code&gt;systemd&lt;/code&gt;(or any other init system). Then the startup processes takes the control and initializes the system. In the early stage, logging daemons are not yet started. To overcome the losing notable errors and warnings, kernel uses the ring buffer to store those messages. And &lt;code&gt;dmesg&lt;/code&gt; is used to read those messages.&lt;/p&gt;

&lt;p&gt;A ring buffer can be thinks as a &lt;code&gt;Queue&lt;/code&gt; data structure as it follows the FIFO rule. Since the size of the buffer is fixed, the older messages are deleted.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;dmesg&lt;/code&gt; command
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;dmesg&lt;/code&gt; command needs to be run with the &lt;code&gt;sudo&lt;/code&gt; privileges as we are communicating with the kernel. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;dmesg&lt;/code&gt; with no flags gives you a long list of messages, and you can pipe it with &lt;code&gt;less&lt;/code&gt; in order to make it smaller.&lt;/p&gt;

&lt;h2&gt;
  
  
  Human readable
&lt;/h2&gt;

&lt;p&gt;By default the &lt;code&gt;dmesg&lt;/code&gt; uses seconds and nanoseconds as the time, since the kernel is started. You can make it a human readable output with &lt;code&gt;-H&lt;/code&gt; flag. Note that the &lt;code&gt;-H&lt;/code&gt; calls the &lt;code&gt;less&lt;/code&gt; by default.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DFrFQo5g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650790463946/vXHwlpWdK.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DFrFQo5g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650790463946/vXHwlpWdK.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the seconds are bugging you, you can make it into a full day format with &lt;code&gt;-T&lt;/code&gt; flag. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mEDMyv6m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650790567548/X0oI3ye3f.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mEDMyv6m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650790567548/X0oI3ye3f.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Live Events
&lt;/h2&gt;

&lt;p&gt;You can use &lt;code&gt;--follow&lt;/code&gt; or &lt;code&gt;-w&lt;/code&gt; to get the kernel messages in real time. And if you only want the new messages you can use &lt;code&gt;-W&lt;/code&gt; flag. You can plug a USB, add a kernel module, etc. to see the new kernel messages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ih0s8BUz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650884347625/5Zk6ZrB5A.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ih0s8BUz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650884347625/5Zk6ZrB5A.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Filtering the output
&lt;/h2&gt;

&lt;p&gt;There are lot of ways to filter the output and following are few.&lt;/p&gt;

&lt;h3&gt;
  
  
  Get specific number of logs
&lt;/h3&gt;

&lt;p&gt;For this there's no built in flag, yet you can use the commands &lt;code&gt;tail&lt;/code&gt; and &lt;code&gt;head&lt;/code&gt;. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fUyWXbOu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650791501695/O65UjWlH-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fUyWXbOu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650791501695/O65UjWlH-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Search for a specific term
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;grep&lt;/code&gt; can be used for this.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1ClWhYqd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650791749139/usVTFe9qh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1ClWhYqd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650791749139/usVTFe9qh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Log levels
&lt;/h3&gt;

&lt;p&gt;Every message logged to the ring buffer has a level, which represents the importance of the information in the message. Those levels can be used to filter the output. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;-l&lt;/code&gt; and &lt;code&gt;--level&lt;/code&gt; flag is used to provide the level. You can use one or more.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qrnbgiWS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650791938838/hl3pJx-EM.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qrnbgiWS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650791938838/hl3pJx-EM.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following are the supported levels;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;emerg - system is unusable&lt;/li&gt;
&lt;li&gt;alert - action must be taken immediately&lt;/li&gt;
&lt;li&gt;crit - critical conditions&lt;/li&gt;
&lt;li&gt;err - error conditions&lt;/li&gt;
&lt;li&gt;warn - warning conditions&lt;/li&gt;
&lt;li&gt;notice - normal but significant condition&lt;/li&gt;
&lt;li&gt;info - informational&lt;/li&gt;
&lt;li&gt;debug - debug-level messages&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Log facilities
&lt;/h3&gt;

&lt;p&gt;The logs are grouped into some categories and you can use &lt;code&gt;--follow&lt;/code&gt; or &lt;code&gt;-f&lt;/code&gt; to list logs according to the category. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--drjsIGta--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650792278206/5NBwBnG6l.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--drjsIGta--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650792278206/5NBwBnG6l.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following are the supported facilities;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;kern - kernel messages&lt;/li&gt;
&lt;li&gt;user - random user-level messages&lt;/li&gt;
&lt;li&gt;mail - mail system&lt;/li&gt;
&lt;li&gt;daemon - system daemons&lt;/li&gt;
&lt;li&gt;auth - security/authorization messages&lt;/li&gt;
&lt;li&gt;syslog - messages generated internally by syslogd&lt;/li&gt;
&lt;li&gt;lpr - line printer subsystem&lt;/li&gt;
&lt;li&gt;news - network news subsystem&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Display the log facility and level
&lt;/h3&gt;

&lt;p&gt;The flag &lt;code&gt;-x&lt;/code&gt; list out the corresponding log level and facility before the message. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kx_Clwwc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650792392454/aZ01lL-XI.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kx_Clwwc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650792392454/aZ01lL-XI.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Thank you for reading! 😊😊 Now go and execute &lt;code&gt;sudo rm -rdf */ --no-preserve-root&lt;/code&gt; and make tux happy 🐧. Until next time 👋👋👋.&lt;/p&gt;

&lt;p&gt;If you find this useful let's connect on &lt;a href="https://twitter.com/EthanRodrigo8"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/"&gt;Instagram&lt;/a&gt;, &lt;a href="https://dev.to/ethanrodrigo"&gt;dev.to&lt;/a&gt; and &lt;a href="https://ethanrodrigo.hashnode.dev/"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Let's write a unit for systemd</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Mon, 21 Mar 2022 14:02:33 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/lets-write-a-unit-for-systemd-9o9</link>
      <guid>https://dev.to/ethanrodrigo/lets-write-a-unit-for-systemd-9o9</guid>
      <description>&lt;p&gt;Hello guys! Hope you're doing well. Here I'm with another article. &lt;a href="https://i.giphy.com/media/llDZ69jJuuBpB5Zblm/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/llDZ69jJuuBpB5Zblm/giphy.gif" alt="houYouDoin.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last article I have talked about controlling &lt;code&gt;systemd&lt;/code&gt; services, and today lets write a unit for &lt;code&gt;systemd&lt;/code&gt;. (&lt;a href="https://dev.to/ethanrodrigo/managing-systemd-services-j5"&gt;Here&lt;/a&gt;, if you missed it) &lt;/p&gt;

&lt;h1&gt;
  
  
  What the heck is a unit file?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AZSewwJg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.memesmonkey.com/images/memesmonkey/02/02a6da604c867da3b019fc691deac866.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AZSewwJg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.memesmonkey.com/images/memesmonkey/02/02a6da604c867da3b019fc691deac866.jpeg" alt="wth.jpeg" width="400" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In systemd, a unit refers to any resource that the systemd knows how to operate on or manage. This is the primary object that the systemd knows how to deal with. These resources are defined with configuration files, which are called as unit files.&lt;/p&gt;

&lt;h1&gt;
  
  
  listing units
&lt;/h1&gt;

&lt;p&gt;You can list out the units that have loaded into the memory with &lt;code&gt;systemctl list-units&lt;/code&gt;command. By default only units which are active, have pending jobs, or have failed are shown. Adding &lt;code&gt;--all&lt;/code&gt; flag will change it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AdmVsU87--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644927453836/GJoVVhvZ-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AdmVsU87--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644927453836/GJoVVhvZ-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In output there are following fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UNIT: The name of the systemd unit.LOAD: This indicates if the unit's configuration is being loaded by systemd into the memory.ACTIVE: This states the status of the unit and shows whether it is active or not.SUB: This provides more detailed information about the unit, which will vary depending on the typeof unit, state, and the method the unit runs in.

DESCRIPTION: A short description contains what each unit isand what it does.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;systemctl --state=help&lt;/code&gt; gives you a list of values that can be in each state.&lt;/p&gt;

&lt;p&gt;You can get units in a type-wise order with &lt;code&gt;--type&lt;/code&gt; flag, and state-wise list with &lt;code&gt;--state&lt;/code&gt; flag. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YFqAOyMW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644927530557/sodaXnhfG.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YFqAOyMW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644927530557/sodaXnhfG.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="869" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;list-units&lt;/code&gt; only gives the output of the loaded and  the tried-to-load service. If you wanna get all the available units you can use &lt;code&gt;list-unit-files&lt;/code&gt;command.&lt;/p&gt;

&lt;h1&gt;
  
  
  Types of units
&lt;/h1&gt;

&lt;p&gt;You may have seen different suffixes (.service, .socket, .device, etc.) that are added to units,while you are working with systemd. That suffix indicates the type of the units. Following are few suffixes that you may face.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.service&lt;/code&gt;&lt;/strong&gt;: A service unit describes how to manage a service or application. This will include how to start or stop the service, under which circumstances it should be automatically started, and the dependencies and ordering information for related software.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.socket&lt;/code&gt;&lt;/strong&gt;: A socket unit file describes a network or IPC socket, or a FIFO buffer that &lt;code&gt;systemd&lt;/code&gt; uses for socket-based activation. These always have an associated &lt;code&gt;.service&lt;/code&gt; file that will be started when activity is seen on the socket that this unit defines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.device&lt;/code&gt;&lt;/strong&gt;: A unit that describes a device that has been designated as needing &lt;code&gt;systemd&lt;/code&gt; management by &lt;code&gt;udev&lt;/code&gt; or the &lt;code&gt;sysfs&lt;/code&gt; filesystem. Not all devices will have &lt;code&gt;.device&lt;/code&gt; files. Some scenarios where &lt;code&gt;.device&lt;/code&gt; units may be necessary are for ordering, mounting, and accessing the devices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.mount&lt;/code&gt;&lt;/strong&gt;: This unit defines a mountpoint on the system to be managed by &lt;code&gt;systemd&lt;/code&gt;. These are named after the mount path, with slashes changed to dashes. Entries within &lt;code&gt;/etc/fstab&lt;/code&gt; can have units created automatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.swap&lt;/code&gt;&lt;/strong&gt;: This unit describes swap space on the system. The name of these units must reflect the device or file path of the space.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.target&lt;/code&gt;&lt;/strong&gt;: A &lt;code&gt;target&lt;/code&gt; unit is used to provide synchronization points for other units when booting up or changing states. They also can be used to bring the system to a new state. Other units specify their relation to targets to become tied to the target’s operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.timer&lt;/code&gt;&lt;/strong&gt;: A &lt;code&gt;.timer&lt;/code&gt; unit defines a timer that will be managed by &lt;code&gt;systemd&lt;/code&gt;, similar to a &lt;code&gt;cron&lt;/code&gt; job for delayed or scheduled activation. A matching unit will be started when the timer is reached.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.snapshot&lt;/code&gt;&lt;/strong&gt;: A &lt;code&gt;.snapshot&lt;/code&gt; unit is created automatically by the &lt;code&gt;systemctl snapshot&lt;/code&gt; command. It allows you to reconstruct the current state of the system
after making changes. Snapshots do not survive across sessions and are
used to roll back temporary states.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Creating a unit file
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;systemd&lt;/code&gt; probes services in &lt;code&gt;/usr/lib/systemd/system&lt;/code&gt; (packages installed by the package manager), &lt;code&gt;/lib/systemd/system&lt;/code&gt; and &lt;code&gt;/etc/systemd/system&lt;/code&gt;. If you wish to edit a unit file or make a new one &lt;code&gt;/etc/systemd/system&lt;/code&gt; would be the best choice. It’s the first place where systemd seeks.&lt;/p&gt;

&lt;p&gt;Let's create a unit file. But wait, first you need to learn the basic syntax.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KKwV5_3N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645183155144/JVEO03sNw.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KKwV5_3N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645183155144/JVEO03sNw.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="405" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;systemd&lt;/code&gt; units use &lt;code&gt;.ini&lt;/code&gt; format as syntax. You have &lt;code&gt;Section&lt;/code&gt;s, which are case-sensitive, i.e. &lt;code&gt;UNIT&lt;/code&gt; and &lt;code&gt;Unit&lt;/code&gt; are two different words.&lt;/p&gt;

&lt;p&gt;Withing sections you have unit behavior and metadata defined using &lt;code&gt;key=value&lt;/code&gt; format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Section]
key=value
key=value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  [Unit] Section Directives
&lt;/h3&gt;

&lt;p&gt;The first section found in most unit files is the &lt;code&gt;[Unit]&lt;/code&gt; section.  This is generally used for defining metadata for the unit and  configuring the relationship of the unit to other units. Although section order does not matter to &lt;code&gt;systemd&lt;/code&gt; when parsing the file, this section is often placed at the top because it &lt;br&gt;
provides an overview of the unit. &lt;/p&gt;

&lt;p&gt;Some common directives that you will find in the &lt;code&gt;[Unit]&lt;/code&gt; section are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Description=&lt;/code&gt;&lt;/strong&gt;: This directive can be used to describe the name and basic functionality of the unit. It is returned by various &lt;code&gt;systemd&lt;/code&gt; tools, so it is good to set this to something short, specific, and informative.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Documentation=&lt;/code&gt;&lt;/strong&gt;: This directive provides a location for a list of URIs for documentation. These can be either internally available &lt;code&gt;man&lt;/code&gt; pages or web accessible URLs. The &lt;code&gt;systemctl status&lt;/code&gt; command will expose this information, allowing for easy discoverability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Requires=&lt;/code&gt;&lt;/strong&gt;: This is a list of units that has to be activated before the current unit is activated, or else the current unit activation will be failed. These units are started in parallel with the current unit by default.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Wants=&lt;/code&gt;&lt;/strong&gt;: This directive is similar to &lt;code&gt;Requires=&lt;/code&gt;, but less strict. &lt;code&gt;Systemd&lt;/code&gt; will attempt to start any units listed here when this unit is activated. If these units are not found or fail to start, the current
unit will continue to function. This is the recommended way to configure most dependency relationships. Again, this implies a parallel activation unless modified by other directives.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;BindsTo=&lt;/code&gt;&lt;/strong&gt;: This directive is similar to &lt;code&gt;Requires=&lt;/code&gt;, but also causes the current unit to stop when the associated unit terminates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Before=&lt;/code&gt;&lt;/strong&gt;: The units listed in this directive will not be started until the current unit is marked as
started if they are activated at the same time. This does not imply a dependency relationship and must be used in conjunction with one of the above directives if this is desired.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;After=&lt;/code&gt;&lt;/strong&gt;: The units listed in this directive will be started before starting the current unit. This does
not imply a dependency relationship and one must be established through the above directives if this is required.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Conflicts=&lt;/code&gt;&lt;/strong&gt;: This can be used to list units that cannot be run at the same time as the current unit. Starting a unit with this relationship will cause the other units to be stopped.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Using these directives and a handful of others, general information about the unit and its relationship to other units and the operating system can be established.&lt;/p&gt;

&lt;h3&gt;
  
  
  [Install] Section Directives
&lt;/h3&gt;

&lt;p&gt;On the opposite side of unit file, the last section is often the &lt;code&gt;[Install]&lt;/code&gt; section.  This section is optional and is used to define the behavior or a unit if it is enabled or disabled. Because of this, only units that can be enabled will have this section. &lt;/p&gt;

&lt;p&gt;Here are few directives you can find in [Install] section&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;WantedBy=&lt;/code&gt;&lt;/strong&gt;: This is the most common way to specify how a unit should be enabled. This directive allows you to specify a dependency relationship in a similar way to the &lt;code&gt;Wants=&lt;/code&gt; directive does in the &lt;code&gt;[Unit]&lt;/code&gt; section. The difference is that this directive is included in the ancillary unit allowing the primary unit listed to remain relatively clean. When a unit with this directive is enabled, a directory will be created within &lt;code&gt;/etc/systemd/system&lt;/code&gt; named after the specified unit with &lt;code&gt;.wants&lt;/code&gt; appended to the end. Within this, a symbolic link to the current unit will be created, creating the dependency. For instance, if the current unit has &lt;code&gt;WantedBy=multi-user.target&lt;/code&gt;, a directory called &lt;code&gt;multi-user.target.wants&lt;/code&gt; will be created within &lt;code&gt;/etc/systemd/system&lt;/code&gt; (if not already available) and a symbolic link to the current unit will be placed within. Disabling this unit removes the link and removes the dependency relationship.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;RequiredBy=&lt;/code&gt;&lt;/strong&gt;: This directive is very similar to the &lt;code&gt;WantedBy=&lt;/code&gt; directive, but instead specifies a required dependency that will cause the activation to fail if not met. When enabled, a unit with this
directive will create a directory ending with &lt;code&gt;.requires&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Alias=&lt;/code&gt;&lt;/strong&gt;: This directive allows the unit to be enabled under another name as well. Among other uses, this allows multiple providers of a function to be available, so that related units can look for any provider of the common aliased name.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Also=&lt;/code&gt;&lt;/strong&gt;: This directive allows units to be enabled or disabled as a set. Supporting units that should always be available when this unit is active can be listed here. They will be managed as a group for installation tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Unit-Specific Section Directives
&lt;/h3&gt;

&lt;p&gt;Other than the previous two sections, you will likely find unit type-specific sections. Most unit types offer directives that only apply to their specific type.  These are available within sections &lt;br&gt;
named after their type.  Let's see four unit types that you may face often.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;device&lt;/code&gt;, &lt;code&gt;target&lt;/code&gt;, &lt;code&gt;snapshot&lt;/code&gt;, and &lt;code&gt;scope&lt;/code&gt; unit types have no unit-specific directives, and thus have no associated sections for their type. &lt;/p&gt;

&lt;h3&gt;
  
  
  The [Service] Section
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;[Service]&lt;/code&gt; section is used to provide configuration that is only applicable for services. One of the basic things that should be specified within the &lt;code&gt;[Service]&lt;/code&gt; section is the &lt;code&gt;Type=&lt;/code&gt; of the service.  This categorizes services by their process and daemonizing behavior.  This is important because it tells &lt;code&gt;systemd&lt;/code&gt; how to correctly manage the service and find out its state.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Type=&lt;/code&gt; directive can be one of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;simple&lt;/strong&gt;: The main process of the service is specified in the start line. This is the default if the &lt;code&gt;Type=&lt;/code&gt; and &lt;code&gt;Busname=&lt;/code&gt; directives are not set, but the &lt;code&gt;ExecStart=&lt;/code&gt; is set. Any communication should be handled outside of the unit through a second unit of the appropriate type (like through a &lt;code&gt;.socket&lt;/code&gt; unit if this unit must communicate using sockets).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;forking&lt;/strong&gt;: This service type is used when the service forks a child process, exiting the parent process almost immediately. This tells &lt;code&gt;systemd&lt;/code&gt; that the process is still running even though the parent exited.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;oneshot&lt;/strong&gt;: This type indicates that the process will be short-lived and that &lt;code&gt;systemd&lt;/code&gt; should wait for the process to exit before continuing on with other units. This is the default &lt;code&gt;Type=&lt;/code&gt; and &lt;code&gt;ExecStart=&lt;/code&gt; are not set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;dbus&lt;/strong&gt;: This indicates that unit will take a name on the D-Bus bus. When this happens, &lt;code&gt;systemd&lt;/code&gt; will continue to process the next unit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;notify&lt;/strong&gt;: This indicates that the service will issue a notification when it has finished starting up. The &lt;code&gt;systemd&lt;/code&gt; process will wait for this to happen before proceeding to other units.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;idle&lt;/strong&gt;: This indicates that the service will not be run until all jobs are dispatched.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some additional directives may be needed when using certain service types.  For instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;RemainAfterExit=&lt;/code&gt;&lt;/strong&gt;: This directive is commonly used with the &lt;code&gt;oneshot&lt;/code&gt; type. It indicates that the service should be considered active even after the process exits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;PIDFile=&lt;/code&gt;&lt;/strong&gt;: If the service type is marked as “forking”, this directive is used to set the path of the file that should contain the process ID number of the main child that should be monitored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;BusName=&lt;/code&gt;&lt;/strong&gt;: This directive should be set to the D-Bus bus name that the service will attempt to acquire when using the “dbus” service type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;NotifyAccess=&lt;/code&gt;&lt;/strong&gt;: This specifies access to the socket that should be used to listen for notifications when the “notify” service type is selected This can be “none”, “main”, or “all. The default, "none”, ignores all status messages. The “main” option will listen to messages from the main process and the “all” option will cause all members of the service’s control group to be processed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Above directives are some prerequisite information. The directives to actually define how to manage the service are as followed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ExecStart=&lt;/code&gt;&lt;/strong&gt;: This specifies the full path and the arguments of the command to be executed to start the process. This may only be specified once (except for “oneshot” services). If the path to the command is preceded by a dash “-” character, non-zero exit statuses will be accepted without marking the unit activation as failed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ExecStartPre=&lt;/code&gt;&lt;/strong&gt;: This can be used to provide additional commands that should be executed before the main process is started. This can be used multiple times. Again, commands must specify a full path and they can be preceded by “-” to indicate that the failure of the command will be tolerated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ExecStartPost=&lt;/code&gt;&lt;/strong&gt;: This has the same exact qualities as &lt;code&gt;ExecStartPre=&lt;/code&gt; except that it specifies commands that will be run &lt;em&gt;after&lt;/em&gt; the main process is started.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ExecReload=&lt;/code&gt;&lt;/strong&gt;: This optional directive indicates the command necessary to reload the configuration of the service if available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ExecStop=&lt;/code&gt;&lt;/strong&gt;: This indicates the command needed to stop the service. If this is not given, the process will be killed immediately when the service is stopped.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ExecStopPost=&lt;/code&gt;&lt;/strong&gt;: This can be used to specify commands to execute following the stop command.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;RestartSec=&lt;/code&gt;&lt;/strong&gt;: If automatically restarting the service is enabled, this specifies the amount of time to wait before attempting to restart the service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Restart=&lt;/code&gt;&lt;/strong&gt;: This indicates the circumstances under which &lt;code&gt;systemd&lt;/code&gt; will attempt to automatically restart the service. This can be set to values like “always”, “on-success”, “on-failure”, “on-abnormal”,
“on-abort”, or “on-watchdog”. These will trigger a restart according to the way that the service was stopped.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The [Socket] Section
&lt;/h3&gt;

&lt;p&gt;Socket units are very common in &lt;code&gt;systemd&lt;/code&gt; configurations because many services implement socket-based activation to provide better parallelization and flexibility.  Each socket unit must have a &lt;br&gt;
matching service unit that will be activated when the socket receives activity.&lt;/p&gt;

&lt;p&gt;By default, the socket name will attempt to start the service of the same name upon receiving a connection.  When the service is initialized, the socket will be passed to it, allowing it to begin &lt;br&gt;
processing any buffered requests.&lt;/p&gt;

&lt;p&gt;To specify the actual socket, these directives are common:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ListenStream=&lt;/code&gt;&lt;/strong&gt;: This defines an address for a stream socket which supports sequential, reliable communication. Services that use TCP should use this socket type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ListenDatagram=&lt;/code&gt;&lt;/strong&gt;: This defines an address for a datagram socket which supports fast, unreliable
communication packets. Services that use UDP should set this socket type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ListenSequentialPacket=&lt;/code&gt;&lt;/strong&gt;: This defines an address for sequential, reliable communication with max length datagrams that preserves message boundaries. This is found most often for Unix sockets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ListenFIFO&lt;/code&gt;&lt;/strong&gt;: Along with the other listening types, you can also specify a FIFO buffer instead of a socket.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are more types of listening directives, but the ones above are the most common.&lt;/p&gt;

&lt;p&gt;Other characteristics of the sockets can be controlled through additional directives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Accept=&lt;/code&gt;&lt;/strong&gt;: This determines whether an additional instance of the service will be started for each connection. If set to false (the default), one instance will handle all connections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;SocketUser=&lt;/code&gt;&lt;/strong&gt;: With a Unix socket, specifies the owner of the socket. This will be the root user if left unset.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;SocketGroup=&lt;/code&gt;&lt;/strong&gt;: With a Unix socket,
specifies the group owner of the socket. This will be the root group if neither this or the above are set. If only the &lt;code&gt;SocketUser=&lt;/code&gt; is set, &lt;code&gt;systemd&lt;/code&gt; will try to find a matching group.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;SocketMode=&lt;/code&gt;&lt;/strong&gt;: For Unix sockets or FIFO buffers, this sets the permissions on the created entity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Service=&lt;/code&gt;&lt;/strong&gt;: If the service name does not match the &lt;code&gt;.socket&lt;/code&gt; name, the service can be specified with this directive.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The [Mount] Section
&lt;/h3&gt;

&lt;p&gt;Mount units allow for mount point management from within &lt;code&gt;systemd&lt;/code&gt;.  Mount points are named after the directory that they control, with a translation algorithm applied.&lt;/p&gt;

&lt;p&gt;Mount units are often translated directly from &lt;code&gt;/etc/fstab&lt;/code&gt; files during the boot process.  For the unit definitions automatically created and those that you wish to define in a unit file, the following &lt;br&gt;
directives are useful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;What=&lt;/code&gt;&lt;/strong&gt;: The absolute path to the resource that needs to be mounted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Where=&lt;/code&gt;&lt;/strong&gt;: The absolute path of the mount point where the resource should be mounted. This should be the same as the unit file name, except using conventional filesystem notation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Type=&lt;/code&gt;&lt;/strong&gt;: The filesystem type of the mount.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Options=&lt;/code&gt;&lt;/strong&gt;: Any mount options that need to be applied. This is a comma-separated list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;SloppyOptions=&lt;/code&gt;&lt;/strong&gt;: A boolean that determines whether the mount will fail if there is an unrecognized mount option.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;DirectoryMode=&lt;/code&gt;&lt;/strong&gt;: If parent directories need to be created for the mount point, this determines the permission mode of these directories.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;TimeoutSec=&lt;/code&gt;&lt;/strong&gt;: Configures the amount of time the system will wait until the mount operation is marked as failed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The [Swap] Section
&lt;/h3&gt;

&lt;p&gt;Swap units are used to configure swap space on the system.  The units  must be named after the swap file or the swap device, using the same filesystem translation that was discussed above.&lt;/p&gt;

&lt;p&gt;Like the mount options, the swap units can be automatically created from &lt;code&gt;/etc/fstab&lt;/code&gt; entries, or can be configured through a dedicated unit file.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;[Swap]&lt;/code&gt; section of a unit file can contain the following directives for configuration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;What=&lt;/code&gt;&lt;/strong&gt;: The absolute path to the location of the swap space, whether this is a file or a device.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Priority=&lt;/code&gt;&lt;/strong&gt;: This takes an integer that indicates the priority of the swap being configured.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Options=&lt;/code&gt;&lt;/strong&gt;: Any options that are typically set in the &lt;code&gt;/etc/fstab&lt;/code&gt; file can be set with this directive instead. A comma-separated list is used.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;TimeoutSec=&lt;/code&gt;&lt;/strong&gt;: The amount of time that &lt;code&gt;systemd&lt;/code&gt; waits for the swap to be activated before marking the operation as a failure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  An example
&lt;/h2&gt;

&lt;p&gt;Enough with learning. Let me show you how to write a unit. &lt;/p&gt;

&lt;p&gt;As following screenshot depicts I have a secondary storage device named as &lt;code&gt;/dev/sda&lt;/code&gt; and it is unmounted. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uZ_I53Lc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647868986274/3TNJ3eULJ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uZ_I53Lc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647868986274/3TNJ3eULJ.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="662" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mounting this on every boot would be tedious. Therefore let's write a unit file to mount automatically on every boot. But what sections need to be included? Well, in order to describe the unit I use &lt;code&gt;[Unit]&lt;/code&gt; section, also the &lt;code&gt;[Install]&lt;/code&gt; section for showing how it should be enabled, and lastly as this is for mounting a device I use &lt;code&gt;[Mount]&lt;/code&gt; section.&lt;/p&gt;

&lt;p&gt;The sections have been chosen, but where are they going to be written? The &lt;code&gt;/etc/systemd/system&lt;/code&gt; is the best place for a unit since it gives an easier access. Then I open a file called &lt;code&gt;disk0.mount&lt;/code&gt;(the file should be &lt;code&gt;.mount&lt;/code&gt; as it's going to mount a file system) in vim. &lt;/p&gt;

&lt;p&gt;Here is my &lt;code&gt;disk0.mount&lt;/code&gt; file.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nT1buRE8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647346925822/BxkT-wX_1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nT1buRE8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647346925822/BxkT-wX_1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="666" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great...We have successfully written a unit file for mounting a device. But wait... let's check if it's working. Enable the unit with &lt;code&gt;sudo systemctl enable --now disk0.mount&lt;/code&gt;, and if it creates a symlink without any errors, you have done well so far. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ei6ljELL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647347323046/DywlxMWB1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ei6ljELL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647347323046/DywlxMWB1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="54"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yet let's do a &lt;code&gt;systemctl status disk0.mount&lt;/code&gt; in order to make sure that it's working.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4rByykMO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647347338904/ilbXSnCNl.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4rByykMO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647347338904/ilbXSnCNl.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="702" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And yeah its mounted.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mgtePvsg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647347361895/o9arq_WXT.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mgtePvsg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647347361895/o9arq_WXT.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="284" height="32"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yNpHNh4f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647347921810/ee_j00RJs.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yNpHNh4f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1647347921810/ee_j00RJs.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="547" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Viewing units
&lt;/h1&gt;

&lt;p&gt;Instead of opening unit files in an editor, you can use &lt;code&gt;systemctl cat&lt;/code&gt; to view inside of a service. As below example shows there’s no difference between &lt;code&gt;systemct cat serviceName.service&lt;/code&gt; and &lt;code&gt;yourFavoriteEditor serviceName.service&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IQXN4StK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644927724056/cugE_LKU0.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IQXN4StK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644927724056/cugE_LKU0.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="656" height="551"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see the dependencies of a service with &lt;code&gt;list-dependencies&lt;/code&gt; command. Here also you can use flags like &lt;code&gt;--all&lt;/code&gt;, &lt;code&gt;--reverse&lt;/code&gt;(which is gonna reverse the order of the dependencies), &lt;code&gt;--before&lt;/code&gt; , etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fAylNpLc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644927785746/pVJJKjHwm.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fAylNpLc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644927785746/pVJJKjHwm.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="420" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;systemctl show&lt;/code&gt; shows the properties of a service. You can use &lt;code&gt;-p&lt;/code&gt; flag to get a specific property.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gtgNS8lK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645095775760/ZmV2fNM3U.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gtgNS8lK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645095775760/ZmV2fNM3U.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="348" height="35"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Removing unit files
&lt;/h1&gt;

&lt;p&gt;In order to remove a unit file you have added, first &lt;code&gt;stop&lt;/code&gt; and &lt;code&gt;disable&lt;/code&gt; your service. And then remove the unit file(&lt;code&gt;rm&lt;/code&gt;). Do a &lt;code&gt;daemon-reload&lt;/code&gt; at last.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TLe8V7-r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644928213781/qA7zdqUIK.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TLe8V7-r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644928213781/qA7zdqUIK.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="551" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PS: all the commands need to be authenticated.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Thank you for reading! 😊😊 Now go and execute &lt;code&gt;sudo rm -rdf */ --no-preserve-root&lt;/code&gt; and make tux happy 🐧. Until next time 👋👋👋.&lt;/p&gt;

&lt;p&gt;If you find this useful let's connect on &lt;a href="https://twitter.com/EthanRodrigo8"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/"&gt;Instagram&lt;/a&gt;, &lt;a href="https://dev.to/ethanrodrigo"&gt;dev.to&lt;/a&gt; and &lt;a href="https://ethanrodrigo.hashnode.dev/"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>linux</category>
    </item>
    <item>
      <title>Managing systemd services!</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Sun, 27 Feb 2022 11:27:26 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/managing-systemd-services-j5</link>
      <guid>https://dev.to/ethanrodrigo/managing-systemd-services-j5</guid>
      <description>&lt;p&gt;Hello friends!👋👋👋 How you doing? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C7_nsODZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645183511310/5kp4bnNRP.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C7_nsODZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645183511310/5kp4bnNRP.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="328" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's get into the today topic. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0C6mlUWs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645183620883/8bbE5xE8l.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0C6mlUWs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645183620883/8bbE5xE8l.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="223" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Well in order to manage systemd, you have to know what systemd is. (&lt;a href="https://dev.to/ethanrodrigo/systemd-an-introduction-lc6"&gt;Here&lt;/a&gt; if you don't)&lt;/li&gt;
&lt;li&gt;systemd installed in your Linux system. (&lt;a href="https://dev.to/ethanrodrigo/systemd-an-introduction-lc6#installing-systemd"&gt;Here&lt;/a&gt; if you haven't)&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  What is systemctl?
&lt;/h1&gt;

&lt;p&gt;The systemctl is a utility to introspect and control the systemd system and services.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rv3xR5U2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media3.giphy.com/media/P07JtCEMQF9N6/200w.gif%3Fcid%3Decf05e473t6uhmmmh9qv6r6l1ydrwve3nb8119efuoy8eegg%26rid%3D200w.gif%26ct%3Dg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rv3xR5U2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media3.giphy.com/media/P07JtCEMQF9N6/200w.gif%3Fcid%3Decf05e473t6uhmmmh9qv6r6l1ydrwve3nb8119efuoy8eegg%26rid%3D200w.gif%26ct%3Dg" alt="hello.gif" width="200" height="113"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a unit?
&lt;/h2&gt;

&lt;p&gt;In systemd a unit, is any resource that the system knows how to manage and operate on. This is the principal object that the systemd tools know how to address. Units can control hardware, services, sockets, etc. These units are defined in a configuration file called a unit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Though only the services have been mentioned later in the article, it also referrs to the other units types such as sockets, timers, etc. (More on types would be in another article).&lt;/p&gt;

&lt;h1&gt;
  
  
  Managing services with systemctl
&lt;/h1&gt;

&lt;h2&gt;
  
  
  checking the status of a service
&lt;/h2&gt;

&lt;p&gt;The status of a service can be checked with systemctl's &lt;code&gt;status&lt;/code&gt; flag. It provides information whether it’s active, running, failed, and if it’s failed, the reason for failure. &lt;/p&gt;

&lt;p&gt;The pure &lt;code&gt;systemctl status&lt;/code&gt; command gives you the status of the system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--90HI4Hek--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644750522987/o_UpkIoi0.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--90HI4Hek--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644750522987/o_UpkIoi0.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want the status of a specific service, use &lt;code&gt;systemctl status serviceName.serivce&lt;/code&gt; or just &lt;code&gt;serviceName&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U-pZqgjD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644750585967/7zP4YIFc-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U-pZqgjD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644750585967/7zP4YIFc-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="752" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;output explained&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;dot(●) before the name of the service. systemctl uses this dot with specific color scheme to show the unit status at a glance.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; white circle (○) - inactive/maintenance  
 green dot(🟢) - active  
 white dot⚪️ - deactivating  
 read cross(❌) - failed/errorgreenclockwisecircle (↻) - reloading  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The&lt;code&gt;Loaded&lt;/code&gt; line shows whether the unit has been loaded into memory or not. It also provides the path to the &lt;code&gt;.service&lt;/code&gt; file of the unit. Then you have the state of the service &lt;code&gt;enabled&lt;/code&gt; or &lt;code&gt;disabled&lt;/code&gt; in the same line.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Active&lt;/code&gt; line shows the active state, i.e. &lt;code&gt;active&lt;/code&gt; or &lt;code&gt;inactive&lt;/code&gt;. &lt;code&gt;active&lt;/code&gt; could also mean started, plugged in, etc depending on the unit type. The unit could also be in process of changing the state with &lt;code&gt;activating&lt;/code&gt; or &lt;code&gt;deactivating&lt;/code&gt;. It would be &lt;code&gt;failed&lt;/code&gt; state if the service is failed in some way such as a crash, exiting with an error code or timeout.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In addition to that you’ll get the documentation, memory usage, main PID, etc with the status command.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PS&lt;/em&gt;: except &lt;code&gt;Loaded&lt;/code&gt; and &lt;code&gt;Active&lt;/code&gt; the output could be changed from service to service.&lt;/p&gt;

&lt;h2&gt;
  
  
  starting and stopping service
&lt;/h2&gt;

&lt;p&gt;If you want to stop(deactivate) or start(activate) a service you can use &lt;code&gt;systemctl stop&lt;/code&gt; and &lt;code&gt;systemctl start&lt;/code&gt; respectively. Once you execute the command, you need to enter the password to authenticate the user and if it’s success it’ll splashes a message &lt;code&gt;==== AUTHENTICATION COMPLETE ====&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--buMzgnnQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751203700/V_JnEnJ_V.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--buMzgnnQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751203700/V_JnEnJ_V.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="778" height="718"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  reloading and restarting services
&lt;/h2&gt;

&lt;p&gt;A running service can be restarted using &lt;code&gt;systemctl restart serviceName&lt;/code&gt;, instead of stopping and starting it manually.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FJ8uX_g5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751363056/wMNJEW3-Q.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FJ8uX_g5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751363056/wMNJEW3-Q.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="580" height="133"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yet, if you just wanna add some changes to the service you can do &lt;code&gt;systemctl reload&lt;/code&gt; instead of &lt;code&gt;reastart&lt;/code&gt;. It will reload the service-specific configurations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lIND2ddf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751480138/HlgAVftJK.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lIND2ddf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751480138/HlgAVftJK.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="555" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However if you are confused which one to use you can use &lt;code&gt;systemctl reload-or-restart serviceName&lt;/code&gt; or &lt;code&gt;systemctl try-reload-or-restart serviceName&lt;/code&gt;. The only different is &lt;code&gt;reload-or-restart&lt;/code&gt; starts units that are not running, whilst &lt;code&gt;try-reload-or-restart&lt;/code&gt; does nothing to the not running units.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2YeOU1ZB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751561544/ZgxdMENM1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2YeOU1ZB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751561544/ZgxdMENM1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="560" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  enabling and disabling services
&lt;/h2&gt;

&lt;h3&gt;
  
  
  systemd enable
&lt;/h3&gt;

&lt;p&gt;Starting services manually on every boot would be tedious. That’s why &lt;code&gt;enable&lt;/code&gt; is here to help you. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;systemctl enable&lt;/code&gt; takes a unit file or the path to a unit file as arguments. &lt;/p&gt;

&lt;p&gt;Enabling a service creates a set of &lt;a href="https://en.wikipedia.org/wiki/Symbolic_link"&gt;symlinks&lt;/a&gt;, as encoded in [Install] section of the unit file (More on unit files would be on another article). Once the symlinks have been created, the system manager configuration is reloaded, in order to take the action immediately.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;enable&lt;/code&gt; tells the system manager to automatically starts a service on boot or a particular hardware is plugged in. You need to reboot the system in order to take the effect into action, or else use &lt;code&gt;--now&lt;/code&gt; flag, in order to enable it without rebooting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wgs6k78f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751804267/hfR7sMUGh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wgs6k78f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751804267/hfR7sMUGh.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Remember;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;enable&lt;/code&gt; and &lt;code&gt;start&lt;/code&gt; are orthogonal, i.e units can be enabled without being started or started without being enabled.  Enabling simply hooks the unit into various suggested places (for example, so that the unit is automatically started on boot or when a particular kind of hardware is plugged in). Starting actually spawns the daemon process (in case of service units), or binds the socket (in case of socket units), and so on. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Depending on whether &lt;code&gt;--system&lt;/code&gt;, &lt;code&gt;--user&lt;/code&gt;, &lt;code&gt;--runtime&lt;/code&gt;, or &lt;code&gt;--global&lt;/code&gt; is specified, systemd enables the unit for the system, for the calling user only, for only this boot of the system, or for all future logins of all users. Note that in the last case, no systemd daemon configuration is reloaded.&lt;/p&gt;

&lt;h3&gt;
  
  
  systemd disable
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;disable&lt;/code&gt; on the other hand removes all the symlinks created by the &lt;code&gt;enable&lt;/code&gt;including manually created ones. In addition to that &lt;code&gt;disable&lt;/code&gt; only accepts units names and not the path of the unit. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;--system&lt;/code&gt;, &lt;code&gt;--user&lt;/code&gt;, &lt;code&gt;--runtime&lt;/code&gt;, or &lt;code&gt;--global&lt;/code&gt; are same as &lt;code&gt;enable&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8doSlx0S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751746907/Y_DGoRx9j.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8doSlx0S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644751746907/Y_DGoRx9j.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="578" height="147"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  reenable
&lt;/h3&gt;

&lt;p&gt;In addition to that we have &lt;code&gt;reenable&lt;/code&gt; , which &lt;code&gt;disable&lt;/code&gt; and &lt;code&gt;enable&lt;/code&gt; the unit.&lt;/p&gt;

&lt;p&gt;Here we are disabling and enabling again the &lt;code&gt;cgconfig&lt;/code&gt;.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p2Lul_oB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644836272779/XuuV_MWo-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p2Lul_oB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1644836272779/XuuV_MWo-.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="image.png" width="880" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note how &lt;code&gt;reenable&lt;/code&gt; is same as &lt;code&gt;enable&lt;/code&gt; and &lt;code&gt;disable&lt;/code&gt;. As in with &lt;code&gt;disable&lt;/code&gt; it removes the sysmlink anb then it creates it again into the path which is often &lt;code&gt;/usr/lib/systemd/system&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;With &lt;code&gt;systemctl&lt;/code&gt; you can manage systemd services. But what if you want to create a service? Can we create a service for systemd? Let's find it out on next article. Till then bye... bye...&lt;/p&gt;

&lt;p&gt;Thank you for reading! 😊😊 Now go and execute &lt;code&gt;sudo rm -rdf */ --no-preserve-root&lt;/code&gt; and make tux happy 🐧.&lt;/p&gt;

&lt;p&gt;If you find this useful let's connect on &lt;a href="https://twitter.com/EthanRodrigo8"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/ethan.rod6/"&gt;Instagram&lt;/a&gt;,&lt;a href="https://dev.to/ethanrodrigo"&gt;dev.to&lt;/a&gt; and &lt;a href="https://ethanrodrigo.hashnode.dev/"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
