<?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: TheYarin</title>
    <description>The latest articles on DEV Community by TheYarin (@theyarin).</description>
    <link>https://dev.to/theyarin</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%2F434938%2F19fdbf8f-b80d-4a0c-aa0d-87730435bd38.png</url>
      <title>DEV Community: TheYarin</title>
      <link>https://dev.to/theyarin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theyarin"/>
    <language>en</language>
    <item>
      <title>Burning an image on a USB flash drive from a Windows machine using Git Bash</title>
      <dc:creator>TheYarin</dc:creator>
      <pubDate>Sat, 13 Feb 2021 18:07:25 +0000</pubDate>
      <link>https://dev.to/theyarin/burning-an-image-on-a-usb-flash-drive-from-a-windows-machine-using-git-bash-414i</link>
      <guid>https://dev.to/theyarin/burning-an-image-on-a-usb-flash-drive-from-a-windows-machine-using-git-bash-414i</guid>
      <description>&lt;h2&gt;
  
  
  tl;dr (for the pros)
&lt;/h2&gt;

&lt;p&gt;Remove all drive letters of the device before burning (using Windows' Disk Management tool, &lt;code&gt;WinKey+X, K&lt;/code&gt; to open).&lt;/p&gt;

&lt;h3&gt;
  
  
  Burning the image:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Run this in an elevated (admin) Git Bash&lt;/span&gt;
&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4M &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;path-to-image-file&amp;gt; &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;path-to-device-file&amp;gt; 
&lt;span class="nv"&gt;conv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;fdatasync &lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;progress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Validating the copying using a hash algorithm:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Check the hash of the original image:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;md5sum.exe &amp;lt;path-to-image-file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check the hash of the burned image on the device:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Run this in an elevated (admin) Git Bash&lt;/span&gt;
&lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;--printf&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"%s"&lt;/span&gt; &amp;lt;path-to-image-file&amp;gt;&lt;span class="si"&gt;)&lt;/span&gt; &amp;lt;path-to-device-file&amp;gt; | md5sum.exe
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; You can burn an OS image even on something like a microSD card, but those tend to malfunction much more often, especially cheap/old ones, probably because they weren't designed for the intensive read/write operations of burning a large image file and installing an OS from it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Full Explanation
&lt;/h2&gt;

&lt;p&gt;You want to burn an image (.img/.iso file) to a flash drive from your Windows machine. You are looking for a legit tool for the job, but you can't find one from a well trusted source. What do you do?&lt;/p&gt;

&lt;p&gt;Git Bash to the rescue!&lt;/p&gt;

&lt;p&gt;Git Bash comes with a tool called &lt;code&gt;dd&lt;/code&gt; which allows you to copy the contents of a file directly onto a storage device.&lt;br&gt;
To do that, we first need to find the right device.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1 - Finding the right device
&lt;/h3&gt;

&lt;p&gt;Git Bash allows us to access our storage devices in a convenient way - as if they were files. (like Linux)&lt;br&gt;
The files that represent devices are available (via Git Bash) in the folder &lt;code&gt;/dev&lt;/code&gt;. This folder contains many files, we are interested in the files whose name starts with "sd".&lt;/p&gt;

&lt;p&gt;You can list those by running this command after you plug in your flash drive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ll /dev/sd&lt;span class="k"&gt;*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll get something like the following files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/dev/sda
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
/dev/sdb
/dev/sdb1
/dev/sdc
/dev/sdc1
/dev/sdc2
/dev/sdc3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Filenames ending with a number represent a partition, and those without numbers represent the device. So, in the above list of files, the device &lt;code&gt;/dev/sda&lt;/code&gt; contains 5 partitions, represented by &lt;code&gt;/dev/sda1&lt;/code&gt; to &lt;code&gt;/dev/sda5&lt;/code&gt;. Remember, we need the file that represents the device, not a partition.&lt;/p&gt;

