Linux判断文件存储移动磁盘的方法

Linux判断文件存储移动磁盘的方法

  • 一、文件位置
  • 二、磁盘信息(方法一)
  • 三、设备属性(方法二)
  • 四、磁盘链接(方法三,仅限USB)


一、文件位置

通过df -h file获取块设备文件存放位置sdb4,sudo fdisk -l获取sdb4在/dev/sdb磁盘

touch test
df -h test 
#-------------------------------------------------------------
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb4        59G   27M   59G   1% /media/ubuntu/7F74-11C0
#-------------------------------------------------------------

sudo fdisk -l
#-------------------------------------------------------------
Disk /dev/sdb: 58.6 GiB, 62914560000 bytes, 122880000 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
Disklabel type: dos
Disk identifier: 0xcad4ebea

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb4  *      256 122879999 122879744 58.6G  c W95 FAT32 (LBA)
#-------------------------------------------------------------

二、磁盘信息(方法一)

lshw获得sdb磁盘为usb类型,capabilities属性指示为模拟设备(示例为虚拟机,真实设备为Removable)

sudo lshw -class disk -class storage
#-----------------------------------------------------------------------------------
  *-usb
       description: Mass storage device
       vendor: HIKSEMI
       physical id: 1
       bus info: usb@4:1
       logical name: scsi33
       version: 1.10
       serial: ZL230324000106
       capabilities: usb-3.20 scsi emulated scsi-host
       configuration: driver=usb-storage maxpower=304mA speed=5000Mbit/s
     *-disk
          description: SCSI Disk
          physical id: 0.0.0
          bus info: scsi@33:0.0.0
          logical name: /dev/sdb
          size: 58GiB (62GB)
          capabilities: partitioned partitioned:dos
          configuration: logicalsectorsize=512 sectorsize=512 signature=cad4ebea
#-----------------------------------------------------------------------------------

三、设备属性(方法二)

cd /sys/class/block/sdb # 或cd /sys/block/sdb
cat removable
# 1 可移动设备

四、磁盘链接(方法三,仅限USB)

ls -l /dev/disk/by-id/usb*

#------------------------------------------------------
lrwxrwxrwx 1 root root  9 Aug  7 20:39 /dev/disk/by-id/usb-HIKSEMI__ZL230324000106-0:0 -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  7 20:39 /dev/disk/by-id/usb-HIKSEMI__ZL230324000106-0:0-part4 -> ../../sdb4
#------------------------------------------------------

你可能感兴趣的:(linux,运维,服务器)