1

I would like to be able to eject a certain disk from the task scheduler. I can find out which disk I want to eject with the lsusb -ciu command. If for example I want to eject disk 5-1.2, how could I do it?

I have tried some scripts that I have seen on some support pages but none have worked. Maybe you are doing something wrong. This just doesn't work for me, the drive is still operational.

echo "5-1.2" > /sys/bus/usb/drivers/usb/unbind

The device is ejected but the nas shows a warning: The device has not been ejected safely.

I have also tried the following script. It also unplugs it but the warning for not ejecting the external hard drive safely reappears.

USBDEVICE="5-1.2"
echo 0 > /sys/bus/usb/devices/$USBDEVICE/authorized

What's going on?

PlayerWet
  • 138

1 Answers1

2

The commands you list just cut the USB connection to the disk, equivalent to pulling the plug. However when you plugged it in, Linux (the underlying OS of the Synology NAS software) had mounted the filesystem contained on it in order to make the files accessible to the software. This operation has to be undone, a process known as unmounting, before you cut the USB connection, otherwise the filesystem may be left in an inconsistent state. This is what happens when you click "remove safely" in the GUI.

In order to do that from a script you have first to find the name of the block device associated with the filesystem partition on the USB disk. This is listed for example in the "Filesystem" column of the output of the df command. A typical name is /dev/sde1 for the first or only partition of the fifth physical disk. You then pass that name to the umount command (note: no 'n' after the initial 'u') like so:

umount /dev/sde1

Note that it is possible for a disk to contain more than one filesystem partition. In that case you'll have to unmount all of them before cutting the USB connection either physically or programmatically.