Cow Script

From CSLabsWiki
Revision as of 15:03, 23 April 2014 by Lundar (talk | contribs) (First)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Cow Script

This Script creates 8 Copy on write devices and sets up vblade servers hosting the devices. These devices are backed by the original image specified. If the system is shutdown, or interupted, the script can be run again and all changes will be preserved. To reset any changes, shut down the system, delete the file $FILE.cow.$loopnumber. and rerun the script. This script can be modified to iterate over a list of mac addresses and bind each vblade a specific mac address.

 modprobe dm_mod
 modprobe dm_mirror
 modprobe dm_snapshot

 IMAGE_FILE=$1

 img_loop_dev=`losetup -f`

 losetup -v -f $IMAGE_FILE

 cow_size=`blockdev --getsize $img_loop_dev`
 echo $cow_size
 chunk_size=64

 FILE=$IMAGE_FILE

 for loopnumber in 0 1 2 3 4 5 6 7 
 do
 dd if=/dev/zero of=$FILE.cow.$loopnumber bs=512 count=0 seek=$cow_size
 COWLOOPDEV=`losetup -f`
 losetup -v -f $FILE.cow.$loopnumber
 echo "0 $cow_size snapshot $img_loop_dev $COWLOOPDEV p $chunk_size" | dmsetup create $FILE.cow.$loopnumber

 vblade 0 $loopnumber eth0 /dev/mapper/$FILE.cow.$loopnumber &

 echo $COWLOOPDEV  is attached to $FILE.cow.$loopnumber
 done

 losetup -a
 dmsetup table