<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Code Bites</title>
    <link rel="dns-prefetch" href="//maxcdn.bootstrapcdn.com">
    <link rel="dns-prefetch" href="//cdn.mathjax.org">
    <link rel="dns-prefetch" href="//cdnjs.cloudflare.com">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Recording the effort...">
    <meta name="robots" content="all">
    <meta name="author" content="Emmanuel Galindo">
    
    <link rel="canonical" href="https://emmanuel-galindo.github.io/">
    <link rel="alternate" type="application/rss+xml" title="RSS Feed for Code Bites" href="/feed.xml" />

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/pixyll.css?202008121940" type="text/css">
    <link rel="stylesheet" href="/css/custom.css?202008121940" type="text/css">

    <!-- Fonts -->
    
    <link href='//fonts.googleapis.com/css?family=Merriweather:900,900italic,300,300italic' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Lato:900,300' rel='stylesheet' type='text/css'>
    
    
      <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">
    

    <!-- MathJax -->
    

    <!-- Verifications -->
    
    

    <!-- Open Graph -->
    <!-- From: https://github.com/mmistakes/hpstr-jekyll-theme/blob/master/_includes/head.html -->
    <meta property="og:locale" content="en_US">
    <meta property="og:type" content="article">
    <meta property="og:title" content="Code Bites">
    <meta property="og:description" content="Recording the effort...">
    <meta property="og:url" content="https://emmanuel-galindo.github.io/">
    <meta property="og:site_name" content="Code Bites">

    <!-- Twitter Card -->
    <meta name="twitter:card" content="summary" />
    
    <meta name="twitter:title" content="Code Bites" />
    <meta name="twitter:description" content="Recording the effort..." />
    <meta name="twitter:url" content="https://emmanuel-galindo.github.io/" />

    <!-- Icons -->
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-160x160.png" sizes="160x160">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">

    
    <script type="text/javascript">
       (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
       (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
       m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
       })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
       ga('create', 'UA-76745738-1', 'auto');
       ga('send', 'pageview');
    </script>
    
</head>

<body class="site animated fade-in-down">
  
	

  <div class="site-wrap">
    <header class="site-header px2 px-responsive">
  <div class="mt2 wrap">
    <div class="measure">
      <a href="https://emmanuel-galindo.github.io" class="site-title">Code Bites</a>
      <nav class="site-nav">
         
<a href="/es/">Posts en español</a>


    

    

    

    

    

    

    

    

    

    

    

    


    

    
        <a href="/contact/">Say Hello</a>
    

    

    

    

    

    

    

    

    

    

    




      </nav>
      <div class="clearfix"></div>
      
        <div class="social-icons">
  <div class="social-icons-right">
    
      <a class="fa fa-github" href="https://github.com/emmanuel-galindo"></a>
    
    
    
    <a class="fa fa-rss" href="/feed.xml"></a>
    
    
    
    
    
      <a class="fa fa-envelope" href="mailto:egalindo@gmail.com"></a>
    
    
      <a class="fa fa-linkedin" href="https://www.linkedin.com/in/emmanuelgalindo"></a>
    
    
    
  </div>
  <div class="right">
    
    
    
  </div>
</div>
<div class="clearfix"></div>

      
    </div>
  </div>
</header>


    <div class="post p2 p-responsive wrap" role="main">
      <div class="measure">
        <div class="posts">
  
  <div class="post py3">
      <p class="post-meta">Aug 11, 2020</p>
      <a href="/en/2020/08/11/kafka-jms-client-to-confluent-cloud/" class="post-link">
        <h3 class="h1 post-title">
          Kafka JMS Client to Confluent Cloud example
        </h3>
      </a>
      <p class="post-summary">
        
      </p>
<!--
    <article class="post-content">
         <p>Confluent has created a JMS Client for that comes handy when working with legacy systems. Notably, it wraps a JMS 1.1 implementation and data flow goes like this:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[kafka-jms-client] &lt;--- kafka protocol ---&gt; [kafka broker]
</code></pre></div></div>


    </article>
-->
  </div>
  
  <div class="post py3">
      <p class="post-meta">Jun 5, 2020</p>
      <a href="/en/2020/06/05/Avoid-adding-credit-card-in-heroku-to-get-MongoDB/" class="post-link">
        <h3 class="h1 post-title">
          Avoid adding credit card in heroku to get MongoDB
        </h3>
      </a>
      <p class="post-summary">
        
      </p>
<!--
    <article class="post-content">
         <h2 id="connecting-mongodb-from-heroku-free-tier">Connecting MongoDB from Heroku free tier</h2>


    </article>
