USB Power shutdown method? And Hard drives?

Run this two commands in ssh console and check if reboot or powering off unmounts usb disks.

wget -O /storage/.config/shutdown.sh https://pastebin.com/raw/ypmbcrEu
dos2unix /storage/.config/shutdown.sh
1 Like

Is ‘umount’ a sufficient command?
Yes it will unmount the filesystem, but is ‘eject’ not required to withdraw power from the device?

… maybe that has changed …

Does Kodi eject really eject the drive or just unmount it? I think it only unmount.

I did, it downloaded and placed shutdown.sh in proper place, then I run the second command and turned off N2. When USB power was cut off disk “clanked” as it does when I don’t remove it safely in Kodi Power Menu. So this does not work for my USB disk…

Btw, my USB HD is mounted as /dev/sda1; should that be put in the command instead
/dev/disk/by-id/usb-* ?

Seems Kodi eject is doing something more.

You can try using hdparm like

hdparm -y /dev/sda

Running hdparm -y /dev/sda1
response: issuing standby command

and USB HD drive goes to sleep.

Then use this command after partitions are unmounted in shutdown.sh.

Where exactly do I put it, like this:

for usb_dev in /dev/disk/by-id/usb-*; do
dev=$(readlink -f $usb_dev)
grep -qw ^$dev /proc/mounts && umount $dev
hdparm -y /dev/sda1
done

for usb_dev in /dev/disk/by-id/usb-*; do
  dev=$(readlink -f $usb_dev)
  grep -qw ^$dev /proc/mounts && umount $dev
  hdparm -y $dev
done

Or maybe better

for usb_dev in /dev/disk/by-id/usb-*; do
  dev=$(readlink -f $usb_dev)
  grep -qw ^$dev /proc/mounts && umount $dev
done
for usb_dev in /dev/disk/by-id/usb-*; do
  dev=$(readlink -f $usb_dev)
  hdparm -y $dev
done

No change with the first version, will try second version later when wife lets me fiddle with the player again :slight_smile:

EDIT, after some sweet talk I could try the second command also :slight_smile:

But, no change with reboot or power off, the drive still goes “clank”. Checking in System Info after running dos2unix /storage/.config/shutdown.sh command my USB HD is still mounted and all content is accessible.

dos2unix command only changes dos formatted shell script to unix :slight_smile:
If you want to execute manually run

sh /storage/.config/shutdown.sh poweroff

Well, no wander that there is no change :slight_smile:

But also no luck with proper command:
CoreELEC:~ # sh /storage/.config/shutdown.sh poweroff
/dev/disk/by-id/usb-*: No such file or directory

This indicates that there is no USB disk attached.

Will try to find some external USB disk to try it myself.

Strange, because just before running the command, and after it I watched my TV series from that disk :slight_smile:

It had previously been ejected?

there are two installations with two USB discs. Cant test “clank” as they are remote, not in my flat, but I guess Sholander has maybe disc with no usb prefix?

One would be WD obviously, second one is Transcend:

FIRST INSTALLATION

/dev/disk/by-id$ ls -la
total 0
drwxr-xr-x    2 root     root           160 Jun 22  2018 .
drwxr-xr-x    7 root     root           140 Jun 22  2018 ..
lrwxrwxrwx    1 root     root            13 Jun 22  2018 mmc-SD16G_0x3f680909 -> ../../mmcblk0
lrwxrwxrwx    1 root     root            15 Jun 22  2018 mmc-SD16G_0x3f680909-part1 -> ../../mmcblk0p1
lrwxrwxrwx    1 root     root            15 Jun 22  2018 mmc-SD16G_0x3f680909-part2 -> ../../mmcblk0p2
lrwxrwxrwx    1 root     root             9 Jun 22  2018 usb-WD_Elements_25A2_575841314141374632375032-0:0 -> ../../sda
lrwxrwxrwx    1 root     root            10 Jun 22  2018 usb-WD_Elements_25A2_575841314141374632375032-0:0-part1 -> ../../sda1
lrwxrwxrwx    1 root     root            10 Jun 22  2018 usb-WD_Elements_25A2_575841314141374632375032-0:0-part2 -> ../../sda2

/dev/disk/by-id$ mount
rootfs on / type rootfs (rw,size=823556k,nr_inodes=205889)
devtmpfs on /dev type devtmpfs (rw,relatime,size=823556k,nr_inodes=205889,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
/dev/mmcblk0p1 on /flash type vfat (ro,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
/dev/sda1 on /storage type ext4 (rw,noatime,data=ordered)

SECOND INSTALLATION

/dev/disk/by-id # ls -la
total 0
drwxr-xr-x    2 root     root           180 Jun 22  2018 .
drwxr-xr-x    7 root     root           140 Jun 22  2018 ..
lrwxrwxrwx    1 root     root             9 Jun 22  2018 ata-WDC_WD10SPZX-22Z10T0_WD-WXT1A77L239C -> ../../sda
lrwxrwxrwx    1 root     root            10 Jun 22  2018 ata-WDC_WD10SPZX-22Z10T0_WD-WXT1A77L239C-part1 -> ../../sda1
lrwxrwxrwx    1 root     root            13 Jun 22  2018 mmc-SB16G_0xd3e81aad -> ../../mmcblk0
lrwxrwxrwx    1 root     root            15 Jun 22  2018 mmc-SB16G_0xd3e81aad-part1 -> ../../mmcblk0p1
lrwxrwxrwx    1 root     root            15 Jun 22  2018 mmc-SB16G_0xd3e81aad-part2 -> ../../mmcblk0p2
lrwxrwxrwx    1 root     root             9 Jun 22  2018 wwn-0x50014ee607e0266c -> ../../sda
lrwxrwxrwx    1 root     root            10 Jun 22  2018 wwn-0x50014ee607e0266c-part1 -> ../../sda1
/dev/disk/by-id # mount
rootfs on / type rootfs (rw,size=823556k,nr_inodes=205889)
devtmpfs on /dev type devtmpfs (rw,relatime,size=823556k,nr_inodes=205889,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
/dev/mmcblk0p1 on /flash type vfat (ro,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
/dev/sda1 on /storage type ext4 (rw,noatime,data=ordered)

You are right, my disk is in /dev/disk/by-id/ata-WDC_xxxxxxxxx like the one in your second installation.

I updated my script on pastebin. It looks for usb and ata devices.

EDIT: Found another USB disk and it got ejected with hdparm. So script should work now.

Yes, now it works, big thnx :smile:
The script removes all my USB drives (HDs and sticks) and runs before power is turned off.

One thing though, wouldn’t it be simpler to put commands only under the last entry *) ?
As I understand, then it will cover all above instances halt) , poweroff) and reboot)

1 Like

Should this be done on reboot too? Try using it under * and report back.
I though reboot actions should not be needed but maybe I’m wrong.

EDIT: I update my script again and put all the actions under * and actions are executed always when script is called.