Skip to content

Commit

Permalink
Merge pull request #536 from churchers/issue/535
Browse files Browse the repository at this point in the history
Resize file backed images after writting cloud image with qemu-img
  • Loading branch information
mateuszkwiatkowski authored Sep 10, 2024
2 parents e392f82 + 350cd9e commit 31358b6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/vm-core
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ core::create(){
case "${_disk_dev}" in
zvol)
zfs::make_zvol "${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_disk_size}" "0" "${_zfs_opts}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "/dev/zvol/${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_img}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "/dev/zvol/${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_img}" "${_disk_dev}" "${_disk_size}"
;;
sparse-zvol)
zfs::make_zvol "${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_disk_size}" "1" "${_zfs_opts}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "/dev/zvol/${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_img}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "/dev/zvol/${VM_DS_ZFS_DATASET}/${_name}/${_disk}" "${_img}" "${_disk_dev}" "${_disk_size}"
;;
custom)
;;
Expand All @@ -236,7 +236,7 @@ core::create(){

# make sure only owner can read the disk image
chmod 600 "${VM_DS_PATH}/${_name}/${_disk}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "${VM_DS_PATH}/${_name}/${_disk}" "${_img}"
[ $_num -eq 0 ] && [ ! -z "$_img" ] && core::write_img "${VM_DS_PATH}/${_name}/${_disk}" "${_img}" "file" "${_disk_size}"
;;
esac

Expand Down Expand Up @@ -330,6 +330,8 @@ core::write_img(){
shift $?
_disk_dev="${1}"
_img="$2"
_disk_type="$3"
_disk_size="$4"
timeout=30
i=0

Expand All @@ -349,6 +351,14 @@ core::write_img(){
if [ $? -ne 0 ]; then
util::err "failed to write img file with qemu-img"
fi

# if disk type is file then we need to resize it
if [ "${_disk_type}" = "file" ]; then
qemu-img resize "${_disk_dev}" "${_disk_size}"
if [ $? -ne 0 ]; then
util::err "failed to resize img file with qemu-img"
fi
fi
}

# 'vm add'
Expand Down

0 comments on commit 31358b6

Please sign in to comment.