Osx

執行dd。為什麼資源很忙?

  • August 19, 2020

我剛剛格式化了 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
$
  1. 列出處理文件的使用者:
$ fuser -u /dev/disk2
/dev/disk2: 
$ fuser -u /dev/disk2s1 
/dev/disk2s1:
$

還:

$ fuser -u /Volumes/UNTITLED
$
  1. 檢查系統消息:
$ 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
  1. 關於我的 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。

2016 年 3 月 22 日更新。弄清楚了。我使用 重新從上面執行lsofand ,終於找到了問題的根源:fuser``sudo

$ 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創建並在卷上保存了大量文件。

蘋果法庭,蘋果規則。嘗試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。)

解除安裝子分區有幫助

/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

引用自:https://unix.stackexchange.com/questions/271471