-->
  </div>
  
  <div class="post py3">
      <p class="post-meta">Jun 4, 2020</p>
      <a href="/en/2020/06/04/fixing-error-found-in-diagram-vscode-umlplant/" class="post-link">
        <h3 class="h1 post-title">
          Fixing Error found in diagram Picked up _JAVA_OPTIONS -Dawt.useSystemAAFontSettings=gasp
        </h3>
      </a>
      <p class="post-summary">
        
      </p>
<!--
    <article class="post-content">
         <p>UMLPlant VSCode extesion will fail to render the diagram code without these steps…
If you’re getting “Error found in diagram Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=gasp”</p>

<p>You’ll get a similar warning when running “java -version”</p>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>java <span class="nt">-version</span>
Picked up _JAVA_OPTIONS:   <span class="nt">-Dawt</span>.useSystemAAFontSettings<span class="o">=</span>gasp
openjdk version <span class="s2">"1.8.0_171"</span>
OpenJDK Runtime Environment <span class="o">(</span>build 1.8.0_171-8u171-b11-2-b11<span class="o">)</span>
OpenJDK 64-Bit Server VM <span class="o">(</span>build 25.171-b11, mixed mode<span class="o">)</span>
</code></pre></div></div>

<p>To fix this, add these lines to your ~/.bashrc (or the one you use):</p>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">_SILENT_JAVA_OPTIONS</span><span class="o">=</span><span class="s2">"</span><span class="nv">$_JAVA_OPTIONS</span><span class="s2">"</span>
<span class="nb">unset </span>_JAVA_OPTIONS
<span class="nb">alias </span><span class="nv">java</span><span class="o">=</span><span class="s1">'java "$_SILENT_JAVA_OPTIONS"'</span>
</code></pre></div></div>


    </article>
-->
  </div>
  
  <div class="post py3">
      <p class="post-meta">Apr 5, 2017</p>
      <a href="/en/2017/04/05/fixing-debian-boot-uefi-grub/" class="post-link">
        <h3 class="h1 post-title">
          Fixing Debian UEFI boot manager with Debian Live
        </h3>
      </a>
      <p class="post-summary">
        
      </p>
<!--
    <article class="post-content">
         <p><strong>Important note:</strong> If you are new to UEFI please read this 30min article to understand what’s happening: <a href="https://www.happyassassin.net/2014/01/25/uefi-boot-how-does-that-actually-work-then/">UEFI boot: how does that actually work, then?</a></p>

<p>The goal of this note is to fix the UEFI Boot Manager (located in the NVRAM) for a Debian installation, by using a Debian Live image to mount a broken system via chroot and then reinstall grub-efi. This will recreate the boot loader for grub2-efi in the EFI System Partition (as /boot/efi) and add an entry for it in the boot manager. 
A possible scenario to execute this workaround is when your current Linux installation dissapeared from the UEFI Boot Manager. The instructions here were executed on a Debian Jessie box.</p>

<p>Steps summary:</p>

<ol>
  <li>Download Debian Live</li>
  <li>Burn it to an USB drive</li>
  <li>Fix UEFI on the USB drive</li>
  <li>Boot Debian Live</li>
  <li>Verify Debian Live was loaded with UEFI</li>
  <li>Review devices location and current configuration</li>
  <li>Mount broken system (via chroot)</li>
  <li>Reinstall grub-efi</li>
  <li>Verify configuration</li>
  <li>Logout from chroot and reboot</li>
</ol>

<h2 id="download-debian-live">Download Debian Live</h2>
<p>Download it from <a href="https://www.debian.org/CD/live/">Debian Live</a>.</p>

<p><strong><em>Important:</em></strong> At this point, UEFI support exists only in Debian’s installation images. The Live images do not have support for UEFI boot.</p>

<h2 id="burn-it-to-an-usb-drive">Burn it to an USB drive</h2>
<p>As stated in the initial recommended reading, UEFI works best with FAT32 and GPT partition table. However, Debian Live does not support it yet
so any method could be chosen. However, be sure to format the USB drive as FAT32. Recommended tools:</p>

<ul>
  <li>For Debian Linux, <a href="https://github.com/resin-io/etcher">Ether</a>. Note that in the instructions use the retired site pgp.mit.edu, therefore use hkp://pool.sks-keyservers.net instead.</li>
  <li>For Windows, <a href="https://rufus.akeo.ie">Rufus</a>. It has the advantage of clearly allow to select the Partition scheme and system type.</li>
</ul>

