RESOLVED: Find "Device Name" for dynamically loaded drive?

Forum rules
Before you post please read this

RESOLVED: Find "Device Name" for dynamically loaded drive?

Postby Webtest on Sat Jul 14, 2012 7:25 pm

Esteemed Forum Participants and Lurkers:
=============================================
Linux Mint 8, Mint 10, & Mint 13 LiveDVD systems

I have a drive drawer on my system which is cabled to the SATA-0 channel and which I use to load and remove various hard drives from my system. Adding the powered up drive to the running system is no problem with:

echo "scsi add-single-device 0 0 0 0" > /proc/scsi/scsi

Once the drive is mounted, if it is my "StarTrek" drive as an example, I can access it with:

ls /media/StarTrek

However, in order to remove the drive from the system so that I can replace it with a different drive requires that I know the "Device Name" - sd? where ? is the device letter index - for the drive in order to use the commands:

hdparm -y /dev/sd? <-- Spin down the drive
echo offline > /sys/block/sd?/device/state <-- Prevent the drive from being restarted and remounted
echo 1 > /sys/block/sd?/device/delete <-- Totally remove all traces of the drive from the system

QUESTION:
Since my drive configuration varies, how do I "Quickly & Easily" determine what device name is mapped to SCSI channel 0 0 0 0 or to /media/StarTrek (as an example) for any given system configuration? SDA, SDB, SDC, and SDD are generally reserved for the 4 flash card slots on my MultiMedia interface. The next open letter gets assigned when I load the hard drive, but it depends on what USB drives I have added or removed from the system before I load the hard drive.

Surely there has to be a simple terminal command line to show the map of SCSI Channels or Media Names to Device Names. Thank you for any and all comments, suggestions, and assistance.

Blessings in abundance, all the best, & ENJOY!
Art in Carlisle PA USA
Last edited by Webtest on Sun Jul 15, 2012 12:55 pm, edited 1 time in total.
BOAT - a hole in the water that you pour money into
LINUX - a hole in your life that you pour TIME into

HP dx2400 Core 2 Duo 4 GB - Mint 10 Gnome, Mint 13 Mate, Mint 15 Mate <on LOCKED Kanguru USB drives>
Webtest
Level 3
Level 3
 
Posts: 186
Joined: Sun Feb 21, 2010 4:45 pm
Location: Carlisle, Pennsylvania, USA

Linux Mint is funded by ads and donations.
 

Re: How to: Find "Device Name" for dynamically loaded drive?

Postby dwasifar on Sat Jul 14, 2012 8:34 pm

Hi Art,

If I understand you correctly, I think the mount command will give you what you want. Just open a terminal and type mount.
User avatar
dwasifar
Level 4
Level 4
 
Posts: 344
Joined: Mon May 09, 2011 10:03 pm

Re: How to: Find "Device Name" for dynamically loaded drive?

Postby Webtest on Sun Jul 15, 2012 12:54 pm

Thank You dwasifar ...
by dwasifar
If I understand you correctly, I think the mount command will give you what you want. Just open a terminal and type mount.
The mount command has exactly what I need plus a lot extra. I discovered that the 'file' /proc/mounts is mostly the same thing (just 2 extra lines and a slightly different format). I munged around with RegEx, which I haven't used in years, and then discovered that grep doesn't even use RegEx (really). So, then I munged around with grep expressions (GrepEx?) and came up with this:
Code: Select all
mint@mint ~ $ mount | egrep -o '^/dev/\w+(\W[[:alnum:]/]+){2}'
/dev/sdc1 on /cdrom
/dev/loop0 on /rofs
/dev/sde1 on /media/HOME
/dev/sdf1 on /media/StarTrek
 . . . OR . . .
mint@mint ~ $ egrep -o '^/dev/\w+\W[[:alnum:]/]+' /proc/mounts
/dev/sdc1 /cdrom
/dev/loop0 /rofs
/dev/sde1 /media/HOME
/dev/sdf1 /media/StarTrek
So ... Thanks, and Mission Accomplished! Now I can figure out EXACTLY which device name to use in my commands when I want to pull the hard drive out of the drawer.

By the way, is there a 'grep' type of program that actually does use the REAL Regular Expressions? Being able to use the \S (not whitespace) term would be really helpful in allowing for special characters in names.

(EDIT: The command for grep with RegEx is egrep)

Blessings in abundance, all the best, & ENJOY!
Art in Carlisle, PA USA
Last edited by Webtest on Wed Aug 08, 2012 9:20 am, edited 1 time in total.
BOAT - a hole in the water that you pour money into
LINUX - a hole in your life that you pour TIME into

