| Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-02-2009, 09:29 PM
|
#1
|
|
Member
Registered: Jun 2008
Location: Northeast Ohio
Distribution: fedora 10, Debian, Ubuntu
Posts: 34
Rep:
|
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.
|
|
|
|
12-03-2009, 12:28 AM
|
#2
|
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,589
|
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.
|
|
|
|
12-13-2009, 09:07 AM
|
#3
|
|
Senior Member
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,320
Rep:
|
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?
|
|
|
|
12-13-2009, 09:32 AM
|
#4
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,897
|
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.
|
|
|
|
12-13-2009, 01:49 PM
|
#5
|
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,589
|
Quote:
Originally Posted by resetreset
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
|
|
|
|
12-15-2009, 01:51 AM
|
#6
|
|
Senior Member
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,320
Rep:
|
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.....
|
|
|
|
12-15-2009, 02:08 AM
|
#7
|
|
Senior Member
Registered: Jan 2009
Location: Japan
Distribution: Debian
Posts: 3,604
|
Quote:
Originally Posted by resetreset
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
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.
|
|
|
|
12-15-2009, 02:47 AM
|
#8
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
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.
|
|
|
|
12-15-2009, 10:10 AM
|
#9
|
|
Senior Member
Registered: May 2009
Location: WV, USA
Distribution: Slackware, Debian, EasyPeasy, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,671
Rep: 
|
Quote:
Originally Posted by resetreset
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:38 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|