Merge pull request #77 from marineam/qcow2

Qemu, Qcow2, and Openstack
This commit is contained in:
Michael Marineau 2013-08-02 12:45:20 -07:00
commit 25576f3d7e
2 changed files with 30 additions and 35 deletions

View File

@ -7,6 +7,7 @@
VALID_IMG_TYPES=( VALID_IMG_TYPES=(
ami ami
openstack
qemu qemu
rackspace rackspace
vagrant vagrant
@ -38,7 +39,7 @@ IMG_DEFAULT_HYBRID_MBR=0
IMG_DEFAULT_OEM_PACKAGE= IMG_DEFAULT_OEM_PACKAGE=
# Name of the target image format. # Name of the target image format.
# May be raw or vmdk (vmware, virtualbox) # May be raw, qcow2 (qemu), or vmdk (vmware, virtualbox)
IMG_DEFAULT_DISK_FORMAT=raw IMG_DEFAULT_DISK_FORMAT=raw
# Name of the target config format, default is no config # Name of the target config format, default is no config
@ -48,6 +49,7 @@ IMG_DEFAULT_CONF_FORMAT=
IMG_DEFAULT_MEM=1024 IMG_DEFAULT_MEM=1024
## qemu ## qemu
IMG_qemu_DISK_FORMAT=qcow2
IMG_qemu_CONF_FORMAT=qemu IMG_qemu_CONF_FORMAT=qemu
## xen ## xen
@ -72,6 +74,10 @@ IMG_vmware_CONF_FORMAT=vmx
IMG_ami_HYBRID_MBR=1 IMG_ami_HYBRID_MBR=1
IMG_ami_OEM_PACKAGE=oem-ami IMG_ami_OEM_PACKAGE=oem-ami
## openstack, supports ec2's metadata format so use oem-ami
IMG_openstack_DISK_FORMAT=qcow2
IMG_openstack_OEM_PACKAGE=oem-ami
## rackspace ## rackspace
# TODO: package doesn't exist yet # TODO: package doesn't exist yet
#IMG_rackspace_OEM_PACKAGE=oem-rackspace #IMG_rackspace_OEM_PACKAGE=oem-rackspace
@ -131,6 +137,7 @@ _disk_ext() {
local disk_format=$(_get_vm_opt DISK_FORMAT) local disk_format=$(_get_vm_opt DISK_FORMAT)
case ${disk_format} in case ${disk_format} in
raw) echo bin;; raw) echo bin;;
qcow2) echo img;;
*) echo "${disk_format}";; *) echo "${disk_format}";;
esac esac
} }
@ -256,6 +263,10 @@ _write_raw_disk() {
mv "$1" "$2" mv "$1" "$2"
} }
_write_qcow2_disk() {
qemu-img convert -f raw "$1" -O qcow2 "$2"
}
_write_vmdk_disk() { _write_vmdk_disk() {
qemu-img convert -f raw "$1" -O vmdk "$2" qemu-img convert -f raw "$1" -O vmdk "$2"
} }
@ -274,52 +285,36 @@ _write_qemu_conf() {
local src_name=$(basename "$VM_SRC_IMG") local src_name=$(basename "$VM_SRC_IMG")
local dst_name=$(basename "$VM_DST_IMG") local dst_name=$(basename "$VM_DST_IMG")
local dst_dir=$(dirname "$VM_DST_IMG") local dst_dir=$(dirname "$VM_DST_IMG")
local conf_path="${dst_dir}/$(_src_to_dst_name "${src_name}" ".conf")" local script="${dst_dir}/$(_src_to_dst_name "${src_name}" ".sh")"
# FIXME qemu 1.4/5 doesn't support these options in config files cat >"${script}" <<EOF
# Seems like submitting a patch to fix that and documenting this #!/bin/sh
# format would be a worthy projects...
# name=${VM_NAME}
# uuid=${VM_UUID}
# m=${vm_mem}
# cpu=kvm64
# smp=2
cat >"${conf_path}" <<EOF SCRIPT_DIR="\`dirname "\$0"\`"
# qemu config file DISK_IMAGE="\${SCRIPT_DIR}/${dst_name}"
# Default to KVM, fall back on full emulation # Default to KVM, fall back on full emulation
[machine] exec qemu-system-x86_64 \
accel = "kvm:tcg" -name "${VM_NAME}" \
-uuid "${VM_UUID}" \
[drive] -m ${vm_mem} \
media = "disk" -machine accel=kvm:tcg \
index = "0" -drive index=0,if=virtio,media=disk,format=qcow2,file="\${DISK_IMAGE}" \
# if = "virtio" -net nic,vlan=0,model=virtio \
file = "${dst_name}" -net user,vlan=0,hostfwd=tcp::2222-:22 \
format = "raw" "\$@"
[net]
type = "nic"
vlan = "0"
model = "virtio"
[net]
type = "user"
vlan = "0"
hostfwd = "tcp::2222-:22"
EOF EOF
chmod +x "${script}"
cat >"${VM_README}" <<EOF cat >"${VM_README}" <<EOF
If you have qemu installed, you can start the image with: If you have qemu installed, you can start the image with:
cd $(relpath "${dst_dir}") ./path/to/$(basename "${script}") -curses
qemu-system-x86_64 -curses -m ${vm_mem} -readconfig "${conf_path##*/}"
SSH into that host with: SSH into that host with:
ssh 127.0.0.1 -p 2222 ssh 127.0.0.1 -p 2222
EOF EOF
VM_GENERATED_FILES+=( "${conf_path}" "${VM_README}" ) VM_GENERATED_FILES+=( "${script}" "${VM_README}" )
} }
# Generate the vmware config file # Generate the vmware config file

View File

@ -9,7 +9,7 @@ DEFAULT_MEM="1024"
DEFAULT_VMDK="ide.vmdk" DEFAULT_VMDK="ide.vmdk"
DEFAULT_VMX="coreos.vmx" DEFAULT_VMX="coreos.vmx"
DEFAULT_VBOX_DISK="os.vdi" DEFAULT_VBOX_DISK="os.vdi"
DEFAULT_QEMU_IMAGE="coreos_developer_qemu_image.bin" DEFAULT_QEMU_IMAGE="coreos_developer_qemu_image.img"
# Minimum sizes for full size vm images -- needed for update. # Minimum sizes for full size vm images -- needed for update.
MIN_VDISK_SIZE_FULL=9216 MIN_VDISK_SIZE_FULL=9216