6

I would like to turn the disk image from a cloud image (former UEC image) into a bootable VirtualBox (for Vagrant). I can run the image in kvm (using https://help.ubuntu.com/community/UEC/Images as a starter), but how can I turn the .img disk file into a bootable VirtualBox disk? I would rather not use the floppy as boot.

htorque
  • 64,798

3 Answers3

1

The solution is indeed to make the image itself bootable. After days of searching the interwebs I found that the solution is to use the package extlinux, which is a derivative of syslinux — a solution for making FAT disks bootable. extlinux works on e2fs and derivatives, this works perfectly on any old ext2 system.

mkdir /mnt/image
mount -o loop cloud-image.img /mnt/image
mkdir /mnt/image/extlinux/
extlinux --install /mnt/image/extlinux/
echo "DEFAULT /vmlinuz" > /mnt/image/extlinux/extlinux.conf
echo "APPEND root=/dev/sda init=/usr/lib/cloud-init/uncloud-init" \
     "ubuntu-pass=ubuntu ds=nocloud" >> /mnt/image/extlinux/extlinux.conf
umount /mnt/image

This will make the image bootable, and disable built-in cloud initialization techniques and so on.

Notes: I haven't worked out how to specify an APPEND which allows it to use the "root=LABEL=cloudimage-rootfs".

The resulting image can then boot using qemu, kvm or vmware, without additional floppies, kernels, or anything. And from what I understand, apt-get upgrading the kernel will make that kernel active the next boot.

edit: I forgot to mention the obvious that you need to perform this loop-back mounting on the raw disk image, and then convert the resulting file to a VDI using vboxmanage convertfromraw cloud-image.img cloud-image.vdi

mogsie
  • 185
  • root=LABEL=cloudimage-rootfs can be replaced with

    root=/dev/disk/by-label/cloudimg-rootfs

    not tested but I'll assume the initrd is using udev

    as far as I know LABEL tends to be an init script variable, meaning its dependant on ubuntu's init scripts which I do not know enough about.

    – strings Jan 07 '13 at 23:07
  • Why not just booting the VM and installing grub? – Blaisorblade Feb 12 '14 at 05:16
  • The point was to be able to do this without having to boot it, so as to support things like cloud-init in a non-cloud environment, using stock UEC images. I think this answer might be obsolete, as I've seen that UEC images actually are bootable as-is (which was not the case a couple of years ago). – mogsie Feb 20 '14 at 11:08
  • If you want to use VirtualBox, you can use VBoxManage internalcommands createrawvmdk -filename cloud-image.vmdk -rawdisk cloud-image.img to create a meta description file for using the image with a new virtual machine. – Florian Aug 02 '16 at 13:22
1

Perhaps this is useful? http://en.wikibooks.org/wiki/QEMU/Images#Exchanging_images_with_VirtualBox

kim0
  • 337
  • While certainly useful, it does not help with the current problem, as the disk file from cloud images is not a bootable disk. It works in KVM because I can boot a specific kernel file, and tell it where the root file system is. What I need is a way to turn the disk image into a bootable disk. – Magne Rasmussen Sep 26 '11 at 06:26
  • 2
    Then you have to solve this problem just like you would with a real computer and load a live cd/usb image, chroot your target disk, and install the boot loader and kernel. Start there, get it working in KVM then convert it to a VirtualBox image. – ppetraki Jan 27 '12 at 03:02
  • @ppetraki want to make that an answer for upvoting? – Tom Brossman Apr 03 '12 at 13:14
  • @Tom: Sorry, I don't use Vbox anymore. – ppetraki Apr 03 '12 at 15:10
0

There is now an Ova formatted image that works after importing into VirtualBox, see my long search below. I still haven't figured out how to boot an image in Virt-manager, and would like to, but extlinux didnt help. It's not seeing the kernel file locations with Direct Boot.

What are the different versions available as Ubuntu cloud-images?

alchemy
  • 762