Created
June 26, 2013 10:03
-
-
Save nevkontakte/5866303 to your computer and use it in GitHub Desktop.
Make Ubuntu Cloud images bootable in virtualbox. Pre-requirements: qemu-img (package qemu-utils in Ubuntu repo), extlinux
Tested under Ubuntu 13.04, might work on other linux distros. Get ubuntu image: http://cloud-images.ubuntu.com/precise/current/*.img
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
## Usage: sudo ubuntu-cloud-bootable.sh precise-server-cloudimg-amd64-disk1.img | |
## | |
set -e | |
mount_point="$(mktemp -d)" | |
raw="$(mktemp)" | |
echo ">>> Converting to raw: $raw ..." | |
qemu-img convert -O raw "$1" "$raw" | |
echo ">>> Installing bootloader..." | |
offset=$(fdisk -l "$raw" | grep -E "${raw}p?1" | awk '{print $3}') | |
mount -o loop,offset=$(($offset * 512)) "$raw" "$mount_point" | |
mkdir "$mount_point/extlinux/" | |
extlinux --install "$mount_point/extlinux/" | |
echo "DEFAULT /vmlinuz" > "$mount_point/extlinux/extlinux.conf" | |
echo "APPEND root=/dev/sda init=/usr/lib/cloud-init/uncloud-init" \ | |
"ubuntu-pass=ubuntu ds=nocloud" >> "$mount_point/extlinux/extlinux.conf" | |
umount "$mount_point" | |
rmdir "$mount_point" | |
echo ">>> Converting to vdi..." | |
vdi="$(dirname "$1")/$(basename "$1" .img)-bootable.vdi" | |
qemu-img convert -O vdi "$raw" "$vdi" | |
rm "$raw" | |
chown --reference="$1" "$vdi" | |
echo "Image ready: $vdi" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment