diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index e91e59f925..2dba153c08 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -148,6 +148,19 @@ _src_to_dst_name() { echo "${1%_image.bin}_${VM_IMG_TYPE}${suffix}" } +# Generate a destination name based on file extension +_dst_name() { + local src_name=$(basename "$VM_SRC_IMG") + local suffix="$1" + echo "${src_name%_image.bin}_${VM_IMG_TYPE}${suffix}" +} + +# Return the destination directory +_dst_dir() { + echo $(dirname "$VM_DST_IMG") +} + + # Get the proper disk format extension. _disk_ext() { local disk_format=$(_get_vm_opt DISK_FORMAT) @@ -330,15 +343,15 @@ _write_dir_to_cpio() { _write_base_cpio_disk() { local root_mnt="${VM_TMP_DIR}/rootfs" - local kernel_name=$(basename $3 .cpio.gz).vmlinuz - local kernel_dir=$(dirname $3) + local dst_dir=$(_dst_dir) + local vmlinuz_name="$(_dst_name ".vmlinuz")" mkdir -p "${root_mnt}" # Roll the rootfs into the CPIO sudo mount -o loop "${TEMP_ROOTFS}" "${root_mnt}" _write_dir_to_cpio "${root_mnt}" "$2" - cp "${root_mnt}"/boot/vmlinuz ${kernel_dir}/${kernel_name} + cp "${root_mnt}"/boot/vmlinuz "${dst_dir}/${vmlinuz_name}" sudo umount "${root_mnt}" rm -rf "${root_mnt}" } @@ -398,15 +411,19 @@ EOF } _write_pxe_conf() { + local dst_name=$(basename "$VM_DST_IMG") + local dst_dir=$(_dst_dir) + local vmlinuz_name="$(_dst_name ".vmlinuz")" + cat >"${VM_README}" <