Koozali.org: home of the SME Server

dock usb pour disque de sauvegarde : gestion du disque

Offline ecureuil

  • *
  • 261
  • +0/-0
dock usb pour disque de sauvegarde : gestion du disque
« on: December 20, 2016, 01:58:39 AM »
bonjour

Je suis en train de tester sur ma debian la gestion des disque usb :
mise en veille ou arrêt du disque après la sauvegarde.
Mise en route du diisqe usb pour la nouvelle sauvegarde.

le but c'est de gérer le disque usb pour ma sauvegarde de ma sme.

noyau sme 9.1 
# uname -r
2.6.32-642.11.1.el6.x86_64

noyau de ma debian
# uname -r
3.16.0-4-amd64

sibsib est intéressé et  est en train de m'aider.
jpp a peut-être fait des tests...


sur ma debian, je connecte mon disque usb
dans nautilus, 2 des options : 'démonter'  et 'retirer le périphérique sans risque'
derrière 'démonter' c'est mount et umount
derrière 'retirer le périphérique sans risque' c'est le mystère au niveau des commandes
Quand je fais 'retirer le périphérique sans risque' , cela arrête le disque est la lumière du dock se met au rouge.
La seule solution pour avoir accès de nouveau au disque c'est de débrancher et rebrancher la prise usb

sibsib a trouvé bind et unbind


Les commandes suivantes ont été faites avec ma sme 9.1

# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 0835:8500 Action Star Enterprise Co., Ltd
Bus 001 Device 003: ID 0b95:7720 ASIX Electronics Corp. AX88772
Bus 001 Device 004: ID 5986:01aa Acer, Inc
Bus 005 Device 002: ID 03f0:231d Hewlett-Packard Broadcom 2070 Bluetooth Combo
Bus 001 Device 061: ID 0835:8501 Action Star Enterprise Co., Ltd
Bus 001 Device 062: ID 04b8:010f Seiko Epson Corp. GT-7200U [Perfection 1250/1250 PHOTO]
Bus 001 Device 063: ID 04e8:328e Samsung Electronics Co., Ltd CLP-310 Color Laser Printer
Bus 001 Device 064: ID 0835:8500 Action Star Enterprise Co., Ltd
Bus 001 Device 065: ID 0835:8502 Action Star Enterprise Co., Ltd
Bus 001 Device 066: ID 1a86:7584 QinHeng Electronics CH340S

# ls -al /dev/sd*
brw-rw---- 1 root disk 8,  0  5 déc.  18:44 /dev/sda
brw-rw---- 1 root disk 8,  1  5 déc.  18:44 /dev/sda1
brw-rw---- 1 root disk 8,  2  5 déc.  18:44 /dev/sda2
brw-rw---- 1 root disk 8,  3  5 déc.  18:44 /dev/sda3

Je connecte mon disque dur usb

# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 0835:8500 Action Star Enterprise Co., Ltd
Bus 001 Device 003: ID 0b95:7720 ASIX Electronics Corp. AX88772
Bus 001 Device 004: ID 5986:01aa Acer, Inc
Bus 005 Device 002: ID 03f0:231d Hewlett-Packard Broadcom 2070 Bluetooth Combo
Bus 001 Device 061: ID 0835:8501 Action Star Enterprise Co., Ltd
Bus 001 Device 062: ID 04b8:010f Seiko Epson Corp. GT-7200U [Perfection 1250/1250 PHOTO]
Bus 001 Device 063: ID 04e8:328e Samsung Electronics Co., Ltd CLP-310 Color Laser Printer
Bus 001 Device 064: ID 0835:8500 Action Star Enterprise Co., Ltd
Bus 001 Device 065: ID 0835:8502 Action Star Enterprise Co., Ltd
Bus 001 Device 066: ID 1a86:7584 QinHeng Electronics CH340S
Bus 001 Device 067: ID 152d:2352 JMicron Technology Corp. / JMicron USA Technology Corp. ATA/ATAPI Bridge

=> le dock apparaît : Bus 001 Device 067: ID 152d:2352 JMicron Technology Corp. / JMicron USA Technology Corp. ATA/ATAPI Bridge

