LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 12-02-2009, 09:29 PM   #1
bbneo
Member
 
Registered: Jun 2008
Location: Northeast Ohio
Distribution: fedora 10, Debian, Ubuntu
Posts: 34

Rep: Reputation: 16
How to identify device descriptor for usb ntfs ext hard drive?


I have inadvertently deleted several files from my external usb ntfs drive and would like to try to recover them using ntfsundelete.

The files are likely intact, since I don't write to the drive often.

I have found the program ntfsundelete, but it expects you to give it a "device" specification for the target drive. I have a "mountpoint" '/media/MyBook', but I don't know how to determine the corresponding device to use with ntfsundelete.

How do I determine the "device" specification for a "mountpoint" for a usb external drive?

Thanks in advance for your help.
 
Old 12-03-2009, 12:28 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
To see all the block devices and shares currently mounted on your system, type the "mount" command without any arguments. It will show you the contents of /etc/mtab.

You can also run "fdisk -l" to see all the block devices available to your system, mounted or not.
 
Old 12-13-2009, 09:07 AM   #3
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,320

Rep: Reputation: 51
I have often wondered this question myself - how do I get the device which is mounted under a particular directory, giving it JUST the directory? Is there a command for this? Does the Linux kernel allow for it?
 
Old 12-13-2009, 09:32 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
I'm not aware of such a command, but you can use one of the methods suggested by David the H. above, or simply the df command:
Code:
df /media/something
a simple parsing using awk can extract just the information you need:
Code:
df /media/something | awk 'NR==2{print $1}'
Moreover you can "create" your own custom command using a shell function, e.g.
Code:
function wdev () {
  df $1 2> /dev/null | awk 'NR==2{print $1}'
}
Then just run:
Code:
wdev /media/something
in case the mount point does not exist, you will get nothing since the redirection of standard error from df to /dev/null.
 
Old 12-13-2009, 01:49 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by resetreset View Post
I have often wondered this question myself - how do I get the device which is mounted under a particular directory, giving it JUST the directory? Is there a command for this? Does the Linux kernel allow for it?
Code:
mount | grep directory
 
Old 12-15-2009, 01:51 AM   #6
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,320

Rep: Reputation: 51
Well that's the easy solution (mount | grep directory) , but what I really wanted to know is - is there a way to query the Linux kernel itself as to which device lies under a particular directory? I think this is one of the mistakes Linux made by making everything a file, that is, when you mount, you give it the name of a device which is a file ("/dev/sda"), and then a directory, which is also a file, that is - you're mounting a file under a file!!!!, which doesn't make sense.....
 
Old 12-15-2009, 02:08 AM   #7
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,196

Rep: Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120Reputation: 1120
Quote:
Originally Posted by resetreset View Post
Well that's the easy solution (mount | grep directory) , but what I really wanted to know is - is there a way to query the Linux kernel itself as to which device lies under a particular directory?
These days this is usually handled by udev (if I correctly understand what you are asking).

Quote:
Originally Posted by resetreset View Post
I think this is one of the mistakes Linux made by making everything a file, that is, when you mount, you give it the name of a device which is a file ("/dev/sda"), and then a directory, which is also a file, that is - you're mounting a file under a file!!!!, which doesn't make sense.....
Joke, right?

Evo2.
 
Old 12-15-2009, 02:47 AM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
when you plug your usb device into your computer and do a mount or df command, what did you see ? normally, something like /dev/xxxx where xxx is anything. that's your [device] to pass to ntfsundelete. On my system, its /dev/sdb1, so the command is
Code:
ntfsundelete /dev/sdb1
make sure you unmount /dev/sdb1 before using.
 
Old 12-15-2009, 10:10 AM   #9
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by resetreset View Post
Well that's the easy solution (mount | grep directory) , but what I really wanted to know is - is there a way to query the Linux kernel itself as to which device lies under a particular directory? I think this is one of the mistakes Linux made by making everything a file, that is, when you mount, you give it the name of a device which is a file ("/dev/sda"), and then a directory, which is also a file, that is - you're mounting a file under a file!!!!, which doesn't make sense.....
What you think of as a file is really just a name. It's a string in a directory that references an inode. Inodes can be regular files or any of several other things like directories (such as where the name to inode reference itself is stored), or devices.

This simplifies programming because you can open things other than regular files using just the same mechanism (API) as for regular files. So once you know the name of the device and have it in a string, you can open the device.

I can, for example, copy one whole hard drive to another like this:

cat < /dev/sdd > /dev/sde

If they are exactly the same size, the whole drive will be copied. In this case the shell will open each drive and pass the descriptors to the "cat" program it runs. Opening devices will usually require elevated permissions (because doing so could reveal info not intended for all users, or allow a user to disrupt and destroy the system).

There is then an ioctl() syscall to get meta information about the opened object that is very specific to what is opened. For block devices, a particular ioctl() call can store a number indicating the size of the device if the kernel knows it.

You can get the names of the mounted devices through a special file called "/proc/mounts". This is the name as it was known when the device was mounted, or the kernel's best determination of the name. Only in extreme instances (like someone deleting a link name in the "/dev" directory) will the information be unusable.

"/proc/mounts" will be more reliable than the "df" command or reading "/etc/mtab" in most cases ... as long as the special "proc" filesystem is mounted at "/proc" (it usually is).

That said ... if you are going to run a program to diagnose and repair a filesystem via its device (that's usually how it is done), then the file system in question should NOT be mounted. If it is mounted, you can note what the device name is, unmount the filesystem, and run the utility giving in that device name. In the case of plugging in a new device, it will typically be automounted. But if not, you can run the "dmesg" command to example what recent messages say about a device being probed. Or you can output the contents of the special file "/proc/partitions" to see what mountable block devices (and their sizes) the kernel believes it has available.
 
  


Reply

Tags
device, externalharddrive, mountpoint, ntfsundelete, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard drive in USB enclosure gets "device descriptor read/64, error -71" oot Linux - Hardware 1 10-19-2009 03:14 AM
device descriptor read/8, error -110 seagate external hard drive genex Linux - Hardware 1 09-08-2007 12:40 PM
SUSE 10.0 ext USB NTFS drive as root only 1kyle Suse/Novell 1 07-22-2006 01:55 PM
9.3(Here's how to Read Windows NTFS files on ext USB drive as user 1kyle Suse/Novell 0 09-01-2005 03:59 AM
Cannot Mount Ext. USB Hard Drive sall Linux - Hardware 32 07-15-2005 11:19 AM


All times are GMT -5. The time now is 01:11 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration