Update blitz.datadrive.sh (#3540)

* Update blitz.datadrive.sh

Updates script for amd64 and nvme drives

* Update home.admin/config.scripts/blitz.datadrive.sh

Co-authored-by: openoms <43343391+openoms@users.noreply.github.com>

* Update blitz.datadrive.sh

Cleaned up code a bit per Openoms suggestion

Co-authored-by: openoms <43343391+openoms@users.noreply.github.com>
This commit is contained in:
allyourbankarebelongtous
2022-12-18 12:15:23 -06:00
committed by GitHub
parent 20c0da709b
commit 19cb9fdbc5

View File

@@ -105,11 +105,16 @@ if [ "$1" = "status" ]; then
fi fi
lsblk -o NAME,SIZE -b | grep -P "[s|vn][dv][a-z][0-9]?" > .lsblk.tmp lsblk -o NAME,SIZE -b | grep -P "[s|vn][dv][a-z][0-9]?" > .lsblk.tmp
while read line; do while read line; do
# cut line info into different informations # cut line info into different informations
testname=$(echo $line | cut -d " " -f 1 | sed 's/[^a-z0-9]*//g') testname=$(echo $line | cut -d " " -f 1 | sed 's/[^a-z0-9]*//g')
if [ $(echo $line | grep -c "nvme") = 0 ]; then
testdevice=$(echo $testname | sed 's/[^a-z]*//g') testdevice=$(echo $testname | sed 's/[^a-z]*//g')
testpartition=$(echo $testname | grep -P '[a-z]{3,5}[0-9]{1}') testpartition=$(echo $testname | grep -P '[a-z]{3,5}[0-9]{1}')
else
testdevice=$(echo $testname | sed 's/\([^p]*\).*/\1/')
testpartition=$(echo $testname | grep -P '[p]{1}')
fi
if [ ${#testpartition} -gt 0 ]; then if [ ${#testpartition} -gt 0 ]; then
testsize=$(echo $line | sed "s/ */ /g" | cut -d " " -f 2 | sed 's/[^0-9]*//g') testsize=$(echo $line | sed "s/ */ /g" | cut -d " " -f 2 | sed 's/[^0-9]*//g')
else else
@@ -134,9 +139,22 @@ if [ "$1" = "status" ]; then
#echo "# hdd(${hdd})" #echo "# hdd(${hdd})"
if [ "$(uname -m)" = "x86_64" ]; then if [ "$(uname -m)" = "x86_64" ]; then
if [ $(echo "$testpartition" | grep -c "nvme") = 0 ]; then
testParentDisk=$(echo "$testpartition" | sed 's/[^a-z]*//g') testParentDisk=$(echo "$testpartition" | sed 's/[^a-z]*//g')
else
testParentDisk=$(echo "$testpartition" | sed 's/\([^p]*\).*/\1/')
fi
if [ $(echo "$OSPartition" | grep -c "nvme") = 0 ]; then
OSParentDisk=$(echo "$OSPartition" | sed 's/[^a-z]*//g') OSParentDisk=$(echo "$OSPartition" | sed 's/[^a-z]*//g')
else
OSParentDisk=$(echo "$OSPartition" | sed 's/\([^p]*\).*/\1/')
fi
if [ $(echo "$bootPartition" | grep -c "nvme") = 0 ]; then
bootParentDisk=$(echo "$bootPartition" | sed 's/[^a-z]*//g') bootParentDisk=$(echo "$bootPartition" | sed 's/[^a-z]*//g')
else
bootParentDisk=$(echo "$bootPartition" | sed 's/\([^p]*\).*/\1/')
fi
if [ "$testdevice" != "$OSParentDisk" ] && [ "$testdevice" != "$bootParentDisk" ];then if [ "$testdevice" != "$OSParentDisk" ] && [ "$testdevice" != "$bootParentDisk" ];then
sizeDataPartition=${testsize} sizeDataPartition=${testsize}
hddDataPartition="${testpartition}" hddDataPartition="${testpartition}"
@@ -153,7 +171,6 @@ if [ "$1" = "status" ]; then
fi fi
fi fi
else else
# default hdd set, when there is no OSpartition and there might be no partitions at all # default hdd set, when there is no OSpartition and there might be no partitions at all
if [ "${OSPartition}" = "root" ] && [ "${hdd}" = "" ] && [ "${testdevice}" != "" ]; then if [ "${OSPartition}" = "root" ] && [ "${hdd}" = "" ] && [ "${testdevice}" != "" ]; then
hdd="${testdevice}" hdd="${testdevice}"
@@ -177,7 +194,7 @@ if [ "$1" = "status" ]; then
# try to detect if its an SSD # try to detect if its an SSD
isSMART=$(sudo smartctl -a /dev/${hdd} | grep -c "Rotation Rate:") isSMART=$(sudo smartctl -a /dev/${hdd} | grep -c "Rotation Rate:")
echo "isSMART=$(isSMART)" echo "isSMART=${isSMART}"
if [ ${isSMART} -gt 0 ]; then if [ ${isSMART} -gt 0 ]; then
#detect using smartmontools (preferred) #detect using smartmontools (preferred)
isSSD=$(sudo smartctl -a /dev/${hdd} | grep 'Rotation Rate:' | grep -c "Solid State") isSSD=$(sudo smartctl -a /dev/${hdd} | grep 'Rotation Rate:' | grep -c "Solid State")
@@ -193,6 +210,9 @@ if [ "$1" = "status" ]; then
hddGigaBytes=0 hddGigaBytes=0
if [ "${hdd}" != "" ]; then if [ "${hdd}" != "" ]; then
hddBytes=$(fdisk -l /dev/$hdd | grep GiB | cut -d " " -f 5) hddBytes=$(fdisk -l /dev/$hdd | grep GiB | cut -d " " -f 5)
if [ "${hddBytes}" = "" ]; then
hddBytes=$(fdisk -l /dev/$hdd | grep TiB | cut -d " " -f 5)
fi
hddGigaBytes=$(echo "scale=0; ${hddBytes}/1024/1024/1024" | bc -l) hddGigaBytes=$(echo "scale=0; ${hddBytes}/1024/1024/1024" | bc -l)
fi fi
echo "hddBytes=${hddBytes}" echo "hddBytes=${hddBytes}"
@@ -201,7 +221,6 @@ if [ "$1" = "status" ]; then
# if positive deliver more data # if positive deliver more data
if [ ${#hddDataPartition} -gt 0 ]; then if [ ${#hddDataPartition} -gt 0 ]; then
# check partition size in bytes and GBs # check partition size in bytes and GBs
echo "hddDataPartitionBytes=${sizeDataPartition}" echo "hddDataPartitionBytes=${sizeDataPartition}"
hddDataPartitionGigaBytes=$(echo "scale=0; ${sizeDataPartition}/1024/1024/1024" | bc -l) hddDataPartitionGigaBytes=$(echo "scale=0; ${sizeDataPartition}/1024/1024/1024" | bc -l)
@@ -213,7 +232,6 @@ if [ "$1" = "status" ]; then
# if 'ext4' or 'btrfs' then temp mount and investigate content # if 'ext4' or 'btrfs' then temp mount and investigate content
if [ "${hddFormat}" = "ext4" ] || [ "${hddFormat}" = "btrfs" ]; then if [ "${hddFormat}" = "ext4" ] || [ "${hddFormat}" = "btrfs" ]; then
# BTRFS is working with subvolumes for snapshots / ext4 has no SubVolumes # BTRFS is working with subvolumes for snapshots / ext4 has no SubVolumes
subVolumeDir="" subVolumeDir=""
if [ "${hddFormat}" = "btrfs" ]; then if [ "${hddFormat}" = "btrfs" ]; then
@@ -286,9 +304,14 @@ if [ "$1" = "status" ]; then
# temp storage data drive # temp storage data drive
mkdir -p /mnt/storage mkdir -p /mnt/storage
if [ $(echo "${hdd}" | grep -c "nvme") = 0 ]; then
nvp=""
else
nvp="p"
fi
if [ "${hddFormat}" = "btrfs" ]; then if [ "${hddFormat}" = "btrfs" ]; then
# in btrfs setup the second partition is storage partition # in btrfs setup the second partition is storage partition
mount /dev/${hdd}2 /mnt/storage 2>/dev/null mount /dev/${hdd}${nvp}2 /mnt/storage 2>/dev/null
isTempMounted=$(df | grep /mnt/storage | grep -c ${hdd}) isTempMounted=$(df | grep /mnt/storage | grep -c ${hdd})
else else
# in ext4 setup the partition is also the storage partition # in ext4 setup the partition is also the storage partition
@@ -317,7 +340,7 @@ if [ "$1" = "status" ]; then
hdd_data_free1Kblocks=$(df -h -k /dev/${hddDataPartitionExt4} | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9') hdd_data_free1Kblocks=$(df -h -k /dev/${hddDataPartitionExt4} | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9')
else else
# BRTS # BRTS
hdd_data_free1Kblocks=$(df -h -k /dev/${hdd}1 | grep "/dev/${hdd}1" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9') hdd_data_free1Kblocks=$(df -h -k /dev/${hdd}${nvp}1 | grep "/dev/${hdd}${nvp}1" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9')
fi fi
if [ "${hdd_data_free1Kblocks}" != "" ]; then if [ "${hdd_data_free1Kblocks}" != "" ]; then
hddDataFreeBytes=$((${hdd_data_free1Kblocks} * 1024)) hddDataFreeBytes=$((${hdd_data_free1Kblocks} * 1024))
@@ -362,7 +385,7 @@ if [ "$1" = "status" ]; then
fi fi
echo "hddGotMigrationData='${hddGotMigrationData}'" echo "hddGotMigrationData='${hddGotMigrationData}'"
# comment this line out if case to study the contect of the storage section # comment this line out if case to study the content of the storage section
umount /mnt/storage umount /mnt/storage
fi fi
else else
@@ -391,7 +414,11 @@ if [ "$1" = "status" ]; then
# on ext4 its the whole /mnt/hdd # on ext4 its the whole /mnt/hdd
hddDataPartition=$(df | grep "/mnt/hdd$" | cut -d " " -f 1 | cut -d "/" -f 3) hddDataPartition=$(df | grep "/mnt/hdd$" | cut -d " " -f 1 | cut -d "/" -f 3)
fi fi
if [ $(echo "${hddDataPartition}" | grep -c "nvme") = 0 ]; then
hdd=$(echo $hddDataPartition | sed 's/[0-9]*//g') hdd=$(echo $hddDataPartition | sed 's/[0-9]*//g')
else
hdd=$(echo "$hddDataPartition" | sed 's/\([^p]*\).*/\1/')
fi
hddFormat=$(lsblk -o FSTYPE,NAME,TYPE | grep part | grep "${hddDataPartition}" | cut -d " " -f 1) hddFormat=$(lsblk -o FSTYPE,NAME,TYPE | grep part | grep "${hddDataPartition}" | cut -d " " -f 1)
if [ "${hddFormat}" = "ext4" ]; then if [ "${hddFormat}" = "ext4" ]; then
hddDataPartitionExt4=$hddDataPartition hddDataPartitionExt4=$hddDataPartition
@@ -444,12 +471,17 @@ if [ "$1" = "status" ]; then
# used space - at the moment just string info to display # used space - at the moment just string info to display
if [ "${isBTRFS}" -gt 0 ]; then if [ "${isBTRFS}" -gt 0 ]; then
if [ $(echo "${hdd}" | grep -c "nvme") = 0 ]; then
nvp=""
else
nvp="p"
fi
# BTRFS calculations # BTRFS calculations
# TODO: this is the final/correct way - make better later # TODO: this is the final/correct way - make better later
# https://askubuntu.com/questions/170044/btrfs-and-missing-free-space # https://askubuntu.com/questions/170044/btrfs-and-missing-free-space
datadrive=$(df -h | grep "/dev/${hdd}1" | sed -e's/ */ /g' | cut -d" " -f 5) datadrive=$(df -h | grep "/dev/${hdd}${nvp}1" | sed -e's/ */ /g' | cut -d" " -f 5)
storageDrive=$(df -h | grep "/dev/${hdd}2" | sed -e's/ */ /g' | cut -d" " -f 5) storageDrive=$(df -h | grep "/dev/${hdd}${nvp}2" | sed -e's/ */ /g' | cut -d" " -f 5)
hdd_data_free1Kblocks=$(df -h -k /dev/${hdd}1 | grep "/dev/${hdd}1" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9') hdd_data_free1Kblocks=$(df -h -k /dev/${hdd}${nvp}1 | grep "/dev/${hdd}${nvp}1" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9')
hddUsedInfo="${datadrive} & ${storageDrive}" hddUsedInfo="${datadrive} & ${storageDrive}"
elif [ "${isZFS}" -gt 0 ]; then elif [ "${isZFS}" -gt 0 ]; then
# ZFS calculations # ZFS calculations
@@ -470,14 +502,12 @@ if [ "$1" = "status" ]; then
echo "hddDataFreeBytes=${hddDataFreeBytes}" echo "hddDataFreeBytes=${hddDataFreeBytes}"
echo "hddDataFreeKB=${hdd_data_free1Kblocks}" echo "hddDataFreeKB=${hdd_data_free1Kblocks}"
echo "hddDataFreeGB=${hddDataFreeGB}" echo "hddDataFreeGB=${hddDataFreeGB}"
fi fi
# HDD Adapter UASP support --> https://www.pragmaticlinux.com/2021/03/fix-for-getting-your-ssd-working-via-usb-3-on-your-raspberry-pi/ # HDD Adapter UASP support --> https://www.pragmaticlinux.com/2021/03/fix-for-getting-your-ssd-working-via-usb-3-on-your-raspberry-pi/
# in both cases (if mounted or not - using the hdd selection from both cases) # in both cases (if mounted or not - using the hdd selection from both cases)
# only check if lsusb command is availabe # only check if lsusb command is availabe
if [ ${#hdd} -gt 0 ] && [ "$(type -t lsusb | grep -c file)" -gt 0 ]; then if [ ${#hdd} -gt 0 ] && [ "$(type -t lsusb | grep -c file)" -gt 0 ]; then
# determine USB HDD adapter model ID # determine USB HDD adapter model ID
hddAdapter=$(lsusb | grep "SATA" | head -1 | cut -d " " -f6) hddAdapter=$(lsusb | grep "SATA" | head -1 | cut -d " " -f6)
if [ "${hddAdapter}" == "" ]; then if [ "${hddAdapter}" == "" ]; then
@@ -487,19 +517,16 @@ if [ "$1" = "status" ]; then
hddAdapter=$(lsusb | grep "ASMedia Technology" | head -1 | cut -d " " -f6) hddAdapter=$(lsusb | grep "ASMedia Technology" | head -1 | cut -d " " -f6)
fi fi
echo "hddAdapterUSB='${hddAdapter}'" echo "hddAdapterUSB='${hddAdapter}'"
hddAdapterUSAP=0 hddAdapterUSAP=0
# check if force UASP flag is set on sd card # check if force UASP flag is set on sd card
if [ -f "/boot/uasp.force" ]; then if [ -f "/boot/uasp.force" ]; then
hddAdapterUSAP=1 hddAdapterUSAP=1
fi fi
# or UASP is set by config file # or UASP is set by config file
if [ $(cat /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c "forceUasp=on") -eq 1 ]; then if [ $(cat /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c "forceUasp=on") -eq 1 ]; then
hddAdapterUSAP=1 hddAdapterUSAP=1
fi fi
# check if HDD ADAPTER is on UASP WHITELIST (tested devices) # check if HDD ADAPTER is on UASP WHITELIST (tested devices)
if [ "${hddAdapter}" == "174c:55aa" ]; then if [ "${hddAdapter}" == "174c:55aa" ]; then
# UGREEN 2.5" External USB 3.0 Hard Disk Case with UASP support # UGREEN 2.5" External USB 3.0 Hard Disk Case with UASP support
@@ -521,27 +548,20 @@ if [ "$1" = "status" ]; then
# Cable Matters USB 3.1 Type-C Gen2 External SATA SSD Enclosure # Cable Matters USB 3.1 Type-C Gen2 External SATA SSD Enclosure
hddAdapterUSAP=1 hddAdapterUSAP=1
fi fi
echo "hddAdapterUSAP=${hddAdapterUSAP}" echo "hddAdapterUSAP=${hddAdapterUSAP}"
fi fi
echo echo
echo "# RAID" echo "# RAID"
echo "isRaid=${isRaid}" echo "isRaid=${isRaid}"
if [ ${isRaid} -eq 1 ] && [ ${isMounted} -eq 1 ] && [ ${isBTRFS} -eq 1 ]; then if [ ${isRaid} -eq 1 ] && [ ${isMounted} -eq 1 ] && [ ${isBTRFS} -eq 1 ]; then
# RAID is ON - give information about running raid setup # RAID is ON - give information about running raid setup
# show devices used for raid # show devices used for raid
raidHddDev=$(lsblk -o NAME,MOUNTPOINT | grep "/mnt/hdd" | awk '$1=$1' | cut -d " " -f 1 | sed 's/[^0-9a-z]*//g') raidHddDev=$(lsblk -o NAME,MOUNTPOINT | grep "/mnt/hdd" | awk '$1=$1' | cut -d " " -f 1 | sed 's/[^0-9a-z]*//g')
raidUsbDev=$(btrfs filesystem show /mnt/hdd | grep -F -v "${raidHddDev}" | grep "/dev/" | cut -d "/" --f 3) raidUsbDev=$(btrfs filesystem show /mnt/hdd | grep -F -v "${raidHddDev}" | grep "/dev/" | cut -d "/" --f 3)
echo "raidHddDev='${raidHddDev}'" echo "raidHddDev='${raidHddDev}'"
echo "raidUsbDev='${raidUsbDev}'" echo "raidUsbDev='${raidUsbDev}'"
else else
# RAID is OFF - give information about possible drives to activate # RAID is OFF - give information about possible drives to activate
# find the possible drives that can be used as # find the possible drives that can be used as
drivecounter=0 drivecounter=0
for disk in $(lsblk -o NAME,TYPE | grep "disk" | awk '$1=$1' | cut -d " " -f 1) for disk in $(lsblk -o NAME,TYPE | grep "disk" | awk '$1=$1' | cut -d " " -f 1)
@@ -558,16 +578,13 @@ if [ "$1" = "status" ]; then
fi fi
done done
echo "raidCandidates=${drivecounter}" echo "raidCandidates=${drivecounter}"
fi fi
echo echo
echo "# SWAP" echo "# SWAP"
echo "isSwapExternal=${isSwapExternal}" echo "isSwapExternal=${isSwapExternal}"
if [ ${isSwapExternal} -eq 1 ]; then if [ ${isSwapExternal} -eq 1 ]; then
echo "SwapExternalPath='${externalSwapPath}'" echo "SwapExternalPath='${externalSwapPath}'"
fi fi
echo echo
exit 1 exit 1
fi fi
@@ -578,7 +595,6 @@ fi
# check basics for formatting # check basics for formatting
if [ "$1" = "format" ]; then if [ "$1" = "format" ]; then
# check valid format # check valid format
if [ "$2" = "btrfs" ]; then if [ "$2" = "btrfs" ]; then
>&2 echo "# DATA DRIVE - FORMATTING to BTRFS layout (new)" >&2 echo "# DATA DRIVE - FORMATTING to BTRFS layout (new)"
@@ -598,7 +614,6 @@ if [ "$1" = "format" ]; then
echo "error='missing parameter'" echo "error='missing parameter'"
exit 1 exit 1
fi fi
if [ "$2" = "btrfs" ]; then if [ "$2" = "btrfs" ]; then
# check if device is existing and a disk (not a partition) # check if device is existing and a disk (not a partition)
isValid=$(lsblk -o NAME,TYPE | grep disk | grep -c "${hdd}") isValid=$(lsblk -o NAME,TYPE | grep disk | grep -c "${hdd}")
@@ -615,13 +630,11 @@ if [ "$1" = "format" ]; then
# get basic info on data drive # get basic info on data drive
source <(/home/admin/config.scripts/blitz.datadrive.sh status) source <(/home/admin/config.scripts/blitz.datadrive.sh status)
if [ ${isSwapExternal} -eq 1 ] && [ "${hdd}" == "${datadisk}" ]; then if [ ${isSwapExternal} -eq 1 ] && [ "${hdd}" == "${datadisk}" ]; then
>&2 echo "# Switching off external SWAP of system drive" >&2 echo "# Switching off external SWAP of system drive"
dphys-swapfile swapoff 1>/dev/null dphys-swapfile swapoff 1>/dev/null
dphys-swapfile uninstall 1>/dev/null dphys-swapfile uninstall 1>/dev/null
fi fi
>&2 echo "# Unmounting all partitions of this device" >&2 echo "# Unmounting all partitions of this device"
# remove device from all system mounts (also fstab) # remove device from all system mounts (also fstab)
lsblk -o UUID,NAME | grep "${hdd}" | cut -d " " -f 1 | grep "-" | while read -r uuid ; do lsblk -o UUID,NAME | grep "${hdd}" | cut -d " " -f 1 | grep "-" | while read -r uuid ; do
@@ -634,7 +647,6 @@ if [ "$1" = "format" ]; then
fi fi
done done
mount -a mount -a
if [ "${hdd}" == "${datadisk}" ]; then if [ "${hdd}" == "${datadisk}" ]; then
>&2 echo "# Make sure system drives are unmounted .." >&2 echo "# Make sure system drives are unmounted .."
umount /mnt/hdd 2>/dev/null umount /mnt/hdd 2>/dev/null
@@ -660,12 +672,19 @@ if [ "$1" = "format" ]; then
fi fi
fi fi
if [ $(echo "${hdd}" | grep -c "nvme") = 0 ]; then
if [[ $hdd =~ [0-9] ]]; then if [[ $hdd =~ [0-9] ]]; then
ext4IsPartition=1 ext4IsPartition=1
else else
ext4IsPartition=0 ext4IsPartition=0
fi fi
else
if [[ $hdd =~ [p] ]]; then
ext4IsPartition=1
else
ext4IsPartition=0
fi
fi
wipePartitions=0 wipePartitions=0
if [ "$2" = "btrfs" ]; then if [ "$2" = "btrfs" ]; then
wipePartitions=1 wipePartitions=1
@@ -673,7 +692,6 @@ if [ "$1" = "format" ]; then
if [ "$2" = "ext4" ] && [ $ext4IsPartition -eq 0 ]; then if [ "$2" = "ext4" ] && [ $ext4IsPartition -eq 0 ]; then
wipePartitions=1 wipePartitions=1
fi fi
if [ $wipePartitions -eq 1 ]; then if [ $wipePartitions -eq 1 ]; then
# wipe all partitions and write fresh GPT # wipe all partitions and write fresh GPT
>&2 echo "# Wiping all partitions (sfdisk/wipefs)" >&2 echo "# Wiping all partitions (sfdisk/wipefs)"
@@ -698,12 +716,9 @@ if [ "$1" = "format" ]; then
fi fi
# formatting old: EXT4 # formatting old: EXT4
if [ "$2" = "ext4" ]; then if [ "$2" = "ext4" ]; then
# prepare temp mount point # prepare temp mount point
mkdir -p /tmp/ext4 1>/dev/null mkdir -p /tmp/ext4 1>/dev/null
if [ $ext4IsPartition -eq 0 ]; then if [ $ext4IsPartition -eq 0 ]; then
# write new EXT4 partition # write new EXT4 partition
>&2 echo "# Creating the one big partition" >&2 echo "# Creating the one big partition"
@@ -737,7 +752,6 @@ if [ "$1" = "format" ]; then
echo "error='failed to unmount /tmp/ext4'" echo "error='failed to unmount /tmp/ext4'"
exit 1 exit 1
fi fi
>&2 echo "# Formatting" >&2 echo "# Formatting"
if [ $ext4IsPartition -eq 0 ]; then if [ $ext4IsPartition -eq 0 ]; then
mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd}1 1>/dev/null mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd}1 1>/dev/null
@@ -762,32 +776,39 @@ if [ "$1" = "format" ]; then
# setting fsk check interval to 1 # setting fsk check interval to 1
# see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467567572 # see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467567572
if [ $(echo "${hdd}" | grep -c "nvme") = 0 ]; then
nvp=""
else
nvp="p"
fi
if [ $ext4IsPartition -eq 0 ]; then if [ $ext4IsPartition -eq 0 ]; then
tune2fs -c 1 /dev/${hdd}1 tune2fs -c 1 /dev/${hdd}${nvp}1
else else
tune2fs -c 1 /dev/${hdd} tune2fs -c 1 /dev/${hdd}
fi fi
>&2 echo "# OK EXT 4 format done" >&2 echo "# OK EXT 4 format done"
exit 0 exit 0
fi fi
# formatting new: BTRFS layout - this consists of 3 volumes: # formatting new: BTRFS layout - this consists of 3 volumes:
if [ "$2" = "btrfs" ]; then if [ "$2" = "btrfs" ]; then
if [ $(echo "${hdd}" | grep -c "nvme") = 0 ]; then
nvp=""
else
nvp="p"
fi
# prepare temp mount point # prepare temp mount point
mkdir -p /tmp/btrfs 1>/dev/null mkdir -p /tmp/btrfs 1>/dev/null
>&2 echo "# Creating BLITZDATA (${hdd})" >&2 echo "# Creating BLITZDATA (${hdd})"
parted -s -- /dev/${hdd} mkpart primary btrfs 1024KiB 30GiB 1>/dev/null parted -s -- /dev/${hdd} mkpart primary btrfs 1024KiB 30GiB 1>/dev/null
sync sync
sleep 6 sleep 6
win=$(lsblk -o NAME | grep -c ${hdd}1) win=$(lsblk -o NAME | grep -c ${hdd}${nvp}1)
if [ ${win} -eq 0 ]; then if [ ${win} -eq 0 ]; then
echo "error='partition failed'" echo "error='partition failed'"
exit 1 exit 1
fi fi
mkfs.btrfs -f -L BLITZDATA /dev/${hdd}1 1>/dev/null mkfs.btrfs -f -L BLITZDATA /dev/${hdd}${nvp}1 1>/dev/null
# check result # check result
loopdone=0 loopdone=0
loopcount=0 loopcount=0
@@ -807,28 +828,26 @@ if [ "$1" = "format" ]; then
fi fi
done done
>&2 echo "# OK BLITZDATA exists now" >&2 echo "# OK BLITZDATA exists now"
>&2 echo "# Creating SubVolume for Snapshots" >&2 echo "# Creating SubVolume for Snapshots"
mount /dev/${hdd}1 /tmp/btrfs 1>/dev/null mount /dev/${hdd}${nvp}1 /tmp/btrfs 1>/dev/null
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
echo "error='mount ${hdd}1 failed'" echo "error='mount ${hdd}${nvp}1 failed'"
exit 1 exit 1
fi fi
cd /tmp/btrfs cd /tmp/btrfs
btrfs subvolume create WORKINGDIR btrfs subvolume create WORKINGDIR
subVolDATA=$(btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3) subVolDATA=$(btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
cd && umount /tmp/btrfs cd && umount /tmp/btrfs
>&2 echo "# Creating BLITZSTORAGE" >&2 echo "# Creating BLITZSTORAGE"
parted -s -- /dev/${hdd} mkpart primary btrfs 30GiB -34GiB 1>/dev/null parted -s -- /dev/${hdd} mkpart primary btrfs 30GiB -34GiB 1>/dev/null
sync sync
sleep 6 sleep 6
win=$(lsblk -o NAME | grep -c ${hdd}2) win=$(lsblk -o NAME | grep -c ${hdd}${nvp}2)
if [ ${win} -eq 0 ]; then if [ ${win} -eq 0 ]; then
echo "error='partition failed'" echo "error='partition failed'"
exit 1 exit 1
fi fi
mkfs.btrfs -f -L BLITZSTORAGE /dev/${hdd}2 1>/dev/null mkfs.btrfs -f -L BLITZSTORAGE /dev/${hdd}${nvp}2 1>/dev/null
# check result # check result
loopdone=0 loopdone=0
loopcount=0 loopcount=0
@@ -847,28 +866,25 @@ if [ "$1" = "format" ]; then
fi fi
done done
>&2 echo "# OK BLITZSTORAGE exists now" >&2 echo "# OK BLITZSTORAGE exists now"
>&2 echo "# Creating SubVolume for Snapshots" >&2 echo "# Creating SubVolume for Snapshots"
mount /dev/${hdd}2 /tmp/btrfs 1>/dev/null mount /dev/${hdd}${nvp}2 /tmp/btrfs 1>/dev/null
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
echo "error='mount ${hdd}2 failed'" echo "error='mount ${hdd}${nvp}2 failed'"
exit 1 exit 1
fi fi
cd /tmp/btrfs cd /tmp/btrfs
btrfs subvolume create WORKINGDIR btrfs subvolume create WORKINGDIR
cd && umount /tmp/btrfs cd && umount /tmp/btrfs
>&2 echo "# Creating the FAT32 partition" >&2 echo "# Creating the FAT32 partition"
parted -s -- /dev/${hdd} mkpart primary fat32 -34GiB 100% 1>/dev/null parted -s -- /dev/${hdd} mkpart primary fat32 -34GiB 100% 1>/dev/null
sync && sleep 3 sync && sleep 3
win=$(lsblk -o NAME | grep -c ${hdd}3) win=$(lsblk -o NAME | grep -c ${hdd}${nvp}3)
if [ ${win} -eq 0 ]; then if [ ${win} -eq 0 ]; then
echo "error='partition failed'" echo "error='partition failed'"
exit 1 exit 1
fi fi
>&2 echo "# Creating Volume BLITZTEMP (format)" >&2 echo "# Creating Volume BLITZTEMP (format)"
mkfs -t vfat -n BLITZTEMP /dev/${hdd}3 1>/dev/null mkfs -t vfat -n BLITZTEMP /dev/${hdd}${nvp}3 1>/dev/null
# check result # check result
loopdone=0 loopdone=0
loopcount=0 loopcount=0
@@ -887,7 +903,6 @@ if [ "$1" = "format" ]; then
fi fi
done done
>&2 echo "# OK BLITZTEMP exists now" >&2 echo "# OK BLITZTEMP exists now"
>&2 echo "# OK BTRFS format done" >&2 echo "# OK BTRFS format done"
exit 0 exit 0
fi fi
@@ -898,7 +913,6 @@ fi
######################################## ########################################
if [ "$1" = "fstab" ]; then if [ "$1" = "fstab" ]; then
# get device to temp mount # get device to temp mount
hdd=$2 hdd=$2
if [ ${#hdd} -eq 0 ]; then if [ ${#hdd} -eq 0 ]; then
@@ -907,9 +921,9 @@ if [ "$1" = "fstab" ]; then
echo "error='missing second parameter'" echo "error='missing second parameter'"
exit 1 exit 1
fi fi
# check if exist and which format # check if exist and which format
# if hdd is a partition (ext4) # if hdd is a partition (ext4)
if [ $(echo "${hdd}" | grep -c "nvme") = 0 ]; then
if [[ $hdd =~ [0-9] ]]; then if [[ $hdd =~ [0-9] ]]; then
# ext4 # ext4
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hdd} | cut -d ' ' -f 1) hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hdd} | cut -d ' ' -f 1)
@@ -917,13 +931,20 @@ if [ "$1" = "fstab" ]; then
# btrfs # btrfs
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hdd}1 | cut -d ' ' -f 1) hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hdd}1 | cut -d ' ' -f 1)
fi fi
else
if [[ $hdd =~ [p] ]]; then
# ext4
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hdd} | cut -d ' ' -f 1)
else
# btrfs
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hdd}p1 | cut -d ' ' -f 1)
fi
fi
if [ ${#hddFormat} -eq 0 ]; then if [ ${#hddFormat} -eq 0 ]; then
echo "# FAIL given device/partition not found" echo "# FAIL given device/partition not found"
echo "error='device not found'" echo "error='device not found'"
exit 1 exit 1
fi fi
# unmount # unmount
if [ ${isMounted} -eq 1 ]; then if [ ${isMounted} -eq 1 ]; then
echo "# unmounting all drives" echo "# unmounting all drives"
@@ -961,7 +982,6 @@ if [ "$1" = "fstab" ]; then
echo "# updating /etc/fstab" echo "# updating /etc/fstab"
sed "/raspiblitz/ i UUID=${uuid1} /mnt/hdd ext4 noexec,defaults 0 2" -i /etc/fstab 1>/dev/null sed "/raspiblitz/ i UUID=${uuid1} /mnt/hdd ext4 noexec,defaults 0 2" -i /etc/fstab 1>/dev/null
fi fi
sync sync
mount -a 1>/dev/null mount -a 1>/dev/null
@@ -981,21 +1001,25 @@ if [ "$1" = "fstab" ]; then
exit 0 exit 0
fi fi
done done
echo "# OK - fstab updated for EXT4 layout" echo "# OK - fstab updated for EXT4 layout"
exit 1 exit 1
elif [ "${hddFormat}" = "btrfs" ]; then elif [ "${hddFormat}" = "btrfs" ]; then
### BTRFS ### ### BTRFS ###
>&2 echo "# BTRFS: Updating /etc/fstab & mount"
>&2 echo "# BTRFS: Updating /etc/fstab & mount"
# get info on: Data Drive # get info on: Data Drive
uuidDATA=$(lsblk -o UUID,NAME,LABEL | grep "${hdd}" | grep "BLITZDATA" | cut -d " " -f 1 | grep "-") uuidDATA=$(lsblk -o UUID,NAME,LABEL | grep "${hdd}" | grep "BLITZDATA" | cut -d " " -f 1 | grep "-")
mkdir -p /tmp/btrfs mkdir -p /tmp/btrfs
mount /dev/${hdd}1 /tmp/btrfs 1>/dev/null if [ $(echo "${hdd}" | grep -c "nvme") = 0 ]; then
nvp=""
else
nvp="p"
fi
mount /dev/${hdd}${nvp}1 /tmp/btrfs 1>/dev/null
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
echo "error='mount ${hdd}1 failed'" echo "error='mount ${hdd}${nvp}1 failed'"
exit 1 exit 1
fi fi
cd /tmp/btrfs cd /tmp/btrfs
@@ -1010,9 +1034,9 @@ if [ "$1" = "fstab" ]; then
# get info on: Storage Drive # get info on: Storage Drive
uuidSTORAGE=$(lsblk -o UUID,NAME,LABEL | grep "${hdd}" | grep "BLITZSTORAGE" | cut -d " " -f 1 | grep "-") uuidSTORAGE=$(lsblk -o UUID,NAME,LABEL | grep "${hdd}" | grep "BLITZSTORAGE" | cut -d " " -f 1 | grep "-")
mount /dev/${hdd}2 /tmp/btrfs 1>/dev/null mount /dev/${hdd}${nvp}2 /tmp/btrfs 1>/dev/null
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
echo "error='mount ${hdd}2 failed'" echo "error='mount ${hdd}${nvp}2 failed'"
exit 1 exit 1
fi fi
cd /tmp/btrfs cd /tmp/btrfs
@@ -1084,7 +1108,6 @@ if [ "$1" = "fstab" ]; then
echo "error='wrong hdd format'" echo "error='wrong hdd format'"
exit 1 exit 1
fi fi
fi fi
######################################## ########################################
@@ -1113,7 +1136,6 @@ if [ "$1" = "raid" ]; then
echo "error='unknown parameter'" echo "error='unknown parameter'"
exit 1 exit 1
fi fi
fi fi
# RAID --> ON # RAID --> ON
@@ -1184,10 +1206,8 @@ if [ "$1" = "raid" ] && [ "$2" = "on" ]; then
>&2 echo "# adding ${usbdev} as BTRFS raid1 for /mnt/hdd" >&2 echo "# adding ${usbdev} as BTRFS raid1 for /mnt/hdd"
btrfs device add -f /dev/${usbdev} /mnt/hdd 1>/dev/null btrfs device add -f /dev/${usbdev} /mnt/hdd 1>/dev/null
btrfs filesystem balance start -dconvert=raid1 -mconvert=raid1 /mnt/hdd 1>/dev/null btrfs filesystem balance start -dconvert=raid1 -mconvert=raid1 /mnt/hdd 1>/dev/null
>&2 echo "# OK - ${usbdev} is now part of a RAID1 for your RaspiBlitz data" >&2 echo "# OK - ${usbdev} is now part of a RAID1 for your RaspiBlitz data"
exit 0 exit 0
fi fi
# RAID --> OFF # RAID --> OFF
@@ -1219,10 +1239,8 @@ if [ "$1" = "raid" ] && [ "$2" = "off" ]; then
echo "error='fail'" echo "error='fail'"
exit 1 exit 1
fi fi
fi fi
######################################## ########################################
# SNAPSHOTS - make and replay # SNAPSHOTS - make and replay
######################################## ########################################
@@ -1255,26 +1273,20 @@ if [ "$1" = "snapshot" ]; then
echo "error='unknown parameter'" echo "error='unknown parameter'"
exit 1 exit 1
fi fi
>&2 echo "# RASPIBLITZ SNAPSHOTS" >&2 echo "# RASPIBLITZ SNAPSHOTS"
partition=$(df | grep "${subvolume}" | cut -d " " -f 1) partition=$(df | grep "${subvolume}" | cut -d " " -f 1)
echo "subvolume='${subvolume}'" echo "subvolume='${subvolume}'"
echo "partition='${partition}'" echo "partition='${partition}'"
if [ "$3" = "create" ]; then if [ "$3" = "create" ]; then
>&2 echo "# Preparing Snapshot ..." >&2 echo "# Preparing Snapshot ..."
# make sure backup folder exists # make sure backup folder exists
mkdir -p ${subvolume}/snapshots mkdir -p ${subvolume}/snapshots
# delete old backup if existing # delete old backup if existing
oldBackupExists=$(ls ${subvolume}/snapshots | grep -c backup) oldBackupExists=$(ls ${subvolume}/snapshots | grep -c backup)
if [ ${oldBackupExists} -gt 0 ]; then if [ ${oldBackupExists} -gt 0 ]; then
>&2 echo "# Deleting old snapshot" >&2 echo "# Deleting old snapshot"
btrfs subvolume delete ${subvolume}/snapshots/backup 1>/dev/null btrfs subvolume delete ${subvolume}/snapshots/backup 1>/dev/null
fi fi
>&2 echo "# Creating Snapshot ..." >&2 echo "# Creating Snapshot ..."
btrfs subvolume snapshot ${subvolume} ${subvolume}/snapshots/backup 1>/dev/null btrfs subvolume snapshot ${subvolume} ${subvolume}/snapshots/backup 1>/dev/null
if [ $(btrfs subvolume list ${subvolume} | grep -c snapshots/backup) -eq 0 ]; then if [ $(btrfs subvolume list ${subvolume} | grep -c snapshots/backup) -eq 0 ]; then
@@ -1284,16 +1296,13 @@ if [ "$1" = "snapshot" ]; then
>&2 echo "# OK - Snapshot created" >&2 echo "# OK - Snapshot created"
exit 0 exit 0
fi fi
elif [ "$3" = "rollback" ]; then elif [ "$3" = "rollback" ]; then
# check if an old snapshot exists # check if an old snapshot exists
oldBackupExists=$(ls ${subvolume}/snapshots | grep -c backup) oldBackupExists=$(ls ${subvolume}/snapshots | grep -c backup)
if [ ${oldBackupExists} -eq 0 ]; then if [ ${oldBackupExists} -eq 0 ]; then
echo "error='no old snapshot found'" echo "error='no old snapshot found'"
exit 1 exit 1
fi fi
>&2 echo "# Resetting state to old Snapshot ..." >&2 echo "# Resetting state to old Snapshot ..."
umount ${subvolume} umount ${subvolume}
mkdir -p /tmp/btrfs 1>/dev/null mkdir -p /tmp/btrfs 1>/dev/null
@@ -1315,14 +1324,11 @@ if [ "$1" = "snapshot" ]; then
fi fi
echo "OK - Rollback done" echo "OK - Rollback done"
exit 0 exit 0
else else
>&2 echo "# third parameter needs to be 'create' or 'rollback'" >&2 echo "# third parameter needs to be 'create' or 'rollback'"
echo "error='unknown parameter'" echo "error='unknown parameter'"
exit 1 exit 1
fi fi
fi fi
################### ###################
@@ -1357,6 +1363,7 @@ if [ "$1" = "tempmount" ]; then
fi fi
# if hdd is a partition # if hdd is a partition
if [ $(echo "${hdd}" | grep -c "nvme") = 0 ]; then
if [[ $hdd =~ [0-9] ]]; then if [[ $hdd =~ [0-9] ]]; then
hddDataPartition=$hdd hddDataPartition=$hdd
hddDataPartitionExt4=$hddDataPartition hddDataPartitionExt4=$hddDataPartition
@@ -1365,7 +1372,16 @@ if [ "$1" = "tempmount" ]; then
hddBTRFS=$hdd hddBTRFS=$hdd
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hddBTRFS}1 | cut -d ' ' -f 1) hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hddBTRFS}1 | cut -d ' ' -f 1)
fi fi
else
if [[ $hdd =~ [p] ]]; then
hddDataPartition=$hdd
hddDataPartitionExt4=$hddDataPartition
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hddDataPartitionExt4} | cut -d ' ' -f 1)
else
hddBTRFS=$hdd
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hddBTRFS}p1 | cut -d ' ' -f 1)
fi
fi
if [ ${#hddFormat} -eq 0 ]; then if [ ${#hddFormat} -eq 0 ]; then
>&2 echo "# FAIL given device not found" >&2 echo "# FAIL given device not found"
echo "error='device not found'" echo "error='device not found'"
@@ -1373,7 +1389,6 @@ if [ "$1" = "tempmount" ]; then
fi fi
if [ "${hddFormat}" == "ext4" ]; then if [ "${hddFormat}" == "ext4" ]; then
if [ "${hddDataPartitionExt4}" == "" ]; then if [ "${hddDataPartitionExt4}" == "" ]; then
echo "error='parameter is no partition'" echo "error='parameter is no partition'"
exit 1 exit 1
@@ -1383,7 +1398,6 @@ if [ "$1" = "tempmount" ]; then
echo "# temp mount /dev/${hddDataPartitionExt4} --> /mnt/hdd" echo "# temp mount /dev/${hddDataPartitionExt4} --> /mnt/hdd"
mkdir -p /mnt/hdd 1>/dev/null mkdir -p /mnt/hdd 1>/dev/null
mount /dev/${hddDataPartitionExt4} /mnt/hdd mount /dev/${hddDataPartitionExt4} /mnt/hdd
# check result # check result
isMounted=$(df | grep -c "/mnt/hdd") isMounted=$(df | grep -c "/mnt/hdd")
if [ ${isMounted} -eq 0 ]; then if [ ${isMounted} -eq 0 ]; then
@@ -1401,12 +1415,17 @@ if [ "$1" = "tempmount" ]; then
bitcoinGID=$(id -g bitcoin) bitcoinGID=$(id -g bitcoin)
# do BTRFS temp mount # do BTRFS temp mount
if [ $(echo "${hddBTRFS}" | grep -c "nvme") = 0 ]; then
nvp=""
else
nvp="p"
fi
mkdir -p /mnt/hdd 1>/dev/null mkdir -p /mnt/hdd 1>/dev/null
mkdir -p /mnt/storage 1>/dev/null mkdir -p /mnt/storage 1>/dev/null
mkdir -p /mnt/temp 1>/dev/null mkdir -p /mnt/temp 1>/dev/null
mount -t btrfs -o degraded -o subvol=WORKINGDIR /dev/${hddBTRFS}1 /mnt/hdd mount -t btrfs -o degraded -o subvol=WORKINGDIR /dev/${hddBTRFS}${nvp}1 /mnt/hdd
mount -t btrfs -o subvol=WORKINGDIR /dev/${hddBTRFS}2 /mnt/storage mount -t btrfs -o subvol=WORKINGDIR /dev/${hddBTRFS}${nvp}2 /mnt/storage
mount -o umask=0000,uid=${bitcoinUID},gid=${bitcoinGID} /dev/${hddBTRFS}3 /mnt/temp mount -o umask=0000,uid=${bitcoinUID},gid=${bitcoinGID} /dev/${hddBTRFS}${nvp}3 /mnt/temp
# check result # check result
isMountedA=$(df | grep -c "/mnt/hdd") isMountedA=$(df | grep -c "/mnt/hdd")
@@ -1429,7 +1448,6 @@ if [ "$1" = "tempmount" ]; then
echo "isMounted=${isMounted}" echo "isMounted=${isMounted}"
echo "isBTRFS=${isBTRFS}" echo "isBTRFS=${isBTRFS}"
exit 1 exit 1
fi fi
if [ "$1" = "unmount" ]; then if [ "$1" = "unmount" ]; then
@@ -1445,7 +1463,6 @@ fi
######################################## ########################################
if [ "$1" = "link" ]; then if [ "$1" = "link" ]; then
if [ ${isMounted} -eq 0 ] ; then if [ ${isMounted} -eq 0 ] ; then
echo "error='no data drive mounted'" echo "error='no data drive mounted'"
exit 1 exit 1
@@ -1465,7 +1482,6 @@ if [ "$1" = "link" ]; then
if [ ${isBTRFS} -eq 1 ]; then if [ ${isBTRFS} -eq 1 ]; then
>&2 echo "# Creating BTRFS setup links" >&2 echo "# Creating BTRFS setup links"
>&2 echo "# - linking blockchains into /mnt/hdd" >&2 echo "# - linking blockchains into /mnt/hdd"
if [ $(ls -F /mnt/hdd/bitcoin | grep -c '/mnt/hdd/bitcoin@') -eq 0 ]; then if [ $(ls -F /mnt/hdd/bitcoin | grep -c '/mnt/hdd/bitcoin@') -eq 0 ]; then
mkdir -p /mnt/storage/bitcoin mkdir -p /mnt/storage/bitcoin
@@ -1475,47 +1491,36 @@ if [ "$1" = "link" ]; then
ln -s /mnt/storage/bitcoin /mnt/hdd/bitcoin ln -s /mnt/storage/bitcoin /mnt/hdd/bitcoin
rm /mnt/storage/bitcoin/bitcoin 2>/dev/null rm /mnt/storage/bitcoin/bitcoin 2>/dev/null
fi fi
>&2 echo "# linking lnd for user bitcoin" >&2 echo "# linking lnd for user bitcoin"
rm /home/bitcoin/.lnd 2>/dev/null rm /home/bitcoin/.lnd 2>/dev/null
ln -s /mnt/hdd/lnd /home/bitcoin/.lnd ln -s /mnt/hdd/lnd /home/bitcoin/.lnd
>&2 echo "# - linking blockchain for user bitcoin" >&2 echo "# - linking blockchain for user bitcoin"
ln -s /mnt/storage/bitcoin /home/bitcoin/.bitcoin ln -s /mnt/storage/bitcoin /home/bitcoin/.bitcoin
>&2 echo "# - linking storage into /mnt/hdd" >&2 echo "# - linking storage into /mnt/hdd"
mkdir -p /mnt/storage/app-storage mkdir -p /mnt/storage/app-storage
chown -R bitcoin:bitcoin /mnt/storage/app-storage chown -R bitcoin:bitcoin /mnt/storage/app-storage
rm /mnt/hdd/app-storage 2>/dev/null rm /mnt/hdd/app-storage 2>/dev/null
ln -s /mnt/storage/app-storage /mnt/hdd/app-storage ln -s /mnt/storage/app-storage /mnt/hdd/app-storage
>&2 echo "# - linking temp into /mnt/hdd" >&2 echo "# - linking temp into /mnt/hdd"
rm /mnt/hdd/temp 2>/dev/null rm /mnt/hdd/temp 2>/dev/null
ln -s /mnt/temp /mnt/hdd/temp ln -s /mnt/temp /mnt/hdd/temp
chown -R bitcoin:bitcoin /mnt/temp chown -R bitcoin:bitcoin /mnt/temp
>&2 echo "# - creating snapshots folder" >&2 echo "# - creating snapshots folder"
mkdir -p /mnt/hdd/snapshots mkdir -p /mnt/hdd/snapshots
mkdir -p /mnt/storage/snapshots mkdir -p /mnt/storage/snapshots
else else
>&2 echo "# Creating EXT4 setup links" >&2 echo "# Creating EXT4 setup links"
>&2 echo "# opening blockchain into /mnt/hdd" >&2 echo "# opening blockchain into /mnt/hdd"
mkdir -p /mnt/hdd/bitcoin mkdir -p /mnt/hdd/bitcoin
>&2 echo "# linking blockchain for user bitcoin" >&2 echo "# linking blockchain for user bitcoin"
rm /home/bitcoin/.bitcoin 2>/dev/null rm /home/bitcoin/.bitcoin 2>/dev/null
ln -s /mnt/hdd/bitcoin /home/bitcoin/.bitcoin ln -s /mnt/hdd/bitcoin /home/bitcoin/.bitcoin
>&2 echo "# linking lnd for user bitcoin" >&2 echo "# linking lnd for user bitcoin"
rm /home/bitcoin/.lnd 2>/dev/null rm /home/bitcoin/.lnd 2>/dev/null
ln -s /mnt/hdd/lnd /home/bitcoin/.lnd ln -s /mnt/hdd/lnd /home/bitcoin/.lnd
>&2 echo "# creating default storage & temp folders" >&2 echo "# creating default storage & temp folders"
mkdir -p /mnt/hdd/app-storage mkdir -p /mnt/hdd/app-storage
mkdir -p /mnt/hdd/temp mkdir -p /mnt/hdd/temp
fi fi
# fix ownership of linked files # fix ownership of linked files
@@ -1542,7 +1547,6 @@ if [ "$1" = "link" ]; then
>&2 echo "# OK - all symbolic links are built" >&2 echo "# OK - all symbolic links are built"
exit 0 exit 0
fi fi
######################################## ########################################
@@ -1550,55 +1554,40 @@ fi
######################################## ########################################
if [ "$1" = "swap" ]; then if [ "$1" = "swap" ]; then
>&2 echo "# RASPIBLITZ DATA DRIVES - SWAP FILE" >&2 echo "# RASPIBLITZ DATA DRIVES - SWAP FILE"
if [ ${isMounted} -eq 0 ]; then if [ ${isMounted} -eq 0 ]; then
echo "error='no data drive mounted'" echo "error='no data drive mounted'"
exit 1 exit 1
fi fi
if [ "$2" = "on" ]; then if [ "$2" = "on" ]; then
if [ ${isSwapExternal} -eq 1 ]; then if [ ${isSwapExternal} -eq 1 ]; then
>&2 echo "# OK - already ON" >&2 echo "# OK - already ON"
exit 1 exit 1
fi fi
>&2 echo "# Switch off/uninstall old SWAP" >&2 echo "# Switch off/uninstall old SWAP"
dphys-swapfile swapoff 1>/dev/null dphys-swapfile swapoff 1>/dev/null
dphys-swapfile uninstall 1>/dev/null dphys-swapfile uninstall 1>/dev/null
if [ ${isBTRFS} -eq 1 ]; then if [ ${isBTRFS} -eq 1 ]; then
>&2 echo "# Rewrite external SWAP config for BTRFS setup" >&2 echo "# Rewrite external SWAP config for BTRFS setup"
sed -i "s/^#CONF_SWAPFILE=/CONF_SWAPFILE=/g" /etc/dphys-swapfile sed -i "s/^#CONF_SWAPFILE=/CONF_SWAPFILE=/g" /etc/dphys-swapfile
sed -i "s/^CONF_SWAPFILE=.*/CONF_SWAPFILE=\/mnt\/temp\/swapfile/g" /etc/dphys-swapfile sed -i "s/^CONF_SWAPFILE=.*/CONF_SWAPFILE=\/mnt\/temp\/swapfile/g" /etc/dphys-swapfile
else else
>&2 echo "# Rewrite external SWAP config for EXT4 setup" >&2 echo "# Rewrite external SWAP config for EXT4 setup"
sed -i "s/^#CONF_SWAPFILE=/CONF_SWAPFILE=/g" /etc/dphys-swapfile sed -i "s/^#CONF_SWAPFILE=/CONF_SWAPFILE=/g" /etc/dphys-swapfile
sed -i "s/^CONF_SWAPFILE=.*/CONF_SWAPFILE=\/mnt\/hdd\/swapfile/g" /etc/dphys-swapfile sed -i "s/^CONF_SWAPFILE=.*/CONF_SWAPFILE=\/mnt\/hdd\/swapfile/g" /etc/dphys-swapfile
fi fi
sed -i "s/^CONF_SWAPSIZE=/#CONF_SWAPSIZE=/g" /etc/dphys-swapfile sed -i "s/^CONF_SWAPSIZE=/#CONF_SWAPSIZE=/g" /etc/dphys-swapfile
sed -i "s/^#CONF_MAXSWAP=.*/CONF_MAXSWAP=3072/g" /etc/dphys-swapfile sed -i "s/^#CONF_MAXSWAP=.*/CONF_MAXSWAP=3072/g" /etc/dphys-swapfile
>&2 echo "# Creating SWAP file .." >&2 echo "# Creating SWAP file .."
dd if=/dev/zero of=$externalSwapPath count=3072 bs=1MiB 1>/dev/null dd if=/dev/zero of=$externalSwapPath count=3072 bs=1MiB 1>/dev/null
chmod 0600 $externalSwapPath 1>/dev/null chmod 0600 $externalSwapPath 1>/dev/null
>&2 echo "# Activating new SWAP" >&2 echo "# Activating new SWAP"
mkswap $externalSwapPath mkswap $externalSwapPath
dphys-swapfile setup dphys-swapfile setup
dphys-swapfile swapon dphys-swapfile swapon
>&2 echo "# OK - Swap is now ON external" >&2 echo "# OK - Swap is now ON external"
exit 0 exit 0
elif [ "$2" = "off" ]; then elif [ "$2" = "off" ]; then
if [ ${isSwapExternal} -eq 0 ]; then if [ ${isSwapExternal} -eq 0 ]; then
>&2 echo "# OK - already OFF" >&2 echo "# OK - already OFF"
exit 1 exit 1
@@ -1621,13 +1610,11 @@ if [ "$1" = "swap" ]; then
>&2 echo "# OK - Swap is now OFF external" >&2 echo "# OK - Swap is now OFF external"
exit 0 exit 0
else else
>&2 echo "# FAIL unknown second parameter - try 'on' or 'off'" >&2 echo "# FAIL unknown second parameter - try 'on' or 'off'"
echo "error='unknown parameter'" echo "error='unknown parameter'"
exit 1 exit 1
fi fi
fi fi
######################################## ########################################
@@ -1640,16 +1627,13 @@ if [ "$1" = "clean" ]; then
# get HDD status # get HDD status
source <(/home/admin/config.scripts/blitz.datadrive.sh status) source <(/home/admin/config.scripts/blitz.datadrive.sh status)
if [ ${isMounted} -eq 0 ]; then if [ ${isMounted} -eq 0 ]; then
>&2 echo "# FAIL: cannot clean - the drive is not mounted'" >&2 echo "# FAIL: cannot clean - the drive is not mounted'"
echo "error='not mounted'" echo "error='not mounted'"
exit 1 exit 1
fi fi
>&2 echo "# Making sure 'secure-delete' is installed ..." >&2 echo "# Making sure 'secure-delete' is installed ..."
apt-get install -y secure-delete 1>/dev/null apt-get install -y secure-delete 1>/dev/null
>&2 echo >&2 echo
>&2 echo "# IMPORTANT: No 100% guarantee that sensitive data is completely deleted!" >&2 echo "# IMPORTANT: No 100% guarantee that sensitive data is completely deleted!"
# see: https://www.davescomputers.com/securely-deleting-files-solid-state-drive/" # see: https://www.davescomputers.com/securely-deleting-files-solid-state-drive/"
@@ -1659,9 +1643,7 @@ if [ "$1" = "clean" ]; then
# DELETE ALL DATA (with option to keep blockchain) # DELETE ALL DATA (with option to keep blockchain)
if [ "$2" = "all" ]; then if [ "$2" = "all" ]; then
if [ "$3" = "-total" ] || [ "$3" = "-keepblockchain" ]; then if [ "$3" = "-total" ] || [ "$3" = "-keepblockchain" ]; then
>&2 echo "# Deleting personal Data .." >&2 echo "# Deleting personal Data .."
# make sure swap is off # make sure swap is off
@@ -1672,23 +1654,19 @@ if [ "$1" = "clean" ]; then
# for all other data shred files selectively # for all other data shred files selectively
for entry in $(ls -A1 /mnt/hdd) for entry in $(ls -A1 /mnt/hdd)
do do
delete=1 delete=1
whenDeleteSchredd=1 whenDeleteSchredd=1
# dont delete temp - will be deleted on every boot anyway # dont delete temp - will be deleted on every boot anyway
# but keep in case during setup a migration file was uploaded there # but keep in case during setup a migration file was uploaded there
if [ "${entry}" = "temp" ]; then if [ "${entry}" = "temp" ]; then
delete=0 delete=0
fi fi
# deactivate delete if a blockchain directory (if -keepblockchain) # deactivate delete if a blockchain directory (if -keepblockchain)
if [ "$3" = "-keepblockchain" ]; then if [ "$3" = "-keepblockchain" ]; then
if [ "${entry}" = "bitcoin" ]; then if [ "${entry}" = "bitcoin" ]; then
delete=0 delete=0
fi fi
fi fi
# decide when to shred or just delete - just delete nonsensitive data # decide when to shred or just delete - just delete nonsensitive data
if [ "${entry}" = "torrent" ] || [ "${entry}" = "app-storage" ]; then if [ "${entry}" = "torrent" ] || [ "${entry}" = "app-storage" ]; then
whenDeleteSchredd=0 whenDeleteSchredd=0
@@ -1705,10 +1683,8 @@ if [ "$1" = "clean" ]; then
if [ "${isSSD}" == "1" ]; then if [ "${isSSD}" == "1" ]; then
whenDeleteSchredd=0 whenDeleteSchredd=0
fi fi
# delete or keep # delete or keep
if [ ${delete} -eq 1 ]; then if [ ${delete} -eq 1 ]; then
if [ -d "/mnt/hdd/$entry" ]; then if [ -d "/mnt/hdd/$entry" ]; then
if [ ${whenDeleteSchredd} -eq 1 ]; then if [ ${whenDeleteSchredd} -eq 1 ]; then
>&2 echo "# shredding DIR : ${entry}" >&2 echo "# shredding DIR : ${entry}"
@@ -1726,11 +1702,9 @@ if [ "$1" = "clean" ]; then
rm /mnt/hdd/$entry rm /mnt/hdd/$entry
fi fi
fi fi
else else
>&2 echo "# keeping: ${entry}" >&2 echo "# keeping: ${entry}"
fi fi
done done
# KEEP BLOCKCHAIN means just blocks & chainstate - delete the rest # KEEP BLOCKCHAIN means just blocks & chainstate - delete the rest
@@ -1739,10 +1713,8 @@ if [ "$1" = "clean" ]; then
for chain in "${chains[@]}" for chain in "${chains[@]}"
do do
echo "Cleaning Blockchain: ${chain}" echo "Cleaning Blockchain: ${chain}"
# take extra care if wallet.db exists # take extra care if wallet.db exists
srm -v /mnt/hdd/${chain}/wallet.db 2>/dev/null srm -v /mnt/hdd/${chain}/wallet.db 2>/dev/null
# the rest just delete (keep blocks and chainstate and testnet3) # the rest just delete (keep blocks and chainstate and testnet3)
for entry in $(ls -A1 /mnt/hdd/${chain} 2>/dev/null) for entry in $(ls -A1 /mnt/hdd/${chain} 2>/dev/null)
do do
@@ -1791,10 +1763,8 @@ if [ "$1" = "clean" ]; then
fi fi
done done
fi fi
>&2 echo "# OK cleaning done." >&2 echo "# OK cleaning done."
exit 1 exit 1
else else
>&2 echo "# FAIL unknown third parameter try '-total' or '-keepblockchain'" >&2 echo "# FAIL unknown third parameter try '-total' or '-keepblockchain'"
echo "error='unknown parameter'" echo "error='unknown parameter'"
@@ -1803,29 +1773,23 @@ if [ "$1" = "clean" ]; then
# RESET BLOCKCHAIN (e.g to rebuilt blockchain ) # RESET BLOCKCHAIN (e.g to rebuilt blockchain )
elif [ "$2" = "blockchain" ]; then elif [ "$2" = "blockchain" ]; then
# here is no secure delete needed - because not sensitive data # here is no secure delete needed - because not sensitive data
>&2 echo "# Deleting all Blockchain Data (blocks/chainstate) from storage .." >&2 echo "# Deleting all Blockchain Data (blocks/chainstate) from storage .."
# set path based on EXT4/BTRFS # set path based on EXT4/BTRFS
basePath="/mnt/hdd" basePath="/mnt/hdd"
if [ ${isBTRFS} -eq 1 ]; then if [ ${isBTRFS} -eq 1 ]; then
basePath="/mnt/storage" basePath="/mnt/storage"
fi fi
# deleting the blocks and chainstate # deleting the blocks and chainstate
rm -R ${basePath}/bitcoin/blocks 1>/dev/null 2>/dev/null rm -R ${basePath}/bitcoin/blocks 1>/dev/null 2>/dev/null
rm -R ${basePath}/bitcoin/chainstate 1>/dev/null 2>/dev/null rm -R ${basePath}/bitcoin/chainstate 1>/dev/null 2>/dev/null
>&2 echo "# OK cleaning done." >&2 echo "# OK cleaning done."
exit 1 exit 1
# RESET TEMP (keep swapfile) # RESET TEMP (keep swapfile)
elif [ "$2" = "temp" ]; then elif [ "$2" = "temp" ]; then
>&2 echo "# Deleting the temp folder/drive (keeping SWAP file) .." >&2 echo "# Deleting the temp folder/drive (keeping SWAP file) .."
tempPath="/mnt/hdd/temp" tempPath="/mnt/hdd/temp"
for entry in $(ls -A1 ${tempPath} 2>/dev/null) for entry in $(ls -A1 ${tempPath} 2>/dev/null)
do do
# sorting file # sorting file
@@ -1835,7 +1799,6 @@ if [ "$1" = "clean" ]; then
fi fi
# delete or keep # delete or keep
if [ ${delete} -eq 1 ]; then if [ ${delete} -eq 1 ]; then
if [ -d "${tempPath}/$entry" ]; then if [ -d "${tempPath}/$entry" ]; then
>&2 echo "# shredding DIR : ${entry}" >&2 echo "# shredding DIR : ${entry}"
rm -r ${tempPath}/$entry rm -r ${tempPath}/$entry
@@ -1843,21 +1806,17 @@ if [ "$1" = "clean" ]; then
>&2 echo "# shredding FILE : ${entry}" >&2 echo "# shredding FILE : ${entry}"
rm ${tempPath}/$entry rm ${tempPath}/$entry
fi fi
else else
>&2 echo "# keeping: ${entry}" >&2 echo "# keeping: ${entry}"
fi fi
done done
>&2 echo "# OK cleaning done." >&2 echo "# OK cleaning done."
exit 1 exit 1
else else
>&2 echo "# FAIL unknown second parameter - try 'all','blockchain' or 'temp'" >&2 echo "# FAIL unknown second parameter - try 'all','blockchain' or 'temp'"
echo "error='unknown parameter'" echo "error='unknown parameter'"
exit 1 exit 1
fi fi
fi fi
######################################## ########################################
@@ -1894,7 +1853,6 @@ if [ "$1" = "uasp-fix" ]; then
echo "# Skipping UASP deactivation ... cmdlineExists(${cmdlineExists}) hddAdapterUSB(${hddAdapterUSB}) hddAdapterUSAP(${hddAdapterUSAP})" echo "# Skipping UASP deactivation ... cmdlineExists(${cmdlineExists}) hddAdapterUSB(${hddAdapterUSB}) hddAdapterUSAP(${hddAdapterUSAP})"
echo "neededReboot=0" echo "neededReboot=0"
fi fi
exit 0 exit 0
fi fi