I have an external eSATA-hdd on an OpenSUSE 12.2 system. The external hdd has an LVM on a dm-crypt partition.

I mount it by powering it up and then doing

cryptsetup -v luksOpen
vgchange -ay

Now when I want to power the hdd down, I do

 vgchange -an extern-1
 cryptsetup -v remove /dev/mapper/extern-1-crypt
 echo 1 >/sys/block/sdf/device/delete

Here the device (sdf) is currently hardcoded in the script. Can I somehow deduce it in the script from the VG or the crypto device?

  • Why do you even need rescan-scsi-bus.sh and device/delete? Just curious because eSATA (AHCI) hotplug works fine without either one on my system. (And my system is 5+ years old.) – frostschutz Jun 3 '13 at 13:16

Yes, you can find the information in /sys/block/$DEVICE/slaves. If you only have the canonical name you can use readlink to get the details, e.g:

devdm="$(readlink -f /dev/mapper/extern-1-crypt)"
ls /sys/block/$dm/slaves/

If you want to remove all you can just utilize directly the sys filesystem:

echo 1 > /sys/block/$dm/slaves/*/../device/delete
  • That gives sdf1, not sdf - but that's a minor problem. – Martin Schröder Jun 2 '13 at 21:30
  • @MartinSchröder added a small section how to directly unpower the device as the slaves are already a link to the sys device – Ulrich Dangel Jun 2 '13 at 22:13
  • There's a catch22: After the vgchange -an && crypsetup --remove the /sys/block/$dm/ is gone. – Martin Schröder Jun 2 '13 at 23:41

There is a lot of possibilities:

:> # 1
:> pvscan
:> # 2
:> vgscan -v extern-1
:> # 3
:> dmsetup table /dev/mapper/extern-1-crypt

:> # 4
:> cd /sys/devices/virtual/block/
:> for dmdev in dm-*; do
:>   if [ xyz = $(< "${dmdev}/dm/name") ]; then
:>     ls -l "${dmsev}/slaves/"
:>   fi
:> done

Or take the "dm-" number from dmsetup ls.

edit 1:

OK, it seems that's been all possibilities except the easy one. After looking at Ulrich's answer I myself have to laugh... Obviously not really looked at /dev/mapper for too long despite of happily using it all the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.