# ls -al /dev/sd*
brw-rw---- 1 root disk 8,  0  5 déc.  18:44 /dev/sda
brw-rw---- 1 root disk 8,  1  5 déc.  18:44 /dev/sda1
brw-rw---- 1 root disk 8,  2  5 déc.  18:44 /dev/sda2
brw-rw---- 1 root disk 8,  3  5 déc.  18:44 /dev/sda3
brw-rw---- 1 root disk 8, 16 19 déc.  18:56 /dev/sdb
brw-rw---- 1 root disk 8, 17 19 déc.  18:56 /dev/sdb1
brw-rw---- 1 root disk 8, 18 19 déc.  18:56 /dev/sdb2

=> le disque usb est dans /dev/sdb

Il faut trouver où le port usb  est monté

# DEV_NAME=/dev/sdb; DEVICE=$(udevadm info --query=path --name=${DEV_NAME} --attribute-walk | egrep "looking at parent device" | head -1 | sed -e "s/.*looking at parent device '\(\/devices\/.*\)\/.*\/host.*/\1/g"); DEV_BUS_ID=${DEVICE##*/};  echo $DEV_BUS_ID
1-2.5.5

pour plus de compréhension de la commande
# DEV_NAME=/dev/sdb; \
> DEVICE=$(udevadm info --query=path --name=${DEV_NAME} --attribute-walk | \
>     egrep "looking at parent device" | head -1 | \
>     sed -e "s/.*looking at parent device '\(\/devices\/.*\)\/.*\/host.*/\1/g"); \
> DEV_BUS_ID=${DEVICE##*/}; \
> echo $DEV_BUS_ID
1-2.5.5

Attention, avant de faire cette commande, le disque usb ne doit pas être monté. (umount)

# echo -n "1-2.5.5" >/sys/bus/usb/drivers/usb/unbind

# ls -al /dev/sd*
brw-rw---- 1 root disk 8, 0  5 déc.  18:44 /dev/sda
brw-rw---- 1 root disk 8, 1  5 déc.  18:44 /dev/sda1
brw-rw---- 1 root disk 8, 2  5 déc.  18:44 /dev/sda2
brw-rw---- 1 root disk 8, 3  5 déc.  18:44 /dev/sda3

Plus de disque /dev/sdb

# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 0835:8500 Action Star Enterprise Co., Ltd
Bus 001 Device 003: ID 0b95:7720 ASIX Electronics Corp. AX88772
Bus 001 Device 004: ID 5986:01aa Acer, Inc
Bus 005 Device 002: ID 03f0:231d Hewlett-Packard Broadcom 2070 Bluetooth Combo
Bus 001 Device 061: ID 0835:8501 Action Star Enterprise Co., Ltd
Bus 001 Device 062: ID 04b8:010f Seiko Epson Corp. GT-7200U [Perfection 1250/1250 PHOTO]
Bus 001 Device 063: ID 04e8:328e Samsung Electronics Co., Ltd CLP-310 Color Laser Printer
Bus 001 Device 064: ID 0835:8500 Action Star Enterprise Co., Ltd
Bus 001 Device 065: ID 0835:8502 Action Star Enterprise Co., Ltd
Bus 001 Device 066: ID 1a86:7584 QinHeng Electronics CH340S
Bus 001 Device 067: ID 152d:2352 JMicron Technology Corp. / JMicron USA Technology Corp. ATA/ATAPI Bridge

Il y a toujours le driver du dock

Je remonte le disk usb

#  echo -n "1-2.5.5" >/sys/bus/usb/drivers/usb/bind

# ls -al /dev/sd*
brw-rw---- 1 root disk 8,  0  5 déc.  18:44 /dev/sda
brw-rw---- 1 root disk 8,  1  5 déc.  18:44 /dev/sda1
brw-rw---- 1 root disk 8,  2  5 déc.  18:44 /dev/sda2
brw-rw---- 1 root disk 8,  3  5 déc.  18:44 /dev/sda3
brw------- 1 root root 8, 16 20 déc.  01:51 /dev/sdb
brw------- 1 root root 8, 17 20 déc.  01:51 /dev/sdb1
brw------- 1 root root 8, 18 20 déc.  01:51 /dev/sdb2

Le disque usb est de nouveau visible

-----

La suite a été testée avec ma debian

J'ai trouvé la commande udisks

Le disque usb n'est plus monté (umount)

udisks
# udisks --detach /dev/sdb

udisks2
# udisksctl power-off -b /dev/sdb

Que ce soit avec la commande udisks ou udisk2, la lumière de mon dock se met au rouge.
Plus rien dans fdisk, lsusb, /dev/sdb

Avec sme on pourrait avoir udisks (udisk2 n'est que dans centos7)

Par contre je ne trouve pas la commande pour remettre en route mon disque usb sans débrancher et rebrancher la prise usb.

Il y a peut-être des personnes qui ont testé ce genre de choses

Anne


« Last Edit: December 20, 2016, 10:56:39 AM by ecureuil »

Offline ecureuil

  • *
  • 261
  • +0/-0
Re: dock usb pour disque de sauvegarde : gestion du disque + script
« Reply #1 on: January 24, 2017, 12:03:39 AM »
bonjoiur

Sibsib a trouvé un script que j'ai testé sur sme

https://github.com/mlogic/suspend-usb-device

Code: [Select]
#!/bin/bash

## set -x

#
#
#  suspend-usb-device: an easy-to-use script to properly put an USB
#  device into suspend mode that can then be unplugged safely
#
#  Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
#  Yan Li <elliot.li.tech@gmail.com>
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#  To reach the auther, please write an email to the address as stated
#  above.

#  ACKNOWLEDGEMENTS:
#      Christian Schmitt <chris@ilovelinux.de> for firewire supporting
#      David <d.tonhofer@m-plify.com> for improving parent device
#      search and verbose output message


usage()
{
    cat<<EOF
suspend-usb-device  Copyright (C) 2009-2016, Yan Li <elliot.li.tech@gmail.com>

This script is designed to properly put an USB device into suspend
mode that can then be unplugged safely. It sends a SYNCHRONIZE CACHE
command followed by a START-STOP command (if the device supports it),
unbinds the device from the driver and then suspends the USB
port. After that you can disconnect your USB device safely.

usage:
$0 [options] dev

sample:
$0 /dev/sde

options:
  -l     show the device and USB bus ID only
  -h     print this usage
  -v     verbose

This program comes with ABSOLUTELY NO WARRANTY.  This is free
software, and you are welcome to redistribute it under certain
conditions; for details please read the licese at the beginning of the
source code file.
EOF
}

set -e -u

SHOW_DEVICE_ONLY=0
VERBOSE=0
while getopts "vlh" opt; do
    case "$opt" in
        h)
            usage
            exit 2
            ;;
        l)
            SHOW_DEVICE_ONLY=1
            ;;
        v)
            VERBOSE=1
            ;;
        ?)
            echo
            usage
            exit 2
            ;;
    esac
done
DEV_NAME=${!OPTIND:-}

if [ -z ${DEV_NAME} ]; then
    usage
    exit 2
fi

# mount checking
if mount | grep "^${DEV_NAME}[[:digit:]]* "; then
    1>&2 echo
    1>&2 echo "the above disk or partition is still mounted, can't suspend device"
    1>&2 echo "unmount it first using umount"
    exit 1
fi

# looking for the parent of the device with type "usb-storage:usb", it
# is the grand-parent device of the SCSI host, and it's devpath is
# like
# /devices/pci0000:00/0000:00:1d.7/usb5/5-8 (or /fw5/fw5-8 for firewire devices)

# without an USB hub, the device path looks like:
# /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host5/target5:0:0/5:0:0:0
# here the grand-parent of host5 is 2-1

# when there's a USB HUB, the device path is like:
# /devices/pci0000:00/0000:00:1d.0/usb5/5-2/5-2.2/5-2.2:1.0/host4/target4:0:0/4:0:0:0
# and the grand-parent of host4 is 5-2.2

DEVICE=$(udevadm info --query=path --name=${DEV_NAME} --attribute-walk | \
    egrep "looking at parent device" | head -1 | \
    sed -e "s/.*looking at parent device '\(\/devices\/.*\)\/.*\/host.*/\1/g")

