Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created September 20, 2013 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshavardhana/6631953 to your computer and use it in GitHub Desktop.
Save harshavardhana/6631953 to your computer and use it in GitHub Desktop.
Script to generate soft lockups in kernel
#!/bin/bash
########################################################################
# This bash script will encypt backups using an unmodified version of
# Cryptsetup.
#
# Usage:
#
# $ dd if=/dev/zero of=/DS02/test/<backup_file> bs=1M count=<count>
#
# $ encrypt_stress {iteration} {size} {loopdevice} {backup_file}
#
# loopdevice -> /dev/loopN
# iteration -> N (any number)
# size -> Should be greater than your backup_file size specified in 'GBs'
# backup_file -> Backup file name created to a specified count earlier
# count -> total 1MB blocks for your <backup_file>
########################################################################
name=`basename $0`
if [ $# -ne 4 ] ; then
echo "usage: $name [ITERATION] [SIZE (in GB)] [loopdevice] [BACKUP_FILE]"
exit 1
fi
tempfile=`mktemp`
password="TestPassword"
iteration="$1"
size="$2"
loopdevice="$3"
backup="$4"
baseName=`echo $backup | cut -d \. -f 1`
containerName=$baseName".aaa.ribs"
echo $containerName
mountPointName=`echo $containerName".mp"`
echo $mountPointName
containerSize=$((size * 1000000))
COUNTER=1
while [ $COUNTER -le "$iteration" ]; do
# Set transaction start message
logger -s `date "+%m/%d/%Y %T"` Encryption Process Beginning for $4
# Create a container file
logger -s `date "+%m/%d/%Y %T"` Creating the container for $4...
dd of=/DS02/test/$containerName bs=1024 count=0 seek=$containerSize
#dd of=/DS02/test/$containerName if=/dev/zero bs=1024 count=$containerSize
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` Container created for $4!
else
logger -s `date "+%m/%d/%Y %T"` Container could not be created for $4!
fi
# Acquire a loop device
#echo "Acquiring loop device..."
#loopdevice=`/sbin/losetup -f`
#echo "Loop device acquired: $loopdevice"
# Attach the loop device to the container
logger -s `date "+%m/%d/%Y %T"` Attaching the loop device: $3
/sbin/losetup $loopdevice /DS02/test/$containerName
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $3 Attached!
else
logger -s `date "+%m/%d/%Y %T"` $3 could not be attached!
fi
# Attach encryption to the container
logger -s `date "+%m/%d/%Y %T"` Attaching encryption...
# Use expect to check for Enter Passphrase prompt and enter password
logger -s `date "+%m/%d/%Y %T"` Using Expect to handle interactive prompt and provide passphrase...
expect <<- DONE
set timeout 30
spawn /sbin/cryptsetup -v -c aes-cbc-plain -s 256 -h ripemd160 create $containerName $loopdevice
expect "?assphrase:*"
send -- "$password\r"
send -- "\r"
expect eof
DONE
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` Encryption Attached to $containerName!
else
logger -s `date "+%m/%d/%Y %T"` Encryption could not be attached to $containerName!
fi
# Format the container
logger -s `date "+%m/%d/%Y %T"` Formatting the container: $containerName...
/sbin/mke2fs -v -m 0 /dev/mapper/$containerName
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $containerName formatted!
else
logger -s `date "+%m/%d/%Y %T"` $containerName could not be formatted!
fi
# Mount the container file as a read-write filesystem
logger -s `date "+%m/%d/%Y %T"` Creating mount point: $mountPointName...
mkdir -p /DS02/test/ribs/$mountPointName
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $mountPointName created! Mounting $containerName...
else
logger -s `date "+%m/%d/%Y %T"` $mountPointName could not be created! Unable to mount $containerName!
fi
mount -v -w -t ext2 /dev/mapper/$containerName /DS02/test/ribs/$mountPointName
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $containerName Mounted!
else
logger -s `date "+%m/%d/%Y %T"` $containerName could not be mounted!
fi
# Move the backup to the encrypted container
logger -s `date "+%m/%d/%Y %T"` Moving $backup to encrypted container: $containerName...
cp -v /DS02/test/$backup /DS02/test/ribs/$mountPointName
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $backup copied to $containerName!
else
logger -s `date "+%m/%d/%Y %T"` $backup could not be copied to $containerName!
fi
# Delete the copied backup from the encrypted container
logger -s `date "+%m/%d/%Y %T"` Removing $backup from $containerName...
rm -f /DS02/test/ribs/$mountPointName/$backup
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $backup was deleted from $containerName!
else
logger -s `date "+%m/%d/%Y %T"` $backup could not be deleted from $containerName!
fi
# Unmount the container
logger -s `date "+%m/%d/%Y %T"` Unmounting $containerName...
umount -v /DS02/test/ribs/$mountPointName
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $containerName unmounted!
else
logger -s `date "+%m/%d/%Y %T"` $containerName could not be unmounted!
fi
# Detach encryption
logger -s `date "+%m/%d/%Y %T"` Detaching cryptsetup from $containerName...
/sbin/cryptsetup remove $containerName
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` Encryption Detached from $containerName!
else
logger -s `date "+%m/%d/%Y %T"` Encryption could not be detached from $containerName!
fi
# Detach the loop device
logger -s `date "+%m/%d/%Y %T"` Detaching the loop device: $loopdevice...
/sbin/losetup -d $loopdevice
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $loopdevice detached!
else
logger -s `date "+%m/%d/%Y %T"` $loopdevice could not be detached!
fi
# Remove mount point
logger -s `date "+%m/%d/%Y %T"` Removing $mountPointName...
rm -R /DS02/test/ribs/$mountPointName
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $mountPointName removed!
else
logger -s `date "+%m/%d/%Y %T"` $mountPointName could not be removed!
fi
# Remove container
logger -s `date "+%m/%d/%Y %T"` Removing $containerName
rm /DS02/test/$containerName
if [ $? -eq 0 ] ; then
logger -s `date "+%m/%d/%Y %T"` $containerName removed!
else
logger -s `date "+%m/%d/%Y %T"` $containerName could not be removed!
fi
let COUNTER=COUNTER+1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment