Created
April 8, 2013 14:56
-
-
Save orymate/5337408 to your computer and use it in GitHub Desktop.
Clone lvm base image.
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/bash | |
VG=xxx | |
BASE=ubuntu-12.04-base | |
DEFSIZE=10G | |
if [ $# -lt 1 -o $# -gt 2 -o "$1" = -h -o "$1" = --help ] | |
then | |
echo "Usage: $0 VolumeName [Size=$DEFSIZE]" >&2 | |
exit 1 | |
fi | |
if [ -n "$2" ] | |
then | |
SIZE=$2 | |
else | |
SIZE="$DEFSIZE" | |
fi | |
if [ ! -d "/dev/$VG/" ] | |
then | |
echo $VG does not exist | |
exit 2 | |
fi | |
if [ ! -r /dev/$VG/$BASE ] | |
then | |
echo Could not read $VG/$BASE | |
exit 3 | |
fi | |
echo lvcreate... | |
if ! lvcreate -L $SIZE -n "$1" $VG | |
then | |
echo lvcreate failed... | |
exit 4 | |
fi | |
dd if=/dev/$VG/$BASE of=/dev/$VG/$1 bs=4M & | |
ddpid=$! | |
( while sleep 20; do kill -USR1 $ddpid; done ) & | |
wpid=$! | |
wait $ddpid | |
kill $wpid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment