Merge pull request #211 from polvi/iso

feat(iso): add iso image format to image_to_vm
This commit is contained in:
polvi 2014-03-31 18:44:46 -07:00
commit c15791ebea
2 changed files with 58 additions and 3 deletions

View File

@ -7,6 +7,7 @@ VM_IMAGE=
VM_KERNEL= VM_KERNEL=
VM_INITRD= VM_INITRD=
VM_MEMORY= VM_MEMORY=
VM_CDROM=
VM_NCPUS="`grep -c ^processor /proc/cpuinfo`" VM_NCPUS="`grep -c ^processor /proc/cpuinfo`"
SSH_PORT=2222 SSH_PORT=2222
SSH_KEYS="" SSH_KEYS=""
@ -102,6 +103,10 @@ if [ -n "${VM_UUID}" ]; then
set -- -uuid "$VM_UUID" "$@" set -- -uuid "$VM_UUID" "$@"
fi fi
if [ -n "${VM_CDROM}" ]; then
set -- -cdrom "$VM_CDROM" "$@"
fi
# Default to KVM, fall back on full emulation # Default to KVM, fall back on full emulation
# ${METADATA} will be mounted in CoreOS as /media/metadata # ${METADATA} will be mounted in CoreOS as /media/metadata
qemu-system-x86_64 \ qemu-system-x86_64 \

View File

@ -8,6 +8,7 @@
VALID_IMG_TYPES=( VALID_IMG_TYPES=(
ami ami
pxe pxe
iso
openstack openstack
qemu qemu
qemu_no_kexec qemu_no_kexec
@ -117,6 +118,11 @@ IMG_pxe_DISK_FORMAT=cpio
IMG_pxe_PARTITIONED_IMG=0 IMG_pxe_PARTITIONED_IMG=0
IMG_pxe_CONF_FORMAT=pxe IMG_pxe_CONF_FORMAT=pxe
## pxe, which is an cpio image
IMG_iso_DISK_FORMAT=iso
IMG_iso_PARTITIONED_IMG=0
IMG_iso_CONF_FORMAT=iso
## gce, image tarball ## gce, image tarball
IMG_gce_DISK_LAYOUT=vm IMG_gce_DISK_LAYOUT=vm
IMG_gce_CONF_FORMAT=gce IMG_gce_CONF_FORMAT=gce
@ -292,9 +298,7 @@ _write_vmdk_scsi_disk() {
qemu-img convert -f raw "$1" -O vmdk -o adapter_type=lsilogic "$2" qemu-img convert -f raw "$1" -O vmdk -o adapter_type=lsilogic "$2"
} }
# The cpio "disk" is a bit special, _write_cpio_common() {
# consists of a kernel+initrd not a block device
_write_cpio_disk() {
local cpio_target="${VM_TMP_DIR}/rootcpio" local cpio_target="${VM_TMP_DIR}/rootcpio"
local dst_dir=$(_dst_dir) local dst_dir=$(_dst_dir)
local vmlinuz_name="$(_dst_name ".vmlinuz")" local vmlinuz_name="$(_dst_name ".vmlinuz")"
@ -350,11 +354,50 @@ EOF
find . | cpio -o -H newc | gzip > "$2" find . | cpio -o -H newc | gzip > "$2"
popd >/dev/null popd >/dev/null
}
# The cpio "disk" is a bit special,
# consists of a kernel+initrd not a block device
_write_cpio_disk() {
local base_dir="${VM_TMP_ROOT}/usr"
local dst_dir=$(_dst_dir)
local vmlinuz_name="$(_dst_name ".vmlinuz")"
_write_cpio_common $@
# Pull the kernel out of the filesystem # Pull the kernel out of the filesystem
cp "${base_dir}"/boot/vmlinuz "${dst_dir}/${vmlinuz_name}" cp "${base_dir}"/boot/vmlinuz "${dst_dir}/${vmlinuz_name}"
VM_GENERATED_FILES+=( "${dst_dir}/${vmlinuz_name}" ) VM_GENERATED_FILES+=( "${dst_dir}/${vmlinuz_name}" )
} }
_write_iso_disk() {
local base_dir="${VM_TMP_ROOT}/usr"
local iso_target="${VM_TMP_DIR}/rootiso"
local dst_dir=$(_dst_dir)
local vmlinuz_name="$(_dst_name ".vmlinuz")"
mkdir "${iso_target}"
pushd "${iso_target}" >/dev/null
mkdir isolinux syslinux coreos
_write_cpio_common "$1" "${iso_target}/coreos/cpio.gz"
cp "${base_dir}"/boot/vmlinuz "${iso_target}/coreos/vmlinuz"
cp -R /usr/share/syslinux/* isolinux/
cat<<EOF > isolinux/isolinux.cfg
INCLUDE /syslinux/syslinux.cfg
EOF
cat<<EOF > syslinux/syslinux.cfg
default coreos
prompt 1
timeout 15
label coreos
menu default
kernel /coreos/vmlinuz
append initrd=/coreos/cpio.gz coreos.autologin
EOF
mkisofs -v -l -r -J -o $2 -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table .
isohybrid $2
popd >/dev/null
}
# If a config format is defined write it! # If a config format is defined write it!
write_vm_conf() { write_vm_conf() {
local conf_format=$(_get_vm_opt CONF_FORMAT) local conf_format=$(_get_vm_opt CONF_FORMAT)
@ -420,6 +463,13 @@ When using -nographic or -serial you must also enable the serial console:
EOF EOF
} }
_write_iso_conf() {
local script="$(_dst_dir)/$(_dst_name ".sh")"
local dst_name=$(basename "$VM_DST_IMG")
_write_qemu_common "${script}"
sed -e "s%^VM_CDROM=.*%VM_CDROM='${dst_name}'%" -i "${script}"
}
# Generate the vmware config file # Generate the vmware config file
# A good reference doc: http://www.sanbarrow.com/vmx.html # A good reference doc: http://www.sanbarrow.com/vmx.html
_write_vmx_conf() { _write_vmx_conf() {