Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to mount external hard drive. As I know, to mount manually, I should use fdisk -l to determine which device refers to the drive.

When I'm doing so without sudo I have next output:

user@desktop:~/tmp$ /sbin/fdisk -l

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000844b8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758   625141759   312320001    5  Extended
Partition 2 does not start on physical sector boundary.
/dev/sda5          501760   625141759   312320000   8e  Linux LVM

Disk /dev/mapper/vg0-root: 348 MB, 348127232 bytes
255 heads, 63 sectors/track, 42 cylinders, total 679936 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-root doesn't contain a valid partition table

Disk /dev/mapper/vg0-swap_1: 8162 MB, 8162115584 bytes
255 heads, 63 sectors/track, 992 cylinders, total 15941632 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-swap_1 doesn't contain a valid partition table

Disk /dev/mapper/vg0-usr: 8996 MB, 8996782080 bytes
255 heads, 63 sectors/track, 1093 cylinders, total 17571840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-usr doesn't contain a valid partition table

Disk /dev/mapper/vg0-var: 2998 MB, 2998927360 bytes
255 heads, 63 sectors/track, 364 cylinders, total 5857280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-var doesn't contain a valid partition table

Disk /dev/mapper/vg0-tmp: 398 MB, 398458880 bytes
255 heads, 63 sectors/track, 48 cylinders, total 778240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-tmp doesn't contain a valid partition table

Disk /dev/mapper/vg0-home: 298.9 GB, 298907074560 bytes
255 heads, 63 sectors/track, 36340 cylinders, total 583802880 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-home doesn't contain a valid partition table

With sudo:

user@desktop:~/tmp$ sudo fdisk -l
[sudo] password for user: 

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000844b8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758   625141759   312320001    5  Extended
Partition 2 does not start on physical sector boundary.
/dev/sda5          501760   625141759   312320000   8e  Linux LVM

Disk /dev/mapper/vg0-root: 348 MB, 348127232 bytes
255 heads, 63 sectors/track, 42 cylinders, total 679936 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-root doesn't contain a valid partition table

Disk /dev/mapper/vg0-swap_1: 8162 MB, 8162115584 bytes
255 heads, 63 sectors/track, 992 cylinders, total 15941632 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-swap_1 doesn't contain a valid partition table

Disk /dev/mapper/vg0-usr: 8996 MB, 8996782080 bytes
255 heads, 63 sectors/track, 1093 cylinders, total 17571840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-usr doesn't contain a valid partition table

Disk /dev/mapper/vg0-var: 2998 MB, 2998927360 bytes
255 heads, 63 sectors/track, 364 cylinders, total 5857280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-var doesn't contain a valid partition table

Disk /dev/mapper/vg0-tmp: 398 MB, 398458880 bytes
255 heads, 63 sectors/track, 48 cylinders, total 778240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-tmp doesn't contain a valid partition table

Disk /dev/mapper/vg0-home: 298.9 GB, 298907074560 bytes
255 heads, 63 sectors/track, 36340 cylinders, total 583802880 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg0-home doesn't contain a valid partition table

Disk /dev/sdb: 500.1 GB, 500105740288 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976769024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002e78d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   976769023   488383488    7  HPFS/NTFS/exFAT

Why I can see plugged device only while launching the command with root rights?

share|improve this question
    
Thanks for explanation. I have figure out that my user account was in the same group as /dev/sda drive and was not in the group which /dev/sdb belongs to. –  Nikita Yashtaev Apr 2 at 13:16
add comment

4 Answers

fdisk -l can just list the filesystems it has the permission to read on. See my test with strace:

user@host:~/test$ strace -e open /sbin/fdisk -l
...
open("/proc/partitions", O_RDONLY)      = 3
open("/dev/sda", O_RDONLY)              = -1 EACCES (Permission denied)
open("/dev/sda1", O_RDONLY)             = -1 EACCES (Permission denied)
open("/dev/sda2", O_RDONLY)             = -1 EACCES (Permission denied)
open("/dev/sda5", O_RDONLY)             = -1 EACCES (Permission denied)
open("/dev/sr0", O_RDONLY)              = 4

This user has only permission to read /dev/sr0, so only this device is listed in fdisk -l.

share|improve this answer
    
+1 I'm beginning to like the usage of strace in answers to accurately describe the behaviour of programs. No magic. –  Herman Torjussen Dec 20 '13 at 17:00
add comment

@chaos and @Braiam have provided good answers on why you aren't getting the behavior you are looking for from fdisk when running as a non-root user. The simple fact is that allowing regular users to read disks directly would allow bypassing file permissions by simply reading the disk data directly, which could be a major problem and certainly would make file and directory permissions completely useless for anything but to prevent simple mistakes.

I'll take a stab at answering the question you probably meant to ask, too: "how do I figure out which partition to mount if I am not root?".

The answer to that, assuming you have a reasonably recent system, is: have a look in /dev/disk/by-id.