HP dx2400 Core 2 Duo 4 GB - Mint 10 Gnome, Mint 13 Mate, Mint 15 Mate <on LOCKED Kanguru USB drives>
Webtest
Level 3
Level 3
 
Posts: 186
Joined: Sun Feb 21, 2010 4:45 pm
Location: Carlisle, Pennsylvania, USA

Re: RESOLVED: Find "Device Name" for dynamically loaded driv

Postby egrath on Sun Jul 15, 2012 3:56 pm

Hello,
if you give the filesystem a name (label; using tune2fs) you can enumerate the corresponding device name (/dev/sdX) using the command 'blkid'.
egrath
User avatar
egrath
Level 1
Level 1
 
Posts: 33
Joined: Thu Jun 14, 2012 5:44 am
Location: Austria

Re: RESOLVED: Find "Device Name" for dynamically loaded driv

Postby Webtest on Wed Aug 08, 2012 8:58 am

Esteemed Forum Participants and Lurkers:
========================================

Just to wrap things up, I occasionally add in 2 drives temporarily, and I needed to figure out the mapping from SATA channel number on the motherboard to SCSI channel for the "add-single-device" command. A google search for "linux map sata to scsi" led me to http://www.webmaster-forums.net/server-management/drive-label-physical-sata-port where Natcoweb.com posted about the lsscsi command which lists all installed scsi port type devices. Of course, lsscsi is not avaiable in Mint distros, so it has to be installed first. So, if you want to map your SATA ports to SCSI "Host - Bus - Target - LogicaUnitNumber", you have to either make a lucky guess, or plug a drive into each channel and look at either /var/log/dmesg (the command "dmesg" achieves this, but the log is very long) or run lsscsi (which gives a perfect list). Here are typical results on my system. Note that "Host 4" is my factory installed multimedia panel where I insert my Boot device ... a locked SD card:
Code: Select all
mint ~ # apt-get install lsscsi
 . . .
mint ~ # lsscsi
[1:0:0:0]    cd/dvd  TSSTcorp CDDVDW TS-H653N  hb02  /dev/sr0
[1:0:1:0]    disk    ATA      ST3250410AS      3.AA  /dev/sda
[4:0:0:0]    disk    Generic- Compact Flash    1.00  /dev/sdb
[4:0:0:1]    disk    Generic- SM/xD-Picture    1.00  /dev/sdc
[4:0:0:2]    disk    Generic- SD/MMC           1.00  /dev/sdd
[4:0:0:3]    disk    Generic- MS/MS-Pro        1.00  /dev/sde

The bottom line is that I now have my SATA ports mapped so that I can dynamically add drives to my system on any vacant SATA channel:
Code: Select all
                          H B T L
SATA0 (Dark Blue)  - SCSI 0 0 0 0  (Normally, Windows Boot Drive - unpowered)
SATA1 (White)      - SCSI 1 0 0 0  (Normallly, CD-ROM)
SATA2 (Light Blue) - SCSI 0 0 1 0  (Normally vacant)
SATA3 (Orange)     - SCSI 1 0 1 0  (Normally vacant)

So, now I can add a drive on any SATA port with the following command, where "H B T L" is the SCSI device ID from the above map:

echo "scsi add-single-device H B T L" > /proc/scsi/scsi

As I have posted elsewhere in this forum, if you want to dynamically REMOVE a drive without stopping the system, just replace "sda" in the following with the proper device id from mount, dmesg, or lsscsi:

Code: Select all
hdparm -y /dev/sda (NOTE: daemons can spin the drive back up at ANY time ... even immediately after you issue this command!)
echo offline > /sys/block/sda/device/state
echo 1 > /sys/block/sda/device/delete

I hope this might be helpful to anyone else trying to dynamically install and remove hard drives on a system.

Blessings in abundance, all the best, & ENJOY!
Art in Carlisle PA USA
BOAT - a hole in the water that you pour money into
LINUX - a hole in your life that you pour TIME into

HP dx2400 Core 2 Duo 4 GB - Mint 10 Gnome, Mint 13 Mate, Mint 15 Mate <on LOCKED Kanguru USB drives>
Webtest
Level 3
Level 3
 
Posts: 186
Joined: Sun Feb 21, 2010 4:45 pm
Location: Carlisle, Pennsylvania, USA


Return to Mounting Partitions

Who is online

Users browsing this forum: No registered users and 2 guests