Created
December 10, 2015 13:28
-
-
Save ravage/8713672c9da41364165c to your computer and use it in GitHub Desktop.
Pre-allocate qemu-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/sh | |
#set -e | |
green="\033[32m" | |
red="\033[31m" | |
normal="\033[0m" | |
log() { | |
if [ $? -eq 0 ]; | |
then | |
echo "$green[*]$normal $1" | |
else | |
echo "$red[*]$normal $1" | |
exit 1 | |
fi | |
} | |
execute() { | |
$1 > /dev/null 2>&1 | |
} | |
if [ $# -lt 2 ]; | |
then | |
echo "$0 <name> <size in GB>" | |
exit 1 | |
fi | |
name=$1 | |
size=$2 | |
format=qcow2 | |
execute "qemu-img create -f $format -o preallocation=metadata $name.img ${size}G" | |
log "Creating a ${size}G image file" | |
bytes=`ls -l $name.img | cut -d ' ' -f5` | |
execute "fallocate -l $bytes ${name}.img" | |
log "Pre-allocating $bytes bytes for image" | |
execute "qemu-img info $name.img" | |
log "Image information" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment