diff --git a/rootfs/standard/usr/bin/clone_drive.py b/rootfs/standard/usr/bin/clone_drive.py index 23e6e69c..6053fd00 100755 --- a/rootfs/standard/usr/bin/clone_drive.py +++ b/rootfs/standard/usr/bin/clone_drive.py @@ -33,6 +33,9 @@ def reset_clone_error(): def reset_clone_confirm(): os.system("rm /tmp/.clone_confirm") +def reset_clone_rescan(): + os.system("rm /tmp/.clone_rescan") + def set_clone_error(error_msg): print_and_log("Clone Error: {}".format(error_msg)) try: @@ -93,6 +96,16 @@ def find_partitions_for_drive(drive): pass return partitions +def is_drive_detected_by_fdisk(d): + detected = False + try: + # Command fails and throws exception if not mounted + ls_output = subprocess.check_output(f"fdisk -l /dev/{d}", shell=True).decode("utf-8") + detected = True + except: + pass + return detected + def is_drive_mounted(d): mounted = True try: @@ -110,7 +123,7 @@ def find_drives(): # Only return drives that are not mounted (VM may have /dev/sda as OS drive) for d in all_drives: - if not is_drive_mounted(d): + if is_drive_detected_by_fdisk(d) and not is_drive_mounted(d): drives.append(d) except: pass @@ -121,6 +134,7 @@ def main(): set_clone_state("detecting") reset_clone_error() reset_clone_confirm() + reset_clone_rescan() os.system("umount /mnt/hdd") os.system("rm /tmp/.clone_target_drive_has_mynode") @@ -204,9 +218,14 @@ def main(): os.system(f"echo {mynode_drive} > /tmp/.clone_source") os.system(f"echo {target_drive} > /tmp/.clone_target") set_clone_state("need_confirm") - while not os.path.isfile("/tmp/.clone_confirm"): + while not os.path.isfile("/tmp/.clone_confirm") and not os.path.isfile("/tmp/.clone_rescan"): time.sleep(1) + # User asked for rescan - recursively call main + if os.path.isfile("/tmp/.clone_rescan"): + main() + return + # Clone drives set_clone_state("in_progress") os.system("echo 'Starting clone.' > /tmp/.clone_progress") diff --git a/rootfs/standard/var/www/mynode/templates/clone_confirm.html b/rootfs/standard/var/www/mynode/templates/clone_confirm.html index 33686e71..ddeba565 100644 --- a/rootfs/standard/var/www/mynode/templates/clone_confirm.html +++ b/rootfs/standard/var/www/mynode/templates/clone_confirm.html @@ -21,6 +21,9 @@ $("#format-confirm").on("click", function() { window.location.href="/?clone_confirm=1" }); + $("#rescan-drives").on("click", function() { + window.location.href="/?clone_rescan=1" + }); $("#reboot-device").on("click", function() { window.location.href="/settings/reboot-device" }); @@ -81,9 +84,11 @@

It is highly recommended that both drives be externally powered. Running two drives from USB power on the device can cause clone failures.


- +

- + +

+