|
|
@ -19,6 +19,31 @@ echo "make sure BTRFS is installed ..." |
|
|
|
sudo apt-get install -y btrfs-tools |
|
|
|
echo "" |
|
|
|
|
|
|
|
# check on/off state |
|
|
|
dataStorageNotAvailableYet=$(sudo btrfs filesystem df /mnt/data 2>&1 | grep -c "ERROR: not a btrfs filesystem") |
|
|
|
if [ "$1" = "1" ] || [ "$1" = "on" ]; then |
|
|
|
echo "Trying to switch additional data storage on ..." |
|
|
|
if [ ${dataStorageNotAvailableYet} -eq 0 ]; then |
|
|
|
echo "FAIL -> data storage is already on" |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
elif [ "$1" = "0" ] || [ "$1" = "off" ]; then |
|
|
|
echo "Trying to switch additional data storage off ..." |
|
|
|
if [ ${dataStorageNotAvailableYet} -eq 1 ]; then |
|
|
|
echo "FAIL -> data storage is already off" |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
else |
|
|
|
echo "FAIL -> Parameter '${$1}' not known." |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
################### |
|
|
|
# SWITCH ON |
|
|
|
################### |
|
|
|
|
|
|
|
if [ "$1" = "1" ] || [ "$1" = "on" ]; then |
|
|
|
|
|
|
|
# detect the two usb drives |
|
|
|
echo "Detecting two USB sticks/drives with same size ..." |
|
|
|
lsblk -o NAME | grep "^sd" | while read -r test1 ; do |
|
|
@ -70,23 +95,43 @@ fi |
|
|
|
echo "OK drives dont contain old data." |
|
|
|
echo "" |
|
|
|
|
|
|
|
# format first drive |
|
|
|
echo "Formatting /dev/${dev1} with BTRFS ..." |
|
|
|
sudo mkfs.btrfs -L DATASTORE -f /dev/${dev1} |
|
|
|
echo "OK" |
|
|
|
echo "" |
|
|
|
|
|
|
|
# mount the BTRFS drive |
|
|
|
echo "Mounting under /mnt/data ..." |
|
|
|
sudo mkdir -p /mnt/data |
|
|
|
sudo mount /dev/sdb1 /mnt/data |
|
|
|
echo "OK" |
|
|
|
echo "" |
|
|
|
|
|
|
|
# adding the second device |
|
|
|
echo "Adding the second device as RAID1 .." |
|
|
|
sudo btrfs device add -f /dev/sdc /mnt/data |
|
|
|
sudo btrfs filesystem balance start -dconvert=raid1 -mconvert=raid1 /mnt/data |
|
|
|
echo "" |
|
|
|
exit 0 |
|
|
|
|
|
|
|
#uuid=$(lsblk -o NAME,UUID | grep "^${dev1}" | awk '$1=$1' | cut -d " " -f 2) |
|
|
|
|
|
|
|
lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | greap "^sd" |
|
|
|
# TODO: find the drives |
|
|
|
fi |
|
|
|
|
|
|
|
################### |
|
|
|
# SWITCH OFF |
|
|
|
################### |
|
|
|
|
|
|
|
# TODO: DETECT if they is already data |
|
|
|
lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL |
|
|
|
if [ "$1" = "0" ] || [ "$1" = "off" ]; then |
|
|
|
|
|
|
|
# check if there is already data on there |
|
|
|
echo "TODO -> Turn off" |
|
|
|
|
|
|
|
# create |
|
|
|
sudo mkfs.btrfs -L DATASTORE -f /dev/sdb |
|
|
|
sudo mkdir -p /mnt/data |
|
|
|
sudo mount /dev/sdb1 /mnt/data |
|
|
|
sudo btrfs filesystem show /mnt/data |
|
|
|
sudo btrfs device add -f /dev/sdc /mnt/data |
|
|
|
sudo btrfs filesystem df /mnt/data |
|
|
|
sudo btrfs filesystem balance start -dconvert=raid1 -mconvert=raid1 /mnt/data |
|
|
|
|
|
|
|
sudo umount /mnt/data |
|
|
|
|
|
|
|
exit 0 |
|
|
|
|
|
|
|
fi |
|
|
|