<?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.us-east-2.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>Teleporting Virtual Machines: Flipping the Script</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Fri, 26 Jun 2026 08:17:52 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/teleporting-virtual-machines-flipping-the-script-5k5</link>
      <guid>https://dev.to/ethanrodrigo/teleporting-virtual-machines-flipping-the-script-5k5</guid>
      <description>&lt;p&gt;In the previous post in this series, &lt;em&gt;Teleporting Servers&lt;/em&gt;, we examined how to move a live virtual machine between physical hosts using the pre-copy method. Pre-copy transfers the VM’s memory in multiple rounds while the source keeps running. When the number of dirtied pages falls below a configurable writable working set (WWS) threshold—or a preset maximum number of iterations is reached—the VM is suspended and its CPU state plus any remaining dirty pages are sent to the target host; that final transfer is the service downtime phase.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Pre-Copy Bottleneck
&lt;/h1&gt;

&lt;p&gt;We were good with pre-copy, right? Why do we need a new method? Well, pre-copy takes seconds and in virtual world, a second is an eternity. Let's see why pre-copy take time.&lt;/p&gt;

&lt;p&gt;What is the cap to stop the iterations of transferring memory? Right, it's WWS floor. But what if the smallest WWS reached is too large? The downtime will be high and the processes that needed to be continued will take some time. This means that pre-copy is good only if the workload of the VM is read-intensive (not too much of page dirtying) and if the workload is write-intensive the downtime will be higher so is the applications' performance.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Post-Copy Flip
&lt;/h1&gt;

&lt;p&gt;Take the analogy from the previous post, the moving in example. What if you take your essentials in the first run and start living in the new apartment? Then you can move your other big items later and hand over the key to the owner.&lt;/p&gt;

&lt;p&gt;Now apply that to the VM migration. First you transmit the VM's processor state to the target and start the VM there. Then actively push the VM's memory pages from the source to target. Meanwhile, if there's any page faults they are sent over the network from the source.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Four Pillars of Post-Copy
&lt;/h1&gt;

&lt;p&gt;Post-Copy under the hood uses 4 methods to make the migration process efficient.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Demand Paging - This is when a page fault occurs and it is requested from the source over the network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Active Push - The pages are sent to the target from the source even without a page fault occurring to make sure the target will not be dependent on the source as soon as possible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prepaging - This is more like a forecasting technique used to identify the page access pattern and get the needed pages even before there's a page fault.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic Self-Ballooning (DSB) - Why are you sending the free pages over when you can just drop them? DSB takes care of that.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Predicting the Future with Bubbles
&lt;/h2&gt;

&lt;p&gt;As mentioned above, pre-paging forecasts what pages will be faulted on the target. Let's see what happens behind the scenes.&lt;/p&gt;

&lt;p&gt;As mentioned earlier, Prepaging is used to make pages available at the target before they are faulted on by the running VM. The effectiveness of the prepaging is measured by the percentage of the page faults that requires an explicit page request to be sent over the network to the source. Smaller the percentage, better the prepaging algorithm.&lt;/p&gt;

&lt;p&gt;But how the pages needed in the future are decided? Computer programs don't usually access memory completely at random. If a program needs to read data at Memory Address 100, there is a very high probability that in the next millisecond, it's going to need Address 101, 102, and 103. This is called &lt;strong&gt;"spatial locality."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now there are two methods in which the pages needed to sent are decided.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bubbling with a Single Pivot
&lt;/h3&gt;

&lt;p&gt;What happens when you throw a rock into a pond? There will be ripples spreading outwards in circles. Now compare it with a network fault. Initially the pages are sent over in one direction (0, 1, 2, ...), where the pivot is page 0. When a network page fault occurs, the pivot moves there. From there the pages are sent in both directions, front and back. Assume that page fault is 50. The pivot will be 50 and then the pages will be sent in backwards 49, 48, 47, ... and also frontwards 51, 52, 53, ... Whenever a pages which has been transferred is met, it is skipped, ensuring the pages are transmitted only once.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bubbling with Multiple Pivots
&lt;/h3&gt;

&lt;p&gt;Now imaging the VM having multiple processes running, the new VM would fault on page on multiple locations. Thus there need to be multiple pivots, causing multiple bubbles. Each bubble will expand around an independent pivot. If one edge of a bubble comes across a page that is already transmitted that edge will -be stopped. As for the efficiency, it has found limiting the number of pivots to around 7 is a good idea. Therefore whenever a new pivot is occurred and the limit is hit, the new pivot will replace the old one.&lt;/p&gt;

&lt;p&gt;As for the direction of the bubble growth, it has found that forward expansion is essential, backwards-only expansion is counter productive and bi-directional expansion performs just right.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to Send First?
&lt;/h2&gt;

&lt;p&gt;Generally, Linux maintains two linked lists in which pages are accessed in Least Recently Used (LRU) order; one for active pages and one for inactive pages. There's a kernel daemon periodically swapping pages around the two lists. Later on, the inactive list is swapped out of RAM to the SWAP device. This is quite helpful in post-copy implementation, while deciding what pages to send first.&lt;/p&gt;

&lt;p&gt;But Linux is lazy. If there's enough memory and no swap device, Linux just sits there and leave the lists unsorted. And the migration's pseudo-paging device is turned on last millisecond of the migration, there's no time to organize the list and migration algorithm has no idea which pages are active and which are inactive.&lt;/p&gt;

