<?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: Mikhail</title>
    <description>The latest articles on DEV Community by Mikhail (@mixartemev).</description>
    <link>https://dev.to/mixartemev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F65664%2F9261dc5c-fa15-490a-93ec-a6edd6862dc4.jpeg</url>
      <title>DEV Community: Mikhail</title>
      <link>https://dev.to/mixartemev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mixartemev"/>
    <language>en</language>
    <item>
      <title>Minimalistic way to create cloud image from ISO with QEMU</title>
      <dc:creator>Mikhail</dc:creator>
      <pubDate>Thu, 25 Mar 2021 20:02:53 +0000</pubDate>
      <link>https://dev.to/mixartemev/minimalistic-way-to-create-cloud-image-from-iso-with-qemu-4lom</link>
      <guid>https://dev.to/mixartemev/minimalistic-way-to-create-cloud-image-from-iso-with-qemu-4lom</guid>
      <description>&lt;h4&gt;
  
  
  Install qemu
&lt;/h4&gt;

&lt;p&gt;This snippet for Mac OS, at Linux dists replace &lt;code&gt;brew&lt;/code&gt; to &lt;code&gt;apt/apk/yum/pkg&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;brew install qemu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create empty hard disk raw image
&lt;/h4&gt;

&lt;p&gt;Specify explicit image format (couse choosing &lt;code&gt;qcow2&lt;/code&gt; is minimal result image size), 1-st argument &lt;strong&gt;image name&lt;/strong&gt; and 2-nd arg &lt;strong&gt;size&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;qemu-img create -f qcow2 raw_hdd_10.qcow2 10G
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create virtual machine
&lt;/h4&gt;

&lt;p&gt;After &lt;code&gt;qemu-system-&lt;/code&gt; you can press &lt;em&gt;tab&lt;/em&gt; and choose your cpu architecture, in my case is &lt;code&gt;-x86_64&lt;/code&gt;. Then specify &lt;code&gt;-boot&lt;/code&gt; disk &lt;code&gt;d&lt;/code&gt; (it's cdrom), &lt;code&gt;-cdrom&lt;/code&gt; image path and main hdd (&lt;code&gt;-hda&lt;/code&gt;) image path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;qemu-system-x86_64 -boot d -cdrom ~/Downloads/alpine-virt-3.13.2-x86_64.iso -hda hdd10.qcow2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Install OS from bootable iso to hdd
&lt;/h4&gt;

&lt;p&gt;In Alpine case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setup-alpine
exit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Shutdown VM, and&lt;/p&gt;

&lt;h4&gt;
  
  
  Load installed OS from hdd image
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;qemu-system-x86_64 -hda hdd10.qcow2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can make any your custom changes in OS.&lt;br&gt;
At finally..&lt;br&gt;
Filling nulls all free space for better compress hdd image, showing count nulled blocks (&lt;code&gt;-v&lt;/code&gt;), From root mount point &lt;code&gt;/&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;fstrim -v /
exit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Compress resulted image
&lt;/h4&gt;

&lt;p&gt;Specify input &lt;code&gt;-f&lt;/code&gt; and output &lt;code&gt;-O&lt;/code&gt; image format, compression flag &lt;code&gt;-c&lt;/code&gt;, then input and output image paths (they may be equal, if you don't need backup)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;qemu-img convert -f qcow2 -O qcow2 -c hdd10.qcow2 hdd10-compressed.qcow2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Voila!&lt;br&gt;
Tommorow we'll upload your custom image &lt;code&gt;hdd10-compressed.qcow2&lt;/code&gt; to cloud using &lt;strong&gt;&lt;em&gt;openstack&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>image</category>
      <category>alpine</category>
      <category>qemu</category>
    </item>
  </channel>
</rss>
