<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Diego A. Carrasco Gubernatis | Personal Website (Posts about qemu)</title><link>https://diegocarrasco.com/</link><description></description><atom:link href="https://diegocarrasco.com/categories/qemu.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2026 &lt;a href="mailto:hi@diegocarrasco.com"&gt;Diego Carrasco G.&lt;/a&gt; </copyright><lastBuildDate>Sat, 09 May 2026 08:04:38 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>How to make an image of an existing physical hard drive and attach it to a VM in virsh-manager and boot from it</title><link>https://diegocarrasco.com/make-an-image-of-an-existing-physical-hard-drive-and-attach-it-to-a-vm-in-virsh-manager-and-boot-from-it/</link><dc:creator>Diego Carrasco G.</dc:creator><description>&lt;h3 id="context"&gt;Context&lt;/h3&gt;
&lt;p&gt;I replaced the hard drive of my desktop, and I wanted to have a full clone of the disk in case I forgot to save anything and stuff like that. As I wanted to use the disk in another device, I made a Disk Image and then attached it to a VM to boot from it and get the same state I previously had.  Here are my notes for that.&lt;/p&gt;
&lt;p&gt;NOTE: This is a note for myself as I tend to forget these steps and commands and spent several hours trying to make this work.&lt;/p&gt;
&lt;h3 id="create-the-disk-image"&gt;Create the disk image&lt;/h3&gt;
&lt;p&gt;To create the image use &lt;code&gt;dd&lt;/code&gt;&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;dd&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/sdX&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/path/to/image.img&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4M&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;progress
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;or using &lt;code&gt;qemu-img&lt;/code&gt;&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;qemu-img&lt;span class="w"&gt; &lt;/span&gt;create&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="w"&gt; &lt;/span&gt;qcow2&lt;span class="w"&gt; &lt;/span&gt;-o&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10G&lt;span class="w"&gt; &lt;/span&gt;/path/to/image.qcow2&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;# set the right size&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I used &lt;code&gt;dd&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="create-the-vm-in-virsh-manager"&gt;Create the VM in &lt;code&gt;virsh-manager&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Then create a new VM in &lt;code&gt;virsh-manager&lt;/code&gt; with UEFI instead of BIOS (only if your original machine used UEFI. If it booted using BIOS, then the default will be enough). &lt;/p&gt;
&lt;p&gt;If the option is not shown, change the defaults for the new machines in &lt;code&gt;vish-manager&lt;/code&gt; -&amp;gt; Preferences -&amp;gt; New VM -&amp;gt; x86 Firmware.&lt;/p&gt;
&lt;p&gt;NOTE: As stated above, if your original device used BIOS, then ignore this part.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Screenshot of the settings screen of virsh manager" src="https://diegocarrasco.com/images/how-to-make-an-image-of-an-existing-physical-hard-drive-and-attach-it-to-a-vm-in-virsh-manager-and-boot-from-it/screenshot-virsh-manager-settings.png"&gt;&lt;/p&gt;
&lt;h3 id="convert-the-img-image-to-qcow2-to-use-with-qemu-and-virsh-manager"&gt;Convert the &lt;code&gt;.img&lt;/code&gt; image to &lt;code&gt;.qcow2&lt;/code&gt; to use with &lt;code&gt;qemu&lt;/code&gt; and &lt;code&gt;virsh-manager&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;If you created the disk image as &lt;code&gt;.img&lt;/code&gt;, convert it to &lt;code&gt;qcow2&lt;/code&gt; with the following command:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;qemu-img&lt;span class="w"&gt; &lt;/span&gt;convert&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="w"&gt; &lt;/span&gt;raw&lt;span class="w"&gt; &lt;/span&gt;-O&lt;span class="w"&gt; &lt;/span&gt;qcow2&lt;span class="w"&gt; &lt;/span&gt;originak_image.img&lt;span class="w"&gt; &lt;/span&gt;converted_image.qcow2
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;NOTE: If you get a permissions problem, try &lt;code&gt;sudo&lt;/code&gt; or set the right permissions of the image using &lt;code&gt;chmod&lt;/code&gt; or &lt;code&gt;chown&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="the-problems-i-had"&gt;The problems I had&lt;/h3&gt;
&lt;p&gt;I had several thing not really working:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In my case the VM was not booting at all, and the first issue was the BIOS → UEFI part (see above).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then it was loading the boot menu but not booting. When trying to boot Linux Mint (the OS inside the disk image), it went to black. I had to go to &lt;strong&gt;advanced options&lt;/strong&gt; and select the &lt;strong&gt;recovery boot&lt;/strong&gt;. There I could get into root, and edit the &lt;code&gt;/etc/fstab&lt;/code&gt; by commenting out the other hard drives I had in the original machine that were no longer available in this machine.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I have done this more than once, and more than once have I forgotten how this goes. Thus, it is now here.&lt;/p&gt;</description><category>linux</category><category>qemu</category><category>virsh</category><category>virsh-manager</category><guid>image-of-an-existing-physical-hard-drive</guid><pubDate>Wed, 28 May 2025 07:00:00 GMT</pubDate></item></channel></rss>