<h2 id="fix-uefi-on-the-usb-drive">Fix UEFI on the USB drive</h2>
<ol>
  <li>Dowload Shell.efi from <a href="https://github.com/tianocore/edk2/tree/master/ShellBinPkg/UefiShell/X64">UEFI Shell</a>.</li>
  <li>On the USB drive create a EFI folder and a BOOT sub folder, then copy Shell.efi to EFI\BOOT\ and rename it to Bootx64.efi.</li>
  <li>Using a text editor, create a file called liveboot.nsh on the root of the USB drive and paste the following into the file:</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>live<span class="se">\v</span>mlinuz <span class="nv">initrd</span><span class="o">=</span>live<span class="se">\i</span>nitrd.img append <span class="nv">boot</span><span class="o">=</span>live components
</code></pre></div></div>

<h2 id="boot-debian-live">Boot Debian Live</h2>
<p>Reboot the computer and hit F8 or F12 to bring the UEFI Boot Menu, and select your USB Drive. If it is shown more than one time, ensure to select the one that mentions UEFI.
After UEFI Shell loads, type liveboot.nsh and press Enter.</p>

<h2 id="verify-debian-live-was-loaded-with-uefi">Verify Debian Live was loaded with UEFI</h2>
<p>When Debian Live finishes loading, verify it it was loaded with UEFI with two basic methods:</p>

<ol>
  <li>Checking dmesg output you should see many lines related to EFI or UEFI.</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>dmesg | <span class="nb">grep</span> <span class="nt">-i</span> efi 
</code></pre></div></div>
<ol>
  <li>Check the EFI vars are correctly loaded</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">ls</span> <span class="nt">-l</span> /sys/firmware/efi | <span class="nb">grep </span>vars
</code></pre></div></div>

<h2 id="review-devices-location-and-current-configuration">Review devices location and current configuration</h2>
<ol>
  <li>Identify the root, boot and EFI partitions from the broken system.
Use fdisk -l to survey the current partition. EFI normally goes into /dev/sdX1. Mount one by one trying to identify which is the correct one. 
As a reference, /boot would normally look like:</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">ls</span> <span class="nt">-l</span> /boot
total 21581
<span class="nt">-rw-r--r--</span> 1 root root   157721 Oct 19 03:45 config-3.16.0-4-amd64
drwxr-xr-x 5 root root     1024 Apr  5 15:26 grub
<span class="nt">-rw-r--r--</span> 1 root root 16023698 Dec  5 09:50 initrd.img-3.16.0-4-amd64
<span class="nt">-rw-r--r--</span> 1 root root  2679264 Oct 19 03:45 System.map-3.16.0-4-amd64
<span class="nt">-rw-r--r--</span> 1 root root  3126448 Oct 19 03:41 vmlinuz-3.16.0-4-amd64
</code></pre></div></div>
<p><strong>Note:</strong> In the case of lvm volumes, you might need to download the lvm2 package and expose the volumes before mounting:</p>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># apt-get install lvm2</span>
<span class="c"># vgscan</span>
<span class="c"># vgchange -a -y</span>
<span class="c"># mount /dev/volumegroup/logicalvolume /mnt</span>
</code></pre></div></div>
<ol>
  <li>Download efibootmgr and review current UEFI Boot Manager configuration</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># apt-get install efibootmgr</span>
<span class="c"># efibootmgr -v</span>
</code></pre></div></div>

<h2 id="mount-broken-system-via-chroot">Mount broken system (via chroot)</h2>
<p>Mounting another system via chroot is the usual procedure to recover broken system’s. Once the chroot comand is issues, Debian Live will treat the broken system’s “/” (root) as its own. Commands run in a chroot environment will affect the broken systems filesystems and not those of the Debian Live.</p>

<ol>
  <li>Mount root partition (for example an lvm)</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># mount /dev/volumegroup/logicalvolume /mnt</span>
</code></pre></div></div>
<ol>
  <li>Mount boot partition (F.e. in drive sda)</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># mount /dev/sda2 /mnt/boot</span>
</code></pre></div></div>
<ol>
  <li>Mount the EFI System Partition (usually in /dev/sda1)</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># mount /dev/sda1 /mnt/boot/efi</span>
</code></pre></div></div>
<ol>
  <li>Mount the critical virtual filesystems with the following single command:</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done</span>
</code></pre></div></div>
<ol>
  <li>Chroot to your normal (and broken) system device</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># chroot /mnt</span>
</code></pre></div></div>
<p><strong>Important:</strong> From now on your changes will affect your normal system.
<br /><br /></p>