There you will find each disk, by bus, model number and serial number, with all detected partitions available as symlinks to device files.

The names there are also persistent, so unlike the /dev/sdXY names, do not change depending on the order in which you plug the disks in or the order in which they are detected. That makes them useful for /etc/fstab, /etc/crypttab and possibly friends.

share|improve this answer
    
I see, thank you. I found two ways to get access to a data on a disk, for which you have read permission: 1) using dd: dd if=/dev/sda of=~/sda.image 2) using cat: cat < /dev/sda > ~/sda.image –  Nikita Yashtaev Apr 2 at 13:18
    
@NikitaYashtaev Regular (non-root) users shouldn't have access to the raw device nodes, even read-only, in the first place. External drives seem to be a special case (at least on Debian, those appear to be mode 1660 owner root:floppy, rather than 1660 root:disk as for internal drives.) –  Michael Kjörling Apr 4 at 7:33
add comment

If your objective is to find out the device name of the external drive you just connected, the easiest ways is to run dmesg | tail -20 or so right after connecting it:

$ dmesg | tail -20
[ 5610.869053] usb 2-1.4: New USB device strings: Mfr=10, Product=11, SerialNumber=5
[ 5610.869058] usb 2-1.4: Product: Iomega Select HDD
[ 5610.869062] usb 2-1.4: Manufacturer: Iomega
[ 5610.869066] usb 2-1.4: SerialNumber: 5E918FFFFFFF
[ 5610.948182] usb-storage 2-1.4:1.0: USB Mass Storage device detected
[ 5610.948350] scsi6 : usb-storage 2-1.4:1.0
[ 5610.948531] usbcore: registered new interface driver usb-storage
[ 5611.948468] scsi 6:0:0:0: Direct-Access     ST950032 5AS  PQ: 0 ANSI: 2 CCS
[ 5611.948916] sd 6:0:0:0: Attached scsi generic sg2 type 0
[ 5611.950745] sd 6:0:0:0: [sdb] 976773168 512-byte logical blocks: (500 GB/465 GiB)
[ 5611.951855] sd 6:0:0:0: [sdb] Write Protect is off
[ 5611.951862] sd 6:0:0:0: [sdb] Mode Sense: 28 00 00 00
[ 5611.952944] sd 6:0:0:0: [sdb] No Caching mode page present
[ 5611.952951] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[ 5611.956083] sd 6:0:0:0: [sdb] No Caching mode page present
[ 5611.956091] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[ 5612.016745]  sdb: sdb1
[ 5612.020134] sd 6:0:0:0: [sdb] No Caching mode page present
[ 5612.020144] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[ 5612.020152] sd 6:0:0:0: [sdb] Attached SCSI disk

That tells me that my drive was recognized as /dev/sdb. Other useful tools in this context are

  • lsusb lists all connected USB devices and hubs. on my system with my external drive plugged in, its output includes this line

    Bus 002 Device 008: ID 059b:047a Iomega Corp. Select Portable Hard Drive
    
  • lsblk lists information about all or the specified block devices. It will show a list of all disks and their partitions:

    $ lsblk 
    NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sda      8:0    0 465.8G  0 disk 
    ├─sda1   8:1    0  39.2M  0 part 
    ├─sda2   8:2    0  14.7G  0 part 
    ├─sda3   8:3    0  78.1G  0 part /winblows
    ├─sda4   8:4    0     1K  0 part 
    ├─sda5   8:5    0     2G  0 part 
    ├─sda6   8:6    0 294.4G  0 part /home
    ├─sda7   8:7    0  68.7G  0 part /
    └─sda8   8:8    0   7.8G  0 part [SWAP]
    sdb      8:16   0 465.8G  0 disk 
    └─sdb1   8:17   0 465.8G  0 part 
    sr0     11:0    1  1024M  0 rom  
    
  • lshw will list all of your hardware, including external drives. Since it's output can be huge, I would filter it based on the make of your drive (Iomega in my case). Something like:

    $ lshal  | grep -C 10 Iomega | grep block.device
    block.device = '/dev/sdb1'  (string)
    
  • The /dev/disk/by-* directories:

    $ ls -l /dev/disk/by-label/ | grep sdb
    lrwxrwxrwx 1 root root 10 Dec 20 15:25 Iomega_HDD -> ../../sdb1
    $ ls -l /dev/disk/by-uuid/ | grep sdb
    lrwxrwxrwx 1 root root 10 Dec 20 15:25 6AC0198FC019629D -> ../../sdb1
    

    You also have the by-path and by-id directories but they are less usueful for the task at hand.

share|improve this answer
add comment

This is because super user or root has complete permissions to probe all devices while the users doesn't have such privileges by default. Whenever it tries it fails hence not listing the details. Some groups may have such privilege too which you can add yourself.

share|improve this answer
    
On lots of systems, that group is disk or floppy. However, there's likely no need to do that, and it opens up other possible problems. –  Michael Kjörling Dec 20 '13 at 13:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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