&lt;p&gt;Therefore the developers have implemented a kernel thread which runs in the background long before the migration starts.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;each time an application touches a page, it flips a tiny switch of the page called a "Referenced bit"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then while the thread goes through memory and if it sees a page with Referenced bit turned on, it clears the bit and moves the page to the top of the Active List.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a page sits there for a long time without its referenced bit being turned on it will be slides down in to the inactive list.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting the Trap: Catching Page Faults
&lt;/h2&gt;

&lt;p&gt;There are three ways of trapping page faults by demand-paging component of post-copy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shadow Paging
&lt;/h3&gt;

&lt;p&gt;Hyperviser have a read-only page table for each VM that matches its pseudo-physical pages to the physical page frames. If the VM tries to read or write a page that hasn't arrived yet, the hypervisor catches the violation, stops the vm, fetch the page and lets it continue.&lt;/p&gt;

&lt;h3&gt;
  
  
  Page Tracking
&lt;/h3&gt;

&lt;p&gt;Page Tracking; During downtime, all the pages on target VM are marked as not present in their PTE. When the VM wakes up, it throws errors on everything, a custom software intercepts. This needs a lot of hacking into the guest OS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pseudo-paging
&lt;/h3&gt;

&lt;p&gt;As soon as migration is started, the memory pages of the migrating VM at the source are swapped out to an in-memory pseudo-paging device, which resides on the guest kernel. Then the CPU state and non-pageable memory are transferred to the target during downtime. But there's a catch: if the OS detects that even a single ounce of its physical memory is missing, it panics (a kernel panic) and crashes. The solution? A heist.&lt;/p&gt;

&lt;p&gt;If you found out there was a priceless diamond in a capital museum, how would you steal it without tripping the alarms? The easiest way is replacing the original with a replica of the exact same weight.&lt;/p&gt;

&lt;p&gt;The same goes for pseudo-paging. If the OS won't let us take the memory, we just replace the original data pages with empty pages. This is called the &lt;strong&gt;MFN Exchange&lt;/strong&gt;. Here's how it works:&lt;/p&gt;

&lt;p&gt;Before the migration starts, the hypervisor goes to its reserves, gathers a massive pile of completely empty, useless physical memory (the sandbags), and temporarily doubles the VM's memory reserve. Next, all the running applications are temporarily frozen so they stop writing new data.&lt;/p&gt;

&lt;p&gt;The guest OS is then instructed to swap out its memory. As it does this, the hypervisor intercepts the pointers. It takes the VM's internal addresses (&lt;strong&gt;PFNs&lt;/strong&gt;) and reconnects them to those empty, useless physical chips (&lt;strong&gt;MFNs&lt;/strong&gt;). The VM is satisfied. Meanwhile, the hypervisor takes the &lt;em&gt;real&lt;/em&gt; physical chips holding the actual data (the diamonds) and quietly hands them over to Domain 0 to be beamed to the new server.&lt;/p&gt;

&lt;p&gt;With the memory safely stolen, the whole VM is suspended for just a few milliseconds and its "brain" is sent over to the target. Once awake on the new server, if the OS hits one of those empty replica pages, it throws a "page fault." A third-party software driver (the MemX client) intercepts this error and immediately pulls the missing data across the network from the old server's Domain 0.&lt;/p&gt;

&lt;h1&gt;
  
  
  Handle the Free Memory
&lt;/h1&gt;

&lt;p&gt;Transferring a large number of free pages is a waste of resources and would increase the total migration time regardless of the migration algorithm you use. Also, if the moved VM asked for a brand new empty page, there will be a page fault and an empty page will be fetched from the source wasting time as once arrived, that page is overwritten anyway.&lt;/p&gt;

&lt;p&gt;A technique called ballooning is used for resizing the memory allocation of a VM. Usually there is a balloon driver in the guest kernel. It can either ask the guest for free memory and give them back to the hypervisor (inflate the balloon), or request pages from the hypervisor and return them to the guest (deflate the balloon).&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic Self-Ballooning
&lt;/h2&gt;

&lt;p&gt;Now that mechanism is used to avoid transmission of free pages during both pre and post copy migrations. The VM performs ballooning continuously over its execution lifetime - and its called Dynamic Self-Ballooning (DSB).&lt;/p&gt;

&lt;p&gt;DSB has three components&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Inflate the balloon - VM has a kernel-level DSB thread that allocates as much as free memory as possible and hand them over to the hypervisor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Detect memory pressure - Memory pressure means some entity needs to access a free page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deflate the balloon - In response to a memory pressure the balloon must be partially deflated, i.e. reverse of inflating. DSB thread re-populates the free memory from the hypervisor and then release them to the guest kernel.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How to detect memory pressure?
&lt;/h3&gt;

&lt;p&gt;Imaging you're a manager of a renowned restaurant. There are 100 tables in the restaurant, and the &lt;em&gt;Reserved&lt;/em&gt; sign is put on 95 of them, and 5 are left as if anyone come those tables can be given. Now a massive VIP party walks in, you get panic and shouts "Get 20 tables and seats for the VIPs".&lt;/p&gt;

&lt;p&gt;Same applies while detecting memory pressure. The DSB process (the manager) takes up (inflate the balloon) to 95% of the available free memory (if taken 100% there would be &lt;em&gt;out-of-memory&lt;/em&gt; trigger). Then if an application (VIPs) asks for memory, and if there's no free memory a panic triggers. And that panic is a "Memory Pressure". In Linux if this panic occurs it sirens an alarm, a shrinker function. It's like yelling "Hey, if anyone has unused cache, throw them away". The DSB periodically do this process to make sure the OS run smoothly.&lt;/p&gt;

&lt;p&gt;Now the developers of post-copy implemented the balloon driver such that it can listen to this alarm, so it can deflate as needed and the application run smoothly.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Reality Check: Did it Actually Work?
&lt;/h1&gt;

&lt;p&gt;The developers didn't just build this in theory; they put their Post-Copy prototype through the wringer with some heavy, real-world server applications. Here is the final scorecard:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Triumphs (Where Post-Copy Wins):&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Bandwidth Savior:&lt;/strong&gt; Because Post-Copy guarantees every page is transferred exactly &lt;em&gt;once&lt;/em&gt;, it absolutely crushes Pre-Copy on network efficiency for write-heavy workloads. No more endless loops of re-sending dirtied data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bubbling is Magic:&lt;/strong&gt; The multi-directional "Bubbling" algorithm, combined with the LRU (Least Recently Used) list sorting, worked beautifully. It predicted the VM's needs so well that it eliminated a massive chunk of the sluggish network page faults.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DSB is a Cheat Code:&lt;/strong&gt; Dynamic Self-Ballooning drastically reduced the total amount of memory that needed to be transferred, speeding up the entire migration process from start to finish.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Catch (Where it Stumbled):&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Downtime Spike:&lt;/strong&gt; In a perfect world, Post-Copy downtime is near zero. However, because their specific "pseudo-paging" hack couldn't swap out the core, protected kernel memory, they had to pause the system to send that chunk over manually. This resulted in a slightly higher downtime than they wanted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read-Heavy Workloads:&lt;/strong&gt; If your server is mostly just reading data (like a static web server), good old-fashioned Pre-Copy is still the reigning champion for overall speed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Final Verdict: Which should you choose?
&lt;/h2&gt;

&lt;p&gt;There is no single silver bullet. They are different tools for different jobs.&lt;/p&gt;

&lt;p&gt;If your server is a calm, &lt;strong&gt;read-intensive&lt;/strong&gt; machine, use &lt;strong&gt;Pre-Copy&lt;/strong&gt;. It's safe, reliable, and keeps downtime incredibly low.&lt;/p&gt;

&lt;p&gt;But if your server is a chaotic, &lt;strong&gt;write-intensive&lt;/strong&gt; beast—like a massive database actively changing gigabytes of memory every second—&lt;strong&gt;Post-Copy&lt;/strong&gt; is the ultimate getaway vehicle.&lt;/p&gt;

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

&lt;p&gt;We discussed how post-copy can be a complementary tool for pre-copy, and how it was implemented.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: This blog post is a summary of the research paper &lt;a href="https://www.researchgate.net/publication/220624148_Post-copy_live_migration_of_virtual_machines" rel="noopener noreferrer"&gt;Post-Copy Live Migration of Virtual Machines&lt;/a&gt;, and the sole purpose of the post is to summarize what I have learnt by reading this paper.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>virtualmachine</category>
      <category>cloud</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Teleporting Virtual Machines: The Magic of Live Virtual Machine Migration</title>
      <dc:creator>Ethan Rodrigo</dc:creator>
      <pubDate>Wed, 03 Jun 2026 04:52:10 +0000</pubDate>
      <link>https://dev.to/ethanrodrigo/teleporting-virtual-machines-the-magic-of-live-virtual-machine-migration-48oe</link>
      <guid>https://dev.to/ethanrodrigo/teleporting-virtual-machines-the-magic-of-live-virtual-machine-migration-48oe</guid>
      <description>&lt;p&gt;Say you want to upgrade your laptop's RAM, what's the first thing you do if you have a new RAM stick in your hand? Turn off the laptop, install the new RAM, and restart. Pretty easy? Now imagine you're a system engineer at Amazon AWS. You are asked to upgrade the RAM of a physical machine, but it got some virtual machines running on it, what would you do? If you stop the server even for a second, the users will notice immediately. How to upgrade the RAM without shutting down the services?&lt;/p&gt;

&lt;h1&gt;
  
  
  The Zero-Downtime Dilemma
&lt;/h1&gt;

&lt;p&gt;One thing you can do is to migrate the processes running on those virtual machines to a new ones. But the problem is the old virtual machine may still be needed for some network and system calls. Thus you can't shutdown the old machine easily.&lt;/p&gt;

&lt;p&gt;What if you could take a virtual machine from one physical host and “teleport” it to another—without anyone noticing?&lt;/p&gt;

&lt;p&gt;That’s not magic. It’s called &lt;strong&gt;live migration&lt;/strong&gt;. With live migration, the users won't be having any issues (nor will they even know) if you replace the host of their virtual world. And on the other hand system engineers will have least time worrying about long migration time.&lt;/p&gt;

&lt;h1&gt;
  
  
  How Do We Live Migrate VMs?
&lt;/h1&gt;

&lt;p&gt;But how is that possible? First let's consider two parties which we have to make sure are happy. The end user; there should not be a &lt;em&gt;downtime&lt;/em&gt;. And the operator of the data center; They should do it in the least &lt;em&gt;total migration time.&lt;/em&gt; If both those factors are achieved, everyone is happy.&lt;/p&gt;