<blockquote>

  <h3 id="note-for-raspberry-pi-os-previously-called-raspbian">Note for Raspberry Pi OS (previously called Raspbian)</h3>
  <p><strong><em>Nathan sent below comment from his experience running these notes, thanks!</em></strong></p>

  <p>For Raspbian LVM (Logical Volumes) are not used. There is no need to create directories for mounting a standard install. Once the partition called Linux Filesystem is mounted in /mnt, you have the /boot/efi folders, but efi is more like a placeholder where the EFI volume is mounted. Thus:</p>

  <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code># sudo mount /dev/mmcblk0p# /mnt     (# = partition number with Linux filesystem)
# sudo mount /dev/mmcblk0p# /mnt/boot/efi     (# = partition number with EFI System)
</code></pre></div>  </div>

</blockquote>

<h2 id="reinstall-grub-efi">Reinstall grub-efi</h2>
<p>Download and Install grub-efi package, set the debian bootloader and create a grub config file based on your disk partitioning schema</p>
<ol>
  <li>Install grub-efi package</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># apt-get install --reinstall grub-efi</span>
</code></pre></div></div>
<ol>
  <li>Put the debian bootloader in /boot/efi and create an appropiate entry in the computer’s UEFI Boot Manager</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># grub-install /dev/sda</span>
</code></pre></div></div>
<ol>
  <li>Re create a grub config file based on your disk partitioning schema</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># update-grub</span>
</code></pre></div></div>

<h2 id="verify-configuration">Verify configuration</h2>
<ol>
  <li>Bootloader exists</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># file /boot/efi/EFI/debian/grubx64.efi </span>
/boot/efi/EFI/debian/grubx64.efi: PE32+ executable <span class="o">(</span>EFI application<span class="o">)</span> x86-64 
<span class="o">(</span>stripped to external PDB<span class="o">)</span>, <span class="k">for </span>MS Windows
</code></pre></div></div>
<ol>
  <li>NVRAM entry was properly created</li>
</ol>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># efibootmgr -v | grep debian</span>
</code></pre></div></div>

<h2 id="logout-from-chroot-and-reboot">Logout from chroot and reboot</h2>
<p>Type ctrl+d or exit to quit the chroot session, and reboot.</p>

    </article>
-->
  </div>
  
  <div class="post py3">
      <p class="post-meta">Apr 4, 2017</p>
      <a href="/en/2017/04/04/shrink-lvm-for-windows-partition/" class="post-link">
        <h3 class="h1 post-title">
          Shrink LVM volume for Windows partition
        </h3>
      </a>
      <p class="post-summary">
        
      </p>
<!--
    <article class="post-content">
         <p>In order to release space from an LVM volume to finally get a free physical partition requires the following steps:</p>

<ol>
  <li>Resize File Sytem in the LVM volume</li>
  <li>Resize Physical Volume</li>
  <li>Create a NTFS partition</li>
</ol>

<p>Also, root access is necessary</p>

<h2 id="resize-file-sytem-in-the-lvm-volume">Resize File Sytem in the LVM volume</h2>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># lvresize --resizefs --verbose -L -30G /dev/machine_vg/root</span>
</code></pre></div></div>

<h2 id="resize-physical-volume">Resize Physical Volume</h2>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># pvresize --setphysicalvolumesize [the size of your volume - 30G] /dev/sdaX</span>
</code></pre></div></div>
<p>If you get an error as:
/dev/sdaX: cannot resize to X extents as later ones are allocated.
It means there’s another volume between the free space and the end. To see it:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># pvs -v --segments /dev/sdaX</span>
</code></pre></div></div>
<p>To move the free space towards the end, grab the last column from the output for the volume to move and use it in pvmove:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># pvmove --alloc anywhere /dev/sdaX:xxxxx-xxxx</span>
</code></pre></div></div>

<h2 id="create-a-ntfs-partition">Create a NTFS partition</h2>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># fdisk</span>
n
c
1-n <span class="o">[</span>partition number, probably sdaX+1]
L
87
<span class="c"># mkfs.ntfs /dev/sdaX</span>
</code></pre></div></div>

    </article>
-->
  </div>
  
</div>
<div class="pagination">
  
    <a class="pagination-item older" href="/./page2.html">Older</a>
  
  
    <!--
    <span class="pagination-item newer">Newer</span>
    -->
  
</div>

      </div>
    </div>
  </div>

  <footer class="center">
  <div class="measure">
    <small>
      Theme crafted with &lt;3 by <a href="http://johnotander.com">John Otander</a> (<a href="https://twitter.com/4lpine">@4lpine</a>).<br>
      &lt;/&gt; available on <a href="https://github.com/johnotander/pixyll">Github</a>.
    </small>
  </div>
</footer>


</body>
</html>