I have an external drive that unmounts after backup jobs are finished. Now I want to schedule a script to remount that drive just before the backup jobs initiate that way the drive is off most of the time and therefore safer. would be great if someone can help me with a script. Thank you
Hi and welcome to the forum. ![]()
You’re more likely to get help if you can demonstrate what you’ve done so-far and where you’re stuck. What does your current script look like?
Note: an unmounted drive is not safe from automatic remounting and malware encryption or deliberate deletion. It needs to be powered-off too.
I used the following script and I can see the drive using ‘‘ls’’ but the hbs3 cannot see the drive so the backup jobs will not work. Thanks
#!/bin/bash
# QNAP USB remount script for ext4 drive (sde1)
# 1. Force the USB bus to scan for disconnected hardware
echo "1" > /sys/bus/pci/rescan
sleep 5
# 2. Hardcoded paths based on your specific setup
USB_PARTITION="/dev/sde1"
MOUNT_POINT="/share/external/DEV3304_1"
# 3. Re-create the mount folder if QNAP deleted it
if [ ! -d "$MOUNT_POINT" ]; then
mkdir -p $MOUNT_POINT
fi
# 4. Mount the ext4 drive back to the NAS using QNAP-compatible flags
if [ -b "$USB_PARTITION" ]; then
if mount -t ext4 $USB_PARTITION $MOUNT_POINT; then
echo "Successfully mounted ext4 drive $USB_PARTITION to $MOUNT_POINT"
else
echo "Error: Mount command failed."
fi
else
echo "Error: Partition /dev/sde1 not detected by the system."
fi
Looks like you’re getting some help from AI. ![]()
When mounting USB drives in QTS, better to give them a volume label. This allows you a predictable mount point. This is needed as the assigned drive letter and QTS mount point can change between mounts.
When you mount the drive, use the volume label instead. This remains the same between mounts.
You bet…I would not be able to write that. hence the call for help.