Skip to content

Instantly share code, notes, and snippets.

@dustymabe
Created June 1, 2015 17:54
Show Gist options
  • Save dustymabe/b4d9a95eee3ff187e916 to your computer and use it in GitHub Desktop.
Save dustymabe/b4d9a95eee3ff187e916 to your computer and use it in GitHub Desktop.
Helper Script to import cloud images into running VMs
#!/bin/bash
# exit on any error
set -o errexit
# A few tunable variables
NAME='atomic'
NAME='try'
#NAME='test'
#DISK='/guests/rhel-guest-image-7.1-20150224.0.x86_64.qcow2'
DISK='/guests/rhel-atomic-cloud-7.1-1.x86_64.qcow2'
DISK='/guests/try.raw'
SEEDISO='/guests/my-seed.iso'
RAMSIZE='2048' # IN MB
DISKSIZE='20' # IN GB
VCPUS='2' # NUM of CPUs
IMAGEDIR='/guests/'
BRIDGE='virbr0'
TMPDISK=${DISK}${RANDOM}
echo "Creating backup disk $TMPDISK"
qemu-img create -f qcow2 -b $DISK $TMPDISK 10G
# Build up the virt-install command
cmd='virt-install --import'
cmd+=" --name $NAME"
cmd+=" --ram $RAMSIZE"
cmd+=" --vcpus $VCPUS"
cmd+=" --disk path=$TMPDISK"
cmd+=" --disk path=$SEEDISO"
cmd+=" --accelerate"
cmd+=" --graphics none"
cmd+=" --force"
cmd+=" --network bridge=$BRIDGE"
# Run the command
echo "Running: $cmd"
$cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment