运行 dd。为什么资源繁忙?

运行 dd。为什么资源繁忙?

我刚刚格式化了 microSD 卡,并想运行dd命令。不幸的是dd命令失败:

$ sudo dd bs=1m if=2016-02-26-raspbian-jessie-lite.img of=/dev/rdisk2
dd: /dev/rdisk2: Resource busy
$

互联网上的每个人都说我需要先卸载磁盘。当然,可以做到这一点并继续前进。但我想了解 OS X 中的原因/到底是什么使设备繁忙?我该如何诊断这个问题?

到目前为止我尝试过:

  1. 列出打开的文件:

    $ lsof /dev/disk2
    $ lsof /dev/disk2s1
    $
    

    还:

    $ lsof /Volumes/UNTITLED
    $
    
  2. 列出处理该文件的用户:

    $ fuser -u /dev/disk2
    /dev/disk2: 
    $ fuser -u /dev/disk2s1 
    /dev/disk2s1:
    $
    

    还:

    $ fuser -u /Volumes/UNTITLED
    $
    
  3. 检查系统消息:

    $ sudo dmesg | grep disk
    $
    

    还:

    $ sudo dmesg | grep /Volumes/UNTITLED
    $
    

我的环境

  1. 操作系统:

    Darwin Eugenes-MacBook-Pro-2.local 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64
    
  2. 有关我的 microSD 的信息:

    diskutil list disk2
    /dev/disk2 (internal, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:     FDisk_partition_scheme                        *31.9 GB    disk2
       1:                 DOS_FAT_32 UNTITLED                31.9 GB    disk2s1
    

PS 我使用的是 OS X 10.11。

更新 22/3/2016。弄清楚了。我使用上面重新运行了lsofand ,终于找到了问题的根源:fusersudo

$ sudo fuser /Volumes/UNTITLED/
/Volumes/UNTITLED/: 62 282
$

和:

$ sudo lsof /Volumes/UNTITLED/
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF      NODE NAME
mds        62 root    8r   DIR    1,6    32768         2 /Volumes/UNTITLED
mds        62 root   22r   DIR    1,6    32768         2 /Volumes/UNTITLED
mds        62 root   23r   DIR    1,6    32768        10 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD
mds        62 root   25u   REG    1,6        0 999999999 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/journalExclusion
mds_store 282 root  txt    REG    1,6     3277        17 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/0.indexGroups
mds_store 282 root  txt    REG    1,6        8        23 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/0.indexCompactDirectory
mds_store 282 root  txt    REG    1,6      312        19 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/0.indexTermIds
mds_store 282 root  txt    REG    1,6     3277        29 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/live.0.indexGroups
mds_store 282 root  txt    REG    1,6     1024        35 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/live.0.indexCompactDirectory
mds_store 282 root  txt    REG    1,6      312        21 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/0.indexPositionTable
mds_store 282 root  txt    REG    1,6     8192        31 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/live.0.indexTermIds
mds_store 282 root  txt    REG    1,6     2056        22 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/0.indexDirectory
mds_store 282 root  txt    REG    1,6     8192        33 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/live.0.indexPositionTable
mds_store 282 root  txt    REG    1,6     8224        34 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/live.0.indexDirectory
mds_store 282 root  txt    REG    1,6       16        16 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/0.indexIds
mds_store 282 root  txt    REG    1,6    65536        48 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/reverseDirectoryStore
mds_store 282 root  txt    REG    1,6      704        24 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/0.indexArrays
mds_store 282 root  txt    REG    1,6    65536        26 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/0.directoryStoreFile
mds_store 282 root  txt    REG    1,6    32768        28 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/live.0.indexIds
mds_store 282 root  txt    REG    1,6    65536        36 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/live.0.indexArrays
mds_store 282 root  txt    REG    1,6    65536        38 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/live.0.directoryStoreFile
mds_store 282 root    5r   DIR    1,6    32768        10 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD
mds_store 282 root   17u   REG    1,6     8192        12 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/psid.db
mds_store 282 root   32r   DIR    1,6    32768        10 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD
mds_store 282 root   41u   REG    1,6       28        15 /Volumes/UNTITLED/.Spotlight-V100/Store-V2/A2D41CCB-48CC-45F3-B8D6-F3B383D91AAD/indexState
$

从上面很容易看出进程被调用mdsmds_store已经创建,并且正在保持该卷上有很多文件。

答案1

苹果法庭,苹果裁决。尝试diskutil

$ diskutil list
...

# if mounted somewhere
$ sudo diskutil unmount $device

# all the partitions (there's also a "force" option, see the manual)
$ sudo diskutil unmountDisk $device

# remember zip drives? this would launch them. good times!
$ sudo diskutil eject $device

(对于磁盘映像,该hdiutil命令也可能令人感兴趣。您也可以在 中单击Disk Utility.app。)

答案2

卸载子分区有帮助

/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *8.0 GB     disk2
   1:             Windows_FAT_16 wr_usb_efi              134.2 MB   disk2s1
   2:                      Linux                         1.1 GB     disk2s2
vgsprasad-mbp:~ vgsprasad$ diskutil umount /dev/disk2s1
Volume wr_usb_efi on disk2s1 unmounted
vgsprasad-mbp:~ vgsprasad$ diskutil umount /dev/disk2s2
disk2s2 was already unmounted

相关内容