当我将 Sony 摄像机插入 Linux 系统时,文件系统会以只读方式挂载。我无法简单地以读写方式挂载它,我必须先使用“hdparm -r0”使“设备”变为读写。为什么会这样?为什么“hdparm -r0”被认为是“危险的”?
接下来是“dmesg”输出。
- 插入设备。
[ 1371.786740] usb 2-1.2: new full-speed USB device number 6 using ehci-pci
[ 1371.875813] usb 2-1.2: New USB device found, idVendor=054c, idProduct=0830
[ 1371.875822] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1371.875827] usb 2-1.2: Product: USB Bus-powered Device
[ 1371.875832] usb 2-1.2: Manufacturer: Sony
[ 1371.875835] usb 2-1.2: SerialNumber: ************
[ 1371.879120] input: Sony USB Bus-powered Device as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/input/input21
[ 1371.879552] hid-generic 0003:054C:0830.0006: input,hidraw4: USB HID v1.11 Device [Sony USB Bus-powered Device] on usb-0000:00:1d.0-1.2/input0
[ 1372.377533] usb 2-1.2: USB disconnect, device number 6
- 正在打开设备。
[ 1395.073294] usb 2-1.2: new high-speed USB device number 7 using ehci-pci
[ 1395.159821] usb 2-1.2: New USB device found, idVendor=054c, idProduct=08de
[ 1395.159831] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1395.159837] usb 2-1.2: Product: HDR-AS100V
[ 1395.159840] usb 2-1.2: Manufacturer: Sony
[ 1395.159844] usb 2-1.2: SerialNumber: ************
[ 1395.198826] usb-storage 2-1.2:1.0: USB Mass Storage device detected
[ 1395.198936] scsi6 : usb-storage 2-1.2:1.0
[ 1395.199078] usbcore: registered new interface driver usb-storage
[ 1396.202342] scsi 6:0:0:0: Direct-Access Sony Camcorder 1.00 PQ: 0 ANSI: 0
[ 1396.218549] scsi 6:0:0:1: Direct-Access Sony Camcorder 1.00 PQ: 0 ANSI: 0
[ 1396.219347] sd 6:0:0:0: Attached scsi generic sg2 type 0
[ 1396.220185] sd 6:0:0:1: Attached scsi generic sg3 type 0
[ 1396.305975] sd 6:0:0:0: [sdc] 123795456 512-byte logical blocks: (63.3 GB/59.0 GiB)
[ 1396.306358] sd 6:0:0:1: [sdd] 102400 512-byte logical blocks: (52.4 MB/50.0 MiB)
[ 1396.307338] sd 6:0:0:0: [sdc] Write Protect is on
[ 1396.307346] sd 6:0:0:0: [sdc] Mode Sense: 03 00 80 00
[ 1396.308599] sd 6:0:0:1: [sdd] Write Protect is on
[ 1396.308605] sd 6:0:0:1: [sdd] Mode Sense: 03 00 80 00
[ 1396.309579] sd 6:0:0:0: [sdc] No Caching mode page found
[ 1396.309586] sd 6:0:0:0: [sdc] Assuming drive cache: write through
[ 1396.310725] sd 6:0:0:1: [sdd] No Caching mode page found
[ 1396.310733] sd 6:0:0:1: [sdd] Assuming drive cache: write through
[ 1396.316948] sd 6:0:0:0: [sdc] No Caching mode page found
[ 1396.316965] sd 6:0:0:0: [sdc] Assuming drive cache: write through
[ 1396.317962] sd 6:0:0:1: [sdd] No Caching mode page found
[ 1396.317979] sd 6:0:0:1: [sdd] Assuming drive cache: write through
[ 1396.319865] sdc:
[ 1396.320881] sdd: sdd1
[ 1396.325818] sd 6:0:0:0: [sdc] No Caching mode page found
[ 1396.325831] sd 6:0:0:0: [sdc] Assuming drive cache: write through
[ 1396.325849] sd 6:0:0:0: [sdc] Attached SCSI removable disk
[ 1396.328067] sd 6:0:0:1: [sdd] No Caching mode page found
[ 1396.328077] sd 6:0:0:1: [sdd] Assuming drive cache: write through
[ 1396.328083] sd 6:0:0:1: [sdd] Attached SCSI removable disk
[ 1396.749464] SELinux: initialized (dev sdc, type fuseblk), uses genfs_contexts
[ 1396.782748] SELinux: initialized (dev sdd1, type vfat), uses genfs_contexts
- 以读/写方式安装设备。
# mount -o rw,remount /dev/sdc
mount: cannot remount /dev/sdc read-write, is write-protected
# hdparm -r0 /dev/sdc
/dev/sdc:
setting readonly to 0 (off)
readonly = 0 (off)
# mount -o rw,remount /dev/sdc
#
答案1
由于这个问题出现在搜索中hdparm -r
:
在 hdparm 版本 2.3 和 2.9(1995-1996 年 - 很古老!)之间,这个-r
标志被标记为危险,没有任何详细说明,但实际执行的操作至今都是一样的。
它调用ioctl(fd, BLKROSET, &readonly)
同样可以做到
blockdev --setro DEVICE
blktool DEVICE readonly on
(需要补丁)
BLKROSET 是 Linux 内核的核心 ioctl 之一,自0.96c-补丁1。
这个 ioctl 似乎被转发到了底层块设备驱动程序这里,因此,根据驱动程序,它实际上可能会重新配置目标存储设备。
然而,我并没有陷入Linux 存储设备堆栈确实证实了这一点,但我找不到任何轶事证据来支持这一点。
所以,我认为它可以安全使用。
请注意,直到最近,scsi 驱动程序(因此,大多数标准硬盘)中都存在一个非常严重的错误,其中只读标志无法保留:
- https://bugzilla.kernel.org/show_bug.cgi?id=198689
- https://bugzilla.redhat.com/show_bug.cgi?id=1548938
该问题已修复,但修复后又引发了新的错误,导致某些设备保持只读状态
- https://bugzilla.kernel.org/show_bug.cgi?id=201221
- https://www.spinics.net/lists/stable/msg283998.html
检查你的内核是否已经针对这些问题进行了修补。