74

I just formatted microSD card, and would like to run a dd command. Unfortunately dd command fails:

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

Everyone on the internet says I need to unmount the disk first. Sure, can do that and move on. But I want to understand why / what exactly in OS X is making the device busy? How do I diagnose this?

So far I tried:

  1. Listing open files:

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

    Also:

    $ lsof /Volumes/UNTITLED $ 
  2. Listing users working on the file:

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

    Also:

    $ fuser -u /Volumes/UNTITLED $ 
  3. Check for system messages:

    $ sudo dmesg | grep disk $ 

    Also:

    $ sudo dmesg | grep /Volumes/UNTITLED $ 

My environment

  1. Operating system:

    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. Information about my 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 

P.S. I'm using OS X 10.11.

Update 22/3/2016. Figured it out. I re-ran the lsof and fuser from above using sudo, and finally got to the bottom of the issue:

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

And:

$ 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 $ 

From the above it's easy to see that processes called mds and mds_store have created and are holding lots of files on the volume.

13
  • Use of=/dev/rdisk2 it is so much faster, and not so taxing to your SD card. Commented Mar 22, 2016 at 13:58
  • Hi @RuiFRibeiro! Yeah, that makes total sense, I forgot about rdisk when writing this. Commented Mar 22, 2016 at 13:59
  • The device is busy because it is automounted...; you umount it, do your dd, and it will get automounted again as soon as dd finishes. Commented Mar 22, 2016 at 14:20
  • @RuiFRibeiro I know, that make sense... But is there some other indication, apart from seeing /Volumes/UNTITLED and knowing it's automounted? Like, some logs, or some better some process responsible for taking the device? Commented Mar 22, 2016 at 14:25
  • 1
    @RuiFRibeiro turns out there are 2 processes currently holding the mounted volume. What I missed was running lsof and fuser with root privileges. After running both with sudo, I figured processes called mds and mds_store created over a dozen of files on the volume. Commented Mar 22, 2016 at 14:39

2 Answers 2

112

Apple court, Apple rules. Try 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 

(In the case of a disk image, the hdiutil command may also be of interest. You can also click around in Disk Utility.app.)

4
  • Hi @thrig, thank you. Yes, I am able to unmount using diskutil, no problem with that. What I'm doing here is I'm learning how to identify problems in the system by saying "Yes" to any warning I can spot. I want to know why "Resource busy" is happening in the first place, not how to get rid of it. What exact process in the OS is making this happen? Commented Mar 22, 2016 at 14:19
  • @gmile the kernel, as far as I know, locks busy devices, so you need to unmount and eject any partition and image to remove that kernel lock. Commented Mar 22, 2016 at 14:26
  • 1
    oh, this is interesting. I'm going to google for kernel locking now. Maybe you have some good resource on your mind where I could read about it? Commented Mar 22, 2016 at 14:28
  • If '''sudo diskutil unmount''' doesn't work, check here (raspberrypi.stackexchange.com/questions/9217/…) Commented Jul 5, 2023 at 6:39
38

Unmounting the sub partitions helped

/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 
3
  • 6
    aside from missing formatting, the OP specifically said "Everyone on the internet says I need to unmount the disk first. Sure, can do that and move on. But I want to understand why / what exactly in OS X is making the device busy?" Commented Jul 14, 2017 at 20:02
  • 1
    @Jeff I ran into the same problem as gmile, I was aiming to write an .iso to a USB stick, and dd returned dd: /dev/disk9: Resource busy. When I unmounted with diskutil umount /dev/disk9s1, the device disappeared from the desktop, but the /dev/disk9 was still mounted so dd couldn't perform as it should. So Mac OSX kept the device busy by creating a short-cut to the USB stick's inner filesystem. Commented Feb 8, 2018 at 8:27
  • Thanks! what I did is to unmount the USB Driver in Disk Utility app, then the error "resource busy" is now resolved. Command: sudo dd if=<location of iso image> of=/dev/disk4 bs=1m Commented Jul 20 at 2:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.