{"id":64,"date":"2008-03-05T16:37:41","date_gmt":"2008-03-05T16:37:41","guid":{"rendered":"http:\/\/blog.danplanet.com\/wordpress\/?p=64"},"modified":"2011-11-29T16:54:52","modified_gmt":"2011-11-29T16:54:52","slug":"making-a-kvm-bootable-image","status":"publish","type":"post","link":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/","title":{"rendered":"Making a KVM-bootable image"},"content":{"rendered":"<p>I&#8217;ve lost count of how many times I&#8217;ve had to re-learn how to create a bootable image from a filesystem tree (such as a tarball of a root filesystem, or a Xen partition image).\u00a0 If for no other reason than recording it for next time, here it is.<\/p>\n<p>Create an image file (lets assume 4MB will do it), partition it, mount the partition, and copy in the root filesystem<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>% dd if=\/dev\/zero of=test.img bs=1M count=4<br \/>\n% parted test.img mklabel msdos<br \/>\n% parted test.img mkpart primary 0 4<br \/>\n% losetup \/dev\/loop0 test.img<br \/>\n% kpartx -a \/dev\/loop0<br \/>\n% mount \/dev\/mapper\/loop0p1 \/mnt<br \/>\n% cp -rav \/path\/to\/root \/mnt\/<\/p><\/blockquote>\n<p>Now, you need to put a kernel and an initrd on it.\u00a0 Assuming a RedHat-like system:<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>% mkdir -p \/mnt\/boot\/grub<br \/>\n% cp \/boot\/vmlinuz-`uname -r` \/mnt\/boot\/vmlinuz<br \/>\n% mkinitrd &#8211;with ata_piix &#8211;with rtl8139 \/mnt\/boot\/initrd `uname -r`<\/p><\/blockquote>\n<p>Next, you need a bootloader:<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>% cat &gt;\/mnt\/boot\/grub\/grub.conf &lt;&lt;EOF<br \/>\ndefault 0<br \/>\ntimeout 5<br \/>\ntitle My System<br \/>\nkernel \/boot\/vmlinuz root=\/dev\/sda1<br \/>\ninitrd \/boot\/initrd<br \/>\nEOF<br \/>\n% cat &gt;\/tmp\/grub_setup &lt;&lt;EOF<br \/>\ndevice (hd0) \/path\/to\/image\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # NB: Put your full path here<br \/>\nroot (hd0,0)<br \/>\nsetup (hd0)<br \/>\nEOF<br \/>\n% grub &lt; \/tmp\/grub_setup<\/p><\/blockquote>\n<p>That&#8217;s it!\u00a0 Now you can unmount your image:<\/p>\n<blockquote style=\"font-family: Courier New,Courier,mono;\"><p>% umount \/mnt<br \/>\n% kpartx -d \/dev\/loop0<br \/>\n% losetup -d \/dev\/loop0<\/p><\/blockquote>\n<p>The resulting image should boot normally in QEMU, KVM, etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve lost count of how many times I&#8217;ve had to re-learn how to create a bootable image from a filesystem tree (such as a tarball of a root filesystem, or a Xen partition image).\u00a0 If for no other reason than &hellip; <a href=\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,6],"tags":[43,46],"class_list":["post-64","post","type-post","status-publish","format-standard","hentry","category-codemonkeying","category-linux","tag-linux-2","tag-virtualization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Making a KVM-bootable image - Right Angles<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Making a KVM-bootable image - Right Angles\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve lost count of how many times I&#8217;ve had to re-learn how to create a bootable image from a filesystem tree (such as a tarball of a root filesystem, or a Xen partition image).\u00a0 If for no other reason than &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/\" \/>\n<meta property=\"og:site_name\" content=\"Right Angles\" \/>\n<meta property=\"article:published_time\" content=\"2008-03-05T16:37:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2011-11-29T16:54:52+00:00\" \/>\n<meta name=\"author\" content=\"Dan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/\"},\"author\":{\"name\":\"Dan\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"headline\":\"Making a KVM-bootable image\",\"datePublished\":\"2008-03-05T16:37:41+00:00\",\"dateModified\":\"2011-11-29T16:54:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/\"},\"wordCount\":244,\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"keywords\":[\"linux\",\"virtualization\"],\"articleSection\":[\"Codemonkeying\",\"Linux\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/\",\"url\":\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/\",\"name\":\"Making a KVM-bootable image - Right Angles\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\"},\"datePublished\":\"2008-03-05T16:37:41+00:00\",\"dateModified\":\"2011-11-29T16:54:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.danplanet.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Making a KVM-bootable image\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\",\"url\":\"https:\/\/www.danplanet.com\/blog\/\",\"name\":\"Right Angles\",\"description\":\"If they&#039;re not right...they&#039;re wrong\",\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\",\"name\":\"Dan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"caption\":\"Dan\"},\"logo\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.danplanet.com\/blog\/author\/dan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Making a KVM-bootable image - Right Angles","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/","og_locale":"en_US","og_type":"article","og_title":"Making a KVM-bootable image - Right Angles","og_description":"I&#8217;ve lost count of how many times I&#8217;ve had to re-learn how to create a bootable image from a filesystem tree (such as a tarball of a root filesystem, or a Xen partition image).\u00a0 If for no other reason than &hellip; Continue reading &rarr;","og_url":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/","og_site_name":"Right Angles","article_published_time":"2008-03-05T16:37:41+00:00","article_modified_time":"2011-11-29T16:54:52+00:00","author":"Dan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dan","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/#article","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/"},"author":{"name":"Dan","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"headline":"Making a KVM-bootable image","datePublished":"2008-03-05T16:37:41+00:00","dateModified":"2011-11-29T16:54:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/"},"wordCount":244,"publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"keywords":["linux","virtualization"],"articleSection":["Codemonkeying","Linux"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/","url":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/","name":"Making a KVM-bootable image - Right Angles","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/#website"},"datePublished":"2008-03-05T16:37:41+00:00","dateModified":"2011-11-29T16:54:52+00:00","breadcrumb":{"@id":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.danplanet.com\/blog\/2008\/03\/05\/making-a-kvm-bootable-image\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.danplanet.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Making a KVM-bootable image"}]},{"@type":"WebSite","@id":"https:\/\/www.danplanet.com\/blog\/#website","url":"https:\/\/www.danplanet.com\/blog\/","name":"Right Angles","description":"If they&#039;re not right...they&#039;re wrong","publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c","name":"Dan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","caption":"Dan"},"logo":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.danplanet.com\/blog\/author\/dan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/64","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":1,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":151,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/64\/revisions\/151"}],"wp:attachment":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}