Skip to content

Instantly share code, notes, and snippets.

@pmoranga
Created May 29, 2013 19:52
Show Gist options
  • Save pmoranga/5673276 to your computer and use it in GitHub Desktop.
Save pmoranga/5673276 to your computer and use it in GitHub Desktop.
clone LVM
#!/bin/bash
if [ "n$2" = "n" -o ! -e "$1" ] ; then
echo "usage: $(basename $0) PATH_TO_LV_SOURCE NAME_OF_NEW_LV "
echo -e "\nEx: $(basename $0) /dev/VG02_ssd/CentOS6 vm03-d1"
exit 1
fi
SOURCE=$1
DEST=$2
size=`sudo lvs -o lv_size --unit=b --noheadings $SOURCE | sed 's/^ *//'`
VG=$(basename $( dirname $SOURCE ) )
echo "new volume size: size=$size on volume $VG"
set -e
lvcreate --size=$size --name=$DEST $VG
echo "LV Volume created now cloning from old disk"
cmd="dd if=$SOURCE of=/dev/${VG}/${DEST} bs=131072"
echo running $cmd
$cmd
lvdisplay /dev/${VG}/${DEST}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment