我需要找到连接到给定机器的所有可写存储设备,无论它们是否已安装.
执行此操作的有趣方法是尝试/dev
对应于可写设备的每个条目(hd* and sd*
)......
有没有更好的解决方案,还是应该坚持使用这个?
/proc/partitions
将列出系统识别的所有块设备和分区.然后,您可以尝试使用它file -s
来确定分区上存在哪种文件系统(如果有).
fdisk -l
即使在诸如EC2 xvda设备之类的奇怪设置上,你总是可以做到这一点似乎工作得很好.
这是m1.large实例的转储:
root@ip-10-126-247-82:~# fdisk -l Disk /dev/xvda1: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders, total 20971520 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: 0x00000000 Disk /dev/xvda1 doesn't contain a valid partition table Disk /dev/xvda2: 365.0 GB, 365041287168 bytes 255 heads, 63 sectors/track, 44380 cylinders, total 712971264 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: 0x00000000 Disk /dev/xvda2 doesn't contain a valid partition table Disk /dev/xvda3: 939 MB, 939524096 bytes 255 heads, 63 sectors/track, 114 cylinders, total 1835008 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: 0x00000000 Disk /dev/xvda3 doesn't contain a valid partition table
虽然mount
说:
root@ip-10-126-247-82:~# mount /dev/xvda1 on / type ext4 (rw) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) fusectl on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev) /dev/xvda2 on /mnt type ext3 (rw)
并/proc/partitions
说:
root@ip-10-126-247-82:~# cat /proc/partitions major minor #blocks name 202 1 10485760 xvda1 202 2 356485632 xvda2 202 3 917504 xvda3边注
如何fdisk -l
工作是我自己想知道的事情.
你也可以尝试lsblk ...在util-linux中...但我也有一个问题
fdisk -l /dev/sdl
没有结果
grep sdl /proc/partitions 8 176 15632384 sdl 8 177 15628288 sdl1 lsblk | grep sdl sdl 8:176 1 14.9G 0 disk `-sdl1 8:177 1 14.9G 0 part
fdisk很好,但不是那么好......看起来它不能"看到"一切
在我的特定示例中,我有一个棒,也有一个读卡器内置,我只能看到使用fdisk的棒:
fdisk -l /dev/sdk Disk /dev/sdk: 15.9 GB, 15931539456 bytes 255 heads, 63 sectors/track, 1936 cylinders, total 31116288 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: 0xbe24be24 Device Boot Start End Blocks Id System /dev/sdk1 * 8192 31116287 15554048 c W95 FAT32 (LBA)
但不是卡(卡是/ dev/sdl)
另外,文件-s效率低下......
file -s /dev/sdl1 /dev/sdl1: sticky x86 boot sector, code offset 0x52, OEM-ID "NTFS ", sectors/cluster 8, reserved sectors 0, Media descriptor 0xf8, heads 255, hidden sectors 8192, dos < 4.0 BootSector (0x0)
那很好......但是
fdisk -l /dev/sdb /dev/sdb1 2048 156301487 78149720 fd Linux raid autodetect /dev/sdb2 156301488 160086527 1892520 82 Linux swap / Solaris file -s /dev/sdb1 /dev/sdb1: sticky \0
要查看有关fdisk无法接收的磁盘的信息,可以使用parted:
parted /dev/sdl print Model: Mass Storage Device (scsi) Disk /dev/sdl: 16.0GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 4194kB 16.0GB 16.0GB primary ntfs arted /dev/sdb print Model: ATA Maxtor 6Y080P0 (scsi) Disk /dev/sdb: 82.0GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 80.0GB 80.0GB primary raid 2 80.0GB 82.0GB 1938MB primary linux-swap(v1)
ls /sys/block
使用HAL(内核2.6.17及更高版本):
#! /bin/bash hal-find-by-property --key volume.fsusage --string filesystem | while read udi ; do # ignore optical discs if [[ "$(hal-get-property --udi $udi --key volume.is_disc)" == "false" ]]; then dev=$(hal-get-property --udi $udi --key block.device) fs=$(hal-get-property --udi $udi --key volume.fstype) echo $dev": "$fs fi done