if [ -z $DEVICE ]; then
    1>&2 echo "cannot find appropriate parent USB/Firewire device, "
    1>&2 echo "perhaps ${DEV_NAME} is not an USB/Firewire device?"
    exit 1
fi

# the trailing basename of ${DEVICE} is DEV_BUS_ID ("5-8" in the
# sample above)
DEV_BUS_ID=${DEVICE##*/}

[[ $VERBOSE == 1 ]] && echo "Found device $DEVICE associated to $DEV_NAME; USB bus id is $DEV_BUS_ID"

if [ ${SHOW_DEVICE_ONLY} -eq 1 ]; then
    echo Device: ${DEVICE}
    echo Bus ID: ${DEV_BUS_ID}
    exit 0
fi

# flush all buffers
sync

# root check
if [ `id -u` -ne 0 ]; then
    1>&2 echo error, must be run as root, exiting...
    exit 1
fi


# send SCSI sync command, some devices don't support this so we just
# ignore errors with "|| true"
#[[ $VERBOSE == 1 ]] && echo "Syncing device $DEV_NAME"
sdparm --command=sync "$DEV_NAME" >/dev/null || true
# send SCSI stop command
#[[ $VERBOSE == 1 ]] && echo "Stopping device $DEV_NAME"
sdparm --command=stop "$DEV_NAME" >/dev/null

# unbind it; if this yields "no such device", we are trying to unbind the wrong device
[[ $VERBOSE == 1 ]] && echo "Unbinding device $DEV_BUS_ID"
if [[ "${DEV_BUS_ID}" == fw* ]]
then
    echo -n "${DEV_BUS_ID}" > /sys/bus/firewire/drivers/sbp2/unbind
else
    echo -n "${DEV_BUS_ID}" > /sys/bus/usb/drivers/usb/unbind

    # suspend it if it's an USB device (we have no way to suspend a
    # firewire device yet)

    # USB power level control is deprecated since 2.6.32. If both power/control
    # and power/level files exist, we are using a new kernel that doesn't support
    # force suspending a USB device. If only the power/level file exists, we
    # will try to suspend the device.
    [[ $VERBOSE == 1 ]] && echo "Checking whether $DEVICE can be suspended"
    POWER_LEVEL_FILE=/sys${DEVICE}/power/level
    POWER_CONTROL_FILE=/sys${DEVICE}/power/control
    if [ ! -f "$POWER_CONTROL_FILE" -a ! -f "$POWER_LEVEL_FILE" ]; then
        1>&2 cat<<EOF
It's safe to remove the USB device now but better can be done. The
power level control file $POWER_LEVEL_FILE
doesn't exist on the system so I have no way to put the USB device
into suspend mode, perhaps you don't have CONFIG_USB_SUSPEND enabled
in your running kernel.

Read
http://elliotli.blogspot.com/2009/01/safely-remove-usb-hard-drive-in-linux.html
for an detailed explanation.
EOF
        exit 3
    elif [ ! -f "$POWER_CONTROL_FILE" ]; then
        # Only the power/level file exists, try to suspend the device
        [[ $VERBOSE == 1 ]] && echo "Suspending $DEVICE by writing to $POWER_LEVEL_FILE"
        echo 'suspend' > "$POWER_LEVEL_FILE"
    fi
    # Do nothing if power/control or both files exist.
fi

J'ai installé sdparm

# yum install sdparm
=>
sdparm                                               x86_64                                               1.04-1.1.el6                                                 base                                                99 k

J'ai mis un dock  usb avec mon serveur sme.

J'ai mis un disque de 2to pour mes sauvegardes

l# lsusb
...
Bus 001 Device 011: ID 152d:2352 JMicron Technology Corp. / JMicron USA Technology Corp. ATA/ATAPI Bridge
...

# ls -al /dev/sd*
brw-rw---- 1 root disk 8,  0 22 janv. 21:23 /dev/sda
brw-rw---- 1 root disk 8,  1 22 janv. 21:23 /dev/sda1
brw-rw---- 1 root disk 8,  2 22 janv. 21:23 /dev/sda2
brw-rw---- 1 root disk 8,  3 22 janv. 21:23 /dev/sda3
brw------- 1 root root 8, 16 23 janv. 22:50 /dev/sdb
brw------- 1 root root 8, 17 23 janv. 22:50 /dev/sdb1
brw------- 1 root root 8, 18 23 janv. 22:50 /dev/sdb2

Je recheche le bus
# ./suspend-usb-device.sh  -vl /dev/sdb
Found device /devices/pci0000:00/0000:00:12.2/usb1/1-2/1-2.5/1-2.5.5 associated to /dev/sdb; USB bus id is 1-2.5.5
Device: /devices/pci0000:00/0000:00:12.2/usb1/1-2/1-2.5/1-2.5.5
Bus ID: 1-2.5.5

A la fin du traitement de la sauvegarde, je mets le disque en standby.
# ./suspend-usb-device.sh  -v /dev/sdb
Found device /devices/pci0000:00/0000:00:12.2/usb1/1-2/1-2.5/1-2.5.5 associated to /dev/sdb; USB bus id is 1-2.5.5
Unbinding device 1-2.5.5
Checking whether /devices/pci0000:00/0000:00:12.2/usb1/1-2/1-2.5/1-2.5.5 can be suspended


# ls -al /dev/sd*
brw-rw---- 1 root disk 8, 0 22 janv. 21:23 /dev/sda
brw-rw---- 1 root disk 8, 1 22 janv. 21:23 /dev/sda1
brw-rw---- 1 root disk 8, 2 22 janv. 21:23 /dev/sda2
brw-rw---- 1 root disk 8, 3 22 janv. 21:23 /dev/sda3

Plus de disque /dev/sdb
Le disque c'est arrêté de tourner et donc ne chauffe plus.

Je remets le disque en fonction
# echo -n "1-2.5.5" >/sys/bus/usb/drivers/usb/bind

A retester et à paufiner

Anne




Offline ecureuil

  • *
  • 261
  • +0/-0
Re: dock usb pour disque de sauvegarde : gestion du disque
« Reply #2 on: March 15, 2018, 03:45:16 PM »
Je viens de paufiner pour sme 9 noyau 2.6.32

J'ai un boitier usb qui contient mon disque de sauvegarde.
Je fais une sauvegarde par jour avec rsync.
Mon but est que mon disque ne tourne pas entre les 2 sauvegardes et que la lumière bleue de mon boitier s'éteigne.

Je crois que j'ai réussi.
En cherchant autre chose, je suis tombée sur un topic
https://loginroot.com/power-off-and-on-usb-device-in-linux-ubuntu/

Quote
Power OFF and ON USB device in linux (ubuntu)

February 20, 2014  linux  linux usb, linux usb power, power off, toggle usb, toggle usb power, usb power

 
There are two methods of doing this. So first method is for kernels after 2.6.32, and second for older ones.

To view kernel version, simply enter:

Code: [Select]
# uname -r
3.8.0-29-generic

find Your USB device, no mather what it is USB flash drive, Yubikey, USB disk drive:
Code: [Select]
#  lsusb
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 005: ID 12d1:14db Huawei Technologies Co., Ltd.
Bus 002 Device 006: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub

#  lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M
        |__ Port 1: Dev 5, If 0, Class=comm., Driver=cdc_ether, 480M
        |__ Port 1: Dev 5, If 1, Class=data, Driver=cdc_ether, 480M
        |__ Port 5: Dev 6, If 0, Class=hub, Driver=hub/4p, 480M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M

Our target is:
Code: [Select]
Bus 002 Device 005: ID 12d1:14db Huawei Technologies Co., Ltd.

Which is located at 2-1.1 (tree part where device 5 is located)

First method (newer kernel)

To turn it off simply echo address:
Code: [Select]
echo '2-1.1'  > /sys/bus/usb/drivers/usb/unbind

here is result from syslog:
Code: [Select]
Feb 20 12:03:27 vgsms6 kernel: [ 1734.993667] cdc_ether 2-1.1:1.0 eth2: unregister 'cdc_ether' usb-0000:00:1d.0-1.1, CDC Ethernet Device

Unfortunately this device was still visible in lsusb, so I turned off whole usb hub there (2-1), and voila, usb device gone.

To enable it, echo same address to “bind” part, for example:
Code: [Select]
echo '2-1.1' > /sys/bus/usb/drivers/usb/bind
 

Second method (older kernel)

You need to go to devices:
Code: [Select]
cd /sys/bus/usb/devices
 

Addressess will be listed similar:
Code: [Select]
/sys/bus/usb/devices# ls -alh
total 0
drwxr-xr-x 2 root root 0 Feb 20 11:34 .
drwxr-xr-x 4 root root 0 Feb 20 11:34 ..
lrwxrwxrwx 1 root root 0 Feb 20 11:34 1-0:1.0   -> ../../../devices/pci0000:00/0000:00:1a.0/usb1/1-0:1.0
lrwxrwxrwx 1 root root 0 Feb 20 11:34 1-1   -> ../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1
lrwxrwxrwx 1 root root 0 Feb 20 11:34 1-1:1.0  > ../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1:1.0
lrwxrwxrwx 1 root root 0 Feb 20 11:34 2-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-0:1.0
lrwxrwxrwx 1 root root 0 Feb 20 11:34 2-1  -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.1  -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1:1.0
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.1:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.1:1.1 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.1
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.5 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.5:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5/2-1.5:1.0
lrwxrwxrwx 1 root root 0 Feb 20 11:34 usb1 -> ../../../devices/pci0000:00/0000:00:1a.0/usb1
lrwxrwxrwx 1 root root 0 Feb 20 11:34 usb2 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2
 

So go to in our example 2-1.1/power (full path /sys/bus/usb/devices2-1.1/power)
 
Code: [Select]
cd /sys/bus/usb/devices2-1.1/power
 

to turn off device:
 
Code: [Select]
echo suspend > level
 

to turn on:
 
Code: [Select]
echo on > level
 


 Je viens de tester avec ma sme et ma debian.
Cela fonctionne très bien

Sur ma sme, # uname -r  => 2.6.32-696.20.1.el6.x86_64

On est dans le deuxième cas.

Il faut trouver l'UUID du disque usb avec la commande : blkid
il faut  récupèrer l'id du bus usb.

Code: [Select]
UUID="UUID_disque"; \
DEV_NAME=$(blkid -U "$UUID"); \
echo "DEV_NAME : $DEV_NAME"; \
DEV_NAME1="/dev/$(basename $(dirname $(readlink /sys/class/block/$(basename $DEV_NAME))))"; \
DEVICE1=$(udevadm info --query=path --name=${DEV_NAME1} --attribute-walk | \
egrep "looking at parent device" | head -1 | \
sed -e "s/.*looking at parent device '\(\/devices\/.*\)\/.*\/host.*/\1/g"); \
DEV_BUS_ID=${DEVICE1##*/}; \
echo "Found device $DEVICE1 associated to $DEV_NAME1; USB bus id is $DEV_BUS_ID"

=>
DEV_NAME : /dev/sdb1
Found device /devices/pci0000:00/0000:00:14.0/usb2/2-1 associated to /dev/sdb; USB bus id is 2-1
 

Dans le script, j'ai 2 variables  en dur
- UUID="UUID_disque"
- BUS_USB="4-2"

Dans le script, j'allume le boitier, lle disque est reconnu
 
Code: [Select]
echo "on allume le boitier usb --- port usb $BUS_USB --- port usb1 ${BUS_USB} ---"
echo 'on' > /sys/bus/usb/devices/${BUS_USB}/power/level
 

Je monte le disque
Je sauvegarde
Je démonte de disque

et j'éteint le boitier
 
Code: [Select]
echo "on éteint le boitier usb"
echo 'suspend' >   /sys/bus/usb/devices/$BUS_USB/power/level
 

Cela a très bien fonctionné cette nuit.
J'ai touché le boitier ce matin, complètement froid et aucune vibration, le disque est au repos.

Anne
« Last Edit: March 15, 2018, 03:47:45 PM by ecureuil »