You are not logged in.

#1 2008-09-20 00:37:01

scrawler
Member
Registered: 2005-06-07
Posts: 312

finding thumby

Hey guys, when I plug in a usb stick, what's the best/most direct way to find out where it is?  lsusb? dmesg?  If it's mounted I can just use "mount."

I'd like to look somewhere or run something to get something like

"this-stick" "/dev/sdb5"

what do you think?

Offline

#2 2008-09-20 01:18:23

Renan Birck
Member
From: Brazil
Registered: 2007-11-11
Posts: 401
Website

Re: finding thumby

in dmesg, when you plug the USB device, it should show something like this:

...
sd 2:0:0:0: [sdc] Assuming drive cache: write through
sdc: sdc1
...

(emphasis mine).

with some scripting you could parse it and format it to your wishes.

Offline

#3 2008-09-20 01:19:47

dsr
Member
Registered: 2008-05-31
Posts: 187

Re: finding thumby

You can run "ls /dev/disk/by-uuid" before plugging in the device and then again after it loads. The second time you run it you'll see a new file, which will be a symlink that points to the device's location.

Offline

#4 2008-09-20 07:20:42

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: finding thumby

dsr: noes, what if the OP plugs in two devices at once? What if a previously registered device hangs and then suddenly decides to mount at that moment?! hmm

-dav7

Last edited by dav7 (2008-09-20 07:27:21)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#5 2008-09-20 08:41:40

byte
Member
From: Düsseldorf (DE)
Registered: 2006-05-01
Posts: 1,872

Re: finding thumby

'fdisk -l' (requires root) or 'cat /etc/blkid.tab'

Last edited by byte (2008-09-20 08:42:28)


I hate sigs. This one only exists to remind myself to get an avatar.

Offline

#6 2008-09-20 10:57:20

fukawi2
Forum Moderator
From: .vic.au
Registered: 2007-09-28
Posts: 4,705
Website

Re: finding thumby

udev?

Offline

#7 2008-09-20 11:27:24

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 3,528

Re: finding thumby

plug it in, dmesg | tail -n 10
Edit: Or perhaps better, make a udev rule that tells you what it's named, or that always gives it the same name.

Last edited by Mr.Elendig (2008-09-20 11:28:36)


Evil #archlinux@freenode channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#8 2008-09-20 16:01:46

dsr
Member
Registered: 2008-05-31
Posts: 187

Re: finding thumby

Some of the other methods mentioned in this thread might be better than my "ls /dev/disk/by-uuid" method (it works fine though). "dmesg | tail" works. So does "more /proc/partitions" (same thing as "fdisk -l" but without requiring root privileges). So does writing a udev rule, etc.

Offline

#9 2008-09-21 17:25:13

scrawler
Member
Registered: 2005-06-07
Posts: 312

Re: finding thumby

dsr wrote:

Some of the other methods mentioned in this thread might be better than my "ls /dev/disk/by-uuid" method (it works fine though). "dmesg | tail" works. So does "more /proc/partitions" (same thing as "fdisk -l" but without requiring root privileges). So does writing a udev rule, etc.

funny you should say that, because your method is my favorite.  All I'm doing with it is writing a wrapper for pmount (just for fun).  I'm actually using the output of a w3m directory listing because it shows symlinks.  Ugly? yes.  Working? Mostly. The way I have it now, if I plug in two usb devices, my wrapper mounts them both.  If I plug in one and mount it, then another, and I mount it, the first one unmounts.  each time I "flip the switch" the mounted state flip-flops.  So I guess I'll just use one usb device at a time.

Thanks for the info everybody.

I don't suppose anyone knows how I can tell my wrapper to ignore swap partions?

Offline

#10 2008-09-21 18:00:24

dsr
Member
Registered: 2008-05-31
Posts: 187

Re: finding thumby

I'm glad it works for you. To determine the type of a partition (e.g. linux-swap), you could do something like

# parted -l | tail -n+`expr 6 + "$1"` | head -n1 | awk '{print $6}'

where $1 is the partition number (the X in /dev/sdaX). Of course you would need to install parted. I'm sure there's a cleaner solution, though.

Last edited by dsr (2008-09-21 18:01:08)

Offline

Board footer

Powered by FluxBB