How to set up cloud image in VirtualBox?

7,646

Solution 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

Solution 2

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

Share:
7,646
sushil
Author by

sushil

Updated on September 18, 2022

Comments

  • sushil
    sushil over 1 year

    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.

  • sushil
    sushil over 12 years
    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.
  • ppetraki
    ppetraki about 12 years
    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.
  • Sanam Patel
    Sanam Patel about 12 years
    @ppetraki want to make that an answer for upvoting?
  • ppetraki
    ppetraki about 12 years
    @Tom: Sorry, I don't use Vbox anymore.
  • strings
    strings over 11 years
    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.
  • Blaisorblade
    Blaisorblade about 10 years
    Why not just booting the VM and installing grub?
  • RealityPC
    RealityPC about 10 years
    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).
  • Florian
    Florian over 7 years
    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.