&lt;p&gt;To run the VM on a new machine, several things must be copied from the original. The most important one is memory, because it represents the VM's entire working state. Therefore first let's see three ways the memory can be transferred.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Push:&lt;/strong&gt; Push the &lt;a href="https://en.wikipedia.org/wiki/Page_(computer_memory)" rel="noopener noreferrer"&gt;memory pages&lt;/a&gt; across the network while the source Virtual Machine (VM) is still running.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stop-and-copy:&lt;/strong&gt; Stop the source VM and copy the pages across the new VM. Then start the new VM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pull:&lt;/strong&gt; Start the new VM while the old one is still running. And if the new VM access a page that hasn't copied yet, make a &lt;a href="https://en.wikipedia.org/wiki/Page_fault" rel="noopener noreferrer"&gt;page fault&lt;/a&gt; and pull it across the network from the source VM.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of these approaches work well on their own. For example if the old VM is completely stopped and start the new one, the downtime for the users is high, so is the total migration time. On the other hand if the new VM is started and pulled as needed, the total migration time is high.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Winning Approach
&lt;/h2&gt;

&lt;p&gt;So none of these approaches work well alone. The solution is to combine them; &lt;em&gt;pre-copy,&lt;/em&gt; A combination of iterative push phases with a very short stop-and-copy phase. The memory pages are sent over the network in an iterative manner and after that the old host is suspended and sent the processor state to the new host so that it can be start.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 5 Phases of Live Migration
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Step 01: Reservation&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A request is issued to migrate an OS from host A to host B. A calls B and says, "Hey, here's something for you". The host B confirms if the necessary resources are available and reserve a VM container of that size. "Yeah I got it, send over".&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE:&lt;/em&gt; Failure to secure resources means the VM simply continues to run on A.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Step 02: Iterative Pre-Copy&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First iteration, all the pages are transferred to B. Subsequent iterations copy the dirtied pages (pages that have been modified) during the previous transfer.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Step 03: Stop-and-Copy&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suspend the running OS instance at A and redirect its network traffic to B. Then any remaining inconsistent memory pages are transferred to B along with the CPU state. Now both A and B have suspended copies of the VM. Still the A's copy is the primary and will resume in case of failure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Step 04: Commitment&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Host B indicates to A that the OS image is successfully received. Host A acknowledges this and it may now discard the original VM. Host B becomes the primary host now.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Step 05: Activation&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The migrated VM on B is now activated. Post-migration code runs to reattach device drivers to the new machine and advertise the moved IP address.&lt;/p&gt;

&lt;h1&gt;
  
  
  The &lt;strong&gt;B&lt;/strong&gt;ottleneck: WWS
&lt;/h1&gt;

&lt;p&gt;Great, we can replace the VMs anywhere we want easily. Not really. It's too good to be perfect. There's a catch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writable Working Set
&lt;/h2&gt;

&lt;p&gt;Consider this analogy. You're moving to a new apartment on the weekend. You have bought the apartment and all you have to do is move the items in your old apartment to the new one. But the problem is you can't move all at once, it may take few days, and you can't hinder your routine tasks, like brushing your teeth, washing yourself and eating.&lt;/p&gt;

&lt;p&gt;Now in the virtual world, the routine tasks are the one that dirties the pages rapidly. Even after copying memory, the VM continues running—meaning new changes are constantly being made. And those are called writable working set.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "Moving"
&lt;/h2&gt;

&lt;p&gt;Let's say for the first round you moved the furniture and other big items you don't use daily into your new apartment. And for the second round you move your clothes and your sports items. Then for the last round you can take all the utensils you use daily and put them in your car and give the keys to the owner and move yourself to the new apartment. There you can unpack those utensils again and live normally.&lt;/p&gt;

&lt;p&gt;Same goes for the VMs, there will be some rounds to send the memory that doesn't change rapidly. Then once the algorithm decides the WWS is small enough the system is frozen and moved (stop-and-copy) to the new VM.&lt;/p&gt;

&lt;h3&gt;
  
  
  Knowing When to Freeze: The Stop Triggers
&lt;/h3&gt;

&lt;p&gt;In practice, systems rely on dynamic heuristics to decide when to stop.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The "good enough rule";&lt;/strong&gt; Once a round is completed, the software asks itself, 'how long will it take to send the remaining pages?'. If the answer is a couple of milliseconds, it just freezes and does the final copy&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hitting the WWS floor;&lt;/strong&gt; Let's say the first round copied 413 MB, the second one did 112 MB, third 15 MB, fourth 14 MB and fifth 15 MB. The system knows it has hit the WWS floor as the dirtied memory isn't shrinking anymore. Thus it stops the iteration and initiate the final copy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Setting a hard limit;&lt;/strong&gt; What if there's a process which never stops writing to the memory. That's when the developers has put a cap on how many times the system will tolerate failure. It just aggressively slows down the rogue process and forces the migration process to finish.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Under the Hood: Two Ways to Build It
&lt;/h1&gt;

&lt;p&gt;There are two ways migration can be done. In each method, managing the dirty pages and freeze are different.&lt;/p&gt;

&lt;h2&gt;
  
  
  Managed Migration
&lt;/h2&gt;

&lt;p&gt;Managed migration is performed by migration daemons running in the management VMs (one special virtual machine in a physical host that is used for the administration and control of the other machines) of the source and destination hosts. '&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting the Trap: Shadow Page Tables
&lt;/h3&gt;