&lt;p&gt;So, which file represents our flash drive?&lt;br&gt;
That's a tricky one. The way I solved it is by looking at Windows' Disk Management tool (which you can open by hitting &lt;code&gt;WinKey+X, K&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tK6Lq3Fo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/935xwx9ngv04c0mv1w10.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tK6Lq3Fo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/935xwx9ngv04c0mv1w10.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In there you can find a list of your storage devices. I'd skip the table of volumes and go to the section below (the second section), it's easier to detect which device (== disk) represents your flash drive over there, either by size, number of partitions or sometimes, by label.&lt;/p&gt;

&lt;p&gt;Now, this usually goes like this: Disk 0 is &lt;code&gt;/dev/sda&lt;/code&gt;, Disk 1 is &lt;code&gt;/dev/sdb&lt;/code&gt; and so on, but make sure you got the right device by checking the size, number of partitions or label.&lt;/p&gt;

&lt;p&gt;(note: the number of partition-representing files seems to be greater than the number of partitions, by 1. So, in the example above, &lt;code&gt;/dev/sda&lt;/code&gt; has 4 partitions, even though there are &lt;code&gt;/dev/sda1&lt;/code&gt;-&lt;code&gt;/dev/sda5&lt;/code&gt;)&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2 - Removing the drive letters
&lt;/h3&gt;

&lt;p&gt;It's important that no process will be accessing the device while we burn an image on it, so we remove the drive letter to avoid any issues.&lt;br&gt;&lt;br&gt;
When I tried burning an image without removing the drive letter first, the copying was corrupted - not all the bytes were successfully written to the device.&lt;/p&gt;

&lt;p&gt;To remove the drive letter, open Windows' Disk Management tool.&lt;br&gt;
Usually, a USB flash drive will only have one partition, so to remove the drive letter you need to right-click the Disk block in the second section and select &lt;code&gt;Change Drive Letter and Paths&lt;/code&gt;. In there, you can remove the drive letter.&lt;br&gt;
If you have more than one partition on the device, you'll need to remove all the drive letters of all partitions that were assigned a drive letter. Do this like you would with a single-partition device, but instead of the Disk block, by right-clicking each partition block.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3 - Burning the image
&lt;/h2&gt;

&lt;p&gt;Now, the copying part! Running the following command will start the copying. Replace &lt;code&gt;/c/Users/User/Downloads/ubuntu-20.04.2.0-desktop-amd64.iso&lt;/code&gt; with the path to your desired image and &lt;code&gt;/dev/sdb&lt;/code&gt; with the path to the correct device file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Run this in an elevated (admin) Git Bash&lt;/span&gt;
&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4M &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/c/Users/User/Downloads/ubuntu-20.04.2.0-desktop-amd64.iso &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/sdb &lt;span class="nv"&gt;conv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;fdatasync &lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;progress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm burning the latest version of Ubuntu, but that works with pretty much any image.&lt;/p&gt;

&lt;p&gt;The output will look like this and will update along the copying process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;226492416 bytes (226 MB, 216 MiB) copied, 19 s, 11.9 MB/s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4 - Checking the hashes
&lt;/h3&gt;

&lt;p&gt;It's worth mentioning that the dd command won't report any write errors that occurred during the copying process, so you might want to make sure that the image was properly written to the flash drive.&lt;/p&gt;

&lt;p&gt;I do this by comparing the hash of the first N bytes of the device with the hash of the image file, where N is the size of the image we burned: (Hashing the entire device might give the wrong result because the device is probably not the same size as your image file)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Run this in an elevated (admin) Git Bash&lt;/span&gt;
 &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;--printf&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"%s"&lt;/span&gt; ~/Downloads/ubuntu-20.04.2.0-desktop-amd64.iso&lt;span class="si"&gt;)&lt;/span&gt; /dev/sdb | md5sum.exe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resulting hash should be the same as the hash of the image file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;md5sum.exe ~/Downloads/ubuntu-20.04.2.0-desktop-amd64.iso
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Tilda (~) is a short for your home (user) directory.&lt;/li&gt;
&lt;li&gt;I used the MD5 hashing algorithm because it's fast, you can use any other hash algorithm (SHA1, SHA256...) if you want.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 5 - Safely ejecting the flash drive
&lt;/h3&gt;

&lt;p&gt;To safely eject the flash drive, you can open Windows' Disk Management tool, right click the flash drive's Disk block in the second section and click eject.&lt;/p&gt;

&lt;h3&gt;
  
  
  That's it.
&lt;/h3&gt;

&lt;p&gt;I hope you found this tutorial helpful.&lt;br&gt;
Feedback is welcome :)&lt;/p&gt;

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