RAID mystery-box generator

12.10.2020, 13:36 - Autor: Mark B.
To run the script you need a linux-box. I used ext4 as the filesystem because that one is also common in NAS-boxes and you can use the free r-Studio Linux for solving them! To create one use the following command:

Mystery_Box_Crator.sh [NO OF DISKS] [DISK-SIZE (MB)] [RAILD LEVEL (0 or 5)] [MOUNTPOINT (e.g /mnt)] [CONTENT-FOLDER]

user@linuxbox:~/$ Mystery_Box_Crator.sh 3 200 0 /mnt /home/user/dummy_content

Source:

#!/bin/bash

if [ "$#" -ne 5 ]; then
	echo ""
	echo "USAGE:"
	echo "-------"
	echo "./$0 [NO OF DISKS] [DISK-SIZE (MB)] [RAILD LEVEL 0 or 5] [MOUNTPOINT e.g /mnt] [CONTENT FOLDER]"
	echo ""
	exit 1
fi

disks=$1
disksize=$2
level=$3
mountpoint=$4
cont_folder=$5

# Generate random stripe-size
chunks[0]=16
chunks[1]=32
chunks[2]=64
chunks[3]=128
chunks[4]=256
chunks[5]=512
id=$[ $RANDOM % 5 ]
chunksize=${chunks[$id]}

echo -n "REMOVING OLD IMAGES "
rm disk*.dd
echo "... DONE"

echo "CREATING IMAGES... "
for ((i=0; i<$disks; i++)); do
	# Generate random number
	rand=$[ $RANDOM % 8999 ]
	rand=$(( $rand + 1000 ))

	# create img-file
	dd if=/dev/zero of=disk$rand.dd bs=1024 count=$[1024*$disksize]

	# save order for raid-creation
	disk_arr[$i]="disk$rand.dd"
done

echo -n "CREATING LOOPDEVICES "
disk_list=""
for ((i=0; i<$disks; i++)); do
	losetup /dev/loop10$i ${disk_arr[$i]}
	echo "losetup /dev/loop10$i ${disk_arr[$i]}"
	disk_list="${disk_list} /dev/loop10$i"
done
echo "... DONE"

echo "CREATING RAID ..."
mdadm --create /dev/md99 --chunk=$chunksize --level=$level --raid-devices=$disks $disk_list
echo "mdadm --create /dev/md99 --chunk=$chunksize --level=$level --raid-devices=$disks $disk_list"

echo "CREATING PARTITION ..."
echo -e "g\nn\n1\n\n\nw" | fdisk /dev/md99
mkfs.ext4 -F /dev/md99p1

# Mounting & copy contents
mount /dev/md99p1 $mountpoint
cp -rv $cont_folder/* $mountpoint


# Stopping, cleaning up writing log-file
echo "STOPPING RAID-ARRAY AND CLEANING UP... "

echo "Stripe-size: $chunksize " > raid.log
echo "Disk-order:" >> raid.log

umount $mountpoint
mdadm --stop /dev/md99
for ((i=0; i<$disks; i++)); do
	losetup -d /dev/loop10$i
	echo ${disk_arr[$i]} >> raid.log
done

Download Generator     Download Dummy-Content     Download Mystery-Boxes

System requrements:

Linux