&lt;p&gt;As mentioned in migration steps, the copying is done in rounds. The first round copies the whole memory and the subsequent rounds only copies the dirtied pages during the previous round. To keep track of those pages dirtied during the rounds a dirty bitmap is used by the &lt;a href="https://en.wikipedia.org/wiki/Hypervisor" rel="noopener noreferrer"&gt;Virtual Machine Manager&lt;/a&gt; (the one who creates and runs the virtual machines) at the start of each round.&lt;/p&gt;

&lt;p&gt;The VMM uses &lt;em&gt;shadow page tables&lt;/em&gt; which is populated using the &lt;a href="https://en.wikipedia.org/wiki/Page_table" rel="noopener noreferrer"&gt;page table&lt;/a&gt; (a map to identify which memory page is used and which are not) of the guest OS, making all the page table entries there read-only. If the guest OS tries to write to a page, there will be a page fault. Then the VMM intercepts the fault, checks if the guest OS actually has permission to write, and if so, logs it in the dirty bitmap and allow the guest OS to write and continue working.&lt;/p&gt;

&lt;p&gt;Once a round is over, the bitmap is cleared and the shadow page table is destroyed and recreated.&lt;/p&gt;

&lt;p&gt;When it's determined that the pre-copy is no longer beneficial (using heuristics as mentioned above), a control message requesting to suspend itself is sent to the OS. Once the OS has done this, VMM informs the control software, the dirty bitmap is scanned one last time for inconsistent memory page, and these are transferred to the destination together with the VM's check-pointed CPU-register state.&lt;/p&gt;

&lt;p&gt;When the final information is received at the destination, the VM state on the source machine can safely be discarded. The control software on the destination machine scans the memory map and rewrites the guest's page table. Execution is then resumed by starting the new VM at the point that the old VM checkpointed itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Self Migration
&lt;/h2&gt;

&lt;p&gt;Self migration is done within the OS being migrated (migratee). It's a bit similar to managed migration. At each pre-copying round every PTE is write-protected. The OS maintains a dirty bitmap tracking dirtied pages. But the OS also manages other page faults like this. Thus to distinguish there is a reserved spare bit in each PTE to indicate that it's only for dirty-logging purposes.&lt;/p&gt;

&lt;p&gt;In managed migration the migratee can be suspended and obtain a consistent checkpoint. But in self migration the OS must continue to run in order to transfer its final state. Thus the final stage is two stepped. First all the OS activities except for migration are disabled and a final scan is performed to find the dirty bitmap. Any pages that are dirtied during this final scan are copied to the shadow buffer. As second final stage, the shadow buffer is transferred as the OS checkpoint.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Cheat Code: Paravirtualization
&lt;/h1&gt;

&lt;p&gt;Paravirtualization is a virtualization technique where the guest operating system is modified to communicate directly with the hypervisor rather than using hardware emulations.&lt;/p&gt;

&lt;p&gt;There are two ways it is beneficial for live migrations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stunning Rogue Process
&lt;/h2&gt;

&lt;p&gt;There may be cases that some processes dirty memory at a rate which can't be transfer via Ethernet, and those are called 'rogue' applications.&lt;/p&gt;

&lt;p&gt;We can mitigate this by forking a monitoring thread within the OS kernel to monitor the WWS of individual processes and take actions if required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Freeing Page Cache Pages
&lt;/h2&gt;

&lt;p&gt;There will be some part of memory that are free but have used to store cache pages. Those are irrelevant while migrating a VM and will reduce the performance. Thus we can just clear the cache and send. But if the contents of the pages be needed again, there will be a little time consumption to read them from the disk again.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;The Invisible Backbone of the Modern Cloud&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;It sounds like magic, but the engineers who designed this system managed to get the downtime for a migrating server down to as little as &lt;strong&gt;60 milliseconds&lt;/strong&gt;. That is faster than the blink of an eye.&lt;/p&gt;

&lt;p&gt;When you read through the mechanics—from shadow page tables trapping memory faults to the operating system dropping its own cache to speed up the move—you realize it isn't magic at all. It is just incredibly clever systems engineering.&lt;/p&gt;

&lt;p&gt;Today, this foundational concept is the invisible backbone of the modern internet. It is the reason AWS, Google Cloud, and Azure can perform massive hardware upgrades, balance millions of terabytes of traffic, and maintain physical servers without ever dropping your Netflix stream or pausing your online game. The next time you are playing a multiplayer game without a single glitch, just remember: the physical server hosting your match might have just been teleported to a completely different rack miles away, and you didn't even notice.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;This post is a simplified breakdown and interpretation of the original research. If you want to dive into the deep technical math and architecture, I highly recommend reading&lt;/em&gt; &lt;a href="https://www.researchgate.net/publication/220831959_Live_Migration_of_Virtual_Machines" rel="noopener noreferrer"&gt;&lt;em&gt;the original 2005 paper&lt;/em&gt;&lt;/a&gt; &lt;em&gt;by Christopher Clark and his team at Cambridge University.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>virtualmachine</category>
      <category>cloud</category>
      <category>computerscience</category>
    </item>
    <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="799" 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="570"&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="428"&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="799" 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="524"&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="799" 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="400" 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="799" 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="799" 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://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%2Fcj5rn61qmkkmxmytub44.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%2Fcj5rn61qmkkmxmytub44.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://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%2Fds4khbdku0tua0a17ug8.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%2Fds4khbdku0tua0a17ug8.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&amp;nbsp;kernel is a&amp;nbsp;computer program&amp;nbsp;at the core of a computer's&amp;nbsp;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://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fy.yarn.co%2Fa90638dc-86a5-4ed9-ad18-9b7c0d8bca9c_text.gif" 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%2Fy.yarn.co%2Fa90638dc-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" rel="noopener noreferrer"&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" rel="noopener noreferrer"&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://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%2Ffwkamqf2kyre2wojij44.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%2Ffwkamqf2kyre2wojij44.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" rel="noopener noreferrer"&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" rel="noopener noreferrer"&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" rel="noopener noreferrer"&gt;system calls&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Resource_management_(computing)" rel="noopener noreferrer"&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" rel="noopener noreferrer"&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" rel="noopener noreferrer"&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" rel="noopener noreferrer"&gt;Hybrid(modular) kernels&lt;/a&gt;
&lt;/h3&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%2F5csyezz5kw12e36vmmsa.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%2F5csyezz5kw12e36vmmsa.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" rel="noopener noreferrer"&gt;Nanokernels&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Exokernel" rel="noopener noreferrer"&gt;Exokernels&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Multikernel" rel="noopener noreferrer"&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" 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;

</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://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%2Fql60fagb6r9jbwm34m24.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%2Fql60fagb6r9jbwm34m24.png" 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" rel="noopener noreferrer"&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://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%2F3r10xhi4jnn8il60r3ln.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%2F3r10xhi4jnn8il60r3ln.jpg" alt="weDontDoThatHere.jpg" width="800" height="449"&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" rel="noopener noreferrer"&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://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%2Fcd0rsreizfdzreyill0o.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%2Fcd0rsreizfdzreyill0o.png" 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://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%2Fbmepngdabsd68n5kxavg.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%2Fbmepngdabsd68n5kxavg.png" 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://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%2F7oytlviqzgg80vc0skmt.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%2F7oytlviqzgg80vc0skmt.png" 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://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%2Foxxozxzq3yyv2ub7kv5n.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%2Foxxozxzq3yyv2ub7kv5n.png" 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://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%2Fztzx1uqgw4m9q8reg0yb.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%2Fztzx1uqgw4m9q8reg0yb.png" 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://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%2F24uuyxj34o1qwj9h3oj6.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%2F24uuyxj34o1qwj9h3oj6.png" 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://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%2F0msxcqtqqpeun3fi64up.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%2F0msxcqtqqpeun3fi64up.png" 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://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%2Fgjxudhu2mm7hvy9vbkjb.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%2Fgjxudhu2mm7hvy9vbkjb.png" 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://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%2Fsw6qc7h02v3ihj06lvni.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%2Fsw6qc7h02v3ihj06lvni.png" 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://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%2F2li9qi862xkyk1wxpy2m.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%2F2li9qi862xkyk1wxpy2m.png" 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://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%2Fiambnodwvh22qspppmde.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%2Fiambnodwvh22qspppmde.png" 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://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%2F7pset2ssvwm9h95z498l.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%2F7pset2ssvwm9h95z498l.png" 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://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%2Fb5ub7yt0nvoz5okspp1p.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%2Fb5ub7yt0nvoz5okspp1p.png" 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://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%2Fjk6anb66q10sis8fmda6.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%2Fjk6anb66q10sis8fmda6.png" 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://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%2Fivd00nc4qw1rn5yn2rpf.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%2Fivd00nc4qw1rn5yn2rpf.png" 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://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%2F82qx4ge9y5otyb7kuppo.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%2F82qx4ge9y5otyb7kuppo.png" 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://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%2F8o8ap58xwcbqofq4q4nc.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%2F8o8ap58xwcbqofq4q4nc.png" 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://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%2Fcklww9c2si25eio68d6t.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%2Fcklww9c2si25eio68d6t.png" 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" 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;

</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" rel="noopener noreferrer"&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" rel="noopener noreferrer"&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://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%2F7b5jpz3qdoqa4784lcu6.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%2F7b5jpz3qdoqa4784lcu6.png" 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://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%2Fb3p1m0shxo61fysy933e.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%2Fb3p1m0shxo61fysy933e.png" 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" rel="noopener noreferrer"&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://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%2Fhptalzelq8uc2l2njgcl.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%2Fhptalzelq8uc2l2njgcl.png" 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://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%2F7zf4v6i7k80vgwjj3rgp.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%2F7zf4v6i7k80vgwjj3rgp.png" 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://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%2Fssg2vdmwfsj0le94g3qu.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%2Fssg2vdmwfsj0le94g3qu.png" 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://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%2Fc6huvlmo7v1pj2uz0n09.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%2Fc6huvlmo7v1pj2uz0n09.png" 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://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%2Fhybfgbqmaszke27qwkuc.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%2Fhybfgbqmaszke27qwkuc.png" 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://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%2Fzg48nthqhazbofdt8r0c.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%2Fzg48nthqhazbofdt8r0c.png" 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://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%2Fxx2kc7i6n9xesx4qebcm.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%2Fxx2kc7i6n9xesx4qebcm.png" 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://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%2Fehmkqns1l24vp4rwmt13.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%2Fehmkqns1l24vp4rwmt13.png" 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://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%2Fx4ozhigqq1kynzfs9wla.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%2Fx4ozhigqq1kynzfs9wla.png" 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://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%2Fi7a9etvc173m5shnj0y5.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%2Fi7a9etvc173m5shnj0y5.png" 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://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%2Fl0pdc2zyg9ja6o2e98gx.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%2Fl0pdc2zyg9ja6o2e98gx.png" 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" rel="noopener noreferrer"&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://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%2Fi6r44al38ukd1hcg60sd.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%2Fi6r44al38ukd1hcg60sd.png" 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://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%2Fi7df22020mrdyu7wyjes.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%2Fi7df22020mrdyu7wyjes.png" 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://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%2F23m9owekx1i1t9a3k09j.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%2F23m9owekx1i1t9a3k09j.png" 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" rel="noopener noreferrer"&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://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%2F4utg5hqjiwhpoenb2506.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%2F4utg5hqjiwhpoenb2506.png" 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://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%2F8ljam2je3hrna9bbmu9e.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%2F8ljam2je3hrna9bbmu9e.png" 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://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%2Fo4aes4tvemwkzh7aknc5.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%2Fo4aes4tvemwkzh7aknc5.png" 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" rel="noopener noreferrer"&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" 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;

</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://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%2Ftz8u79qnf8l5aiac0ybo.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%2Ftz8u79qnf8l5aiac0ybo.png" 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://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%2F7rs2u733g75c09gor8kp.gif" 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%2F7rs2u733g75c09gor8kp.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" rel="noopener noreferrer"&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://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%2Fhkowlniudfmbmn6x12pc.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%2Fhkowlniudfmbmn6x12pc.png" 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://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%2Fhcwlrwnw6h0puaunlsex.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%2Fhcwlrwnw6h0puaunlsex.png" alt="image.png" width="798" height="161"&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://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%2Fyyceq5d0qmbx08x93lrc.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%2Fyyceq5d0qmbx08x93lrc.png" 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://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%2Fn41e06u3ecd0moo9ahpb.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%2Fn41e06u3ecd0moo9ahpb.png" 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." rel="noopener noreferrer"&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" rel="noopener noreferrer"&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" rel="noopener noreferrer"&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://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%2F6v8tn8y0fd6f3nbtmch0.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%2F6v8tn8y0fd6f3nbtmch0.png" 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)" rel="noopener noreferrer"&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://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%2Fp07n8foosxby7rwuhihf.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%2Fp07n8foosxby7rwuhihf.png" 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://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%2Fch62tbph4x0fxh6kjjwx.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%2Fch62tbph4x0fxh6kjjwx.png" 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" rel="noopener noreferrer"&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://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%2Fiw2an6klolzn0np9a73b.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%2Fiw2an6klolzn0np9a73b.png" 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://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%2F270zieh76je5dlvt8dzs.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%2F270zieh76je5dlvt8dzs.png" 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://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%2Frmcw1jtc8lfl004wihk0.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%2Frmcw1jtc8lfl004wihk0.png" 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" rel="noopener noreferrer"&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://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%2Flacgc858qh6n1xs8wjf9.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%2Flacgc858qh6n1xs8wjf9.png" 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://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%2Fdzlqjupsarz96eot922k.webp" 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%2Fdzlqjupsarz96eot922k.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://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%2F980lon6xg4zhgzqef57v.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%2F980lon6xg4zhgzqef57v.png" 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://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%2Fhxwdyuhyhcucup0dntf4.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%2Fhxwdyuhyhcucup0dntf4.png" 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" rel="noopener noreferrer"&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" 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;

</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://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%2Fsmaebu9ml5xj9yvw7tr6.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%2Fsmaebu9ml5xj9yvw7tr6.png" 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://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%2F6fsr23o9iv31l3u7owa5.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%2F6fsr23o9iv31l3u7owa5.png" 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" rel="noopener noreferrer"&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://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%2Ffrjbddo0lfz5xiuv9b68.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%2Ffrjbddo0lfz5xiuv9b68.png" alt="image.png" width="800" height="534"&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" rel="noopener noreferrer"&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://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%2Fyetaauux120hj4l9xhuv.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%2Fyetaauux120hj4l9xhuv.jpg" 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://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%2F62om4gn4amac3cygnvuz.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%2F62om4gn4amac3cygnvuz.png" 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://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%2Fde8dskn4ag5nqrjrdq2u.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%2Fde8dskn4ag5nqrjrdq2u.png" 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://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%2Fyath0tb2vh1dsmk2yzfp.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%2Fyath0tb2vh1dsmk2yzfp.png" 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://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%2Ftr9ecrnr3yfvq4j1n7cx.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%2Ftr9ecrnr3yfvq4j1n7cx.png" 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://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%2F9wx3a89z107jnqhfje7w.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%2F9wx3a89z107jnqhfje7w.png" 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://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%2Feawd2n0k7rwga21hxm31.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%2Feawd2n0k7rwga21hxm31.png" 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://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%2Fz5fkqyrgx72iugvef93f.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%2Fz5fkqyrgx72iugvef93f.png" 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://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%2Fvwboxmtgaaa1tv1gfa3t.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%2Fvwboxmtgaaa1tv1gfa3t.png" 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://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%2F9ia6o2fyynyvgfugi1ca.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%2F9ia6o2fyynyvgfugi1ca.png" 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://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%2Fj9b69qx0sj0nc8qdznju.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%2Fj9b69qx0sj0nc8qdznju.png" 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" rel="noopener noreferrer"&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://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%2Fze9c87h657vk1z6ukmwx.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%2Fze9c87h657vk1z6ukmwx.png" 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://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%2Fnt2qd1km1ntynve8h4js.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%2Fnt2qd1km1ntynve8h4js.png" 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://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%2Fj1pan7v2u5d6ybzlaxm0.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%2Fj1pan7v2u5d6ybzlaxm0.png" 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://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%2F6kfw1beky6v4iw0jvf7y.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%2F6kfw1beky6v4iw0jvf7y.png" 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://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%2F5f3a3f3k8g29p927a7n6.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%2F5f3a3f3k8g29p927a7n6.png" 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://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%2Fugch0qyiubn3xk27pk4b.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%2Fugch0qyiubn3xk27pk4b.png" 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://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%2Fc5x021ryuhsisld8jtga.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%2Fc5x021ryuhsisld8jtga.png" 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" 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;

</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://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%2Fy8umrb64yvtvo74w9tct.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%2Fy8umrb64yvtvo74w9tct.png" 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://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%2F1lisu3jigcdkmngzmer7.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%2F1lisu3jigcdkmngzmer7.png" 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/" rel="noopener noreferrer"&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://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%2Fnvh4ewfnafabcossjgqv.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%2Fnvh4ewfnafabcossjgqv.png" alt="image.png" width="800" height="236"&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://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%2Fioine2eqgkyrx6khs86p.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%2Fioine2eqgkyrx6khs86p.png" 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://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%2F7kooreeopeni9v40vvbg.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%2F7kooreeopeni9v40vvbg.png" alt="image.png" width="800" height="426"&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://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%2F08lhjoup6n7mf0wmxifr.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%2F08lhjoup6n7mf0wmxifr.png" alt="image.png" width="799" height="378"&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://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%2Fzk4yo8p17748vto6uctl.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%2Fzk4yo8p17748vto6uctl.png" alt="image.png" width="799" height="279"&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://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%2Fn4fdfkfvm31f1jfeipv6.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%2Fn4fdfkfvm31f1jfeipv6.png" alt="image.png" width="800" height="153"&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://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%2Fa3vbwiny2eiaklkneud6.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%2Fa3vbwiny2eiaklkneud6.png" alt="image.png" width="800" height="377"&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://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%2Fviedj1h8bkrana57xd47.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%2Fviedj1h8bkrana57xd47.png" alt="image.png" width="800" height="243"&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://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%2F8go1yy2g9sijdztll0v1.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%2F8go1yy2g9sijdztll0v1.png" alt="image.png" width="800" height="165"&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" rel="noopener noreferrer"&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://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%2Fwotreaofm7imzngmbewn.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%2Fwotreaofm7imzngmbewn.png" 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://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%2Fw4h1kqp2b7tz25b8qcne.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%2Fw4h1kqp2b7tz25b8qcne.png" alt="image.png" width="800" height="387"&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://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%2Fda2ljgiv6xo9kjg45o4e.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%2Fda2ljgiv6xo9kjg45o4e.png" alt="image.png" width="799" height="264"&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://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%2F9v6kw6f59s1vgeamj6f1.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%2F9v6kw6f59s1vgeamj6f1.png" 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://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%2Fh6hf2p6ay6xu4hr6uxie.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%2Fh6hf2p6ay6xu4hr6uxie.png" alt="image.png" width="797" height="127"&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://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%2Fn1oixgzz20vuppeu91yt.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%2Fn1oixgzz20vuppeu91yt.png" alt="image.png" width="800" height="234"&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://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%2Fgxxi6y824po59us9f2c6.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%2Fgxxi6y824po59us9f2c6.png" 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://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%2F5dvibbhcrovb2sburiic.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%2F5dvibbhcrovb2sburiic.png" alt="image.png" width="800" height="231"&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://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%2Fn3nptw8iuzndjwdlj9st.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%2Fn3nptw8iuzndjwdlj9st.png" alt="image.png" width="800" height="385"&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://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%2Fyenx1ps9bo3xbg30fcuq.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%2Fyenx1ps9bo3xbg30fcuq.png" alt="image.png" width="799" height="349"&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://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%2F75bpi65lgoxudq6nxwzu.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%2F75bpi65lgoxudq6nxwzu.png" 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://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%2Ffpaemawsa06afiqnm4q5.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%2Ffpaemawsa06afiqnm4q5.png" alt="image.png" width="799" height="423"&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://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%2F4stsxf060tg5ppp9hnbg.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%2F4stsxf060tg5ppp9hnbg.png" alt="image.png" width="800" height="411"&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://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%2Fxg4aqc44xk0sgsgsc8fw.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%2Fxg4aqc44xk0sgsgsc8fw.png" alt="image.png" width="800" height="425"&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://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%2Flkcmuur11qe9e9gbv9pm.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%2Flkcmuur11qe9e9gbv9pm.png" alt="image.png" width="800" height="372"&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://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%2Fbt13m7bishepv8ov7u4p.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%2Fbt13m7bishepv8ov7u4p.png" alt="image.png" width="800" height="399"&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://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%2Fpg3xxhl1moipf6avgtsm.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%2Fpg3xxhl1moipf6avgtsm.png" alt="image.png" width="800" height="284"&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://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%2F8k6200i28m6a727k8ja7.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%2F8k6200i28m6a727k8ja7.png" alt="image.png" width="800" height="393"&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://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%2F7kzl02fb4tpjs8nneu1l.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%2F7kzl02fb4tpjs8nneu1l.png" alt="image.png" width="800" height="419"&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" 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://ethanrodrigo.hashnode.dev/" rel="noopener noreferrer"&gt;Hashnode&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
