Nik*_*aev 6 mount fdisk external-hdd not-root-user
我正在尝试安装外部硬盘驱动器。据我所知,要手动安装,我应该使用fdisk -l
来确定哪个设备指的是驱动器。
当我在没有sudo
下一个输出的情况下这样做时:
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
Run Code Online (Sandbox Code Playgroud)
与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
Run Code Online (Sandbox Code Playgroud)
为什么我只能在以 root 权限启动命令时才能看到插入的设备?
fdisk -l
可以只列出它有权读取的文件系统。请参阅我的测试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
Run Code Online (Sandbox Code Playgroud)
此用户只有读取权限/dev/sr0
,因此 中仅列出此设备fdisk -l
。
@chaos和@Braiam已经提供了很好的答案,说明了在fdisk
以非 root 用户身份运行时为什么没有获得所需的行为。一个简单的事实是,允许普通用户直接读取磁盘将允许通过简单地直接读取磁盘数据来绕过文件权限,这可能是一个主要问题,并且肯定会使文件和目录权限完全无用,只能防止简单的错误。
我会在回答你可能的问题采取刺伤意味着要问,太:“我怎么找出挂载的分区,如果我不是根?”。
假设您有一个相当新的系统,答案是:查看/dev/disk/by-id
.
在那里,您将按总线、型号和序列号找到每个磁盘,所有检测到的分区都可用作设备文件的符号链接。
那里的名称也是持久的,因此与/dev/sdXY
名称不同,不会根据插入磁盘的顺序或检测到它们的顺序而改变。这使它们对/etc/fstab
,/etc/crypttab
甚至可能是朋友有用。
如果您的目标是找出刚刚连接的外部驱动器的设备名称,最简单的方法是dmesg | tail -20
在连接后立即运行:
$ 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
Run Code Online (Sandbox Code Playgroud)
这告诉我我的驱动器被识别为/dev/sdb
. 在这种情况下其他有用的工具是
lsusb
列出所有连接的 USB 设备和集线器。在我插入外部驱动器的系统上,它的输出包括这一行
Bus 002 Device 008: ID 059b:047a Iomega Corp. Select Portable Hard Drive
Run Code Online (Sandbox Code Playgroud)lsblk
列出有关所有或指定块设备的信息。它将显示所有磁盘及其分区的列表:
$ 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
Run Code Online (Sandbox Code Playgroud)lshw
将列出您的所有硬件,包括外部驱动器。由于它的输出可能很大,我会根据您的驱动器(在我的情况下为 Iomega)的品牌对其进行过滤。就像是:
$ lshal | grep -C 10 Iomega | grep block.device
block.device = '/dev/sdb1' (string)
Run Code Online (Sandbox Code Playgroud)该/dev/disk/by-*
目录:
$ 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
Run Code Online (Sandbox Code Playgroud)
您也有by-path
和by-id
目录,但它们对于手头的任务不太有用。
归档时间: |
|
查看次数: |
2678 次 |
最近记录: |