virtualboxhttp://www.turnkeylinux.org/taxonomy/term/63/0
enConverting a virtual disk image: VDI or VMDK to an ISO you can distributehttp://www.turnkeylinux.org/blog/convert-vm-iso
<p>Why would anyone in their right mind want to convert a VM into an ISO?</p>
<p>Good question, the answer for Conor Fox (who was the inspiration for this post - thanks Conor!) was to distribute his customized TurnKey PostgreSQL image so others could use it.</p>
<p>Distributing an ISO as opposed to a VM image allows it to be installed on any virtualization platform, as well as on bare metal, with the added bonus of running live.</p>
<p>I suppose that's a good enough reason, so lets get to it.</p>
<!--break-->
<br/>
<h2>Convert VM disk to raw image and mount it</h2>
<p>First we need to get qemu-img, a tool bundled with <a href="http://www.qemu.org">qemu</a> (KVM's virtualization backend) to convert the VM disk to a raw image, and <a href="http://www.turnkeylinux.org/docs/tklpatch">TKLPatch</a>, the TurnKey customization mechanism to package the ISO.</p>
<p>If you are not using a TurnKey installation, see the <a href="http://www.turnkeylinux.org/docs/tklpatch/installation">TKLPatch installation notes</a>.</p>
<pre>
apt-get install qemu
apt-get install tklpatch</pre>
<p>I'll show how to convert a VMWare VMDK image into raw disk format. If you are using a different virtualization platform such as Virtualbox, see <a href="http://www.turnkeylinux.org/blog/convert-vdi-vmdk">this post</a> on converting a VDI to a raw image.</p>
<pre>
qemu-img convert -f vmdk turnkey-core.vmdk -O raw turnkey-core.raw
</pre>
<p>Next, mount the raw disk as a loopback device.</p>
<pre>
mkdir turnkey-core.mount
mount -o loop turnkey-core.raw turnkey-core.mount</pre>
<p><strong>GOTCHA 1</strong>: If your VM has partitions, it's a little tricker. You'll need to setup the loop device, partition mappings and finally mount the rootfs partition. You will need kpartx to setup the mappings.</p>
<pre>
loopdev=$(losetup -s -f turnkey-core.raw)
apt-get install kpartx
kpartx -a $loopdev
<em># p1 refers to the first partition (rootfs)</em>
mkdir turnkey-core.mount
mount /dev/mapper/$(basename $loopdev)p1 turnkey-core.mount</pre>
<h2><br />
Extract root filesystem and tweak for ISO configuration</h2>
<p>Now, make a copy of the root filesystem and unmount the loopback.</p>
<pre>
mkdir turnkey-core.rootfs
rsync -a -t -r -S -I turnkey-core.mount/ turnkey-core.rootfs
umount -d turnkey-core.mount
# If your VM had partitions (GOTCHA 1):
kpartx -d $loopdev
losetup -d $loopdev</pre>
<p>Because the VM is an installed system as opposed to the ISO, the file system table needs to be updated.</p>
<pre>
cat&gt;turnkey-core.rootfs/etc/fstab&lt;&lt;EOF
aufs / aufs rw 0 0
tmpfs /tmp tmpfs nosuid,nodev 0 0
EOF</pre>
<p><strong>GOTCHA 2:</strong> If your VM uses a kernel optimized for virtualization (like the one included in the TurnKey VM builds), you need to replace it with a generic kernel, and also remove vmware-tools if installed.</p>
<pre>
tklpatch-chroot turnkey-core.rootfs
<em># inside the chroot</em>
apt-get update
apt-get install linux-image-generic
dpkg --purge $(dpkg-query --showformat='${Package}\n' -W 'vmware-tools*')
dpkg --purge $(dpkg-query --showformat='${Package}\n' -W '*-virtual')
exit</pre>
<h2><br />
Generate the ISO</h2>
<p>Finally, prepare the cdroot and generate the ISO.</p>
<pre>
tklpatch-prepare-cdroot turnkey-core.rootfs/
tklpatch-geniso turnkey-core.cdroot/</pre>
<p>Thats it!</p>
<p>Bonus: By default the ISO will boot automatically. If you want to include the <a href="http://www.turnkeylinux.org/screenshots/boot">TurnKey bootsplash and bootmenu</a>, extract the cdroot from a TurnKey ISO and tell tklpatch-prepare-cdroot to use it as a template.</p>
<pre>
tklpatch-extractiso turnkey-core.iso
tklpatch-prepare-cdroot turnkey-core.rootfs/ turnkey-core.cdroot/
tklpatch-geniso turnkey-core.cdroot/</pre>
<p><strong>Ever needed to package a VM as a distributable ISO? <a href="#comment-form">Post a comment</a>!</strong></p></br/>http://www.turnkeylinux.org/blog/convert-vm-iso#commentsconvertvirtualboxvmwareThu, 11 Feb 2010 07:21:03 +0000Alon Swartz1019 at http://www.turnkeylinux.orgConverting a virtual disk image: VDI to VMDK to a raw loopback file you can mounthttp://www.turnkeylinux.org/blog/convert-vdi-vmdk
<p>By default, VirtualBox creates virtual disk images in a special format called VDI, which is unique to VirtualBox. Disk images are stored in $HOME/.VirtualBox/HardDisks.</p>
<p>You'll need to convert VDI into another format if you want to run a VirtualBox VM on another virtualization platform, such as VMWare or KVM.</p>
<!--break-->
<p>The VMDK virtual disk format is a good choice because even though it originated with VMWare it is supported by other virtualization platforms including VirtualBox and KVM.</p>
<p>VirtualBox enables the conversion using the low-level &quot;VBoxManage clonehd&quot; command:</p>
<pre class="literal-block">
VBoxManage list hdds # prints a list of disk image UUIDs
VBoxManage clonehd &lt;UUID&gt; -o converted.vmdk format VMDK
cd ~/.VirtualBox/HardDisks/
ls -la converted.vmdk
</pre>
<p>Once you have converted to VMDK you can use qemu-img, a tool bundled with qemu (KVM's virtualization backend) to further convert VMDK to other formats.</p>
<p>A particularly useful format to convert to is 'raw' which you can then mount as a loopback device:</p>
<pre class="literal-block">
apt-get install qemu
qemu-img convert -f vmdk converted.vmdk -O raw converted.raw
mount -o loop converted.raw /mnt<strong><br /></strong></pre>
<p><strong>Ever had to convert between disk image formats? <a href="#comment-form">Post a comment</a>!</strong></p>http://www.turnkeylinux.org/blog/convert-vdi-vmdk#commentsconvertvirtualboxvmwareTue, 09 Feb 2010 18:00:00 +0000Liraz Siri1009 at http://www.turnkeylinux.org